Re: code organization style



On Fri, 2005-04-22 at 20:42 +0300, Gabor Szabo wrote:
As I have just started to learn Gtk and never wrote anything more than one
simple window in Tk either I would like to get your opinion on how to
organize code ?

So far I have an application with several windows all in one file of
over 1000 rows.

If you have lots of code that is responsible for building an interface
and connecting up signal handlers then you may be able to replace much
of it by using Glade.  Glade is a GTK GUI designer that allows you to
assemble you UI using drag and drop.  You can also add the names of your
signal handler routines directly in the GUI builder.  

The user interface definition gets saved into a .glade file.  You put
the bulk of your code into a .pm file.  Then you have one short wrapper
script that uses Gtk2::GladeXML to load the .glade file and connect it
to the .pm file.

I've recently written an article for the Perl Review on exactly this
subject.  If you want to be a 'technical reviewer' drop me a line off
list.

It is getting too big for one file so I am think of splitting it up
and puting each popup window in a separate class.

That's the approach I've taken with Sprog:

  http://sprog.sourceforge.net/

I have a number of different classes that make up the user interface.
Some use Glade and some use Perl to assemble widgets manually.

The Sprog code is downloadable from the above link.  Unfortunately you
won't be able to run it on Windows without Gnome2::Canvas.  Should work
under Linux though.

Also the main window has two panes, both of the are TreeViews and are getting
complex so I think I should put each one of the in a separate class.

Sounds like a good idea.  If you use Glade, the trick is that
Gtk2::GladeXML will build the view for you but you'll need to use
get_widget to find the TreeView and then create and attach the model and
column definitions from Perl.

Cheers
Grant




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