Re: Help with closing a notebook page (GTK2)



You seem to be unintentionally making things very hard for yourself.  I don't 
know anything about the purpose of your app, but you do not need to implement 
your own linked list, GLib already has a very capable list API built in.  Also, 
the notebook already behaves like a linked list, so all the list related 
operations you're coding are only serving to cause you headaches.  If you want 
to code a linked list for learning purposes, choose a very simple approach, like 
a list of integers.  Code it in a separate program.  Once you understand how all 
the operations affect the list, use the GLib code.  It is already stable and 
effective.  If it's an issue of not knowing whether the functionality is 
implemented for you, check the reference material.  Don't be hesitant about 
consulting the GLib/GTK docs or code.  There's much to be learned there.
As far as things like page numbers, if you need to keep track of information 
that is associated with the page, but not actually part of the page, I suggest 
you look into using g_object_set_data () and g_object_get_data ().  Again, the 
wheel has already been invented and debugged.
You made a statement that I think might be at the heart of your troubles.  If 
you are not interested in using the best method, you are only making things 
harder on yourself.  Of course the "best" method is always subjective.  A method 
tends to be the viewed as the best when it gets the job done in the fewest lines 
of code, and takes most advantage of code that has already been written and 
stabilized.  You would do yourself a huge favor by making this your approach.  
That may mean more reading than coding at first, but the payoff is undeniable.
take it easy
walter  




________________________________
From: Neil Munro <neilmunro gmail com>
To: gtk-app-devel-list gnome org
Sent: Tue, July 5, 2011 6:51:01 AM
Subject: Re: Help with closing a notebook page (GTK2)

On 4 July 2011 15:02, walter tallent <w41t3r yahoo com> wrote:
Hi.
I know I'm coming late to this party, but if you're packing the button  into 
the
tab, it's a child of that notebook page.  Can't you retrieve  the page you're 
on
by simply calling gtk_notebook_page_num () with the  button passed in as the
child during the button's clicked signal  handler?  Then you pass the returned
page number to  gtk_notebook_remove_page ().  This way you'll always remove 
the
correct  page, and it doesn't matter if the user brings that page to the front
first or not.

Or is there something I've overlooked?
walter



________________________________
From: Bill C <billc netspace net au>
To: gtk-app-devel-list gnome org
Sent: Sun, July 3, 2011 3:54:13 PM
Subject: Re: Help with closing a notebook page (GTK2)

On 04/07/11 06:26, Neil Munro wrote:
On 3 July 2011 19:31, Thomas  Bollmeier<TBollmeier web de>  wrote:
----Ursprüngliche Nachricht-----
Von: "Neil Munro"<neilmunro gmail com>
Gesendet: 02.07.2011 23:40:02
An: gtk-app-devel-list gnome org
Betreff: Help with closing a notebook page (GTK2)

Hi, I have used pygtk before so I am familiar with some of the basic
concepts of gtk, but this is my first attempt with an actual gtk+ C
application and I have run into a few issues.

I have a notebook that I wish to have a close button on the page tabs
that when clicked closes the tabs.

I know that it's a bit off a faf to do as you don't know the page
prior to the event. So you have to dynamically detect which tab is
being closed by using a tab child widget.

Now I believe I have done this in code, except it always returns -1
which then firmly tells me I have done something wrong.

I have attached the code for your reference in the hopes that someone
shall be able to point out my no doubt simple mistake.

Many thanks in advance,
Neil Munro
I faced a similar problem when I wrote an editor for the first version of my
gobjectcreator tool some time ago. It was
implemented in PyGTK - nevertheless it should work in C as well. The 
solution
may not be elegant but it
worked:
I registered a handler for the "clicked"-signal of the close button within 
the
tab label widget (a GtkHBox).
Within the handler implementation I looped over all pages of the notebook 
and
checked whether the button instance
in the page label was identical to the sender instance of the 
"clicked"-signal.
If yes then I had to remove the
corresponding page.
You can find the code example here:

https://github.com/ThomasBollmeier/GObjectCreator/blob/master/gobject_creator/ui/documents_view.py

y

(see lines 342ff. and 378ff. respectively)

Hope that helps.

Regards,
Thomas



___________________________________________________________
Schon gehört? WEB.DE hat einen genialen Phishing-Filter in die
Toolbar eingebaut! http://produkte.web.de/go/toolbar

Thanks to this and Bills suggestion the correct page closes, but I
need to determine a way to re-calculate the page as soon as a tab is
closed, am sure I will figure something out, but thanks for the
patience and help!
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Hi Neil

Yes the page numbers can change when a page is closed, so you cant use
original page numbers directly to switch pages.

I think I redesigned so that I did not use page numbers. Let the user
switch pages and process the page the user is working with.  Ensure the
user cant delete pages that are prior to a page you want to reference
directly.  As Thomas said...  Not totally elegant.

Rgds Bill
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Well I have a method to correctly get the tab page, it might not be
the best way but it's what came naturally to me, I am having issues
with the memory management. Now I understand the principle of linked
lists/memory management etc but I have only previously created small
test programs, nothing inside a real program, so am having trouble
applying theory to practical.

Below is the function I am writing, I am aware I am not freeing any
memory yet, but some tabs wont close even after I have supposedly
adjusted the linked list, so I am at a loss as to how I am to make
this work, any help would be appreciated!

static void Close( GtkWidget *widget, struct data *tmp )
{
    // Re-configure linked list to reflect new tab positions
    struct node *ptr = head;
    struct node *prev = ptr;

    g_print( "Old list!\n\n" );    

    ptr = head;

    while( ptr->Next != NULL )
    {
        if( ptr == tmp->Ptr )
        {
            g_print( "Ptr->Page to remove: %d\n", ptr->Page );
            // Close page
            gtk_notebook_remove_page( GTK_NOTEBOOK( tmp->Notebook ), tmp->Page 
);
            g_print( "Removing node... " );
            prev = ptr->Prev;
            ptr = ptr->Next;
            prev->Next = ptr;
            ptr->Prev = prev;
            g_print( "Done!\n" );
        }

        else
            ptr = ptr->Next;
    }    

    ptr = head;
    gint i = 0;
    
    //while( ptr->Next != NULL )
    for( i = 0; i < gtk_notebook_get_n_pages( tmp->Notebook ); i++ )
    {
        g_print( "Page was: %d\n", ptr->Page );
        ptr->Page = i;
        g_print( "Page is: %d\n", ptr->Page );
        ptr = ptr->Next;
    }
}

If you need more of the code you can check out git://gitorious.org/x2/x2.git

I am also looking at the examples people have given me, but it's slow
going to understand other people's code.

Thanks,
Neil Munro
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]