Re: [pygtk] how to add to a scrolledwindow?
On Sun, 02 Jan 2011 19:20:28 BST, Timo wrote: On 02-01-11 14:42, Brian Keck wrote: ... A minimal example is ... Not tested, but try these changes: ... Your changes made it work, something similar also fixed my hildon app. But when I tried to understand why it fixed the example, I realized that I'd made a silly mistake with 'window' (which I guess you saw). Just fixing the mistake made it work (with button_press_event as well as clickable). So thanks, but sorry for the noise, Brian Keck ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
[pygtk] how to add to a scrolledwindow?
Hello, I've written very little pygtk ( no straight gtk), am stuck trying to add to a vbox inside a scrolledwindow. A minimal example is ... import gtk window = gtk.Window() window.connect('destroy', gtk.main_quit) scrolled = gtk.ScrolledWindow() window.add(scrolled) vbox = gtk.VBox() scrolled.add_with_viewport(vbox) def addbutton(window, event): vbox.pack_start(gtk.Button('extra')) window.show_all b1 = gtk.Button('aaa') b1.connect('button_press_event', addbutton) vbox.pack_start(b1) b2 = gtk.Button('bbb') vbox.pack_start(b2) window.show_all() gtk.main() I click 'aaa' but no 'extra' appears. The actual application starts with a list of book authors as button labels. Clicking on an author should insert the author's book titles (a vbox of buttons) between this author the next. Also, it's for a Nokia N900 really uses hildon.PannableArea etc. Thanks for any help, Brian Keck ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
[pygtk] Threading Question
Got some help last week in regard to a problem which put me on the trail of understanding threading. Through reading and playing around I've this working example. What I don't understand are how certain parts of it work. BTW, I'm working on a windows PC. import threading import random, time import gtk #Initializing the gtk's thread engine gtk.gdk.threads_init() class FractionSetter(threading.Thread): This class sets the fraction of the progressbar def run(self): progressbar.set_fraction(random.random()) print 'first' time.sleep(2) progressbar.set_fraction(random.random()) print 'second' time.sleep(2) gtk.main_quit() def stop(self): Stop method, sets the event to terminate the thread's main loop self.stopthread.set() def main_quit(obj): fs.stop() gtk.main_quit() #Gui bootstrap: window and progressbar window = gtk.Window() progressbar = gtk.ProgressBar() window.add(progressbar) window.show_all() window.connect('destroy', main_quit) #Creating and starting the thread fs = FractionSetter() fs.start() gtk.gdk.threads_enter() gtk.main() gtk.gdk.threads_leave() My question is: a) What does putting gtk.main() between gtk.gdk.threads _enter gtk.gdk.threads _leave actually do? b) Am I right in thinking the time.sleep(2) are there so that the progressbar is changed and the gui window is updated? c) Without the time.sleep(2) I'm thinking the progressbar would be changed but the gui window wouldn't be updated. Correct? Still getting my head around threads. See all sorts of references all of which seem a wee bit beyond my comprehension at the moment. Any comments would be appreciated. Thanks Brian ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Updating a window
Thought I'd put together a small example to show what I mean: import pygtk pygtk.require(2.0) import gtk import sys import time def do_stuff(): time.sleep(5) print 'brian' # handles class handles: def on_login_window_destroy(event): sys.exit(1) # define main class LoginApp: def __init__(self): # set the glade file self.builder = gtk.Builder() self.builder.add_from_file(login.glade) self.window = self.builder.get_object(login_window) self.builder.connect_signals(handles.__dict__) self.server = self.builder.get_object(server) self.info = self.builder.get_object(info) self.window.show() def __getitem__(self,key): # provide link to widgets return self.builder.get_object(key) # run application if __name__ == '__main__': ghs = LoginApp() do_stuff() gtk.main() The window outline appears but no inside until after 5 sec when the full window takes shape my name then appears. What I want is the full window appearing at the beginning and then 5 sec later my name appears. Make sense? Brian -Original Message- From: Michael Urman [mailto:mur...@gmail.com] Sent: Wednesday, 23 June 2010 12:46 p.m. To: Brian Rowlands (Greymouth High School) Cc: pygtk@daa.com.au Subject: Re: [pygtk] Updating a window On Tue, Jun 22, 2010 at 18:33, Brian Rowlands (Greymouth High School) rowlan...@greyhigh.school.nz wrote: The issue I have is that the outline of the window appears with the inside blank until do_stuff() completes when the window is fully defined. If I have: gtk.main() do_stuff() then the window appears fine but nothing gets done. Don’t know if there is a command to update a window. Probably simple. If not, a reference/pointer would be appreciated. The right answer really depends on what sort of things you are doing inside do_stuff. If it's work that makes sense to move piecewise to signal handlers, then do that. If it's a batch of work with convenient locations to do event processing (say every time through a loop), call gtk.main_iteration() from time to time, possibly within a while gtk.events_pending(). Welcome to event-based programming! -- Michael Urman ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Updating a window
Appreciate the time you've taken to respond. Yes, I'm new to all of this. Had toyed with the thread idea but wanted learned thoughts from people the time BEFORE I committed the time to studying the various options. I'll certainly read what you referenced. Your response made good sense. Thanks so much. Brian Rowlands -Original Message- From: A.T.Hofkamp [mailto:a.t.hofk...@tue.nl] Sent: Wednesday, 23 June 2010 9:19 p.m. To: Brian Rowlands (Greymouth High School) Cc: Michael Urman; pygtk@daa.com.au Subject: Re: [pygtk] Updating a window Brian Rowlands (Greymouth High School) wrote: Thought I'd put together a small example to show what I mean: import pygtk pygtk.require(2.0) import gtk import sys import time def do_stuff(): time.sleep(5) print 'brian' # handles class handles: def on_login_window_destroy(event): sys.exit(1) # define main class LoginApp: def __init__(self): # set the glade file self.builder = gtk.Builder() self.builder.add_from_file(login.glade) self.window = self.builder.get_object(login_window) self.builder.connect_signals(handles.__dict__) self.server = self.builder.get_object(server) self.info = self.builder.get_object(info) self.window.show() def __getitem__(self,key): # provide link to widgets return self.builder.get_object(key) # run application if __name__ == '__main__': ghs = LoginApp() do_stuff() gtk.main() There is only one thread of control, so after constructing the LoginApp() object, you block the *whole* program for 5 seconds by sleeping, print your name, and *then* start event handling of the window. The latter does drawing, and rereshing. That is why the program behaves as it does. The window outline appears but no inside until after 5 sec when the full window takes shape my name then appears. What I want is the full window appearing at the beginning and then 5 sec later my name appears. Make sense? What you want is clear to all, but the way you want it, is not going to fly. You cannot block in the thread of control that does 'gtk.main()' (well, you can, but it does not do what you want). There are 2 solutions to this: 1. start another thread to do your processing, and have it coummunicate with the gtk.main() thread to update the window. 2. do everything event-based. Instead of sleeping, start a timer, and attach 'print name' to the handler that gets called when it times out. I would recommend that you look at the tutorial (http://pygtk.org/pygtk2tutorial/index.html), in particular chappters 19, 20, and 24. The latter is an example. To understand those chapters you may want to do the entire tutorial. Since you seem new to event-based programming, it won't be wasted time, I think. Albert ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
[pygtk] Updating a window
Novice but eager to learn. I'm writing a login script which displays a GUI window and which I want to update with comments as the script runs. My script finishes with: if __name__ == '__main__': ghs = LoginApp() ghs['user'].set_text(user) ghs['pc'].set_text(pc_name) set_up_login_window() ghs.window.show() do_stuff() gtk.main() The issue I have is that the outline of the window appears with the inside blank until do_stuff() completes when the window is fully defined. If I have: .. gtk.main() do_stuff() then the window appears fine but nothing gets done. Don't know if there is a command to update a window. Probably simple. If not, a reference/pointer would be appreciated. Many Thanks ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Updating a window
Thanks for that. Do_stuff consists of things like: Impersonate a user Copy Db to c: drive Read sql DB and obtain PC settings Log-off certain types of users Change the registry Set printers inc default printer Write to a log file Etc So event handlers doesn't seem to fix the bill in my mind. Roughly speaking, the GUI window displays a message to the user. Periodically, this changes as the login script runs through it's tasks. Even displays a goodbye message on the occasions the user shouldn't be allowed to log in. When I used Perl, there was a window update function. Alas, I'm unsure of where to go now. BTW, wrote GUI window in Glade if that makes any difference. Would appreciate feedback Thanks -Original Message- From: Michael Urman [mailto:mur...@gmail.com] Sent: Wednesday, 23 June 2010 12:46 p.m. To: Brian Rowlands (Greymouth High School) Cc: pygtk@daa.com.au Subject: Re: [pygtk] Updating a window On Tue, Jun 22, 2010 at 18:33, Brian Rowlands (Greymouth High School) rowlan...@greyhigh.school.nz wrote: The issue I have is that the outline of the window appears with the inside blank until do_stuff() completes when the window is fully defined. If I have: gtk.main() do_stuff() then the window appears fine but nothing gets done. Don’t know if there is a command to update a window. Probably simple. If not, a reference/pointer would be appreciated. The right answer really depends on what sort of things you are doing inside do_stuff. If it's work that makes sense to move piecewise to signal handlers, then do that. If it's a batch of work with convenient locations to do event processing (say every time through a loop), call gtk.main_iteration() from time to time, possibly within a while gtk.events_pending(). Welcome to event-based programming! -- Michael Urman ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Updating a window
Thanks for the suggestion but it doesn't make any difference. Thanks for replying. Window only appears after the contents of do_stuff() have completed their tasks Do_stuff completes tasks like: * copy DB to c: drive from server * read DB * check user is allowed to log in * impersonate [ using Active Directory in a Win32 environment ] * etc Sorry. Brian From: cmni...@gmail.com [mailto:cmni...@gmail.com] On Behalf Of muhamed niyas Sent: Wednesday, 23 June 2010 4:11 p.m. To: Brian Rowlands (Greymouth High School) Subject: Updating a window Hi... Can u re-arrange the statement ghs.window.show() below the do_stuff() I mean the code like this if __name__ == '__main__': ghs = LoginApp() ghs['user'].set_text(user) ghs['pc'].set_text(pc_name) set_up_login_window() do_stuff() ghs.window.show() gtk.main() Pls try this and let me know the status... -- Thanks Best Regards, Muhamed Niyas C (NuCore Software Solutions Pvt Ltd) Mobile: +91 9447 468825 URL: www.nucoreindia.com Email: ni...@nucoreindia.com ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
[pygtk] Win 32 query
Hi Folks Hope you can help me with a simple problem. I have a login script that requires me to display the username and domain controller the user connects through when logging in to Active Directory. I can get their username via: from win32api import GetUserName user = GetUserName() My question is how do I get the domain controller they authenticated through? Hope you can help. Brian ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Win 32 query
Hi Folks After searching for the best part of an hour AND posting a cry for help via this list I immediately found what I wanted via Google. dc = win32net.NetGetDCName (None, None) produces what I want. Question: When should I really give up and ask for help? H Brian ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Linking textview and combobox
Hi Folks Found my mental block: divisions = [] textbuffer = cbc['divisions'].get_buffer() text = cbc['divisions'].get_buffer().get_text(*textbuffer.get_bounds()) divisions = text.splitlines() -- needed this and a minor change in the lines above if no_divisions != '': #set divisions list store = gtk.ListStore(str) for i in divisions: if i != '' : store.append([i]) cbc['divisionCB'].set_model(store) cell = gtk.CellRendererText() cbc['divisionCB'].pack_start(cell, True) cbc['divisionCB'].add_attribute(cell, 'text', 0) Cheers Brian ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
[pygtk] Linking textview and combobox
Hi folks I'm trying to populate a combobox with the lines showing in a textview widget. My question is how do I do this? I've a textview widget called 'divisions'. This coding reads its associated buffer: textbuffer = cbc['divisions'].get_buffer() divisions = cbc['divisions'].get_buffer().get_text(*textbuffer.get_bounds()) If the lines in textview are: First line Second line Then divisions contains all these characters including \n. This coding creates one character entries in the combobox called divisonsCB: store = gtk.ListStore(str) for i in divisions: if i != '\n' : store.append(i) cbc['divisionCB'].set_model(store) cell = gtk.CellRendererText() cbc['divisionCB'].pack_start(cell, True) cbc['divisionCB'].add_attribute(cell, 'text', 0) Can someone help me think logically on this issue please? Thanks Brian ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Which is the active radiobutton?
Thanks for all the good advice. Found my mental block. Solution: radio = [r for r in cbc['radio_ped'].get_group() if r.get_active()][0] radiolabel = radio.get_label() where radio_ped is the group name of the radio buttons Brian ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
[pygtk] Which is the active radiobutton?
Hi Guys Just a newbie using Python Glade and have the code below: some code ... class BowlsApp: def __init__(self): # set the glade file self.builder = gtk.Builder() self.builder.add_from_file(Bowls.glade) self.window = self.builder.get_object(tournament) self.builder.connect_signals(handles.__dict__) def __getitem__(self,key): # provide link to widgets return self.builder.get_object(key) # run application if __name__ == '__main__': cbc = BowlsApp() cbc.window.show() gtk.main() The GUI contains 4 radio buttons [ I'll call them four, three, two, one ] in a group called four. My research came across: radio = [r for r in cbc['four'].get_group() if r.get_active()] which gets me the active button with print radio giving me: [gtk.RadioButton object at 0xe903c8 (GtkRadioButton at 0x13ab548)] My question: how do i get the 'name' of the button which is active? Tried print radio.get_label() and that failed as there is no attribute called label. Any help appreciated. Even a reference. Thanks ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
[pygtk] Newbie question
Hi Guys I'm very, very new to both Python and Glade and I'm not even sure if I should be posting to this list. Anyway, here goes as I need help - even a useful reference. I'm working on a Win32 platform and have begun to create a python program as follows: #!/usr/bin/env python import pygtk pygtk.require(2.0) import gtk import sys # handles class handles: def __init__(self): self.gladefile = Bowls.glade def on_quit_clicked(event): sys.exit(1) def on_tournament_destroy(event): sys.exit(1) def on_show_settings_clicked(event): pass # define main class EventApp: def __init__(self): # set the glade file builder = gtk.Builder() builder.add_from_file(Bowls.glade) self.window = builder.get_object(tournament) builder.connect_signals(handles.__dict__) # run application if __name__ == '__main__': w = EventApp() w.window.show() gtk.main() My simple question is: how do I reference a textfield [ example 'no_teams' ] when the button 'on_show_settings' is clicked. Say, print it's contents. Any help greatly appreciated. ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Python / PytGTK GNOME Panel applet tutorial
On 9/23/07, Adolfo González Blázquez [EMAIL PROTECTED] wrote: I maintain a python applet called Computer Temperature Monitor. You can download it and take a look on how it works. Hope it helps.. Adolfo: That actually does help, thanks! I am also looking for bonobo server file examples, and I take it that gets generated during the ./configure, make, etc? thanks again. -- brian ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Python / PytGTK GNOME Panel applet tutorial
I am trying to learn the basics of writing GNOME panel applets with Python / PyGTK using Arturo's and Lorenzo's tutorial: http://www.pygtk.org/articles/applets_arturogf/ Even though this tutorial is from 2004, may I safely assume that everything is current, with the exception that gnome.applet is now gnomeapplet? Also, it seems that documentation for writing panel applets is a little sketchy (or maybe my google skills suck) - regardless, if anyone has additional documentation I should read or tips on getting started I'd really appreciate it. I'm assuming that the PyGTK mailing list is the appropriate place for these questions, if not, my apologies in advance. thanks -- brian ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Selecting a treeView row
On Fri, 2006-15-12 at 14:52 +, Peter Morgan wrote: Am going round the houses with this problem (and a pygtk newbie) I've got the function below load_data() and wish to keep the current col sort (which works) and the selected row. The number of rows does not change When I enter the load_data function the iter is there from the first line. However the last line fails with GtkWarning: gtk_list_store_get_path: assertion `iter-stamp == GTK_LIST_STORE (tree_model)-stamp' failed Can anyone shed some light on the problem please.. tia Pete def load_data(self): model, iter = self.selection.get_selected() ## This lines shows the 2 objects print model, iter prev_col = self.usersListStore.get_sort_column_id() self.usersListStore.clear() req = urllib2.Request( self.config['url'] ) response = urllib2.urlopen(req) page_contents = response.read() lines = page_contents.splitlines() for line in lines: self.usersListStore.append(line.split('\t')) if prev_col[0] == None: colo = 1 else: colo = prev_col[0] if prev_col[1] == None: dir = gtk.SORT_ASCENDING else: dir = prev_col[1] self.usersListStore.set_sort_column_id(colo,dir) self.enable_radio_controls(False) if iter: ### ERROR GtkWarning: gtk_list_store_get_path: assertion `iter-stamp == GTK_LIST_STORE (tree_model)-stamp' failed self.selection.select_iter(iter) If I'm not mistaken. The iter becomes dead when the model is changed by an append, etc.. I don't have time to check my facts right now. But It might shed light on it for you. I know in our treeview use when we rebuild our data model we look for the row data that was prevoiusly selected, then after the data is reloaded we then select that row. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Hyperlinks
On Sat, 2006-16-12 at 02:34 +, Peter Morgan wrote: Been searching high and low and cant find a way to make an url in pygtk. My application has a setting to a web page.. all I want is something like a label that can be clicked on which launches a browser. Can anyone point me in the right direction pls pete This is part of some info added to a gtkTextView. View the entire module here: http://porthole.cvs.sourceforge.net/porthole/trunk/packagebook/summary.py?revision=1.3view=markup some code chunks from our app: table = create( {'name': ({'weight': pango.WEIGHT_BOLD, 'scale': pango.SCALE_X_LARGE, 'pixels-above-lines': 5}), 'description': ({style: pango.STYLE_ITALIC}), 'url': ({'foreground': 'blue'}), 'property': ({'weight': pango.WEIGHT_BOLD}), 'value': ({}), 'useset': ({'foreground':'darkgreen'}), 'useunset':({'foreground':'red'}), 'masked': ({style: pango.STYLE_ITALIC}), }) return table def on_url_event(self, tag, widget, event, iter): Catch when the user clicks the URL if event.type == gtk.gdk.BUTTON_RELEASE: load_web_page(tag.get_property(name)) def on_mouse_motion(self, widget, event, data = None): # we need to call get_pointer, or we won't get any more events pointer = self.window.get_pointer() x, y, spam = self.window.get_pointer() x, y = self.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, x, y) tags = self.get_iter_at_location(x, y).get_tags() if self.underlined_url: self.underlined_url.set_property(underline,pango.UNDERLINE_NONE) self.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(None) self.underlined_url = None for tag in tags: if tag in self.url_tags: tag.set_property(underline,pango.UNDERLINE_SINGLE) self.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(gtk.gdk.Cursor (gtk.gdk.HAND2)) self.underlined_url = tag if self.reset_cursor: # defaults to gtk.gdk.XTERM - reset it to None self.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(None) self.reset_cursor = False return False def append_url(text, url, colour): Append URL to textbuffer and connect an event tag = self.buffer.create_tag(url) tag.set_property(foreground, colour) tag.connect(event, self.on_url_event) self.url_tags.append(tag) append(text, tag.get_property(name)) -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Show command output (new IEs4Linux GUI)
On Fri, 2006-08-12 at 03:38 -0200, Internet Explorer Linux wrote: Hey, thank you guys! I decided to do it with threads. See how it looks now: tatanka.com.br/ies4linux/news I just looked at your source. You are not using threads. you only are initiating gtk to allow threads. The threads.enter() and leave() functions are not needed in your code as is as all that code is running in the main thread anyway. You have not imported and used the threads or threading modules that actually run the code in another thread. As Edward Catmur said. If you can do it without threads, it can save a lot of heartache if you don't get it right. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Show command output (new IEs4Linux GUI)
On Fri, 2006-08-12 at 13:41 +, Ed Catmur wrote: Brian wrote: On Fri, 2006-08-12 at 03:38 -0200, Internet Explorer Linux wrote: Hey, thank you guys! I decided to do it with threads. See how it looks now: tatanka.com.br/ies4linux/news I just looked at your source. You are not using threads. you only are initiating gtk to allow threads. The threads.enter() and leave() functions are not needed in your code as is as all that code is running in the main thread anyway. You have not imported and used the threads or threading modules that actually run the code in another thread. As Edward Catmur said. If you can do it without threads, it can save a lot of heartache if you don't get it right. Nah, the threading module is imported (and the spawn/watch thread created) in ies4linux.py; the gtkgui file is just a module for constructing the gui. I really don't approve of the implied threading semantics, and reiterate that the non-threaded solution is always technically superior (especially in languages like Python with advanced control flow inversion abilities), but other than that the coding is competent enough for the chosen solution; it should work as intended. Ed Sorry :( So much for a quick look late at night when I should have gone to bed. I never looked at that other file. I was also looking at it with my own preconceived notion of what it should look like. We got away from the threads.enter() leave() pair long ago as it is too hard to keep straight when a program is more complex with lots of sources for initiating callbacks, etc.. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] gobject timeout when callback is complete
On Sat, 2006-09-12 at 04:22 +, John Kelly wrote: Hello everyone, How do i tell gobject to launch a callback after a callback has finished doing whatever it should. In gobject.timeout_add(interval, callback). I basically want the interval to be the time it takes for the callback to finish whatever its doing. How can i do this? John one way would be to create your own gobject.signal and then at the end of your callback, activate that signal. But, forgive me if I'm seeing your statement wrong. What you wrote says you want to run your callback again as soon as it finishes. Sounds like you should just set it to run inside a loop until you trip a stop flag. go_for it = True while go_for_it: # do some stuff then from somewhere else in your program set go_for_it = False -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Show command output (new IEs4Linux GUI)
On Thu, 2006-30-11 at 04:14 -0200, Internet Explorer Linux wrote: Hi everybody! This is my first email to this list. My name is Sergio and I'm IEs4Linux project's main developer (maybe someone use my program :-) I'm working on a pygtk user interface to my script. My GUI configures some things and run an executable (IEs4linux installer, written in bash). I need to open some kind of window to show the installer output. I tried with TextView, but I don't know how to make it non-blocking. I tried with Threads, but it waits until installer finishes to show the output on TextView. I searched on Google and got some pages talking about this (even with solutions), but I could not make it work. So, if anyone can help me with this thing I will be very thankful :-) Sérgio Lopes From Brazil You can check out our installer gui app. The terminal is all python and does compiler message filtering, etc. There are 2 main areas that you should look at for how we handle the textview updates. 1) in terminal/terminal.py update() where we process the text and update the relevant textview buffers. 2) in readers/process_reader.py which reads the virtual terminal output (in a thread) and passes it back to the main gui for processing. There are other ways of handling it as well, but that one works well for us. If you look around you will also find out how to autoscroll the text as it is added, among other things. The link: http://porthole.cvs.sourceforge.net/porthole/trunk/ -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Problem with CellRendererToggle
On Sat, 2006-18-11 at 10:52 +0100, Pipen wrote: On 11/18/06, Brian [EMAIL PROTECTED] wrote: you need to check the path in the toggled callback to see if it is on the toggle. I have three cell renderers in one column, so the path I get in 'button-clicked' callback is always the same no matter what cell I click in the column. Is there a way to know exactly what whas clicked in the column? I have to check if I'll be able to get cell renderer position boundaries and match it with button-press event x/y position. However it'll be a bit dirty, even if it works. We use to have the toggle packed into a column like that as well. If I remember correctly clicking anywhere on the row would always toggle the toggle. The other problem we had was that it would not always render correctly. The line spacing was wrong with rows overlapping I think. Then we added more columns with additional information as well as right mouse button popup menus. I would recommend you separate out the toggle into its own column. It will simplify things. Otherwise I think you will have to get mouse pointer coordinates and compute its position on your window... until you figure out if it was your toggle it was over. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Problem with CellRendererToggle
On Fri, 2006-17-11 at 18:28 +0100, Pipen wrote: Hi. Each row in my TreeView contains a column with: toggle, pixbuf and text renderer respectively. If need to maintain the following situations: - user clicks on the toggle - toggle receives 'toggled' event; treeview row cursor should not change. - user clicks on the rest of the row (pixbuf, text) - treeview row cursor should change, toggle should not receive 'toggled' event. The program does not work as I expected. I receive 'toggled' and 'cursor-changed' events no matter what part the user clicks. If the user clicks on the toggle, the treeview row cursor changes to the row clicked toggle is in. The following code sets up the TreeView (SETS_COL_TOGGLE is 0, SETS_COL_ICON is 1, SETS_COL_NAME is 2). store = gtk.TreeStore( bool, gtk.gdk.Pixbuf, str, int ) col = gtk.TreeViewColumn( 'Sets' ) # Toggle. cell = gtk.CellRendererToggle() cell.set_property( 'activatable', True ) cell.connect_object( 'toggled', self.on_set_toggled, store ) col.pack_start( cell, False ) col.add_attribute( cell, 'active', SETS_COL_TOGGLE ) # Pixbuf. cell = gtk.CellRendererPixbuf() col.pack_start( cell, False ) col.add_attribute( cell, 'pixbuf', SETS_COL_ICON ) # Text. cell = gtk.CellRendererText() col.pack_start( cell, True ) col.add_attribute( cell, 'text', SETS_COL_NAME ) self.treesets.append_column( col ) self.treesets.set_model( store ) I successfuly set up this kind of tree behavior using Qt, I'm fighting Gtk right now. Any kind of suggestion would be appreciated. you need to check the path in the toggled callback to see if it is on the toggle. Here is some code from our app that uses several columns in a treeview, one of which is a toggle (not always shown/used for some views). Sorry, I wasn't the one that originated this code and I have not worked on it lately. You should be able to figure out what you need from it and the embedded comments. class PackageView(CommonTreeView): # Note! this is a gtk.TreeView type class and swap out the treeview models # dependending on what we need to display at the time. # connect to clicked event self.connect(cursor_changed, self._clicked) self.connect(button_press_event, self.on_button_press) def on_button_press(self, treeview, event): utils.debug.dprint(VIEWS: Handling PackageView button press event) self.event = event # save the event so we can access it in _clicked() if event.type != gtk.gdk.BUTTON_PRESS: utils.debug.dprint(VIEWS: Strange event type got passed to on_button_press() callback...) utils.debug.dprint(VIEWS: event.type = %s %str(event.type)) if event.button == 3: # secondary mouse button self.dopopup = True # indicate that the popup menu should be displayed. else: self.dopopup = False # Test to make sure something was clicked on: pathinfo = treeview.get_path_at_pos(int(event.x), int(event.y)) if pathinfo == None: self.dopopup = False return True else: path, col, cellx, celly = pathinfo utils.debug.dprint(VIEWS: pathinfo = %s %str(pathinfo)) #treeview.set_cursor(path, col, 0) # Note: sets off _clicked again return False def on_toggled(self, widget, path): self.toggle = path utils.debug.dprint(VIEWS: Toggle activated at path '%s' % path) self.set_cursor(path) # sets off _clicked return True def _clicked(self, treeview, *args): Handles treeview clicks utils.debug.dprint(VIEWS: Package view _clicked() signal caught) # get the selection package = get_treeview_selection(treeview, 2) #utils.debug.dprint(VIEWS: package = %s % package.full_name) if (not package and not self.toggle) or package.full_name == None: self.mainwindow_callback(package changed, None) return False if self.toggle != None : # for upgrade view iter = self.get_model().get_iter(self.toggle) #if self.upgrade_model.get_value(iter, 0) != None: check = self.upgrade_model.get_value(iter, 1) check = not check self.upgrade_model.set_value(iter, 1, check) package.is_checked = check self.dopopup = False # don't popup menu if clicked on checkbox self.toggle = None return True # we've got it sorted else: #utils.debug.dprint(VIEWS: full_name != _last_package = %d %(package.full_name != self._last_selected)) self.mainwindow_callback(package changed, package) self._last_selected = package.full_name #pop up menu if was rmb-click if self.dopopup: [snip] -- Brian [EMAIL
Re: [pygtk] Different background color per row in TreeView
On Wed, 2006-08-11 at 10:59 +0100, Volker Helm wrote: Hi, I know how to change the color of a row from default (value False) to one other color (value True) depending of the value of a cell in the row. Now, I've got the problem, that I need to change the color of a row depending on the value of a cell using at least three different colors. Thanks for your help in advance, Volker I don't know myself, but I have seen this this come up before. You should be able to find something in the archives of this list. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Setting application name in pygtk?
On Mon, 2006-06-11 at 15:21 -0800, Lynn Monsanto wrote: Hi all, I'm a developer working on the Orca screen reader: http://live.gnome.org/Orca. We are currently starting Orca using a bash script (see below). This works okay, but has one problem. The AT-SPI returns the application name as -c. Is there a way to explicitly set an application name in pygtk when starting an application using the -c flag? Thanks and best regards! Lynn Monsanto # Runs orca. # runOrca() { [EMAIL PROTECTED]@ [EMAIL PROTECTED]@ export PYTHONPATH @PYTHON@ -c import orca.orca; orca.orca.main() $ARGS } In your app just before you show your window. window.set_title('My Title') Actually you can change the title at any time. In our specialized terminal app. we change the title to the status bar text when the window is minimized. That allows the taskbar to show the status of what is running. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] question about a updating a textview as an object
On Wed, 2006-18-10 at 23:50 -0500, shawn bright wrote: hey there. i have a gtk GUI app that uses 4 text views to update info from 4 different threads. the code i use to update the view is this. def buffer_add(self, input_data, buffer, textview): self.buffer.insert (self.buffer.get_end_iter(), input_data) if self.buffer.get_line_count() 400: self.buffer.delete(self.buffer.get_start_iter(), self.buffer.get_iter_at_line (200)) mark = self.buffer.create_mark(end, self.buffer.get_end_iter(), False) self.textview.scroll_to_mark(mark, 0.05, True, 0.0, 1.0) now, i have the same function in all four threads. Each updates a different textview. the threads run in a class threading.thread. the code that calls them is like this. S1 = Serial1(self.Input1Buffer, self.TTYS14View) S1.start() each thread has some initial code like this class Serial1(threading.Thread): def __init__(self, buffer, textview): threading.Thread.__init__(self) self.buffer = buffer self.iter = self.buffer.get_end_iter() self.textview = textview my question is. from the main app, if i pass the textview and buffer to each thread that needs one, can i, from the thread pass those as objects to one function that will update the text view? if so, do i need to make that function a global object ? or can i just declare it at the beginning of the program ? does this question make sense? if you have read this far, i thank you for your time. shawn Yes, you can pass the buffer pointers around. I have done it many times. No you do not need to make them global. Updating any gui items from a thread other than the main gui thread is asking for trouble. For any thread to safely access the textview buffer you need to wrap it with calls to gtk to get clearance (sorry, don't recall the actual function names atm) to modify them without causing conflicts. Something that can hold up your thread waiting for the update to sync with the gui. A much safer way to go is to gather your info in the threads and then pass that info back to the main gui thread to update the correct buffer. A good example of this is using the dispatcher module we've come up with that handles the inter-thread communication collision free. see attached code. You will see in the example code that the buffer pointer is passed to the method that appends the text to the buffer. It should be easy to modify the example code to use different buffers for each thread. I have used global variables in our app which has several notebook tabs each with their own textview and use the same append method. I used global lists to store the buffer pointers and pass the index number to the append module as there are several other things that use the index number as well. Word of caution if you intend on using a list to store the pointers use the list.append() to add them to an empty list, don't initialize the list like: buffer_list = [None, None] # it won't work buffer_list = [] # works buffer_list.append(buffer_pointer1) buffer_list.append(buffer_pointer2) code snipit: def append(self, num, text, tagname = None): Append text to a text buffer. Line numbering based on the process window line count is automatically added. BUT -- if multiple text buffers are going to be updated, always update the process buffer LAST to guarantee the line numbering is correct. Optionally, text formatting can be applied as well #dprint(Notebook: overwrite() -- num= + str(num)) #dprint(self.current_tab) line_number = self.view_buffer[TAB_PROCESS].get_line_count() iter = self.view_buffer[num].get_end_iter() lntext = str(line_number).zfill(6) + ' ' if self.last_text[num].endswith('\n'): self.view_buffer[num].insert_with_tags_by_name(iter, lntext, 'linenumber') if tagname == None: #self.view_buffer[num].insert(iter, text) #dprint(Notebook: append(): attempting to set text with tagnames + str(self.current_tagnames)) self.view_buffer[num].insert_with_tags_by_name(iter, text, *self.current_tagnames) else: self.view_buffer[num].insert_with_tags_by_name(iter, text, tagname) if self.auto_scroll[num] and num == self.current_tab: self.scroll_current_view() self.last_text[num] = text In the dispatcher example you will see that the method -- Brian [EMAIL PROTECTED] #! /usr/bin/env python # Fredrik Arnerup [EMAIL PROTECTED], 2004-12-19 # Brian Dolbec[EMAIL PROTECTED],2005-3-30 import gobject, os, Queue from select import select class Dispatcher: Send signals from a thread to another thread through a pipe in a thread-safe manner def __init__(self, callback_func, *args, **kwargs
Re: [pygtk] Help: Problems with threads and pygtk
On Wed, 2006-04-10 at 18:58 -0700, David Hirschfield wrote: I've run into a serious problem using threads with pygtk, and I was hoping someone could give me suggestions. My program is a pygtk interface with a processor thread that pulls from a safely synchronized queue of requests and processes each one. Seems simple, and it should have been...but it freezes solid when I run it. Not a traceback of any kind, the interface and the python interpreter freeze. I've checked all the things that should be obvious problems: I'm calling: gobject.threads_init() gtk.gdk.threads_init() before gtk.main() is called There is no race condition or blocking call causing everything to get stuck. The thread's only interaction with the rest of the program is via the Queue.Queue object that keeps the requests to be processed. I've stepped through with pdb and it freezes in a completely innocuous place in the code (during a loop where I append to a list). The freeze occurs in slightly different places depending on what kind of debugging code I put in, changes to the order of things, etc...so it feels like it's some kind of corruption in the interpreter stack. Running the processor thread in a dummy app without the pygtk part never freezes up. Running the pygtk app with a non-threaded processor, which just sequentially runs the requests and waits till they complete, never freezes up. I'm at my wit's end here...I know threads are just asking for trouble, and usually I avoid them, but circumstances here basically require threading (all the request time is spent waiting on different kinds of IO). The setup was so simple, I figured I couldn't possibly run into trouble...yet here I am. So, anyone have any idea what could cause the entire python interpreter to freeze solid? Are there known issues with pygtk and python threads that I should be aware of? Is there some way to verify that the interpreter stack is not getting screwed up somehow? Any help at this point would really be useful, -Dave Try this dispatcher.py module for ideas of where you may be going wrong. Use the dispatcher-example for how to use it for inter-thread communication. It has worked very well for our app and eliminated a number of problems. -- Brian [EMAIL PROTECTED] #! /usr/bin/env python # Fredrik Arnerup [EMAIL PROTECTED], 2004-12-19 # Brian Dolbec[EMAIL PROTECTED],2005-3-30 import gobject, os, Queue from select import select class Dispatcher: Send signals from a thread to another thread through a pipe in a thread-safe manner def __init__(self, callback_func, *args, **kwargs): self.callback = callback_func self.callback_args = args self.callback_kwargs = kwargs self.continue_io_watch = True self.queue = Queue.Queue(0) # thread safe queue self.pipe_r, self.pipe_w = os.pipe() gobject.io_add_watch(self.pipe_r, gobject.IO_IN, self.on_data) def __call__(self, *args): Emit signal from thread self.queue.put(args) # write to pipe afterwards os.write(self.pipe_w, X) def on_data(self, source, cb_condition): if select([self.pipe_r],[],[], 0)[0] and os.read(self.pipe_r,1): if self.callback_args: args = self.callback_args + self.queue.get() self.callback(*args, **self.callback_kwargs) else: self.callback(*self.queue.get(), **self.callback_kwargs) return self.continue_io_watch #! /usr/bin/env python # Fredrik Arnerup [EMAIL PROTECTED], 2004-12-19 # Brian Dolbec[EMAIL PROTECTED],2005-3-30 import pygtk; pygtk.require(2.0) import gtk from time import sleep import threading, gobject, os from dispatcher import Dispatcher # # dispatcher # example code: # # # class Thread(threading.Thread): def __init__(self, dispatcher, thread_num, length): threading.Thread.__init__(self) self.setDaemon(1) # quit even if this thread is still running self.dispatcher = dispatcher self.thread_num = thread_num self.sleep_length = length def run(self): done = False print(thread_num = %s; process id = %d %(self.thread_num,os.getpid())) pid_func(self.thread_num) for num in range(250): #print self.thread_num, num = ,num sleep(self.sleep_length) data = [ self.thread_num, (: time is slipping away: %d\n %num), num, done] self.dispatcher(data) # signal main thread done = True data = [ self.thread_num, (: Time slipped away: I'm done), num, done] self.dispatcher(data) # signal main thread def pid_func(threadnum): print(pid_func: called from thread_num = %s; process id = %d %(threadnum,os.getpid())) def message_fun(buffer, message): #print (got
Re: RE : Re: [pygtk] event handling
On Tue, 2006-05-09 at 14:02 +0200, Felix Rabe (public) wrote: Hi, You guessed, and it doesn't work. Maybe you use a special kind of Python, but with the standard one ... It wasn't a guess, just faulty memory :( Brian wrote: As a space separated list. dic = {some_handle : my_handler arg1 arg2, some_other_handle : my_other_handler} $ python d = {foo: 5 6 7} ^ did you redefine the number five to something else? File stdin, line 1 d = {foo: 5 6 7} ^ SyntaxError: invalid syntax --- Greetings, Felix Anyway here is a portion of the Pygtk FAQ: http://www.async.com.br/faq/pygtk/index.py?req=editfile=faq22.004.htp Here's an example where arguments other than the widget are passed to the signal handler (note the tuple for handling clicks to the ok button): wTree2 = libglade.GladeXML(somefile.glade,proxy1) proxywidget = wTree2.get_widget(proxy1) id=1 dic= {on_cancel_clicked: proxywidget.destroy, gtk_widget_destroy: proxywidget.destroy, on_ok_clicked: ( handle_ok_clicked, wTree2,id)} wTree2.signal_autoconnect (dic) Sorry for the bad advice the first time. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: RE : Re: [pygtk] event handling
On Mon, 2006-04-09 at 12:42 +0200, Pascal DUCHATELLE wrote: David M. Cook [EMAIL PROTECTED] a écrit : On Sun, Sep 03, 2006 at 08:37:13AM +0200, Pascal DUCHATELLE wrote: dic = {on_mainWindow_destroy : gtk.main_quit, on_hello_key_press_event : self.hellorecompile} followed by this: self.wTree.signal_autoconnect(dic) Is there a way to use the second solution but also pass an argument like in the first one ? You can use a tuple in your dic. See http://www.async.com.br/faq/pygtk/index.py?req=showfile=faq22.004.htp Also, you can use a closure: foo = 5 baz = 6 def my_handler(*args): print foo print baz dic = {some_handle : my_handler} Dave Cook ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/ Hi Dave, I will turn my question differently: in your answer your my_handler accepts keywords. Then how do you pass them to your my_handler in the dic since using a coma as separator is considered to be followed by the next dic key-entry pair. Maybe I'm wrong. Or is a tuple or a list OK as an entry in such a dictionary ? Thank you Pascal As a space separated list. dic = {some_handle : my_handler arg1 arg2, some_other_handle : my_other_handler} -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Greek letter delta using Pango markup?
On Tue, 2006-15-08 at 08:46 -0500, [EMAIL PROTECTED] wrote: How (if at all) do I display a Greek capital letter delta in a label using Pango markup (or any other means)? This is via Glade v.2. I'm using a US keyboard. I'm pretty sure I can figure out how to do it from Python code, but since it's a static label I see no reason to pollute my application with such stuff. Thanks, From a gnome desktop, Acessories=Charachter Map, select greek, then drag and drop the character into the label field of the widget propeties dialog. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Re: pygtk.org mockup
On Thu, 2006-20-07 at 18:39 +0300, Panos Laganakos wrote: I did a 1024x768 version so you can have a better look at it, and did some other visual improvements too, which brings the mockup to version 03: http://panos.solhost.org/mockups/pygtk-03.png On 7/20/06, Panos Laganakos [EMAIL PROTECTED] wrote: I saw that gtkmm.org received a style update, so I thought I'd give a try at a new look for pygtk.org Keep in mind that it'll look small on normal resolutions (1280 ) 'cause I hacked it on a 800x600 CRT (yuck!). http://panos.solhost.org/mockups/pygtk-01.png http://panos.solhost.org/mockups/pygtk-02.png Lemme know what you think. Looks nice, but... There is too little contrast for the date and author lines. I know, I know I'm getting old :( my eyes aren't as good as they used to be. As for the 800 x 600 size. I like it, I often prefer slightly smaller web page sizes especially if I'm flipping between tutorials/reference's and an editor window. That way I can keep an eye on both. And no I can't afford a new 30in. high resolution widescreen monitor for my old eyes. So if you do proceed with the a new style keep the minimum sizes for the frames reasonable for smaller page sizes when desired. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] placing info from scrollbar into variable
On Thu, 2006-06-22 at 22:30 -0700, Christopher Spears wrote: I am trying to create a gui that consists of a vertical scrollbar and two buttons. I want to be able to pick a number representing degrees Fahrenheit using the scrollbar. When I click the Convert button after picking a number, the gui would convert the number into degrees Celsius and print the answer to the screen. Here is what I have written so far: #!/usr/bin/python import pygtk pygtk.require('2.0') import gtk def scale_set_default_values(scale): scale.set_update_policy(gtk.UPDATE_CONTINUOUS) scale.set_digits(1) scale.set_value_pos(gtk.POS_LEFT) scale.set_draw_value(True) scale.set_sensitive(True) class Conversion_GUI: def convert_to_celsius(self, adj): #print Data: , adj.value self.degC = (adj.value - 32)/1.8 return def print_celsius(self, widget): #degC = self.convert_to_celsius(adj1) print self.degC #data def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect(destroy, lambda w: gtk.main_quit()) self.window.set_title(Convert to Celsius) self.window.set_default_size(200,240) box1 = gtk.VBox(False, 0) self.window.add(box1) box2 = gtk.HBox(False, 10) box2.set_border_width(10) box1.pack_end(box2, True, True, 0) box3 = gtk.HBox(False, 10) box3.set_border_width(10) box1.pack_end(box3, True, True, 0) adj1 = gtk.Adjustment(32.0, 32.0, 213.0, 0.1, 1.0, 1.0) self.vscale = gtk.VScale(adj1) self.vscale.set_size_request(20, 300) scale_set_default_values(self.vscale) box1.pack_start(self.vscale, True, True, 0) adj1.connect(value_changed,self.convert_to_celsius) quit_button = gtk.Button(Quit) quit_button.connect(clicked, lambda w:gtk.main_quit()) self.degC = 0 convert_button = gtk.Button(Convert) convert_button.connect(clicked, self.print_celsius) box3.pack_start(convert_button, True, True, 0) box2.pack_start(quit_button, True, True, 0) self.vscale.show() convert_button.show() quit_button.show() box3.show() box2.show() box1.show() self.window.show() def main(self): gtk.main() return 0 if __name__ == '__main__': convert = Conversion_GUI() convert.main() Basically, the scrollbar feeds information into convert_to_celsius, which does the conversion. What I want to do is somehow store the information generated in convert_to_celsius in a variable and send it to print_celsius to print out the answer after the Convert button is pressed. I've looked at the tutorials and the docs and couldn't find anything, so I thought someone on this mailing list could give me advice. That should work (not tested). Basically you just can use a class global variable to store the converted variable in. self.degC I also removed a few function parameters you'll see. I think you should change the adj1.connect() to store the adj value and print the degF value in something in your window, then use the commented out method in the print_celcius to convert then print the temp. That should give you a few more ideas :) -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Updating scrolled windows
On Thu, 2006-06-22 at 17:09 -0700, N. French wrote: I have a gtk.ScrolledWindow that I use as an interactive console (I take entry from a gtk.Entry and display the results in a gtk.TextView housed in a gtk.ScrolledWindow). Below is my function to write the text to the buffer and set the ScrolledWindow's scroll bar to the end. I want it to behave like an xterm would, new text appears at the bottom and you scroll upwards to see old stuff. This basically works. My problem is it doesn't quite scroll the window all the way to the bottom, it's always short by one line. Any suggestions? Thanks, Nathan French Yeah, it doesn't always work unless you make a mark at the end of the buffer. Set the property so that any text inserted will be to the left of the mark. Then scroll_to_mark. That will scroll the text onscreen every time. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] User defined interface
On Sun, 2006-04-06 at 10:36 +0200, Preben Randhol wrote: Hi First I'm new to Python and PyGTK, but I have used Gtk for some years now. Currently I'm making an application with PyGTK. The application is supposed to show some data that is read from an XML file. Now what I need is to give the user the flexibility that she/he can set up how she/he wants the display widget to look like. My idea is to use a table widget as the base and that the user can put Labels, Pixmaps, and choose where in the table to display the data (and later also be able to edit data). So my question is: Given that the layout is defined in an XML file is it better to: 1. in some way (if possible) to use libglade to read a XML file that doesn't have a main window but only a Table widget as the base? As the layout will change depending on what data to display. 2. make ones own parser to read and generate the display GUI from the XML structure. I'm also thinking that later when I want to add edit capabilities I need to hook callbacks to the different edit widgets and that may be easier without libglade 3. or has somebody already made something like this that is available in as a library or similar? The program will be licensed as GPL or BSD if finished. Thanks in advanced for any hints. Preben Look at Gaspacho and Kiwi. It sounds like that may be able to do what you would like. Or at least part way to what you are trying to achieve. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Bold-Face line in a TreeView with glib2.10
On Sat, 2006-27-05 at 18:02 +0200, Nemesis wrote: On Sat, 27 May 2006 09:01:04 -0700 Brian [EMAIL PROTECTED] wrote: [problems with weight-set] It's working for my app just fine. Currently at glib-2.10.2 [...] def cell_data_func(self, column, renderer, model, iter, data): function to render the package name according to whether it is in the world file or not #full_name = model.get_value(iter, 0) color = model.get_value(iter, 5) if model.get_value(iter, 4): renderer.set_property(weight, pango.WEIGHT_BOLD) else: renderer.set_property(weight, pango.WEIGHT_NORMAL) But you aren't using 'weight-set', you are setting the weight property each time to WEIGHT_BOLD or WEIGHT_NORMAL. Sorry, I wasn't fully awake yet this morning :) I just grabbed the chunk of code we have been using. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] gtk.button stock images, color change possible?
In our app, I have put 3 buttons on the bottom of the window beside the status bar. I have made bare buttons and use stock images for two. One is a pause image, another is a play image and the third is a custom clock image. (specialized terminal app, command queue features {pause, run, timer}) Is it possible to change the foreground color of the image depending on the state? I have tried using the gtk.Widget.modify_fg(), but it does not seem to work. The reason I am trying to change it is because it is difficult to see whether it is active or not since they are small buttons. I realize some of this can be changed by changing my desktop theme. I would like to stay with stock images if possible it suits the purpose. Do I have to use custom images for this to work? snipit: self.pause_btn.modify_fg(gtk.STATE_INSENSITIVE, gtk.gdk.color_parse(#962A1C)) # dark red self.pause_btn.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(#DA311B)) # med red self.pause_btn.modify_fg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse(#F65540))# light red self.play_btn.modify_fg(gtk.STATE_INSENSITIVE, gtk.gdk.color_parse(#3C6E38)) # dark green self.play_btn.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(#4EBA44)) # med green self.play_btn.modify_fg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse(#58F64A)) # light green I just realized something that may be affecting my results. I have an instance of the app running some package upgrades from before this change. Would that cause python to not create new .pyc files for the modified files since there is another instance loaded and running? I'm tired, and heading off to bed. In the morning ill have an updated system with gtk+-2.8.18 to test out. -- Brian Dolbec [EMAIL PROTECTED] -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Bold-Face line in a TreeView with glib2.10
On Sat, 2006-27-05 at 15:26 +0200, Nemesis wrote: Hi all, I'm experimenting a strange behaviour with newer gtk release (the ones with glib 2.10). I need to set some lines in a treeview in bold-face and some not. So I set the textrenderer property weight to pango.FONT_WEIGHT and the I use row by row the property weight-set to select wich row must be in bold face. This approach is not working with newer gtk releases, the bold face is not set, if there is at least one row with the property weight-set set to False. I read that Sylpheed-Claws had the same problem and they fixed it by setting row by row the weight property. I could fix my application in the same way but I'd like to know if this is a GTK bug or I'm using in the wrong way the weight and weight-set properties. What do you think? It's working for my app just fine. Currently at glib-2.10.2 some snipits: # add the text renderer text = gtk.CellRendererText() self._column.pack_start(text, expand = True) self._column.add_attribute(text, text, 0) self._column.set_cell_data_func(text, self.cell_data_func, None) def cell_data_func(self, column, renderer, model, iter, data): function to render the package name according to whether it is in the world file or not #full_name = model.get_value(iter, 0) color = model.get_value(iter, 5) if model.get_value(iter, 4): renderer.set_property(weight, pango.WEIGHT_BOLD) else: renderer.set_property(weight, pango.WEIGHT_NORMAL) if color: #if color == 'blue': renderer.set_property(foreground, color) #else: #renderer.set_property(background, color) else: renderer.set_property(foreground-set, False) #renderer.set_property(background-set, False) #renderer.set_property(text, full_name) -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] gtk.TreeModelRowIter.next
It says: When there are no more rows left the StopIteration exception is raised. But I can't find out any more about the StopIteration. ie. where is it defined, where do you import it from. I can't find it in any of the gtk.Constants, treeview, treemodel, etc.. The only code I googled up, did not have it defined, just stuck there like the following snipit. Google says that kiwi/~/list.py had it but that link was dead and the list.py I found did not have it. some code snipit: try: self.process_iter.next() except StopIteration: pass -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] gtk.TreeModelRowIter.next
On Tue, 2006-16-05 at 23:33 -0700, David M. Cook wrote: On Tue, May 16, 2006 at 10:54:40PM -0700, Brian wrote: It says: When there are no more rows left the StopIteration exception is raised. But I can't find out any more about the StopIteration. ie. where is it defined, where do you import it from. I can't find it in any of the gtk.Constants, treeview, treemodel, etc.. It's already loaded into __builtins__, so you don't have to import anything. dir(__builtins__) Dave Cook Thank you everyone for the answer. At one point I thought it might be a builtin, but was getting too frustrated not finding anything (overtired). I see I should not have included gtk in my google search. If you're just trying to find out how to get the data sequencially from a model, this is how you do it: for row in model At least for gtk.ListStore, gtk.TreeStore is slightly trickier. Johan It was a Treestore, but a ListStore is all that was needed. The next() is the correct choice for this as the List is somewhat dynamic and could change. It is part of a command queue to process. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Widget resizability
On Sat, 2006-08-04 at 15:04 +0530, Divya Kamat wrote: hello friends I have posted this problem before, but havent got a concrete solution as yet. In my application, there are Hboxes and Vboxes...in each box, scrolled windows are packed. I want to make these scrolled window resizable by dragging with mouse pointer at runtime; but am unable to do so. Kindly help. It sounds like you need to use panes. There are vpaned and hpaned widgets that you would put you scrolled windows in. That method has worked well for us. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] shutting down worker threads
On Tue, 2006-28-03 at 14:38 -0600, Jason Pepas wrote: Hi guys, I have been wrapping my brain around the idea of getting asynchronous gui updates with worker threads working, and I have covered all but the last step. When I want to stop my program, how do I interrupt what the worker threads are doing to tell them it is time to stop? I have attached a simple example which demonstrates what I am working on. Try hitting the thread button a bunch of times and them closing the window. Thanks, Jason Pepas Here are some code snipits we use for shutting down threads. class CommonWorker(threading.Thread): Common threading class def __init__( self ): Initialize threading.Thread.__init__(self) # for keeping status self.count = 0 # we aren't done yet self.done = False # cancelled will be set when the thread should stop self.cancelled = False # quit even if thread is still running self.setDaemon(1) def please_die( self ): Tell the thread to die and is safe to call from other threads self.cancelled = True class UpgradableListReader(CommonWorker): Read available upgrades and store them in a tuple def __init__( self, installed, upgrade_only, view_prefs ): Initialize CommonReader.__init__(self) # [snip] def run( self ): fill upgrade tree #[snip] # in appropriate places such as loops add this line if self.cancelled: self.done = True; return from the main thread: self.up_thread = UpgradableListReader(installed_list, upgrade_only_flag, preferences) ... self.up_thread.please_die() -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] shutting down worker threads
On Tue, 2006-28-03 at 18:10 -0800, Brian wrote: CommonReader.__init__(self) # [snip] In case you didn't notice: It should be: CommonWorker.__init__(self) That's what I get for trying to change things in snipits. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Question abt sudo and password
On Wed, 2006-15-03 at 12:04 -0500, Hussein Vastani wrote: Hello All, In my application, I run external programs by running a shell using subprocess.Popen and then writing commands to it (like 'ls -la') and reading output from it which I then display it on the screen. It works fine as long as the external program does not need to run as sudo (like tethereal), in which case, I need to provide the password to it (on the konsole). I tried looking at the gksu module. Using the gksu module I can instantiate its Context class and then call the sudo_run() method after setting the command and the password in the Context instance. That works fine but is not the approach I want to take since I want to run commands and read their ouput back. So sticking to my use of Popen to execute commands, and assuming I have a way to get the sudo password from the user via a Dialog box, how do I then exectue my command without it asking me a password on the konsole? I would not like to modify the /etc/sudoers file. Is there any other approach? Any help is appreciated Thanks Hussein Vastani I don't have time to explain it right now. I also was not the one to code it. Check out our project : terminal.py http://cvs.sourceforge.net/viewcvs.py/porthole/porthole/terminal.py?rev=1.145view=log It has functionality for detecting the sudo prompt and passing it the password thru a dialog. It seems to work quite well. We were waiting for the gksu python interface to go mainstream (in gnome-python-extras) before integrating it. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Problem with threads
On Sat, 2006-25-02 at 13:19 -0400, David Cohen wrote: Hi, I don't know if it is a problem with pygtk. I am trying to use thread (from threading module) on a program using als pygtk. I create the thread and pass a function as the target (mythread = threading.Thread(target = myfunc). Then I call the mythread.start() but the thread never really starts, just when I call the mythread.join() method. But it I do the samething without the pygtk, the thread works well. Dows anybody could help me? BR, David Did you call gtk.threads_init() first? -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] treview segfaults due to sorting
Our app has several treeviews. One of those has several models that are switched out, 3 are flat lists, 1 currently has one expander and child nodes. If the expander is opened, when switching to any of the other models, it gets an instant segfault from the model.clear(). If I comment out the clear() it segfaults still, just a little different. The only thing I've been able to do so far to prevent the segfault is to force a re-sort by clicking on one of the other column headers. Normally the sort is on the first column (0). All models share the same treestore model. The checkbox is hidden for all but one view. def PackageModel(): Common model for a package Treestore store = gtk.TreeStore( gobject.TYPE_STRING,# 0: package name gobject.TYPE_BOOLEAN, # 1: checkbox value in upgrade view gobject.TYPE_PYOBJECT, # 2: package object gtk.gdk.Pixbuf, # 3: room for various icons gobject.TYPE_BOOLEAN, # 4: true if package is in 'world' file gobject.TYPE_STRING,# 5: foreground text colour gobject.TYPE_STRING,# 6: size gobject.TYPE_STRING,# 7: installed version gobject.TYPE_STRING,# 8: portage recommended version gobject.TYPE_STRING,# 9: description ) store.set_sort_func(6, size_sort_func) store.set_sort_func(8, latest_sort_func) store.set_sort_func(7, installed_sort_func) return store I do not know if this is a gtk bug yet or something we are doing wrong. Googling showed that Johan was the main contributor of that section of code, so I thought this list might be the best place to ask for any insights as to what to look for, etc., besides it is a pygtk app :). I've been far too busy lately to create a simple test app to duplicate the problem. Mostly what I am looking for now is any insight from others that may have experienced similar problems and solved them. I am attaching a file which is an accumulation of several gdb backtraces for those that might be able to discern some valuable info from it. Any help is very much appreciated... Brian. -- Brian [EMAIL PROTECTED] (gdb) continue Continuing. [New Thread 32770 (LWP 28631)] [Thread 32770 (LWP 28631) exited] [New Thread 49154 (LWP 28636)] Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 16384 (LWP 28625)] 0xb783a4be in gtk_tree_view_expand_all () from /usr/lib/libgtk-x11-2.0.so.0 (gdb) bt #0 0xb783a4be in gtk_tree_view_expand_all () from /usr/lib/libgtk-x11-2.0.so.0 #1 0xb7834597 in gtk_tree_view_get_fixed_height_mode () from /usr/lib/libgtk-x11-2.0.so.0 #2 0xb7834692 in gtk_tree_view_get_fixed_height_mode () from /usr/lib/libgtk-x11-2.0.so.0 #3 0xb774dcc0 in gtk_marshal_VOID__UINT_STRING () from /usr/lib/libgtk-x11-2.0.so.0 #4 0xb7b3e146 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0 #5 0xb7b4f485 in g_signal_emit_by_name () from /usr/lib/libgobject-2.0.so.0 #6 0xb7b4e537 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0 #7 0xb7b4e7c6 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0 #8 0xb7814ad3 in gtk_tree_model_rows_reordered () from /usr/lib/libgtk-x11-2.0.so.0 #9 0xb782540f in gtk_tree_store_move_after () from /usr/lib/libgtk-x11-2.0.so.0 #10 0xb7825500 in gtk_tree_store_move_after () from /usr/lib/libgtk-x11-2.0.so.0 #11 0xb7820b4b in gtk_tree_sortable_set_sort_column_id () from /usr/lib/libgtk-x11-2.0.so.0 #12 0xb7a3f997 in init_gtk () from /usr/lib/python2.4/site-packages/gtk-2.0/gtk/_gtk.so #13 0xb7f20089 in PyCFunction_Call () from /usr/lib/libpython2.4.so.1.0 (gdb) continue Continuing. [New Thread 32770 (LWP 31588)] [Thread 32770 (LWP 31588) exited] [New Thread 49154 (LWP 31589)] Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 16384 (LWP 31315)] 0xb78344f8 in gtk_tree_view_get_fixed_height_mode () from /usr/lib/libgtk-x11-2.0.so.0 (gdb) bt #0 0xb78344f8 in gtk_tree_view_get_fixed_height_mode () from /usr/lib/libgtk-x11-2.0.so.0 #1 0xb7b50233 in g_cclosure_marshal_VOID__BOXED () from /usr/lib/libgobject-2.0.so.0 #2 0xb7b3e146 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0 #3 0xb7b4f485 in g_signal_emit_by_name () from /usr/lib/libgobject-2.0.so.0 #4 0xb7b4e537 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0 #5 0xb7b4e7c6 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0 #6 0xb7814a25 in gtk_tree_model_row_deleted () from /usr/lib/libgtk-x11-2.0.so.0 #7 0xb7822ca5 in gtk_tree_store_remove () from /usr/lib/libgtk-x11-2.0.so.0 #8 0xb7823a15 in gtk_tree_store_iter_depth () from /usr/lib/libgtk-x11-2.0.so.0 #9 0xb78239d8 in gtk_tree_store_iter_depth () from /usr/lib/libgtk-x11-2.0.so.0 #10 0xb7823a8c in gtk_tree_store_clear () from /usr/lib/libgtk-x11-2.0.so.0 #11 0xb7a2a413 in init_gtk () from /usr/lib/python2.4/site-packages/gtk-2.0/gtk/_gtk.so #12 0xb7f558f4 in PyEval_GetFuncDesc () from /usr/lib/libpython2.4.so.1.0 Program
RE: [pygtk] treview segfaults due to sorting
On Thu, 2006-05-01 at 11:53 +0100, Leeuw van der, Tim wrote: Hi Brian, Other than that you're using Python 2.4 and GTK2, I don't see any information about the versions of software you're using, or the platform on which you're developing. Can you please tell us which version of GTK and PyGTK you're using? And if you have version-details on other components (such as exact python version, Glib, etc) for us, they're welcome too. Cheers, --Tim Yeah, I realized shortly after I hit send... Distro - gentoo python - 2.4.2 pygtk - 2.8.2 gtk+ - 2.8.9 glib - 2.8.4 gcc - 3.3.5.20050130-r1 ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/ -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Getting tooltips color
On Thu, 2005-10-11 at 23:54 -0500, Andrew Conkling wrote: I was wondering if it were possible to get the GTK+ theme's color for tooltips. gtk.Tooltips() does not have a .get_style() since it's not a subclass of gtk.Widget(), so it seems some voodoo magic would be necessary to get the color. Also, a related question for my purposes: is it possible to set a border around a gtk.Window()? If so, I'll need to figure out the color of the tooltips' border also. :) Thanks, Andrew I believe that came up just a few weeks ago and had replies with solutions. Although it may have been on the gtk-app-devel mail list. Check the archives and you should find your solution. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Quick notebook question...
self.notebook.connect('switch-page', self.on_notebook_switch) def on_notebook_switch(self, notebook, page_ptr, page_num, data=None): page = self.notebook.get_nth_page(page_num) ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Quick notebook question...
On Wed, 2005-02-11 at 13:53 -0500, Thomas Mills Hinkle wrote: On 11/2/05, Rob Marino [EMAIL PROTECTED] wrote: Hi all. Quick question regarding notebook signals: I have an app with a notebook. I need to detect when a user switches to another page. Problem is this - when I detect the 'switch_page' signal and use notebook.get_current_page() I'm getting the page that the user *was *on. The other signals like 'switch_page' and 'change_current_page' don't seem to be being fired at all. I need a way to detect the page the user has selected after he has switched to it. How is this done please? Today seems to be my day for sharing ugly solutions with the list... here's what I do: def hackish_notebook_switcher_handler (*args): # because the switch page signal happens before switching... # we'll need to look for the switch with an idle call gobject.idle_add(self.notebookChangeCB) def notebookChangeCB (*args): page=self.notebook.get_current_page() # Do something with the page... self.notebook.connect('switch-page',hackish_notebook_switcher_handler) Yeah, as I said not pretty. Knowing myself, I imagine I looked pretty hard for a better solution before implementing that, so this may be what you have to do. If not, someone please show me the better way too! Tom Here is how we do it without a hack. self.notebook.connect(switch-page, self.switch_page) def switch_page(self, notebook, page, page_num): callback function changes the current_page setting in the term structure dprint(TERMINAL: switch_page; page_num = %d %page_num) self.term.current_tab = self.term.visible_tablist[page_num] if self.term.auto_scroll[self.term.current_tab]: self.scroll_current_view() return You should be able to decipher the above code snipit without more explanation. We have a number of tabs that may or may not be visible. The pygtk reference page: http://www.pygtk.org/pygtk2reference/class-gtknotebook.html and the pertinent info: The switch-page gtk.Notebook Signal def callback(notebook, page, page_num, user_param1, ...) notebook : the notebook that received the signal page : the new current page page_num : the index of the new current page user_param1 : the first user parameter (if any) specified with the connect() method ... : additional user parameters (if any) The switch-page signal is emitted when the notebook page is changed. Note the page parameter is a GPointer and not usable within PyGTK. Use the page_num parameter to retrieve the new current page using the get_nth_page() method. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] gtk threading tutorial.
On Fri, 2005-28-10 at 14:35 +0200, Antoon Pardon wrote: Well I made a version of my demo program based on this dispatcher, it is at http://www.pardon-sleeuwaegen.be/antoon/python/demo3c.py Unfortunatly I managed to deadlock it. Could you have a look at it, to see I'm using it as it is supposed to. A quick look thru (this morning before I go to work)... You are using 1 global instance of Dispatcher for several threads. That is where the trouble is. Several threads trying to access it at the same time will deadlock it. Instead pass each thread an instance of Dispatcher as parameter for it's private use. There is no need to assign an instance to a variable name. class Counting (Thread): def __init__(self, Id, dispatcher): self.Id = Id self.dispatcher = dispatcher self.ctrl = True self.Running = False self.ShowMode = 0 self.Time = 0 self.Value = 250 self.lock = Lock() self.lock.acquire() self.PRG = Random() Thread.__init__(self) #end __init__ snip later replace: gtkdispatch(self.Id, self.ShowTime, self.ShowValue) with (2 spots): self.dispatcher(self.Id, self.ShowTime, self.ShowValue) change: Worker = [ Counting(i) for i in xrange(7) ] to : Worker = [ Counting(i,Dispatcher(canvas.Adjust)) for i in xrange(7) ] delete: gtkdispatch = Dispatcher(canvas.Adjust) That should fix it. Note: untested, gotta go I'm going to be late :) -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] gtk threading tutorial.
On Thu, 2005-27-10 at 14:06 +0200, Antoon Pardon wrote: I have written a small gtk threading tutorial with a number of demo's and an (IMO) helpfull module. I don't fancy myself to be a good writer, but I thought the demo's would make up for that. Let me know what you think. http://www.pardon-sleeuwaegen.be/antoon/python/page0.html That is a nice tutorial. I have not had a chance to study it in detail, but from looking at your iotube.py and idletube.py scripts I think they might be more complex than needed. I will study it more later. Attached is the dispatcher.py script that another developer on our project came up with and I tweaked a little and has been working very good for us. The dispatcher instance can be based from any thread and allows a queue'd set of data arguments to be passed back to it without collision. It is also very generic and most any python data types can be passed thru it. -- Brian [EMAIL PROTECTED] #! /usr/bin/env python # Fredrik Arnerup [EMAIL PROTECTED], 2004-12-19 # Brian Dolbec[EMAIL PROTECTED],2005-3-30 import gobject, os, Queue from select import select class Dispatcher: Send signals from a thread to another thread through a pipe in a thread-safe manner def __init__(self, callback_func, *args, **kwargs): self.callback = callback_func self.callback_args = args self.callback_kwargs = kwargs self.continue_io_watch = True self.queue = Queue.Queue(0) # thread safe queue self.pipe_r, self.pipe_w = os.pipe() gobject.io_add_watch(self.pipe_r, gobject.IO_IN, self.on_data) def __call__(self, *args): Emit signal from thread self.queue.put(args) # write to pipe afterwards os.write(self.pipe_w, X) def on_data(self, source, cb_condition): if select([self.pipe_r],[],[], 0)[0] and os.read(self.pipe_r,1): if self.callback_args: args = self.callback_args + self.queue.get() self.callback(*args, **self.callback_kwargs) else: self.callback(*self.queue.get(), **self.callback_kwargs) return self.continue_io_watch #! /usr/bin/env python # Fredrik Arnerup [EMAIL PROTECTED], 2004-12-19 # Brian Dolbec[EMAIL PROTECTED],2005-3-30 from dispatcher import Dispatcher # # dispatcher # example code: # # # class Thread(threading.Thread): def __init__(self, dispatcher, thread_num, length): threading.Thread.__init__(self) self.setDaemon(1) # quit even if this thread is still running self.dispatcher = dispatcher self.thread_num = thread_num self.sleep_length = length def run(self): done = False print(thread_num = %s; process id = %d %(self.thread_num,os.getpid())) pid_func(self.thread_num) for num in range(250): #print self.thread_num, num = ,num #sleep(self.sleep_length) data = [ self.thread_num, (: time is slipping away: %d\n %num), num, done] self.dispatcher(data) # signal main thread done = True data = [ self.thread_num, (: Time slipped away: I'm done), num, done] self.dispatcher(data) # signal main thread def pid_func(threadnum): print(pid_func: called from thread_num = %s; process id = %d %(threadnum,os.getpid())) def message_fun(buffer, message): #print (got a message : %s %(message[0] + str(message[1]))) if message[3]: thread_finished[message[0]] = True buffer.insert(buffer.get_end_iter(), message[0] + str(message[1]) + \n\n) else: #message2 = (%d x 3 = %d\n %(message[2],message[2]*3)) buffer.insert(buffer.get_end_iter(), message[0] + str(message[1])) # + message2) return def timerfunc(): if (not thread_finished[thread1]) or (not thread_finished[thread2]) \ or (not thread_finished[thread3]) or (not thread_finished[thread4]): pbar.pulse() #print 'Plusing ProgressBar, since a thread is not finished' return True else: pbar.set_fraction(0) pbar.set_text(Done) return False def on_window_map_event(event, param): print 'Window mapped' thread1 = Thread(Dispatcher(message_fun, buffer), thread1, 0.1) thread2 = Thread(Dispatcher(message_fun, buffer), thread2, 0.1) thread3 = Thread(Dispatcher(message_fun, buffer), thread3, 0.1) thread4 = Thread(Dispatcher(message_fun, buffer), thread4, 0.1) gobject.timeout_add(100, timerfunc) thread1.start() thread2.start() thread3.start() thread4.start() if __name__ == __main__: import pygtk; pygtk.require(2.0) import gtk from time import sleep gtk.threads_init() window = gtk.Window(gtk.WINDOW_TOPLEVEL) textview = gtk.TextView() buffer = textview.get_buffer() sw = gtk.ScrolledWindow
Re: [pygtk] button not responding
On Fri, 2005-28-10 at 10:37 +1000, vector wrote: Hi I feel a little embarrased and silly asking this and not sure how to say it but here goes. Newbie,, be nice I have a window with two buttons in it (actually its a lot more than that but i dont think thats important) one button starts the system doing some calcs. the other button can be used to terminate. Its acting as if once i hit the first button python is not interested in anything until its finished. ie the second button is not processed until its finished button 1s task.. I thought (ohh dear) that a gtk widget, like the second button would interrupt the previous process. I think im being naive ? pygtk/gtk+ like most everything can only do one thing at a time. If you have a long slow calculation task to do it is usually better to do that in a thread so that it does not tie up the gui interface. There are several methods for dealing with that. In fact someone just yesterday posted to this list that he just made a tutorial for working with threads. Here is his tutorial link: http://www.pardon-sleeuwaegen.be/antoon/python/page0.html Check the archives and you will find plenty of questions/answers about threads and doing larger computations and working with the gui interface. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: Using adjustments to 'remember' treeview's position
I'm not sure that I totally grok what you are trying to do, so forgive me if this is not helpful. But, you can use the adjustment's values to remember its position (or at least get it close). For an adjustment, adj, you have the following: adj.value (current value), adj.lower (lowest value), adj.higher (highest value), and adj.page_size (how the adjustment breaks up values in pages). So, if you want to remember where you are, and the overall size of your view in that context does not change, you can just save adj.value, and then call adj.set_value(v) to restore the position. Or, you can use all the available values to determine a relative value, if the view is shrinking and growing a lot. ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Threading issues...
On Mon, 2005-29-08 at 13:18 +1000, Simon Gerber wrote: Greetings all, I'm, err, having threading problems. I've googled through this list, and indeed as much of the Internet as I can reach, looking for answers and workaround to no avail. I am still just learning, really, and have a feeling I've bitten off more than I can chew. The situation is this: I am trying to create a gnome applet that checks mail accounts, displaying the usual stuff. The files involved are: gnoptray.py - script that launches the applet cApplet.py - Module containing the applet class cAccounts.py - Module containing an 'Account' class. It is built using (not extending) imaplib and poplib. It stores an internal dictionary of message headers, can update itself, fetch and delete messages. guiAccount.py - GTK extensions to the cAccounts.Account class. Creates a GUI that sets account attributes, such as username, password, etc... The problem I'm having is with checking mail. I started by creating a timeout that would call the update() method of a guiAccount object. Obviously, this freezes the entire UI. I don't really want to update the GUI while checking... I just want my menus and such to appear while it's churning away in the background. So I tried threads... Throwing in gtk.threads_init(), wrapping gtk.main() in gtk.threads_enter() and gtk.threads_leave() - doing the same with my time-out callback. e.g ... if interval != 0: self.timeout_ids[name] = (gobject.timeout_add(interval, self.check_mail, name)) def check_mail(self, name): thread1 = threading.Thread(target=self.accounts[name].update()) thread1.start() return 1 But nothing really worked. The UI still froze until checking was complete. Is it worth pursuing this path? I have tried generators, but they did not work as expected. I am now considering writing a daemon application to do the actual mail checking - and just feed it into the GUI through an input_add(). Either that or toss out my cAccounts.py module and build a gtk version of imap/poplib using input_add. Any help would be much appreciated. Cheers, To handle threads and inter thread communication You have a couple options. There is a dispatcher.py project out there that can handle all sorts of inter process communications, etc.. We have come up with a small simple way of handling threads and gtk callbacks. I've attached a small dispatcher.py script and an example script that shows how to use it. This dispatcher code has fixed a lot of bugs and intermittent problems with our project. It does a great job of separating code and callbacks when dealing with threads. It allows you to run all gtk/gui calls from one thread while other threads can trigger callbacks and pass data into or out of a thread. The dispatcher code can reside in any thread and receive calls from any other thread. For our project the dispatcher instances all belong to the main gtk thread and receive signals from feeder threads. It is engineered generic enough to be able to pass any python data between threads. -- Brian [EMAIL PROTECTED] #! /usr/bin/env python # Fredrik Arnerup [EMAIL PROTECTED], 2004-12-19 # Brian Dolbec[EMAIL PROTECTED],2005-3-30 import gobject, os, Queue from select import select class Dispatcher: Send signals from a thread to another thread through a pipe in a thread-safe manner def __init__(self, callback, args=None): self.callback = callback self.callback_args = args self.continue_io_watch = True self.queue = Queue.Queue(0) # thread safe queue self.pipe_r, self.pipe_w = os.pipe() gobject.io_add_watch(self.pipe_r, gobject.IO_IN, self.on_data) def __call__(self, *args): Emit signal from thread self.queue.put(args) # write to pipe afterwards os.write(self.pipe_w, X) def on_data(self, source, cb_condition): if select([self.pipe_r],[],[], 0)[0] and os.read(self.pipe_r,1): if self.callback_args is not None: self.callback(self.callback_args, *self.queue.get()) else: self.callback(*self.queue.get()) return self.continue_io_watch #! /usr/bin/env python # Fredrik Arnerup [EMAIL PROTECTED], 2004-12-19 # Brian Dolbec[EMAIL PROTECTED],2005-3-30 from dispatcher import Dispatcher # # dispatcher # example code: # # # class Thread(threading.Thread): def __init__(self, dispatcher, thread_num, length): threading.Thread.__init__(self) self.setDaemon(1) # quit even if this thread is still running self.dispatcher = dispatcher self.thread_num = thread_num self.sleep_length = length def run(self): done = False print(thread_num = %s; process id = %d %(self.thread_num,os.getpid())) pid_func
Re: [pygtk] Vbox packing problem
On Wed, 2005-24-08 at 11:21 +0100, Jono Bacon wrote: Hi all First post to the list. :) I have a glade file which is loaded into my application. At the top of the window (in a VBox) I have a button. When I click the button, I want the button to be replaced with a different labelled button (Stop instead of Execute) and hook up to a different function. To do this I figured I would destroy() the button and then replace it. Here is my code: self.mainStartButton.destroy() self.mainStopButton = gtk.Button(None, gtk.STOCK_MEDIA_STOP) self.mainStopButton.connect(clicked, self.on_mainStopButton_clicked) self.vbox1.pack_start(self.mainStopButton, True, False) When I run this code, the button is destroyed but the new button is placed at the bottom of the window. How can I solve this? Cheers, Jono Put your buttons where you want them in an hbox in that vbox and then just hide() or show() them at your choosing. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] ANNOUNCE: Gazpacho 0.6.0
I tried modifying the gentoo ebuild to emerge -0.6.0 but the setup.py does not have execute permissions set. Changing that and running setup.py manually it failed, due to no glade directory and glade files. I just saw the -0.6.1 and tried it. It too has the setup.py lack of execute, but does include the glade files. setting the permission and running setup.py manually worked. Now to get the ebuild to change the permissons before running setup.py ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Re: pygtk + help guide
On Tue, 2005-09-08 at 11:01 +0200, Luigi Pantano wrote: i want create a help browser like this: http://www.cs.cf.ac.uk/systems/html/322/node7.html but multiplatform. Why create one when you can just import one from python. Here is some code from our program. we recently added a custom web browser choice if the user wishes rather than the the default web browser that python knows about. dprint() is our utils print function that prints to stderr if the debug flag was passed at startup. [code] # if using gnome, see if we can import it try: import gnome try: import gnomevfs except: # try the depricated module import gnome.vfs except ImportError: # no gnome module #print stderr, ('Module gnome not found. ' # 'You will not be able to use gnome to open web pages.') dprint('LOADERS: Module gnome not found. ' 'You will not be able to use gnome to open web pages.') # get the standard webbrowser module try: import webbrowser except ImportError: #print stderr, ('Module webbrowser not found. ' # 'You may not be able to open web pages.') dprint(' * LOADERS: Module webbrowser not found. You may not be able to open web pages.') def load_web_page(name, prefs): Try to load a web page in the default browser dprint(LOADERS: load_web_page(); starting browser thread) browser = web_page(name, prefs) browser.start() return def load_help_page(name, prefs): Load a locale-specific help page with the default browser. dprint(LOADERS: load_help_page: %s % name) lc = prefs.globals.LANG if not lc: lc = en helpdir = os.path.join(prefs.DATA_PATH, 'help') if os.access(os.path.join(helpdir, lc, name), os.R_OK): pagename = file:// + os.path.join(helpdir, lc, name) elif os.access(os.path.join(helpdir, lc.split('_')[0], name), os.R_OK): pagename = file:// + os.path.join(helpdir, lc.split('_')[0], name) elif os.access(os.path.join(helpdir, en, name), os.R_OK): pagename = file:// + os.path.join(helpdir, en, name) else: dprint( * LOADERS: failed to find help file '%s' with LANG='%s'! % (name, prefs.globals.LANG)) return False load_web_page(pagename, prefs) class web_page(threading.Thread): Try to load a web page in the default browser def __init__(self, name, prefs): dprint(LOADERS: web_page.__init__()) threading.Thread.__init__(self) self.name = name self.prefs = prefs self.setDaemon(1) # quit even if this thread is still running def run(self): dprint(LOADERS: web_page.run()) if self.name == '' or self.name == None: return if self.prefs.globals.use_custom_browser: command = self.prefs.globals.custom_browser_command if '%s' not in command: command += ' %s' browser = webbrowser.GenericBrowser(command) try: browser.open(self.name) except: dprint(LOADERS: failed to open '%s' with browser command '%s' % (self.name, command)) else: try: gnome.url_show(self.name) except: dprint(LOADERS: Gnome failed trying to open: %s %self.name) try: webbrowser.open(self.name) except: dprint(LOADERS: webbrowser failed trying to open: %s -- giving up %self.name) pass dprint(LOADERS: Browser call_completed for: %s %self.name) [/code] -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] gtk.Plug and gtk.Socket
On Wed, 2005-03-08 at 21:27 +0200, Stefano Esposito wrote: Hi all, I'm trying to embed an xterm window into my app, i find something about gtk.Plug and gtk.Socket, but it seems that they will work only with apps that uses GtkSocket or GtkPlug and i don't think xterm does... Any hint? For a gtk native terminal widget. check out vte. It is the main library that gnome-terminal uses. The library widget was split out of gnome-terminal some time ago. I have experimented with it some, but it's python API is not quite as complete as the c API. It should do most anything that you may need. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: Themes and Stand Alone GTK
Two simple questions: 1) There's a way to set the theme that an app will use, without setting it globally or for the user? Like, just that app will use a different theme... 2) Using Python or py2exe to generate a standalone executable requires the installation of the gtk runtime for win32, there's a way to pack the runtime in some way that doesn't require installing the whole package? Like, a private gtk installation on the apps dir. I can answer #1 for you. You can have an application specific stylesheet, which you can read in intialization with gtk.rc_parse(filename), or you can use an inline style sheet, embedding in the code, which you can parse with gtk.rc_parse_string(string). An inline style looks something like this: my_style_string = style white_background { fg[NORMAL] = #00 bg[NORMAL] = #FF text[NORMAL] = #00 base[NORMAL] = #FF } widget *.white_bgd style white_background gtk.rc_parse_string(my_style_string) I think you got a good answer to #2 already... ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: Popup menus on Notebook tabs
Did you find the bug in my code? tab_label_box = gtk.EventBox() tab_label = gtk.Label(Some label here) tab_label_box.add(tab_label) tab_label_box.connect('event', on_tab_click, your_page_widget) notebook.append_page(your_page_widget, tab_label_box) def on_tab_click(self, widget, event, child): if event.type == gtk.gdk.BUTTON_PRESS: n = notebook.page_num(child) # this will automagically switch to whatever page you click on notebook.set_current_page(n) if event.button == 3: menu = create_a_menu() # I still use the ItemFactory menu.popup(None, None, None, event.button, event.time) ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: Popup menus on Notebook tabs
I'm trying to produce a menu effect in PyGTK similar to the Mozilla tab bar, where a right-click on the tab produces a popup menu to perform various actions on the tabs (and/or contents thereof). I can get most of the way (sort of) with a button-press-event handler, but there's a couple of things I can't manage to effect: (a) A right-click on the untabbed portion of the tab list still gives the menu, and (b) I can't work out which tab was clicked on. For (a), you can call notebook.popup_disable() when you create the notebook, as long as you don't need the default popup menu that the notebook creates. For an easy way to create popup menus, and figuring out which tab a click comes from, put your tab labels into event boxes: tab_label_box = gtk.EventBox() tab_label = gtk.Label(Some label here) tab_label_box.add(tab_label) tab_label_box.connect('event', on_tab_click) notebook.append_page(your_page_widget, tab_label_box) def on_tab_click(self, widget, event, child): if event.type == gtk.gdk.BUTTON_PRESS: n = notebook.page_num(child) # this will automagically switch to whatever page you click on notebook.set_current_page(n) if event.button == 3: menu = create_a_menu() # I still use the ItemFactory menu.popup(None, None, None, event.button, event.time) ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] cannot import gnome
On Fri, 2005-20-05 at 13:19 +0200, Martijn Brouwer wrote: Hi, I have a Debian Sarge system with python 2.3 and python-gnome-2.6.1. Importing pygtk in the way described by the tutorial does not work: import pygtk pygtk.require(2.0) import gtk import gnome Traceback (most recent call last): File stdin, line 1, in ? ImportError: No module named gnome However, when I do not import pygtk import gnome does work: import gtk import gnome I came across this problem because pybliographic did not start. It import gtk and gnome after pygtk. The hal-device-manager works correctly, because it does not first import pygtk. Is this a feature change that should be reflected into the code of the applications, or is this a bug? Bye, Martijn Brouwer The path variable has gotten messed up. Did you upgrade python? Since I don't know debians workings you will have to get help on the repair by someone else. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] New gtk.ToolButoon setting gtk.Tooltips
On Sun, 2005-15-05 at 16:21 -0700, Brian wrote: I was thinking of including some code to handle both API's so people can see the difference, and possibly include support for both API's so that their code can be more flexible. I have just been too busy to create a simple code sample and explanation. I will do one as soon as I get the chance. Well, I got the chance tonight and modified the tooltips.py tutorial example to use the old or new API. Hopefully it all should work and show how to use both versions of the buttons and tooltips use as well as some checking as to what the pygtk version is to verify which API is available. Can everyone take a look at it and see if there is anything that should be changed. :) -- Brian [EMAIL PROTECTED] tooltip.py Description: application/python ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] New gtk.ToolButoon setting gtk.Tooltips
On Sun, 2005-15-05 at 18:19 -0300, Christian Robottom Reis wrote: On Tue, May 10, 2005 at 09:49:38AM +0200, Danny Milosavljevic wrote: Hi, Am Montag, den 09.05.2005, 16:50 -0700 schrieb Brian: How do you set a tooltip for the new gtk.ToolButton. It seems that a ToolButton is a subclass of a ToolItem which has a set_tip(). But how do you access it from the gtk.ToolButton widget? tooltips = gtk.Tooltips() [...] toolbar = gtk.Toolbar() toolbar.set_tooltips(True) toolbutton = gtk.ToolButton() toolbutton.set_tooltip(tooltips, hi) - FAQ 9.6 http://www.async.com.br/faq/pygtk/index.py?req=showfile=faq09.006.htp Take care, -- Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 3376 0125 I was thinking of including some code to handle both API's so people can see the difference, and possibly include support for both API's so that their code can be more flexible. I have just been too busy to create a simple code sample and explanation. I will do one as soon as I get the chance. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] New gtk.ToolButoon setting gtk.Tooltips
On Tue, 2005-10-05 at 09:49 +0200, Danny Milosavljevic wrote: Hi, Am Montag, den 09.05.2005, 16:50 -0700 schrieb Brian: How do you set a tooltip for the new gtk.ToolButton. It seems that a ToolButton is a subclass of a ToolItem which has a set_tip(). But how do you access it from the gtk.ToolButton widget? tooltips = gtk.Tooltips() [...] toolbar = gtk.Toolbar() toolbar.set_tooltips(True) toolbutton = gtk.ToolButton() toolbutton.set_tooltip(tooltips, hi) cheers, Danny But that is what is driving me crazy over this: bash-2.05b$ ./tooltip.py Traceback (most recent call last): File ./tooltip.py, line 78, in ? tt = Tooltips() File ./tooltip.py, line 51, in __init__ button1.set_tip(tooltips) AttributeError: 'gtk.ToolButton' object has no attribute 'set_tip' attached you will find a modified tooltips script from the pygtk tutorial that I updated somewhat to use gtk.ToolButton's instead of gtk.Button's. uncomment the set_tip() lines to get the error. I have tried every permutation I can think of. The new ToolButton is just borked :( -- Brian [EMAIL PROTECTED] tooltip.py Description: application/python ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] New gtk.ToolButoon setting gtk.Tooltips
On Tue, 2005-10-05 at 11:01 -0300, Christian Robottom Reis wrote: On Tue, May 10, 2005 at 07:00:58AM -0700, Brian wrote: On Tue, 2005-10-05 at 09:49 +0200, Danny Milosavljevic wrote: Hi, Am Montag, den 09.05.2005, 16:50 -0700 schrieb Brian: How do you set a tooltip for the new gtk.ToolButton. It seems that a ToolButton is a subclass of a ToolItem which has a set_tip(). But how do you access it from the gtk.ToolButton widget? tooltips = gtk.Tooltips() [...] toolbar = gtk.Toolbar() toolbar.set_tooltips(True) toolbutton = gtk.ToolButton() toolbutton.set_tooltip(tooltips, hi) cheers, Danny But that is what is driving me crazy over this: bash-2.05b$ ./tooltip.py Traceback (most recent call last): File ./tooltip.py, line 78, in ? tt = Tooltips() File ./tooltip.py, line 51, in __init__ button1.set_tip(tooltips) AttributeError: 'gtk.ToolButton' object has no attribute 'set_tip' But the example above has set_tooltip, not set_tip. Take care, -- Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 3376 0125 Duho !!! Thanks, I guess I was struggling with it too much to see the obvious! It works now, Thanks again. Attached is a working example. -- Brian [EMAIL PROTECTED] tooltip.py Description: application/python ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] New gtk.ToolButoon setting gtk.Tooltips
On Tue, 2005-10-05 at 17:37 -0300, Christian Robottom Reis wrote: On Tue, May 10, 2005 at 09:56:17PM +0200, Danny Milosavljevic wrote: Am Dienstag, den 10.05.2005, 11:01 -0300 schrieb Christian Robottom Reis: On Tue, May 10, 2005 at 07:00:58AM -0700, Brian wrote: On Tue, 2005-10-05 at 09:49 +0200, Danny Milosavljevic wrote: Hi, Am Montag, den 09.05.2005, 16:50 -0700 schrieb Brian: How do you set a tooltip for the new gtk.ToolButton. It seems that a ToolButton is a subclass of a ToolItem which has a set_tip(). But how do you access it from the gtk.ToolButton widget? tooltips = gtk.Tooltips() [...] toolbar = gtk.Toolbar() toolbar.set_tooltips(True) toolbutton = gtk.ToolButton() toolbutton.set_tooltip(tooltips, hi) cheers, Danny But that is what is driving me crazy over this: bash-2.05b$ ./tooltip.py Traceback (most recent call last): File ./tooltip.py, line 78, in ? tt = Tooltips() File ./tooltip.py, line 51, in __init__ button1.set_tip(tooltips) AttributeError: 'gtk.ToolButton' object has no attribute 'set_tip' But the example above has set_tooltip, not set_tip. Yes, but what I'm not getting where the imaginary tool_item_set_tip comes from. This is the most confusing exchange ever witnessed on pygtk-list. Danny, you and Brian need to stop taking drugs wink. Take care, -- Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 3376 0125 The only drugs I am on are prescribed :) (cholesterol, not mind altering :D). What really got me confused was trying to update our program to use the new toolbar API, (Only one tooltip is dynamic.). Where I got into trouble was that a gtk.Button uses gtk.Tooltips.set_tip() while the new inherited method is .set_tooltip(). The 2 names are so similar that my brain didn't notice the difference. The other confuser was that both use gtk.Tooltips, but differently. The new toolbar seems to only use the instance for the enable/disable(), the old API seemed to store the tooltip string in the gtk.Tooltips instance. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Problems getting color values
Does anybody know how to get the rgb values from a gtk.gdk.GC? Attempting to access the values returns garbage, as evidenced by this example: Python 2.4 (#1, Mar 9 2005, 09:57:26) [C] on irix6 Type help, copyright, credits or license for more information. import pygtk pygtk.require('2.0') import gtk widget = gtk.Window() widget.show() style = widget.get_style() gc = style.fg_gc[gtk.STATE_NORMAL] gc.foreground GdkColor at 0x10327ce0 gc.foreground.red 4107 gc.foreground.green 30416 gc.foreground.blue 0 colormap = widget.get_colormap() red = colormap.alloc_color(0x, 0x00, 0x00) red.red 65535 red.green 0 red.blue 0 gc.foreground = red gc.foreground.red 4107 gc.foreground.green 30416 gc.foreground.blue 0 The color in the gc draws correctly to the screen. I need the rgb values to match gtk colors with rendering done by other code. ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] How can I create hyperlink on a Dialog Box
On Fri, 2005-29-04 at 05:28 -0700, Mahmad Sadique Hannure wrote: I am working on a module called Report Bugs which requires a hyperlink which open our web site in default browser. I am able to implement effect looks like a hyperlink by using Pango Markup language as like label.set_text(span foreground=\blue\ underline=\single\ +[PROTECTED WEB SITE] + /span) label.set_use_markup(True) So if any one knows the solution please help me Thaank You __ I don't know if this will work in a dialog box the same, but here is how we do it in a TextBuffer. It should be very similar. http://cvs.sourceforge.net/viewcvs.py/porthole/porthole/summary.py?view=markup Hope this helps. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Application responsiveness problem (with Glade)
On Sun, 2005-17-04 at 15:08 +0200, Lszl Monda wrote: I'd like to send you another example (actually it's the third one, so don't hit me, please ;) to demonstrate an even more problematic situation with threading. I've implemented this example a week ago or so with your dispatcher too, but that didn't work either. The expected behaviour is that when one clicks on the button, the progress bar should show up in the VBox and pulse while DoThread fills up the TreeStore, then show up the TreeView in the same position. When you press the button for the first time, it works magically. But when you try it after that, it freezes the application. I think I used threads_enter() and threads_leave() according to the golden rules so I don't really get what's wrong. My guess would be some glade bug. The other possible reason is probably that I'm just plain stupid and messed up something very hard. Any ideas? It works here on my system, only glitch is a white box smaller than the target shows briefly during the transition. my system currently: gentoo x86, 32bit (the -r1 in the package versions are gentoo ebuild revisions) gtk+-2.6.4-r1, has this patch applied # fix #86979 bmp_reject_corrupt.patch pygtk-2.6.1 python-2.3.4-r1 with all these patches: sed -ie 's/OpenBSD\/3.\[01234/OpenBSD\/3.\[012345/' configure || die OpenBSD sed failed #Fixes security vulnerability in XML-RPC server - pythonhead (06 Feb 05) #http://www.python.org/security/PSF-2005-001/ epatch ${FILESDIR}/${PN}-2.3-xmlrpc.patch # adds /usr/lib/portage/pym to sys.path - liquidx (08 Oct 03) # prepends /usr/lib/portage/pym to sys.path - liquidx (12 Apr 04) epatch ${FILESDIR}/${PN}-2.3-add_portage_search_path_take_2.patch # adds support for PYTHON_DONTCOMPILE shell environment to # supress automatic generation of .pyc and .pyo files - liquidx (08 Oct 03) epatch ${FILESDIR}/${PN}-2.3-gentoo_py_dontcompile.patch epatch ${FILESDIR}/${PN}-2.3.2-disable_modules_and_ssl.patch epatch ${FILESDIR}/${PN}-2.3-mimetypes_apache.patch epatch ${FILESDIR}/${PN}-2.3-db4.2.patch # installs to lib64 [ ${CONF_LIBDIR} == lib64 ] epatch ${FILESDIR}/python-2.3.4-lib64.patch # fix os.utime() on hppa. utimes it not supported but unfortunately reported as working - gmsoft (22 May 04) [ ${ARCH} = hppa ] sed -e 's/utimes //' -i ${S}/configure -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] threading
On Wed, 2005-13-04 at 09:16 -0400, John Ehresman wrote: Brian wrote: try setting the environment variable PYGTK_USE_GIL_STATE_API to true before calling gobject.threads_init() Johan It locks up at another thread that produces the data needed for a different view. What version of Python and of pygtk are you using? What platform are you on? Thanks, John python-2.3.4, pygtk-2.6.1, gtk+-2.6.4 There are things in that thread are are a no-no. When I re-wrote it to add a bunch of things I call some other code that builds a gtk.TreeStore then it traverses it to build the data (another gtk.TreeStore) I need. It wasn't till I was nearly finished debugging that I realized I was multi-threading gtk calls. I tried adding the gtk.thread_enter/leave() pair but I think things froze up. I have not had the time nor have I been able to get my brain to concentrate on re-writing a version that is thread friendly. But interestingly enough, that thread has never otherwise caused a crash. Thanks everyone. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] threading
I have a problem in that another python program (not under our development) we import is not thread friendly. The problem I have is that mostly it is imported and used from the base thread, but there are several areas of code that need to run from a thread so as to not tie up the mainloop and general gui operations. The result is intermittent segfaults/ lately it does: Fatal Python error: PyThreadState_Get: no current thread Killed I have thought of recoding and spawning a process that imports the program to act as a server, but that would entail pickling/unpickling the python data types to pass thru pipes, etc.. Is it possible to run the mainloop of our program from another thread? Is it dfficult/not advisable? -- Brian Dolbec [EMAIL PROTECTED] -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] threading
On Wed, 2005-13-04 at 01:17 -0300, Johan Dahlin wrote: Brian wrote: I have a problem in that another python program (not under our development) we import is not thread friendly. The problem I have is that mostly it is imported and used from the base thread, but there are several areas of code that need to run from a thread so as to not tie up the mainloop and general gui operations. The result is intermittent segfaults/ lately it does: Fatal Python error: PyThreadState_Get: no current thread Killed try setting the environment variable PYGTK_USE_GIL_STATE_API to true before calling gobject.threads_init() Johan It locks up at another thread that produces the data needed for a different view. It is showing that different view and then activating the problem thread that seems to cause the intermittent segfaults/PyThreadState_Get more often. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Application responsiveness problem (advanced)
On Fri, 2005-01-04 at 13:52 +0200, Antoon Pardon wrote: On Thu, Mar 31, 2005 at 10:12:12PM -0800, Brian wrote: On Thu, 2005-31-03 at 11:39 +0200, Lszl Monda wrote: On Wed, 2005-03-30 at 19:54 -0800, John Finlay wrote: Lszl Monda wrote: Could anyone shed some lights on what's really going on here? Well, problem solved, great. There were some minor errors in the code beyond thread.start(). I corrected them all and attached the source. It would make a nice threading example IMO. I don't remember any examples where more than one thread would manipulate the GUI simultaneously. Someone could add it to some parts of the documentation or should I contact with a documentation manintainer? Here is a different way for threads to communicate between each other. This way you can keep all GUI stuff in one thread only. I have updated the example code to include some of your examples features. The dispatcher code has been created to be very generic so that it can pass most any data between threads safely. The majority of the code I fear that your code can become very unresponsive in particular circumstances. AFAICS you have no saveguard against multiple threads producing data more rapidly than the gtk-thread can handle. My experience is that when that happens, resons suffers. Actually I just changed the other example to 4 threads and it stalled out the whole desktop. The mouse was even extremely unresponsive. I changed mine to 4 threads, even commented out the sleep time. The window did not update ongoing but stayed blank till about half way thru, then updated again at the end. The desktop remained responsive throughout. The reason the desktop remained responsive is that the dispatcher() uses a queue to pass the data which will store up the data until the gui thread retrieves it. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Application responsiveness problem (advanced)
On Thu, 2005-31-03 at 11:39 +0200, Lszl Monda wrote: On Wed, 2005-03-30 at 19:54 -0800, John Finlay wrote: Lszl Monda wrote: Could anyone shed some lights on what's really going on here? Well, problem solved, great. There were some minor errors in the code beyond thread.start(). I corrected them all and attached the source. It would make a nice threading example IMO. I don't remember any examples where more than one thread would manipulate the GUI simultaneously. Someone could add it to some parts of the documentation or should I contact with a documentation manintainer? Here is a different way for threads to communicate between each other. This way you can keep all GUI stuff in one thread only. I have updated the example code to include some of your examples features. The dispatcher code has been created to be very generic so that it can pass most any data between threads safely. The majority of the code -- Brian [EMAIL PROTECTED] dispatcher.py Description: application/python ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] setting tags for text at runtime
On Sun, 2005-27-03 at 08:51 -0500, Saurabh Wagh wrote: Hey there , As posted in a different query, i ve been able to achieve printing the contents of a list on a textview, one string on a line. I am facing another problem. The list that i get is at runtime , from the server ( as a result of xmlrpc call ) and i am displaying the contents of the list on a textview using the code : ( variable name for list is result ) for text in result: textbuffer.insert_at_cursor(text+'/n') I ve got to make hyperlink for each item ( which points to a different link ) so i had to use tags for each item. Now, since each link is different, i ve to identify each click as a distinct click and, ideally, the code for that could have been : iter1 = textbuffer.get_start_iter() iter2 = textbuffer.get_start_iter() for text in result: textbuffer.insert_at_cursor(text) iter2.forward_word_end() textbuffer.apply_tag(tag,iter1,iter2) iter2 = iter1.forward_line() iter1 = iter2.copy() However this code gives me an error as iters are invalidated if buffer is modified. I however have to give tags in the same loop as i put things on buffer as i need to get their identity while making the links. Could this be achieved. I ve tried Text Marks but the tags to be applied cant take marks as parameters but only iters. Can any one help me out with this problem ? -- Saurabh Take a look at summary.py in our code. It handles multiple url's mouse motion, highlighting, etc.. http://cvs.sourceforge.net/viewcvs.py/*checkout*/porthole/porthole/summary.py?rev=1.21 -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] os.popen to gtk.TextView
On Fri, 2005-25-03 at 09:46 +0100, Marcus Habermehl wrote: Fernando San Martn Woerner schrieb: El mi, 23-03-2005 a las 21:27 +0100, Marcus Habermehl escribi: Hi. I want to write the output of os.popen('command') to a gtk.TextView. there's the example http://cvs.gnome.org/viewcvs/gnome-python/pygtk/examples/ide/gtkcons.py?view=markup That could be what I'm searching for. But I think that I doesn't understand the script realy. :( I think the class gtkoutfile in this script is interesting for me. But there are so many token like __w, __b, __fn, a, etc. That makes me perplexes. :( Sorry. Marcus def __init__(self, w, fn, font): self.__fn = fn self.__w = w self.__b = w.get_buffer() self.__ins = self.__b.get_mark('insert') self.__font = font you can simply rename them. def __init__(self, w, fn, font): self.passed_fn = fn self.use_this_window = w self.the_textbuffer = w.get_buffer() self.insert_mark = self.__b.get_mark('insert') self.__font = font If you want full terminal capability you can use the vte terminal widget. It is the library widget that gnome-terminal uses. It has a python interface, not as complete as the 'c' interface, but does work. It will give you a full speed fully working terminal in a pygtk app. http://developer.gnome.org/arch/gnome/widgets/vte.html -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] TextView: signal when cursor changes position
On Fri, 2005-25-03 at 21:54 +0100, Hans-Joachim Widmaier wrote: Brian: On Fri, 2005-25-03 at 17:40 +0100, Hans-Joachim Widmaier wrote: Hans-Joachim Widmaier: I'm using cursor-changed, which seems to get emitted on all changes. Works great for me. Gah! Have to follow up on my own post. (Never post when in a hurry!) Sorry, I misread TextView for TreeView. There's probably no cursor-changed signal on the former. It is cursor_changed for list and tree views Sorry, I can't see your point. There isn't a gtk.List nor a gtk.ListView, and the signal is shown with a hyphen in the pygtk 2 reference. And it definately works in that spelling in my code. No offence meant, really, None taken. :) I know, the list stuff was deprecated I believe. I just checked, the spelling cursor_changed has been working in our code for a year now. I wasn't the one to code that one, but I just double checked, and it works both spellings. I just checked glade and it shows the signal with the underscore, while in Idle's shell a help(gtk.TreeView) shows it with a hyphen. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] window_state_event
I have been trying in vane to figure out the event that triggers the window_state_event callback. The docs are as clear as mud! I am trying to get the minimize and restore events so I can change the window title to the same as the statusbar message when the window is minimized. Then restore the title along with the window for normal viewing. Does anyone know how to decipher the event passed to the callback for these to user actions? Any help is very much appreciated. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] [OFF-TOPIC] Reply-To
On Sun, 2005-20-03 at 11:28 -0300, Eric Jardim wrote: Is the reply-to correctly set on the list? I just replied an email to Brian and it only return to him. Then I resent it to the list. Is this behaviour correct? Or is this some 'gmail' side-effects? thanks, [Eric Jardim] Apparently it is not recommended for lists to set the reply-to field back to the list. But I don't know the details. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] window_state_event
On Sun, 2005-20-03 at 11:09 -0300, Eric Jardim wrote: On Sat, 19 Mar 2005 22:40:54 -0800, Brian [EMAIL PROTECTED] wrote: I have been trying in vane to figure out the event that triggers the window_state_event callback. The docs are as clear as mud! I am trying to get the minimize and restore events so I can change the window title to the same as the statusbar message when the window is minimized. Then restore the title along with the window for normal viewing. When PyGTK is not enough you can always apeal to the GTK+2.0 docs: http://www.gtk.org/api/2.6/gtk/index.html http://www.gtk.org/api/2.6/gdk/index.html But in this case I think everything you need is in: http://www.pygtk.org/pygtk2reference/class-gdkevent.htm There it says: The attributes available for a gtk.gdk.Event are dependent on the type of the event. The event types are described in the Description section. Look carefully at the gtk.gdk.WINDOW_STATE section.. I did, obviously though not carefully enough :) Does anyone know how to decipher the event passed to the callback for these to user actions? You can always use a friendly dir(event) function. I did it and discovered that there is a new_window_state. There is also a change_mask, but I dont think it will help you. Study and meditate on the code below and I think your questions will be answered. state = event.new_window_state That did it. I must have been too tired, I didn't see to add the reference to .new_window_state Hope helped, [Eric Jardim] Yes, it did. Thanks... -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] window_state_event
On Sun, 2005-20-03 at 11:09 -0300, Eric Jardim wrote: import gtk import gtk.gdk as gdk def quit(data=None): gtk.main_quit() def window_event(window, event): state = event.new_window_state if state == 0: window.set_title('Normal') elif state == gdk.WINDOW_STATE_ICONIFIED: window.set_title('Iconified') elif state == gdk.WINDOW_STATE_MAXIMIZED: window.set_title('Maximized') window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.connect('destroy', quit) window.connect('window-state-event', window_event) window.set_title('Normal') window.show() gtk.main() Hope helped, [Eric Jardim] This code does not always work as expected. This is due to the new_window_state and changed_mask possibly having more than one flag attached. The event.new_window_state and event.changed_mask are enumerated data types. Here is an example of the event.new_window_state passed to the callback function: (actual debug print of event.new_window_state) flags GDK_WINDOW_STATE_ICONIFIED | GDK_WINDOW_STATE_MAXIMIZED of type GdkWindowState So far I have not found out how to properly look for a specific flag when there are more than one. I have found this doc http://www.python.org/workshops/1994-11/BuiltInClasses/BuiltInClasses_5.html which describes how to integrate CType structures into python. It is seems too terse for my understanding though. I have got some code working (so far) using the change_mask which so far is only passing one flag, but in the docs it states that it too can have combinations of flags. [quote] changed_mask Read/Write The mask specifying what flags have changed - a combination of:...[snip] [/quote] working code: def new_window_state(self, widget, event): set the minimized variable to change the title to the same as the statusbar text dprint(event.new_window_state) # debug print statements dprint(event.changed_mask) if event.changed_mask == gtk.gdk.WINDOW_STATE_ICONIFIED: if not self.minimized: dprint(TERMINAL: new_window_state; event = minimized) self.minimized = True self.window.set_title(self.status_text) else: # self.minimized: dprint(TERMINAL: new_window_state; event = unminimized) self.minimized = False self.window.set_title(self.title) return False A potential problem with this code is if the self.minimized variable gets out of sync with the actual window state. Anyone know how to do correctly? -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] window_state_event
On Mon, 2005-21-03 at 01:49 -0300, Eric Jardim wrote: On Sun, 20 Mar 2005 20:08:59 -0800, Brian [EMAIL PROTECTED] wrote: This code does not always work as expected. This is due to the new_window_state and changed_mask possibly having more than one flag attached. The event.new_window_state and event.changed_mask are enumerated data types. Hmm, that is right. You may have to change the '==' tests to a bitwise 'and' comparison: (...) if state gdk.WINDOW_STATE_ICONIFIED: window.set_title('Iconified') (...) If you just want to have a flag to know that it is iconified you can do something like: class MyWindow(GtkWindow): def __init__(self): self.minimized = False ... def new_window_state(self, widget, event): state = event.new_window_state if state gdk.WINDOW_STATE_ICONIFIED: self.minimized = True else self.minimized = False I think that what you want to do is simple, so do not complicate it :) [Eric Jardim] That's better. I knew there had to be an easy way. I just was not finding it. In fact I googled the hell out of it but could not find anything that listed comparison operators for it. Thanks again -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] freeze problem
On Mon, 2005-14-03 at 13:23 +0100, Le Boulanger Yann wrote: Hi, I've a problem when I use gtk.Dialog.run() funtion in a thread I attached a small example that shows the problem. If you run test.py, it works (in this case threads are not used). But now if you run core.py (which launch a thread that does exactly the same thing) when I press a key in the dialog window, the dialog is not destroyed and the application freezes. I don't understand why this happens and what can I do to have it working with threads. My intention is from the thread to run() the dialog and wait for the user to give the password and then use it. run() would normally do this, but it freezes with threads. I saw a workaround in FAQ 10.17 (about dialog.run running in the mainloop), but that won't block in a mainloop so it doesn't suit me. does someone has an idea ? You are running the dialog from a thread which is not good. You should run all gui stuff from the main thread, even if they are controlled by other threads. Here is an example of thread safe communication and control that can easily be changed to do what you were trying to do in your core.py. The dispatcher function in this example can pass arbitrary data between threads as long as each party knows what to expect. This makes it very universal so that it can be used by many different threads with different data passing needs. -- Brian [EMAIL PROTECTED] dispatcher.py Description: application/python ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] dynamic tooltip not working with new toolbar API
Here are some code snipits, This code works correctly for the old tollbar API, but the new toolbar API only shows tooltips preset in the glade file. Not the one set dynamically Anyone know what has to be done differently? I know there was a bug about that a while back, but it was supposed to be fixed. # setup a convienience tuple self.tool_widgets = [emerge_package1,adv_emerge_package1,unmerge_package1,btn_emerge, btn_adv_emerge,btn_unmerge, btn_sync] self.widget = {} for x in self.tool_widgets: self.widget[x] = self.wtree.get_widget(x) if not self.widget[x]: dprint(MAINWINDOW: __init__(); Failure to obtain widget '%s' %x) # get an empty tooltip self.synctooltip = gtk.Tooltips() self.sync_tip = _( Syncronise Package Database \n The last sync was done:\n) self.synctooltip.set_tip(self.widget[btn_sync], self.sync_tip + self.last_sync) self.synctooltip.enable() -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] CellRendererText doesn't have clicked signal now what?
On Sat, 2005-19-02 at 14:15 +0200, Nikos Kouremenos wrote: I have a treeview with: COL1 COL2 COL3 toggle | string | string I want if the user clicks on the text on a row of *col2* or *col3* to toggle the bool in the *col1*. I cannot find a way to do that in GTK. Here are some code snipits from our app that do the same as you want. In this case the first time a row is clicked it only selects that row, the toggle is only changed on every other click in that same row. I hope it is clear enough for you. class PackageView(CommonTreeView): Self contained treeview of packages def __init__(self): Initialize # initialize the treeview CommonTreeView.__init__(self) # setup the treecolumn self._column = gtk.TreeViewColumn(_(Packages)) self._column.set_resizable(True) self.append_column(self._column) # connect to clicked event self.connect(cursor_changed, self._clicked) def _init_view(self): Set the treeview column # add the toggle renderer check = gtk.CellRendererToggle() self._column.pack_start(check, expand = False) self._column.add_attribute(check, active, 1) # set the last selected to nothing self._last_selected = None def _clicked(self, treeview, *args): Handles treeview clicks # get the selection package = get_treeview_selection(treeview, 1) if not package: if self._package_changed: self._package_changed(None) return if package.full_name == self._last_selected: model, iter = self.get_selection().get_selected() check = model.get_value(iter, 1) model.set_value(iter, 1, not check) self._last_selected = package.full_name -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] unicode error
One of the users of our program is having a problem. ordinateur gnoniqoz # porthole pycrash module not found. For best debug info Please emerge = dev-python/pycrash-0.4pre2 Traceback (most recent call last): File /usr/bin/porthole, line 59, in ? import gtk, time File /usr/lib/python2.3/site-packages/gtk-2.0/gtk/__init__.py, line 33, in ? import gobject as _gobject ImportError: /usr/lib/python2.3/site-packages/gtk-2.0/gobject.so: undefined symbol: PyUnicodeUCS4_AsUnicode I know that any previous problems with gtk have turned out to be permissions not set correctly. Any ideas what to look for? Thank you. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] unicode error
On Wed, 2005-09-02 at 16:03 +0900, Guillaume Proux wrote: Hi Brian, Not sure I am barking the right tree, but I am pretty sure that Python can be compiled to represent unicode object either with UCS2 or UCS4. Check that out: http://python.fyxm.net/doc/FAQ.html#id182 Ah the joy of the i compile all myself distribs ;) G Thanks. There was a security update to python just released. It looks like a pygtk re-install should fix the unicode mismatch. Brian wrote: One of the users of our program is having a problem. ordinateur gnoniqoz # porthole pycrash module not found. For best debug info Please emerge = dev-python/pycrash-0.4pre2 Traceback (most recent call last): File /usr/bin/porthole, line 59, in ? import gtk, time File /usr/lib/python2.3/site-packages/gtk-2.0/gtk/__init__.py, line 33, in ? import gobject as _gobject ImportError: /usr/lib/python2.3/site-packages/gtk-2.0/gobject.so: undefined symbol: PyUnicodeUCS4_AsUnicode I know that any previous problems with gtk have turned out to be permissions not set correctly. Any ideas what to look for? Thank you. -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] detect libglade-2.4.1
On Fri, 2005-07-01 at 14:18 +, Stephen Kennedy wrote: I'm trying to work around this bug where old glade files do not load with libglade-2.4.1 http://bugzilla.gnome.org/show_bug.cgi?id=160586 One workaround is to ship two sets of glade files and choose which one to load based on the libglade version. Any ideas on how to programmatically determine libglade version? Or any other workarounds? Stephen. Here is how I did it so far on a gentoo system. Your method for checking the installed version will be different for a different distribution. ver_match() pads the version strings to three digits per so 2.4.1 would become 002.004.001-r000. -r000 being the install ebuild revision number. Then checks for a match in the ranges specified. portagelib is our programs interface to the imported portage modules (gentoo's package management system). I will most likely need to modify the code to choose which version to use if both ranges are installed. In gentoo I recommended that libglade-2.4.1 be masked due to bugs and incompatibility with existing apps. I also recommended it be slotted differently than current libglade-2 versions (which could mean there may be up to 3 simultaneous libglade versions installed on the system). def check_glade(): determine the libglade version installed and return the correct glade file to use porthole_gladefile = porthole.glade # determine glade version versions = portagelib.get_installed(gnome-base/libglade) if versions: dprint(versions) old, new = ver_match(versions, [2.0.1,2.4.0-r99], [2.4.1,2.99.99]) if old: porthole_gladefile = porthole.glade elif new: porthole_gladefile = porthole-new.glade else: dprint(MAINWINDOW: No version list returned for libglade) return None dprint(MAINWINDOW: __init__(); glade file = %s %porthole_gladefile) return porthole_gladefile def ver_match(versions, range1, range2 = None): looks for a version match in range1 and optionaly in range2 if not versions: return None plist = pad_ver(get_versions_only(versions)) r1 = pad_ver(range1) if range2: r2 = pad_ver(range2) if not plist: dprint(VERSION_SORT: ver_match(); plist[] creation error) return False, False match1 = False match2 = False for x in plist: if (x = r1[0] and x = r1[1]): dprint(VERSION_SORT: ver_match(); match1 %s, %s:%s %(x,r1[0],r1[1])) match1 = True if range2 and (x = r2[0] and x = r2[1]): dprint(VERSION_SORT: ver_match(); match2 %s, %s:%s %(x,r2[0],r2[1])) match2 = True return match1, match2 class MainWindow: Main Window class to setup and manage main window interface. def __init__(self, preferences = None, config = None): preferences.use_gladefile = check_glade() # setup prefs self.prefs = preferences self.config = config # setup glade self.gladefile = self.prefs.DATA_PATH + self.prefs.use_gladefile self.wtree = gtk.glade.XML(self.gladefile, main_window, self.prefs.APP) [snip] -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] easy hyperlink builder (email-http link)
On Mon, 2004-27-12 at 21:01 -0500, Francis Lavoie wrote: David Eriksson wrote: On Sun, 2004-12-26 at 12:33 -0500, Francis Lavoie wrote: Is there an easy way to put mail link and http link on a textlabel? I use pango markup like this : span foreground=#99 underline=single weight=bold[EMAIL PROTECTED]/span but it's not automaticly clickable to open the default mail-client. And it is not theme-friendly Is there another way to go that I mist? Thank you Here are some code snipits from our project. I hope they help. I did not code it, Someone else patched it to use multiple links. You can find the project homepage along with a few screenshots here: http://porthole.sourceforge.net/ The source file of the snipits, summary.py here: http://cvs.sourceforge.net/viewcvs.py/porthole/porthole/summary.py?rev=1.20view=auto def __init__(self): # Capture any mouse motion in this tab so we # can highlight URL links change mouse pointer self.connect(motion_notify_event, self.on_mouse_motion) # List of active URLs in the tab self.url_tags = [] self.underlined_url = False def on_url_event(self, tag, widget, event, iter): Catch when the user clicks the URL if event.type == gtk.gdk.BUTTON_RELEASE: load_web_page(tag.get_property(name)) def on_mouse_motion(self, widget, event, data = None): # we need to call get_pointer, or we won't get any more events pointer = self.window.get_pointer() x, y, spam = self.window.get_pointer() x, y = self.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, x, y) tags = self.get_iter_at_location(x, y).get_tags() if self.underlined_url: self.underlined_url.set_property(underline,pango.UNDERLINE_NONE) self.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(None) self.underlined_url = None for tag in tags: if tag in self.url_tags: tag.set_property(underline,pango.UNDERLINE_SINGLE) self.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(gtk.gdk.Cursor (gtk.gdk.HAND2)) self.underlined_url = tag return gtk.FALSE def append_url(text): Append URL to textbuffer and connect an event tag = self.buffer.create_tag(text) tag.set_property(foreground,blue) tag.connect(event, self.on_url_event) self.url_tags.append(tag) append(text, tag.get_property(name)) # Insert homepage(s), if any x = 0 if homepages: for homepage in homepages: if x 0: append( ', ') append_url(homepage) x += 1 nl(2) -- Brian [EMAIL PROTECTED] ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] GenericCellRenderer problem
I am trying to implement a custom cell renderer by subclassing gtk.GenericCellRenderer. The on_activate and on_start_editing methods of gtk.GenericCellRenderer are never called, although on_get_size and on_render work fine. Is there something I am missing? Do these functions work? ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] feature request: binding for gtk_propagate_event?
With gtk1/gnome1, binding the signals seems to happen when a widget-tree is added to the AppletWidget container. So, if you add Buttons to a GtkHBox, and then add that box to the AppletWidget, the button-events are processed by the panel. If you first add the GtkHBox, and then add the buttons to the GtkHBox, then those buttons receive events button2 and button3. Some explicit mechanism for gnome2 to bind the signals would be better. Hmm, interesting that you mention this layout, because I just tried the same hack with a different applet (one that puts a GtkButton and a GtkProgressBar into a VBox, then the VBox in the applet), and in this case the hack does not help. I suspect the signals are being sent to the VBox, which ignores them. So the menu is accessible by button3 from within the progress bar, but not from the button (just as it without the parent.emit hack). Am I right in thinking that events are propagated backwards (from window to parent window and so on up to the root window) until somebody claims them, but that gtk signals are not? That might be why the gnome-applets authors used gtk_propagate_event instead of re-emitting signals: the immediate parent might not be the appropriate recipient. More ideas are most welcome.. thanks, -Brian ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] feature request: binding for gtk_propagate_event?
Have you tried container.emit() instead of propagate_event? I think there's a good chance of it working. Thanks, that seems to help. The right-clicks now drop through to the underlying panel and manage to bring up the menu (and make it go away again). I haven't figured out how to send button2 through (to invoke the drag-applet stuff), but I figure I'll probably have to look more deeply into gnome-panel to figure out what events it wants to receive that the GtkButton is consuming. I still wish I knew why this stopped working in Gnome2. I'm pretty sure it was easier to use back in Gnome1. For reference, here's the pair of helper functions I ended up using. Just use MyButton() whereever you'd use gtk.Button(), and mouse2/3 press/release events will be sent up to the Button's container: def button_hack_helper(widget, event, updown): if event.button != 1: if updown == press: widget.parent.emit(button_press_event, event) else: widget.parent.emit(button_release_event, event) return gtk.TRUE return gtk.FALSE def MyButton(): b = gtk.Button() b.connect('button_press_event', button_hack_helper, press) b.connect('button_release_event', button_hack_helper, release) return b thanks for the help, -Brian ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] feature request: binding for gtk_propagate_event?
Howdy all.. I've been trying to rewrite my python/gnome1 -based applets in python/gnome2 (somewhat forced into it because of the recent debian/unstable gnome2 switch). One of the more significant changes in gtk2/gnome2 that shows up in panel applets is that right-clicks on top of GtkButtons no longer result in the applet's menu appearing. I don't know if this is because GtkButtons consume the button2 and button3 events instead of passing them up to their containers (they do, but from what I can tell they did in gtk1.2 as well) or because the new bonobo-based libpanel-applet system does something different than the old applet-widget scheme (it does, but I don't know if it is not implementing an old workaround or if something else changed). The net result is that, in the applets I write that contain buttons, it is difficult to get to the applet's context menu (to configure or remove the applet). If the applet is all button, it is impossible. Several of standard Gnome applets (in gnome-applets-2.0.3), drivemount and mini-commander in particular, have a hack to work around this. The hack adds a signal handler to the GtkButton which catches button2/button3 and uses gtk_propagate_event() to send the event off to the applet as a whole, which responds by putting up the context menu. button1 events are ignored/refused; the signal handler returns FALSE to let the event go to the GtkButton as usual. In lieu of seeing GtkButtons changed to let button2/button3 events get passed along to their containers, I wanted to implement this same hack in my python applets. But gtk_propagate_event() is missing from the python binding, as it is listed in an %ignore clause in the gtk.override file. Any idea why there is no binding for this function? Or how hard it would be to add one? If there's a better workaround for this problem I'd love to hear it, but I suspect a real fix would involve changes to gtk that aren't going to happen any time soon. thanks, -Brian ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Building on cygwin
Then [EMAIL PROTECTED] spoke up and said: First of all, are you talking about porting pygtk on cygwin using XFree (http://cygwin.com/xfree/) or the win32 port of gtk+ (as available from http://www.gimp.org/win32/) ? If you plan to use XFree, things should be xfree. I'm a unix sysadmin and would normally run linux or freebsd on my laptop, but it turns out I also need access to Windows software. My solution is to use the cygwin package with the cygwin port of xfree. It works extremely well, and building packages mostly just works. P.S. : what do you mean by the binary package is not cygwin friendly. You use python as provided by the cygwin distribution ? If it's the case, you must use XFree and port gtk+ and pygtk accordingly. Exactly. Sorry, I should have specifically mentioned xfree. In any event, it configures/builds just fine, except that when I try to use it, I discover that none of the widgets exist. pretty straightforward using the configure script. You might have to fight with dlltool/dllwrap to generate the _gtk.pyd though. If you want to use What's a .pyd? Also, there doesn't seem to be a Makefile rule for the creation of _gtk.py*. Perhaps this is my problem? ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Building on cygwin
Then [EMAIL PROTECTED] spoke up and said: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9) Gecko/20020311 What's a .pyd? Also, there doesn't seem to be a Makefile rule for the creation of _gtk.py*. Perhaps this is my problem? For some reason, with the windows version of python, they sometimes rename the dll extension modules to the extension .pyd (they are still dlls). The pygtk build should build and install a shared library called _gtkmodule.dll. Does htis build okay on cygwin? Hrm. It seems to only be building .a files, not .dll (or .pyd, or anything else). It is possible that the problem you are seeing is that the GTK.py file overwrote the gtk.py file when unpacking the tarball. This problem has been fixed on the development branch, but remains broken on the stable branch (renaming the module would break compatibility). This is definitely what happened! For my own installation (where I don't use GTK.py), I've now renamed GTK.py to GTK_.py (and updated the references). Now to convince it to build the .dll. msg03756/pgp0.pgp Description: PGP signature
Re: [pygtk] Strange error.
On Thu, 2002-01-03 at 06:37, Morelli Enrico wrote: I have to create a temporary directory to copy some data (no problem using os.mkdir), but if the directory exist, the program must remove it. Why are you using system? import shutil shutil.rmtree(self.CDR_multi) -- = | JAVA must have been developed in the wilds of West Virginia. | | After all, why else would it support only single inheritance??| = | Finger [EMAIL PROTECTED] for my public key.| = ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] Greetings!
Greetings! I'm a Python/pygtk newbie, looking for documentation (or outright help ::grin::). I'm working on a program where I'd like to be able to swap window-widget sub-sets around with other pre-defined widget sub-sets, if this is possible. I'm not sure how to explain exactly what I'm trying to do, so I'll spew out a quick example. Starting with the window pictured at http://linus.smenet.org/~ballbee/pygtklist/main_window.gif I'd like to have it load the widget-set from another window, pictured at http://linus.smenet.org/~ballbee/pygtklist/log_in_form.gif into the viewport on the right on launch, and after a successful log-in, swap _that_ widget-set out (again) with the widget-set shown at http://linus.smenet.org/~ballbee/pygtklist/chronicle_properties.gif Hope that makes sense... Any help would be appreciated (even if it's a RTFM comment, if you can tell me where TFM is ::grin::) +--+ | Brian Allbee | | [EMAIL PROTECTED] | +--+ ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk