Re: signal functions in a package module file

On Jul 20, 2008, at 8:30 PM, anguila wrote:

Like you say, or I understand..  i make 2 files, a,
(the file with the signals) and also the .glade file.

I have 2 windows, the first one (window1) it have a button (button1)
that open window2 with a label a entrybox and another button
(button2), when you click thise button the text of the label is
changed by the text of the entry.

When I click button1 it opens the window2, so the signal is work, but
in window2 when I click button2 doesn't catch the signal and does
anything. I don't know why :S

Your problem can be summed up in one word:  Scope.

In (in the package "main"), you create a lexical called $programa holding a reference to a Gtk2::GladeXML, and connect its signals to the package "aviam". Then you click on the button and it wants to call "init". Since you set up the autoconnect to look in "aviam", it executes "aviam::init".

Over in aviam::init(), you want to show the window, so you need a reference to it. So, you use $programa. But wait, that's a *different* variable! it's the lexical "$aviam::programa", created at program startup (by the "use aviam" statement). This Gtk2::GladeXML instance isn't set up to handle any signals, so nothing happens when you click the buttons.

Two possible solutions:

1. Somehow share the Gtk2::GladeXML instance between the two packages, either by having the main program use avaim's instance, or having aviam somehow get the instance from the main program.

2. Put the windows in separate .glade files -- one for the main app and one for aviam, and let each one have its own gladexml instance. This is a much more modular and reusable approach, but can be a bit more work. Note also that if you do this you don't have to given a package argument to autoconnect anymore, because it will automatically look in the current package.

Also, beware that your windows have the default delete-event behavior, meaning that you can't reuse the dialogs. Either change the code to hide the dialog window in response to the delete-event, or reload the glade file every time you need to use the window.

One, two, free, four, five, six, sebben, eight, nine, ten, elebben, twull, fourteen, sickteen, sebbenteen, eightteen, elebbenteen, fiffeen, elebbenteen!
  -- Zella, aged three, counting to twenty.

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