Thanks,

Do you find that using Glade is worth the trouble over just hacking it up in
gtk directly? I've heard opinions both ways.

I'll check over your code. Doing cli programming takes 1/4 the time over gui
programming. I'm creating a cli version of my program to satisfy the powers
that be while I work on the async gui version which effectively gives
someone a couple of buttons and a bunch of progress bars. Really in the end
it's just prettier for a while lot more work.

Grant McWilliams
http://grantmcwilliams.com/

Some people, when confronted with a problem, think "I know, I'll use
Windows."
Now they have two problems.



On Wed, Sep 7, 2011 at 7:15 AM, Tony Freeman <[email protected]> wrote:

> I should mention that my office is using RHEL5 ... so pygtk and
> associated are at the 2.10 version.
>
>
> On Wed, Sep 7, 2011 at 10:07 AM, Tony Freeman <[email protected]>
> wrote:
> > Hello Grant,
> >
> > Below is the entire bit of code I was working on at that time.  Pay
> > attention to the spawn_async stuff. Good luck!
> >
> > -- Tony
> >
> >
> >
> > #!/usr/bin/python
> >
> > ####################################################
> > ## THIS IS A GUI FRONT END TO THE adjust_grids.sh
> > ## SCRIPT LOCATED IN /DATA/LOCAL/IFPS/
> > ##
> > ####################################################
> >
> > ####################################################
> > ## SETUP THE ENVIRONMENT:
> > ####################################################
> >
> > import pygtk
> > import gtk
> > import gtk.glade
> > import gobject
> > import os
> >
> > os.chdir("/awips/dev/localapps/adjust_grids/")
> >
> > ####################################################
> > ### GLOBAL VARIABLES AND SITE CONFIGURATION:
> > ####################################################
> >
> > import siteConfig
> >
> > xxxxxx  = siteConfig.xxxxxx
> > guess   = siteConfig.guess
> > program = siteConfig.program
> >
> > ### GLOBAL VARIABLES:
> >
> > keep_pulsing = True
> >
> > ####################################################
> > ### PULL IN THE GUI:
> > ####################################################
> >
> > wTree = gtk.glade.XML('adjust_grids.glade')
> >
> > ### MAIN WINDOW ITEMS (window1):
> >
> > calendar  = wTree.get_widget('calendar1')
> > gridbox   = wTree.get_widget('combobox_grid')
> > modelbox  = wTree.get_widget('combobox_model')
> > hourbox   = wTree.get_widget('combobox_hour')
> > statusbar = wTree.get_widget('label_status')
> >
> > ### PROGRESS WINDOW ITEMS (window2):
> >
> > window2 = wTree.get_widget('window2')
> > dialog1 = wTree.get_widget('dialog1')
> >
> > progressbar = wTree.get_widget('progressbar1')
> > progress_headline = wTree.get_widget('label_progress_headline')
> > progress_info = wTree.get_widget('label_progress_info')
> >
> > textview = wTree.get_widget('textview1')
> > textbuffer=textview.get_buffer()
> >
> > ####################################################
> > ### FILL IN THE LIST BOXES:
> > ####################################################
> >
> > for i in xxxxxx:
> >        gridbox.append_text(i)
> >
> > for i in guess:
> >        modelbox.append_text(i)
> >
> > gridbox.set_active(0)
> > modelbox.set_active(0)
> > hourbox.set_active(0)
> >
> > ####################################################
> > ### DEFINE FUNCTIONS:
> > ####################################################
> >
> > def write_status(comment):
> >        statusbar.set_text(comment)
> >        progress_info.set_text(comment)
> >
> > def cstdout_callback(fd, condition, channel):
> >        global keep_pulsing
> >        if condition == gobject.IO_HUP:
> >                keep_pulsing=False
> >        elif condition == gobject.IO_IN:
> >                text = channel.readline()
> >                iter = textbuffer.get_end_iter()
> >                textbuffer.insert(iter, text)
> >                textview.scroll_to_mark(textbuffer.get_insert(),0)
> >        return keep_pulsing
> >
> > def update_progress_callback():
> >        global keep_pulsing
> >        if keep_pulsing:
> >                progressbar.pulse()
> >        else:
> >                write_status("Done")
> >                window2.hide()
> >        return keep_pulsing
> >
> > def run_command(command):
> >        global keep_pulsing
> >        keep_pulsing=True
> >        textbuffer.set_text("")
> >        (cpid, cstdin, cstdout, cstderr) =
> >
> gobject.spawn_async(command,flags=gobject.SPAWN_DO_NOT_REAP_CHILD,standard_output=True)
> >        channel = os.fdopen(cstdout)
> >        gobject.io_add_watch(cstdout, gobject.IO_HUP|gobject.IO_IN,
> > cstdout_callback, channel)
> >        gobject.timeout_add(150, update_progress_callback)
> >        window2.show()
> >
> > def get_active_text(combobox):
> >        model = combobox.get_model()
> >        active = combobox.get_active()
> >        if active < 0:
> >                return None
> >        return model[active][0]
> >
> > def build_timestamp():
> >        year, month, day = calendar.get_date()
> >        hour = get_active_text(hourbox)
> >        month = "%02d" % month
> >        day = "%02d" % day
> >        timestamp = str(year) + str(month) + str(day) + "_" + str(hour)
> >        return timestamp
> >
> > def on_dialog1_destroy(*args):
> >        write_status("Backgrounded script")
> >        dialog1.hide()
> >
> > def on_closebutton1_clicked(*args):
> >        write_status("Backgrounded script")
> >        dialog1.hide()
> >
> > def on_window1_destroy(*args):
> >        write_status("Good-bye!")
> >        gtk.main_quit()
> >
> > def on_window2_destroy(*args):
> >        window2.hide()
> >        dialog1.show()
> >        write_status("Continuing in background")
> >        return True
> >
> > def on_window2_delete_event(*args):
> >        window2.hide()
> >        dialog1.show()
> >        write_status("Continuing in background")
> >        return True
> >
> > def on_button_quit_clicked(*args):
> >        write_status("See ya next time")
> >        gtk.main_quit()
> >
> > def on_button_apply_clicked(*args):
> >        scripttime = build_timestamp()
> >        scriptmodel = get_active_text(modelbox)
> >        scriptgrid = get_active_text(gridbox)
> >        command = [program, scriptgrid, scriptmodel, scripttime]
> >        write_status("Here we go ...")
> >        run_command(command)
> >
> > ####################################################
> > ### CONNECT SIGNALS TO OUR HANDLERS:
> > ####################################################
> >
> > wTree.signal_autoconnect(locals())
> >
> > ####################################################
> > ### START UP THE PROGRAM:
> > ####################################################
> >
> > gtk.main()
> >
> >
> > On Wed, Aug 3, 2011 at 7:44 AM, Grant McWilliams
> > <[email protected]> wrote:
> >> Tony Freeman <t0ny.fr33man <at> gmail.com> writes:
> >>
> >> Can you post the whole code anyway for those of us trying to figure out
> the same
> >> thing.
> >>
> >> _______________________________________________
> >> pygtk mailing list   [email protected]
> >> http://www.daa.com.au/mailman/listinfo/pygtk
> >> Read the PyGTK FAQ: http://faq.pygtk.org/
> >>
> >
>
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to