Re: [pygtk] Translation: Different locales directories

2010-05-31 Thread Walter Leibbrandt
Op 30/05/2010 18:04, het Cornelius Kölbel geskryf:
> Hello List,
>
> i got an application with translation.
>
> I am doing this...
>
>  gettext.bindtextdomain(APP_NAME, LOCALE_DIR)
>  gettext.textdomain(APP_NAME)
>
> But my problem is, that I do different packaging types like source, deb
> and rpm. In these different cases, the location of the mo file is not
> the same for the different packages.
>
> What is the recommended way to handle this?
> Can I provide more than one locale dirs?
> Should I change the code, for each packaging type?
> Should I set an environment variable that contains the correct locales dir?
The get_abs_data_filename() function [1] as used by Virtaal [2] does the 
job on at least Windows and Linux, running from source or from intsallation.

Another solution I've seen is to calculate this location on installation 
and programmatically change a specific source file, from where this 
value is imported/accessed by the application.

[1]: 
https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/translate/misc/file_discovery.py
[2]: 
https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/baseview.py

HTH,
-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Ubuntu PPA for Translate Toolkit and Virtaal
http://www.translate.org.za/blogs/walter/en/content/ubuntu-ppa-translate-toolkit-and-virtaal

___
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] Any way to create a drop down menu for a button without using gtk.MenuToolButton?

2010-05-14 Thread Walter Leibbrandt
Op 14/05/2010 17:02, Smartboy het geskryf:
> Specifically, I
> am looking at giving switchButton a drop down menu.
I implemented this for the main project I'm working on at the moment:
https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/widgets/popupbutton.py

The biggest issue I had was calculating the menu's position (relative to
the button, see the _calculate_popup_pos() method), but it's mostly working.

HTH,
-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Ubuntu PPA for Translate Toolkit and Virtaal
http://www.translate.org.za/blogs/walter/en/content/ubuntu-ppa-translate-toolkit-and-virtaal

___
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] pygtk.glade import problem

2010-04-30 Thread Walter Leibbrandt
Op 30/04/2010 16:28, Krisztian Buza het geskryf:
> Dear Colleagues,
>
> I am new with Python. I have installed Python (version 2.6), PyGTK and
> Glade (http://ftp.gnome.org/pub/GNOME/binaries/win32/glade3/) under
> Windows.
>
> The
>
> "import pygtk"
>
> command works nice (i.e. without error message), but
>
> "import pygtk.glade"
>
> does not seem to work: I get this error message:
>
> "No module named glade".
>
> I tried to add the glade-directories to the path:
> C:\Program Files\Glade\lib\glade3\modules;C:\Program Files\Glade\bin;
>
> May be, I did not add the right glade directories?
>
> Could anyone help me?
>
> Thank you very much in advance,
>

The "pygtk" module is not really the module you're looking for; it's 
usually only used for pygtk.require(). The actual GTK stuff is in the 
"gtk" module, which puts Glade in "gtk.glade" and not "pygtk.glade".

Regards,
-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Ubuntu PPA for Translate Toolkit and Virtaal
http://www.translate.org.za/blogs/walter/en/content/ubuntu-ppa-translate-toolkit-and-virtaal

___
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] Get textview from scrolledwindow

2010-03-02 Thread Walter Leibbrandt
Op 02/03/2010 12:44, Alexander Kuleshov het geskryf:
> Hi to all. I have one gtk.ScrolledWindow and gtk.textView in it. How
> can i get this textview?
textview = scrolledwindow.child
-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Ubuntu PPA for Translate Toolkit and Virtaal
http://www.translate.org.za/blogs/walter/en/content/ubuntu-ppa-translate-toolkit-and-virtaal

___
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] where is the api for "window.connect"

2009-12-07 Thread Walter Leibbrandt
Op 07/12/2009 13:05, engine spot het geskryf:
>  When I learn the tutoral ,I find this code
>
>  self.window.connect("destroy", self.destroy)
>
>  but when I search pygtk 2.0 reference manual,I can not find the
> api , only what I do is I know or I can guess the meaning of it
>
>  the trtoral is in
> http://www.pygtk.org/pygtk2tutorial/ch-GettingStarted.html#sec-HelloWorld
All widgets inherit from GObject, where connect() comes from.

http://library.gnome.org/devel/pygobject/stable/class-gobject.html#method-gobject--connect
-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Ubuntu PPA for Translate Toolkit and Virtaal
http://www.translate.org.za/blogs/walter/en/content/ubuntu-ppa-translate-toolkit-and-virtaal

___
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] Popup always on top of everything

2009-11-16 Thread Walter Leibbrandt
Op 13/11/2009 20:08, sandbox_m...@yahoo.de het geskryf:
> Dear all,
> I cannot find any information how to solve the following problem:
>
> In a window I have an entry. In order to support the user when writing
> into this entry I display a gtk.Window(gtk.WINDOW_POPUP) that looks like
> a tooltip underneath the entry whenever the user enters something wrong.
>
> My problem is that the popup window stays on top of any window and not
> only my application.
>
> How can I tell pygtk that the popup should always be on top of my
> application but should not be on top of other windows?
The work-around we use in Virtaal, is to manage the popup window's 
visibility in a manual way, ie. when the main window is shown/hidden, 
show/hide the popup too (if appropriate). If you're interested in 
looking at our approach, see 
https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/plugins/tm/tmwidgets.py
 
for the popup window and 
https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/plugins/tm/tmview.py
 
for the main window.

The popup is still not 100% "connected" to the main window (there are 
still some weird artifacts), but it helps a lot.

HTH,
-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Ubuntu PPA for Translate Toolkit and Virtaal
http://www.translate.org.za/blogs/walter/en/content/ubuntu-ppa-translate-toolkit-and-virtaal

___
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] How do I accumulate return values from a signal

2009-09-29 Thread Walter Leibbrandt
Op 29/09/2009 14:25, samwyse het geskryf:
> When my main program emits a signal, is there a best way to accumulate
> the results returned by everything that is connected?  The
> documentation refers to a gobject method that hints at doing this:
> "The signal_accumulator_true_handled() function is only used as
> accumulator argument when registering signals."  However, I see no
> other references to "accumulator arguments" anywhere.  I've also
> thought of passing, say, a list object as an extra parameter and
> letting each plug-in append to the list before returning.
>
> Finally, I intend to use the above to allow a plug-in to insert itself
> into the GUI.  Maybe I'm taking the wrong approach.  Is there a better
> way to allow a plug-in to insert action groups or add ui from a
> string?

I tend to use a slightly different approach... Since the first argument 
to a signal is always the emitting object, you have the opportunity to 
use it in any signal handler. So, in your case, you can simply use an 
attribute of the object that the handlers modify.

HTH
-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Showing the current git branch in the Bash prompt
http://www.translate.org.za/blogs/walter/en/content/showing-current-git-branch-bash-prompt

___
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] Creating an object browser

2009-08-28 Thread Walter Leibbrandt
Op 27/08/2009 19:46, Marcus Vinicius Eiffle Duarte het geskryf:
> I would like to create a GUI with sidepanel showing an "object browser",
> which is a tree of nested (graphic) objects to select. I guess the best
> screenshots of this type of application are like the ones here:
> http://www.salome-platform.org/home/screenshots/ (Salomé is a great Qt
> application, by the way). I am talking about the panel titled "Object
> Browser" on the left. Can anyone point me to some resource showing hot to do
> it with pygtk?

That looks like a simple TreeStore used with a TreeView. The first 
column of the TreeView has two cell renderers, though: a 
CellRendererPixmap for the icon and a CellRendererText for the object name.

-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Conquering the CellRendererWidget
http://www.translate.org.za/blogs/walter/en/content/conquering-cellrendererwidget

___
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] Make the TreeView widget look different (like in Transmission)

2009-07-27 Thread Walter Leibbrandt
Op 27/07/2009 09:09, ivanko.rus het geskryf:
> Hello everybody! I am making a little app here, it should be a front-end for
> mencoder and I'd like to have the file list looking like Transmission's
> (BitTorrent client) file list. So, my question is - is there a way to do
> that using PyGTK? Thanks in advance, I'll be grateful for any help!

Good news: It's definitely possible.
Bad news: It's not easy and may become messy.

The way to achive this is by creating a custom cell renderer or by using 
more than one of the standard cell renderers.

Using multiple cell renderers has the disadvantage of only being 
rendered horizontally next to each other. I am not aware of any way to 
change this behaviour (but would be glad if someone else can point it out).

Using custom cell renderers, there are, again, two options:
* Create a cell renderer that will custom-render the entire layout. In 
an attempt to achive a generic solution to this problem, I've created a 
CellRendererWidget that renders an arbitrary widget (meant to be a 
container), but it's not entirely stable. If you're interested, you can 
get the source at 
https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/widgets/cellrendererwidget.py
* Create a cell renderer that combines various other renderers. This 
seems to be a cleaner way (as well as Transmission's way) of doing 
things. Looking at lines 537-544 of 
http://trac.transmissionbt.com/browser/trunk/gtk/torrent-cell-renderer.c 
(the business end of the render_minimal() function), you can see that 
the 4 wrapped cell renderers' rendering functions are simply called with 
modified areas.

HTH,
-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Conquering the CellRendererWidget
http://www.translate.org.za/blogs/walter/en/content/conquering-cellrendererwidget

___
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] liststore column names

2009-07-20 Thread Walter Leibbrandt
Imre Horvath wrote:
> How can I get the column names in a liststore?

[column.get_title() for column in treeview.get_columns()]

I assume you are referring to the column names of a gtk.TreeView, since 
gtk.ListStores don't have column names.

-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Conquering the CellRendererWidget
http://www.translate.org.za/blogs/walter/en/content/conquering-cellrendererwidget

___
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] Problem in fetching Unicode from URL and displaying it in PyGTK widget

2009-07-17 Thread Walter Leibbrandt
Bertrand Kintanar wrote:
> On 7/17/09 9:19 PM, saeed wrote:
>> s1 = 'Guzán'
>> s2 = ''
>> n = len(s1)
>> i = 0
>> while i>if i>  if s1[i:i+3]=='&#x' and s1[i+5]==';':
>>s2 += unichr(int(s1[i+3:i+5], 16)).encode('utf-8')
>>i += 6
>>continue
>>s2 += s1[i]
>>i += 1
>> print s2
> Now this fixes it all. Thanks alot. I hope there is some sexier way to 
> do this though. but this will work. thanks again
import re
htmluni = re.compile(r'&#x([\dA-Fa-f]+);')
data = 'Guzán   Guzán'

match = htmluni.search(data)
while match:
 data = data[:match.start()] + unichr(int(match.group(1), 16)) + 
data[match.end():]
 match = htmluni.search(data)

-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Conquering the CellRendererWidget
http://www.translate.org.za/blogs/walter/en/content/conquering-cellrendererwidget

___
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] what key is pressend, key-press-event

2009-07-15 Thread Walter Leibbrandt
nohics nohics wrote:
> I found it, I think that we have to do check the string value returned by:
> gtk.gdk.keyval_name(event.keyval)
Or you can compare event.keyval to the constants defined in gtk.keysyms.
To test for modifiers like control and alt, you can test the set bits in 
event.state according to 
http://library.gnome.org/devel/pygtk/2.14/gdk-constants.html#gdk-modifier-constants

HTH,
-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Conquering the CellRendererWidget
http://www.translate.org.za/blogs/walter/en/content/conquering-cellrendererwidget

___
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] Internationalization my App

2009-06-17 Thread Walter Leibbrandt
mahdieh saeed wrote:
> every thing is OK but I want to use *built in* stock as icon .For 
> example use gtk.STOCK_OK but with *custom label* or *translation label 
> to Persian language*.
>
>
> Is there any way to do this?
The only way I've found to do this is to create a container-type button, 
add a gtk.HBox containing an image (the stock icon) and a label.

HTH,

-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Conquering the CellRendererWidget
http://www.translate.org.za/blogs/walter/en/content/conquering-cellrendererwidget


___
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] problem with focus in notebook

2009-06-04 Thread Walter Leibbrandt
Mike Bernson wrote:
> I have a notebook that I want to control where the focus goes on page 
> switches.
>
> I connect to the switch-page signal.
>
> In the handle for the switch-page signal I set the focus to a Entry widget. 
> The
> focus ends up on the tab for the page. If I call idle_add with function to 
> set the
> focus to the Entry widget it works.
>
> I do not like using the idle_add to set the focus widget. It looks like a 
> hack and
> I would like to find a better way to handle this.
>   
How about using the "show" event of one of the widgets on the page? Like 
your "top"-level container (the page's child).

HTH,

-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Conquering the CellRendererWidget
http://www.translate.org.za/blogs/walter/en/content/conquering-cellrendererwidget


___
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] Rendering arbitrary widgets in a CellRenderer

2009-05-20 Thread Walter Leibbrandt
Neil Muller wrote:
> Since you're looking to allocate enough space to display the widget,
> you shouldn't need to realize the widgets first. It looks like the
> problem is with your use of set_size_request() and get_size_request(),
> since get_size_request() only returns the values set via
> set_size_request(). Just using size_request() should do what you want.
For some inexplicable reason I've always believed that get_size_request() and 
size_request() are the same. Thank you for enlightening me, it helped a lot.

-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Conquering the CellRendererWidget
http://www.translate.org.za/blogs/walter/en/content/conquering-cellrendererwidget


___
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] Rendering arbitrary widgets in a CellRenderer

2009-05-13 Thread Walter Leibbrandt
Walter Leibbrandt wrote:
> Hi,
>
> I took another swing at creating a custom cell renderer that can render 
> any arbitrary widget in a TreeView. It currently works, albeit with a 
> few annoyances. The source is available at 
> https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/widgets/cellrendererwidget.py
>
> The widget (retrieved from the TreeView's model) is rendered by wrapping 
> it in a gtk.CellEditable, which was the only way I could find to render 
> arbitrary widgets. This means that the cell renderer must use the 
> editable mode and that the activatable mode is of no use. So the cell is 
> currently rendered in one of three states:
> * Unselected: A CellRendererText is emulatedwith the strfunc callable 
> supplying the string to render.
> * Selected (not editing): When selecting a row (with the mouse or 
> keyboard) the cell is empty. Neither the string or the widget is rendered.
> * Editing: When clicking on the cell (or pressing Enter on it) after it 
> has been selected it enters editing mode and displays the appropriate 
> widget.
>
> The problem is the second state mentioned above and that brings me to my 
> actual question: How can I get CellRenderer to enter editing mode as 
> soon as it is selected?
>
> I have tried testing the flags parameter (in on_render) for 
> gtk.CELL_RENDERER_SELECTED and then calling self.start_editing() myself. 
> I have confirmed that my on_start_editing() is indeed called, but that 
> does not seem to be enough to put the cell in editing mode and show the 
> widget.
>
> This is has been solved in Virtaal (the application I'm working on), but 
> it involved creating a custom TreeModel implementation. This model would 
> return True for get_value() calls on the (hard-coded) column number of 
> the editable property, only if the internal iterator matched the 
> get_value() call's parameter. This is a big hack I'd like to avoid in my 
> implementation. For this implementation the CellRenderer is in 
> https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/widgets/storeviewwidgets.py
>  
> and the CellEditable is in 
> https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/unitview.py
>
> Any insight would be greatly appreciated.
>
> Thanks in advance,
>
>   
I've got it working with a hack, but one important problem remains: The 
CellRenderer's size is calculated based on the string rendered for 
unselected cells. This means that, if the widget rendered in a selected 
cell needs more space than the rendered string, it is simply cut off. 
The problem (as far as I can tell) seems to arise from the fact that the 
widget to render in the cell has not yet been realize()d and thus has no 
allocation.

So this is a call to anyone who has implemented a custom cell renderer's 
do_get_size() to please take a look at the code and make any 
recommendations and/or observations that might help me calculate the 
correct size for the cell. The code is at 
https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/widgets/cellrendererwidget.py

Thanks in advance,

-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Conquering the CellRendererWidget
http://www.translate.org.za/blogs/walter/en/content/conquering-cellrendererwidget


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] Rendering arbitrary widgets in a CellRenderer

2009-05-08 Thread Walter Leibbrandt
Hi,

I took another swing at creating a custom cell renderer that can render 
any arbitrary widget in a TreeView. It currently works, albeit with a 
few annoyances. The source is available at 
https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/widgets/cellrendererwidget.py

The widget (retrieved from the TreeView's model) is rendered by wrapping 
it in a gtk.CellEditable, which was the only way I could find to render 
arbitrary widgets. This means that the cell renderer must use the 
editable mode and that the activatable mode is of no use. So the cell is 
currently rendered in one of three states:
* Unselected: A CellRendererText is emulatedwith the strfunc callable 
supplying the string to render.
* Selected (not editing): When selecting a row (with the mouse or 
keyboard) the cell is empty. Neither the string or the widget is rendered.
* Editing: When clicking on the cell (or pressing Enter on it) after it 
has been selected it enters editing mode and displays the appropriate 
widget.

The problem is the second state mentioned above and that brings me to my 
actual question: How can I get CellRenderer to enter editing mode as 
soon as it is selected?

I have tried testing the flags parameter (in on_render) for 
gtk.CELL_RENDERER_SELECTED and then calling self.start_editing() myself. 
I have confirmed that my on_start_editing() is indeed called, but that 
does not seem to be enough to put the cell in editing mode and show the 
widget.

This is has been solved in Virtaal (the application I'm working on), but 
it involved creating a custom TreeModel implementation. This model would 
return True for get_value() calls on the (hard-coded) column number of 
the editable property, only if the internal iterator matched the 
get_value() call's parameter. This is a big hack I'd like to avoid in my 
implementation. For this implementation the CellRenderer is in 
https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/widgets/storeviewwidgets.py
 
and the CellEditable is in 
https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/views/unitview.py

Any insight would be greatly appreciated.

Thanks in advance,

-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Firefox-style button with a pop-up menu
http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu


___
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] Combobox with thousands of rows

2009-03-26 Thread Walter Leibbrandt
Rob Brown-Bayliss wrote:
> I need a way to let users pick one of approx 8000 names from a list 
> and had thought to use a combobox but it is far too slow taking 
> several seconds to pop up, and scrolling is unusable.
Have you tried using multiple columns? gtk.ComboBox.set_wrap_width()
> Does any one have an idea or solution that does not take up too much 
> screen space.
If your users have a good idea of what is in the collection or what 
they're searching for, you could use a gtk.Entry with an associated 
gtk.EntryCompletion (or even a gtk.ComboBoxEntry with completion). I 
have used EntryCompletions in Spelt 
(https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/spelt/spelt/gui/edit_area.py)
 
and added some optimization hacks:
* Line 542: The completion is only done once the text in the Entry has 
reached a predetermined minimum length.
* Lines 543-548: A timeout is used to implement a delay between the last 
change made to the text and starting the completion.
* Method _complete_root(): A filtered TreeModel is used as the 
completion's model.

This approach has been tested with 100 000 rows and was still usable, 
although slightly slow.

If, on the other hand, your users have no knowledge about the data they 
are looking for, then your best bet is probably a TreeView.

-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Firefox-style button with a pop-up menu
http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu


___
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] quoting text for markup

2009-03-19 Thread Walter Leibbrandt
Hi

Darren Hart wrote:
> When adding text with an & character to a cellrenderertext I get some
> rendering glitches (and the actual text doesn't get rendered at all).
> Is there a standard mechanism for quoting text destined for the markup
> property?
Since Pango markup strings are XML strings, you should also quote your 
markup strings as such. That means that an & should become &.

HTH,

-- 
Walter Leibbrandt  Software Developer
Recent blogs:
* Firefox-style button with a pop-up menu
http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu


___
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] Fwd: Is there a way to use markup in gtk.CellRendererCombo's popup using pygtk?

2009-03-16 Thread Walter Leibbrandt
Johan Dahlin wrote:
> I tried many ways but i none worked =/
It seems not. You will need the ComboBoxEntry used internally by 
CellRendererCombo (if it even has one) in order to customise its 
CellRenderers. Inspecting a CellRendererCombo quickly, I didn't see 
anything promising.

This is the first time that I see the CellRenderer of a CellRenderer 
coming into play. :)

HTH,

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Firefox-style button with a pop-up menu
http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu
* Virtaal's MVCisation
* Things that changed the way I code


___
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] Callbacks

2009-03-11 Thread Walter Leibbrandt

Hi,

Maybe I should just let some code do the talking. See attached script.

The button's "clicked" handler adds an "x" to the entry. The toggle 
button uses handler_(un)block_by_func() on addx_clicked so that it is 
only enabled if the toggle button is active. Note that 
handler_(un)block_by_func() was called on btn, seeing as that is the 
widget to which the handler is connected.


This is quite an exciting discovery for myself too. Seeing as its in 
GObject and not in Glade, I can use this with my custom widgets too and 
need not keep signal dictionaries anymore! :)


P.S. In this context "handler" means the function/method connected to a 
signal.


Peyman wrote:

Hi Walter

I am running into problems using it. To use 
handler_bloc_by_func(callable) you have to pass callable: a callable 
python object. I have tried using the widget itself, and it's callback 
functions, but neither is working. What exactly do i have to pass as a 
parameter. You made reference to passing the "handler" to it.


Cheers



Peyman Askari

On 11 Mar 2009, at 12:53, Walter Leibbrandt wrote:


Hi,

It seems that this has been asked before: 
http://osdir.com/ml/gnome.gtk+.python/2003-04/msg00089.html


Short answer: no, it doesn't seem like you can. I have, however, 
found the handler_block_by_func() and handler_unblock_by_func() 
methods of gobject.GObject. Although I haven't tested this yet, it 
seems from the docs 
(http://library.gnome.org/devel/pygobject/stable/class-gobject.html#method-gobject--handler-block-by-func) 
that you can simply pass your handler to it to (un)block it from 
being called.


Let me know how/if it works.

HTH,

Peyman wrote:
I realize that once you call connect() it returns the handle_id. But 
if glade is doing this for me, are the handle id's stored somewhere? 
Surely there has to be a widget.get_handle_id('callback_function') 
method. I can't seem to find anything on this over the net though.


--
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Firefox-style button with a pop-up menu
http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu 


* Virtaal's MVCisation
* Things that changed the way I code






--
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Firefox-style button with a pop-up menu
http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu
* Virtaal's MVCisation
* Things that changed the way I code


#!/usr/bin/env python

import gtk
import gtk.glade

xml = gtk.glade.XML('gui.glade')
win = xml.get_widget('window')
btn = xml.get_widget('button')
entry = xml.get_widget('entry')

def addx_clicked(*args):
entry.props.text += 'x'

def enable_toggled(togglebtn):
if togglebtn.get_active():
btn.handler_unblock_by_func(addx_clicked)
else:
btn.handler_block_by_func(addx_clicked)

win.connect('destroy', lambda *args: gtk.main_quit())
btn.connect('clicked', addx_clicked)
xml.get_widget('togglebutton').connect('toggled', enable_toggled)

win.show_all()
gtk.main()


gui.glade
Description: application/glade
___
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] Callbacks

2009-03-11 Thread Walter Leibbrandt
Hi,

It seems that this has been asked before: 
http://osdir.com/ml/gnome.gtk+.python/2003-04/msg00089.html

Short answer: no, it doesn't seem like you can. I have, however, found 
the handler_block_by_func() and handler_unblock_by_func() methods of 
gobject.GObject. Although I haven't tested this yet, it seems from the 
docs 
(http://library.gnome.org/devel/pygobject/stable/class-gobject.html#method-gobject--handler-block-by-func)
 
that you can simply pass your handler to it to (un)block it from being 
called.

Let me know how/if it works.

HTH,

Peyman wrote:
> I realize that once you call connect() it returns the handle_id. But 
> if glade is doing this for me, are the handle id's stored somewhere? 
> Surely there has to be a widget.get_handle_id('callback_function') 
> method. I can't seem to find anything on this over the net though.

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Firefox-style button with a pop-up menu
http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu
* Virtaal's MVCisation
* Things that changed the way I code


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] Text border inside a TextView

2009-03-11 Thread Walter Leibbrandt
Hi everyone,

I'm trying to show the "selection" of a certain sub-string in a 
gtk.TextView by drawing a border around the word. The only way to mark 
text in a TextView that I've found so far is by placing TextTags with 
modified properties. This does not seem to offer a way to draw a border, 
though, or am I missing something?

Does anyone know of an alternative way to draw such a border?

Thanks in advance,

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Firefox-style button with a pop-up menu
http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu
* Virtaal's MVCisation
* Things that changed the way I code


___
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] Callbacks

2009-03-11 Thread Walter Leibbrandt
Hi,

Peyman wrote:
> Hello
>
> Is there a clean way to temporarily cancel callbacks? For example  
> consider a combobox CB1 with the following callback function
>
> on_CB1_changed(...):
>   someVar= the new entry
>
> now if I manually change the combobox to, for example "Select item", I  
> don't want the changed signal to be generated since I don't want  
> someVar to be set to "Select item".
>   
To temporarily block specific signal handlers from running, you can use 
the GObject.handler_block() and GObject.handler_unblock() methods 
(http://www.pygtk.org/docs/pygobject/class-gobject.html#method-gobject--handler-block),
 
because all widgets (and most of the classes in the gtk module) 
sub-class gobject. The "handler_id" mentioned there is the integer value 
returned by the original connect() call.

HTH

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Firefox-style button with a pop-up menu
http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu
* Virtaal's MVCisation
* Things that changed the way I code


___
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] Inserting items into ComboBox

2009-03-06 Thread Walter Leibbrandt

Johannes Bauer wrote:

Timo schrieb:
  

for item in ["foo", "bar"]:
   combobox.get_model().append([item])

Apparently after entering something in Glade, the liststore etc are
generated. And by removing these items, it keeps these.



Sadly, my version of Glade does not generate the XML the way you
described when I do it the way you described :-(

I guess I'll stick with Walter's solution then. It's just very very
confusing for a GTK beginner to have to do such low-level tasks in order
to perform such a relatively simple and common thing.

Kind regards and thanks for your help,
Johannes
  
And so I learn something new! On a hunch, I compared a Glade file with 
an empty (unaltered) combo box and a combo box with its "Items" field 
"changed". I put the "changed" in quotes, because what I did was add a 
character and delete it again, so no text was really added. It turns out 
that the output XML differs by one line that defines an "items" property 
(see attached comboboxes.diff).


The inclusion of that "items" property causes the created ComboBox to be 
initialized (ListStore and CellRendererText created and correctly 
associated with the ComboBox). In fact you can use the *_text() methods 
with such an "initialized" ComboBox!


I've attached my test program and Glade file as well.

This is certainly a new discovery for me and should make it much simpler 
to work with simple ComboBoxes.


HTH,

--
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Firefox-style button with a pop-up menu
http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu
* Virtaal's MVCisation
* Things that changed the way I code


--- combo_without_items.glade	2009-03-06 17:05:47.0 +0200
+++ combo_with_items.glade	2009-03-06 17:04:04.0 +0200
@@ -1,11 +1,12 @@
 
 
-
+
 
   
 
   
 True
+
   
 
   


combo_with_items.glade
Description: application/glade
#!/usr/bin/env python

import gtk
from gtk import glade

xml = glade.XML('combo_with_items.glade')
win = xml.get_widget('window1')
win.connect('destroy', lambda *args: gtk.main_quit())

cmb = xml.get_widget('combobox1')
# ^^ Note that there is no more combo box initialization above!

# Add initial items to combo box
for i in ['a', 'b', 'c', 'd']:
cmb.get_model().append([str(i)])

# Test _text() methods
cmb.append_text('e')# Items: a b c d e
cmb.insert_text(2, 'X') # Items: a b X c d e
cmb.prepend_text('_')   # Items: _ a b X c d e
cmb.remove_text(1)  # Items: _ b X c d e

win.show_all()
gtk.main()
___
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] Gtk+ RC Files for Styling Widgets?

2009-03-05 Thread Walter Leibbrandt
http://www.pygtk.org/docs/pygtk/class-gtkrcstyle.html

Kevin wrote:
> I see nothing about GTK RC files in the PyGTK documentation.  Is there 
> perhaps some way to wrap the relevant functions?
>   

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Firefox-style button with a pop-up menu
http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu
* Virtaal's MVCisation
* Things that changed the way I code


___
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] Inserting items into ComboBox

2009-03-03 Thread Walter Leibbrandt
Hi,

Johannes Bauer wrote:
> Hi list,
>
> I've tried for an hour to insert items into a ComboBox - but just don't
> know how. append_text and its variants (insert_text, modify_text,
> prepend_text) don't seem to do the job as they're (from what I could
> read in the GTK documentation) only available for a specialized
> list-type combobox.
>
> So how do I simply insert items into a combobox during runtime?
>
> Kind regards,
> Johannes
>   
The *_text() methods are only applicable if the ComboBox was created 
with gtk.combo_box_new_text() or gtk.combo_box_entry_new_text(). If the 
ComboBox was created in another way (such as in Glade), you have to 
initialize it yourself:

def create_combo_with_items(items):
combo = gtk.ComboBox()
ls = gtk.ListStore(str)
for i in items:
ls.append([str(i)])
combo.set_model(ls)
cellr = gtk.CellRendererText()
combo.pack_start(cellr)
combo.add_attribute(cellr, 'text', 0)
return combo

See the documentation for the used methods for more information.

HTH

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Firefox-style button with a pop-up menu
http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu
* Virtaal's MVCisation
* Things that changed the way I code


___
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] date changed signal ?

2009-03-02 Thread Walter Leibbrandt
Hi,

Darren Hart wrote:
> I have a TreeView that renders rows differently depending on the state
> of the object being represented.  This state is in part dependent on
> the date.  Rather than calculate the state everytime I render the row,
> I set the state explicitly when certain events occur.  Is there some
> kind of datechanged() signal I can register a callback for?  Or do I
> just need to setup timers every minute or so to check if the date is
> different than last time?  This approach seems like overkill for
> something that happens once every 24 hours, and at a time when the app
> is unlikely to be being used - but I'm trying to be thorough :-)
>
> Thanks
I am not aware of any such signal in gtk-/gobject space. Maybe some 
other service (like dbus) has something that can suite your needs? 
Personally, I would go for a simple gobject.timeout_add() call.

HTH

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Virtaal's MVCisation
http://www.translate.org.za/blogs/walter/en/content/virtaals-mvcisation
* Things that changed the way I code
* Switching from Subversion to git


___
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] Restore a scrolling position

2009-02-19 Thread Walter Leibbrandt
Hi,

If you are changing the store, I would suggest a different approach:

This would require you to have some way to identify any given row 
uniquely (unless the first "matching" row is acceptable) and also to 
"remember" the selected row before performing your update. Then you can 
use gtk.TreeView.scroll_to_cell() to scroll back to the remembered row. 
Using scroll_to_cell(path, column, True, 0.5, 0.5) you can get the 
remembered row nice and centered (if possible). See the docs () for more 
details on the parameters: 
http://www.pygtk.org/docs/pygtk/class-gtktreeview.html#method-gtktreeview--scroll-to-cell

HTH

Lionel Dricot wrote:
> Hello,
>
> In a previous mail, I asked about restoring the scrolling position in 
> a treeview :
> http://www.mail-archive.com/pygtk@daa.com.au/msg17224.html
>
> This was solved thanks to Neil and Walter with the following line of 
> codes at the end of my refresh function :
> gobject.idle_add(self.task_tview.get_vadjustment().set_value,vscroll_value)
> gobject.idle_add(self.task_tview.get_hadjustment().set_value,hscroll_value)
>
> (with values being read at the start of the refresh function, of course)
>
>
> But I discovered a problem : if elements have been removed from the 
> treeview, the scroll will go to an empty position.
>
> In some case, it means that you will see only a blank treeview because 
> remaining elements are hidden on top (but no scrollbar are displayed).
>
> So how can check before inserting the scroll_value that I didn't pass 
> the upper bound of the possible scroll ?

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Virtaal's MVCisation
http://www.translate.org.za/blogs/walter/en/content/virtaals-mvcisation
* Things that changed the way I code
* Switching from Subversion to git


___
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] Getting string with in pixels

2009-02-13 Thread Walter Leibbrandt
Hi,

Vladimír Jícha wrote:
> Hello,
>
> I'm trying to get width of a text string. I found a FAQ 4.15 
> (http://faq.pygtk.org/index.py?req=show&file=faq04.015.htp) which has a 
> solution for this. But unfortunately it doesn't work. If I use "font = 
> widget.get_style().font", I get following error message: AttributeError: 
> 'gtk.Style' has no attribute 'font'.
>
> Is the FAQ outdated? What syntax should I use?
>
> Thank yo
Try widget.get_style().get_font().

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Virtaal's MVCisation
http://www.translate.org.za/blogs/walter/en/content/virtaals-mvcisation
* Things that changed the way I code
* Switching from Subversion to git


___
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] Scrolling to the previous position in a TreeView

2009-01-30 Thread Walter Leibbrandt
Hi,

Lionel Dricot wrote:
> I perfectly agree. That's why I'm not satisfied with this solution. 
> But, at least, it works and I prefer having an ugly working code than 
> a non functionnal software.
Looks like I didn't succeed in saying what I wanted to say (I seem to do 
that a lot :/). The reason why I mentioned gobject.idle_add() is to 
suggest that you try it as an alternative to timeout_add()... Or have 
you tried it?
>
> From my point of view (which is very new and not well exeperienced), 
> it looks like a pygtk/gtk bug/design flaw. If I set a value for the 
> adjustement, it should be done, not matter what. If waiting 100ms  
> before calling a function change your software's behaviour, I call 
> that a bug.
In that case, *please* stay away from a multi-threading in Gtk+ apps. ;)
>
> Maybe there's something that I don't understand because I really 
> believe that going to a specific scroll position is a very common 
> usecase.  (but it looks like the documentation on this part is very 
> weak. Look at the get_vadjustement which refers to set_vadjustement 
> which, itself, just says : "it set the adjustement" without explaining 
> what an adjustement is)

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Virtaal's MVCisation
http://www.translate.org.za/blogs/walter/en/content/virtaals-mvcisation
* Things that changed the way I code
* Switching from Subversion to git


___
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] Scrolling to the previous position in a TreeView

2009-01-30 Thread Walter Leibbrandt
Hi,

Lionel Dricot wrote:
> So it works with :
>
> gobject.timeout_add(100, 
> self.task_tview.get_vadjustment().set_value,vscroll_value)
>
> The problem is that the delay is very noticable ! You see the content 
> jumping up and down and it's really ugly. A smaller delay (10) doesn't 
> work at all. 50 works but I believe that it might not work everywhere.
When I need to do a "do-this-a-bit-later" kind of call, I always try 
gobject.idle_add(func) first. With idle_add() the delay is only as long 
as it takes for the requests in the event queue to be processed 
(depending on a few things). No more and no less. It's usually less than 
any custom time-out value and not specific to the development machine.

IMHO using idle_add() is already an ugly hack. Using timeout_add() (for 
things where specific time measurement is not involved) is even uglier 
and should be used with caution.

HTH

Walter

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Virtaal's MVCisation
http://www.translate.org.za/blogs/walter/en/content/virtaals-mvcisation
* Things that changed the way I code
* Switching from Subversion to git


___
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] Event ordering

2009-01-27 Thread Walter Leibbrandt
Hi,

Yang Zhang wrote:
> Yang Zhang wrote:
>   
>> Hi, I'm trying to position a pop-up Window to always be directly under 
>> an Entry box, but I'm not sure what signal(s) to react to.
>>
>> For instance, I tried entry.connect_after('focus-in-event', ...) to 
>> handle the initial positioning (I also hide the window on 
>> 'focus-out-event'), and that mostly seems to work, but if I resize the 
>> window, the reaction is too early since the geometry of the entry is not 
>> yet fully updated.  How can I handle this situation appropriately?
>> 
>
> Another example: I'd like to set the cursor position in the entry to the 
> end of the text whenever focus changes to the entry, but doing this from 
> focus-in-event doesn't work (the entire text still gets highlighted).
>   
http://www.pygtk.org/docs/pygtk/class-gtkwidget.html#signal-gtkwidget--configure-event

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Virtaal's MVCisation
http://www.translate.org.za/blogs/walter/en/content/virtaals-mvcisation
* Things that changed the way I code
* Switching from Subversion to git


___
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] get_active() of CheckButton added to ScrolledWindow

2009-01-20 Thread Walter Leibbrandt
Hi,

Firstly, on a conceptual note, "self.window" is not really an accurate 
name for the glade.XML object created. It does not represent any one 
window, but rather the whole GUI (windows and widgets) created in Glade. 
You can see the glade.XML object as a factory object, taking the XML 
output from the Glade UI designer ("check.glade" in your case) as input 
and giving you the constructed widgets as output.

Having said that, there is no way for the glade.XML object to know about 
widgets that were created at run-time and not specified in its input XML 
and that is why self.window.get_widget("test") returns None. Also the 
string you passed as argument to gtk.CheckButton() is the button's label 
and not it's name. The difference is that the label is the string that 
is displayed on the button and the name is used as an internal string 
identifier for the widget.

The most common way to achieve what you are trying to do here, is to 
keep a reference to all new, custom-created widgets. So if you replace 
"button = gtk.CheckButton('test')" with "self.button = 
gtk.CheckButton('test')", you can simply do "state = 
self.button.get_active()" in your "button2_clicked()" event handler.

HTH

Walter

Daniel Roesler wrote:
> Howdy all,
>
> I'm just learning pygtk and glade, and I have a question about
> accessing widgets that were added during an called function. In my
> example, I have two buttons. The first button that adds a checkbox to
> a scrolled window area. The second button prints the activity status
> (True/False) of the checkbox.
>
> The first button works fine. However, when I push button two, python
> says "AttributeError: 'NoneType' object has no attribute
> 'get_active'". Obviously, this means that I'm not reaching the
> checkbox widget correctly.
>
> So my question, how can I get properties of a widget added after the
> initial glade file was loaded?
>
> Here's my program, and I've attached my glade file. Thanks all!
> ---
> import pygtk
> import gtk
> import gtk.glade
>
> class app_gui:
>   def __init__(self):
> self.window = gtk.glade.XML("check.glade")
> dic = { "on_button1_clicked" : self.button1_clicked,
> "on_button2_clicked" : self.button2_clicked,
> "on_window1_destroy" : (gtk.main_quit) }
> self.window.signal_autoconnect(dic)
> return
>
>   def button1_clicked(self,widget):
> button = gtk.CheckButton("test")
> self.window.get_widget("scrolledwindow1").add_with_viewport(button)
> button.show()
> return
>
>   def button2_clicked(self,widget):
> status = self.window.get_widget("test").get_active()
> print status
> return
>
> app=app_gui()
> gtk.main()
> ---
>
> Avast!
> Daniel Roesler
> diaf...@gmail.com
>   
> 
>
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Virtaal's MVCisation
http://www.translate.org.za/blogs/walter/en/content/virtaals-mvcisation
* Things that changed the way I code
* Switching from Subversion to git


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] Replacing text with paste

2009-01-05 Thread Walter Leibbrandt
Hi,

I manage my own undo buffer of changes made to a gtk.TextView. This 
necessarily means that the undo controller is connected to the relevant 
TextBuffer's "delete-range" and "insert-text" signals. Changes made 
during these signals are stored on the undo stack.

Then I ran into some weird behavior: when I select any region of the 
text in the text buffer and then paste something in that was previously 
copied to the clipboard, an "insert-text" and then a "delete-range" 
signal is emitted. This means that, when undoing, the "delete-range" is 
undone first and this leaves both the originally selected text as well 
as the text it was replaced with in the TextView, until undo is called 
again, undoing the "insert-text" changes.

Is there a signal I can connect to to catch this special case, or does 
anyone have another idea of how to combine these two into a single undo 
step?

Thanks in advance,

Walter

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Virtaal's MVCisation
http://www.translate.org.za/blogs/walter/en/content/virtaals-mvcisation
* Things that changed the way I code
* Switching from Subversion to git


___
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] Getting Widget geometry

2009-01-05 Thread Walter Leibbrandt
Hi,

Yang Zhang wrote:
> Hi, I'm trying to create a pop-up window positioned immediately below an
> Entry.  How do I figure out the coordinates to pass into
> Window.move(x,y)?  I couldn't find how to extract this information from
> an Entry.  Thanks in advance for any hints.
>   

The best way I found was the gtk.Widget.get_allocation() method. 
Although I'm not sure if this includes window decorations - the window I 
use it with is also a pop-up window, so does not have any decorations.

It took quite some hacking to get the positioning and sizing to work 
just right, so in the interest of (hopefully) saving you a few hours, 
have a look at the TMWindow.update_geometry() method in 
https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/plugins/tm/tmwidgets.py.

HTH

Walter

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Virtaal's MVCisation
http://www.translate.org.za/blogs/walter/en/content/virtaals-mvcisation
* Things that changed the way I code
* Switching from Subversion to git


___
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] Entry.connect_after('changed', ...) doesn't see updated cursor position

2009-01-05 Thread Walter Leibbrandt
Hi everybody,

I hope everyone had a very festive season and that 2009 will be a great 
year for everyone! :)

Yang Zhang wrote:
> Well, another problem is that I don't want this to just fire when text 
> is being inserted.  I'm building an auto-completion widget, so if 
> someone deletes text or in any way changes the contents of the text box, 
> I want the list of completions to be updated all the same.
>   
Virtaal, our off-line translation tool, contains a pretty isolated 
(code-wise) auto completor 
(https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/virtaal/virtaal/plugins/autocompletor.py).
 
It is written to not make assumptions about the source of the strings, 
but only supports TextViews at the moment. :/

HTH

Walter

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Virtaal's MVCisation
http://www.translate.org.za/blogs/walter/en/content/virtaals-mvcisation
* Things that changed the way I code
* Switching from Subversion to git


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] Getting widget geometry

2008-12-12 Thread Walter Leibbrandt
Hi there,

How can I find the geometry (X, Y, width and height) of a widget (a 
gtk.TextView in this case) buried in a nested layout of Tables and 
VBoxes? The get_size_request() method always returns (-1, -1) and 
size_request() returns obviuosly wrong values (a width of 18 when it's 
at least 150). The gtk.gdk.Rectangle I get from the get_allocation() 
method also contains similar values (-1 for x and y and 1 for width and 
height). The get_window() method also returns None for all values of the 
parameter and the TextView's props.window is also None.

The TextView's "realize" and "show" events have been fired before I try 
to access this data.

If it is relevant in any way, I want to use this information to move 
different window so that the bottom left corner of the TextView lines up 
with the top left corner of the window (I'm creating a "fake" drop-down 
box).

Any help would be greatly appreciated.

Thanks in advance,

Walter

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Virtaal's MVCisation
http://www.translate.org.za/blogs/walter/en/content/virtaals-mvcisation
* Things that changed the way I code
* Switching from Subversion to git


___
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] Moving two windows at the same time

2008-12-04 Thread Walter Leibbrandt
Hi,

When a window is moved it fires the "configure-event" signal (from 
gtk.Widget). You can connect to that signal and move your dialog to the 
window's new location. The downside is that "configure-event" isn't 
fired _while_ moving a window, only afterwards.

http://pygtk.org/docs/pygtk/class-gtkwidget.html#signal-gtkwidget--configure-event

Regards,

Walter

Daniel Hernández Bahr wrote:
> Hello everybody ..
>
> Is there any way in PyGtk to move two windows at the same time?
>
> The thing is, having a window and a modal dialog transient for that 
> window, how can i (the program) move the dialog if the user moves de 
> window, like binding them together .. ??
>
> Cheers!!
>
> -- 
> Daniel Hernández Bahr
> Universidad de las Ciencias Informáticas.
>
> 
>
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Things that changed the way I code
http://www.translate.org.za/blogs/walter/en/content/things-changed-way-i-code
* Switching from Subversion to git
* The first official release of Spelt


___
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] Notebook

2008-12-04 Thread Walter Leibbrandt
Hi,

How about notebook.set_show_tabs(False)?

Frédéric wrote:
> Hi,
>
> I open a config dialog from another dialog. This config dialog mainly 
> contains a notebook with several pages. When opening the config dialog, I 
> select one page, and I would like to disable all other pages.
>
> Is it possible?
>
>   

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Things that changed the way I code
http://www.translate.org.za/blogs/walter/en/content/things-changed-way-i-code
* Switching from Subversion to git
* The first official release of Spelt


___
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] examples

2008-11-17 Thread Walter Leibbrandt
Hi,

Carlos Albornoz wrote:
> carlos albornoz escribió:
>   
>> hello list.
>>
>> I'm new at this, and I'm looking for examples but I find nothing, I need to
>> learn pygtk+mysql
>>
>> if someone here would be a big help guide me.
>>
>> thanks.
>>
>>   
>> 
> nobody have examples to show me for learn?
>
> cheers
>   
For PyGtk, the pygtk-demo program (that should be installed with PyGtk) 
contains some great examples. See http://mysql-python.sourceforge.net/ 
for more information about using MySQL in Python.

Regards,
Walter

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Switching from Subversion to git
http://www.translate.org.za/blogs/walter/en/content/switching-subversion-git
* The first official release of Spelt
* Auto-completion and auto-correction for Gtk+ widgets


___
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] Application name is '-c'

2008-10-14 Thread Walter Leibbrandt
Frédéric wrote:
> Le 14/10/2008, "Walter Leibbrandt" <[EMAIL PROTECTED]> a écrit:
>   
> No, it won't work, at least in local, because I would have a
> papywizard.py file which will mask the papywizard/ module. So the import
> will fail. That's why I used a shell script. But it should work once
> installed in /usr/local, I think...
>
>   
Of course, yes. We use bin/appname.py.

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Switching from Subversion to git
http://www.translate.org.za/blogs/walter/en/content/switching-subversion-git
* The first official release of Spelt
* Auto-completion and auto-correction for Gtk+ widgets


___
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] Application name is '-c'

2008-10-14 Thread Walter Leibbrandt
Hi,


$ cat papywizard.sh
#/bin/sh

python -c "from papywizard.scripts.main import main; main()" $@

... and there's your "-c". If you had replaced papywizard.sh with 
papywizard.py:

#!/usr/bin/env python
from papywizard.scripts.main import main
main()

... and `chmod +x papywizard.py`, you also would not have had that problem.

If you still really want a shell script, you can call papywizard.py from 
there.

But I have seen Willie's method used a lot too.

Regards,
Walter

Willie Walker wrote:
> Here's the hack we did in Orca to prevent this from happening:
>
> # We're going to force the name of the app to "orca" so pygtk
> # will end up showing us as "orca" to the AT-SPI.  If we don't
> # do this, the name can end up being "-c".  See bug 364452 at
> # http://bugzilla.gnome.org/show_bug.cgi?id=364452 for more
> # information.
> #
> import sys
> sys.argv[0] = "orca"
>
> Will
>
> On Oct 14, 2008, at 6:56 AM, Frédéric wrote:
>
>>
>> Le 14/10/2008, "Walter Leibbrandt" <[EMAIL PROTECTED]> a écrit:
>>
>>> This is just a hunch, but I'll bet that you don't get that behavior 
>>> when
>>> you run your program from the command-line? My first guess is that it
>>> has something to do with the way in which your program is launched (ie.
>>> the exact command executed).
>>
>> Unfortunatly, I always have the problem, whatever the way I launch it.
>>
>>> It would help to have a link to your sources, though.
>>
>> Sure:
>>
>> http://trac.gbiloba.org/papywizard/browser/trunk
>>
>> I'm wondering if the problem did not appear when I start using i18n...
>> Could it be related? My dialogs are made with glade-3 (they are all in
>> the papywizard/view dir).
>>
>> -- 
>>Frédéric
>> ___
>> pygtk mailing list   pygtk@daa.com.au
>> http://www.daa.com.au/mailman/listinfo/pygtk
>> Read the PyGTK FAQ: http://faq.pygtk.org/
>

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Switching from Subversion to git
http://www.translate.org.za/blogs/walter/en/content/switching-subversion-git
* The first official release of Spelt
* Auto-completion and auto-correction for Gtk+ widgets


___
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] Application name is '-c'

2008-10-14 Thread Walter Leibbrandt
Frédéric wrote:
> In several places, instead of having my application name, I get '-c'.
> It can be on warnings, like:
>
> (-c:24058): Gtk-WARNING **: Locale not supported by C library.
> Using the fallback 'C' locale.
>
> or in the taskbar of my KDE desktop (only when 2 or more windows of the
> application are opened).
>
> Any idea?
>
> --
>Frédéric
>   
Hi,

This is just a hunch, but I'll bet that you don't get that behavior when 
you run your program from the command-line? My first guess is that it 
has something to do with the way in which your program is launched (ie. 
the exact command executed).

It would help to have a link to your sources, though.

Regards,
Walter

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Switching from Subversion to git
http://www.translate.org.za/blogs/walter/en/content/switching-subversion-git
* The first official release of Spelt
* Auto-completion and auto-correction for Gtk+ widgets


___
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] Window grows too much when loading data into TreeView

2008-10-14 Thread Walter Leibbrandt
Roberto Bonvallet wrote:
> Dear all,
> I have written a small PyGTK program for the first time in order to 
> help me visualize some data, but I have this problem I hope someone 
> can help me to solve.
>
> The window contains a VBox, whose bottom cell contains a HBox with a 
> TreeView and its VScrollbar.  The TreeView is populated by loading 
> data from a file when the user presses a button.
>
> I tested my program in a tiled window manager (Ion3), where the window 
> size is fixed by the containing tile, and it works fine: the TreeView 
> fits the window and can be scrolled down with the VScrollbar.
>
> But now I've run my program in Gnome, and now the TreeView grows to 
> show all its contents, so I get a very tall window that doesn't fit 
> the screen and the scrollbar doesn't work, so I can only see the first 
> handful of rows.
>
> I have set the window default size, and changed the window size after 
> loading the data, but it doesn't help.
>
> The relevant widget creation and packing code:
> [...]
> self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
> self.window.set_default_size(200, 400)
>
> self.vbox = gtk.VBox()
> self.window.add(self.vbox)
> self.data_box = gtk.HBox()
> self.vbox.pack_start(self.data_box, expand=True)
>
> self.data_view = gtk.TreeView()
> self.data_box.pack_start(self.data_view, expand=True)
>
> v = self.data_view.get_vadjustment()
> self.sb <http://self.sb> = gtk.VScrollbar(adjustment=v)
> self.data_box.pack_start(self.sb <http://self.sb>, expand=False)
> [...]
>
> Does anybody know what's wrong, and how could I solve this?
> I'd be very thankful for any hint.
>
> Cheers,
> -- 
> Roberto Bonvallet
>
Hi,

Have you tried packing your TreeView in a ScrolledWindow? You can then 
use the ScrolledWindow's set_policy() method to specify when to shown 
which scrollbar(s).


Regards,
Walter

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Switching from Subversion to git
http://www.translate.org.za/blogs/walter/en/content/switching-subversion-git
* The first official release of Spelt
* Auto-completion and auto-correction for Gtk+ widgets


___
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] Change the appearance for all labels in a glade file

2008-10-08 Thread Walter Leibbrandt
Hi,

Patty Ackermann wrote:
> Is there a fast way to change the appearance of all the labels (using 
> pango) in a glade file instead of doing it manually? I guess I am 
> hinting at returning a list of widgets that are only labels and 
> concatenating the pango markup.

labels = [w for w in glade_xml.get_widget_prefix('') if w is gtk.Label]


Although I would also suggest looking at RC files if it's applicable.

Regards,

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Switching from Subversion to git
http://www.translate.org.za/blogs/walter/en/content/switching-subversion-git
* The first official release of Spelt
* Auto-completion and auto-correction for Gtk+ widgets


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] Connecting gtk.MenuItems to existing accelerators

2008-10-02 Thread Walter Leibbrandt
Hi,

Much more than the subject, I cannot explain well, so I'll let the code 
do the talking:

self.accel_group = gtk.AccelGroup()
self.main_window.add_accel_group(self.accel_group)

gtk.accel_map_add_entry("/Edit/Undo", gtk.keysyms.z, 
gdk.CONTROL_MASK)
gtk.accel_map_add_entry("/Edit/Search", gtk.keysyms.F3, 0)
gtk.accel_map_add_entry("/Navigation/Up", 
gtk.keysyms.Up, gdk.CONTROL_MASK)
gtk.accel_map_add_entry("/Navigation/Down", 
gtk.keysyms.Down, gdk.CONTROL_MASK)
gtk.accel_map_add_entry("/Navigation/PgUp", 
gtk.keysyms.Page_Up, gdk.CONTROL_MASK)
gtk.accel_map_add_entry("/Navigation/PgDown", 
gtk.keysyms.Page_Down, gdk.CONTROL_MASK)

self.accel_group.connect_by_path("/Edit/Undo", 
self._on_undo)
self.accel_group.connect_by_path("/Edit/Search", 
self._on_search)


This, in its own, works fine, but then I added "Edit" and "Navigation" 
menu's via Glade and added the following code directly below the block 
above (self.gui is the Glade.XML object):

# gtk.Menu's:
self.gui.get_widget('menu_edit').set_accel_group(self.accel_group)

self.gui.get_widget('menu_navigation').set_accel_group(self.accel_group)

# gtk.MenuItems:

self.gui.get_widget('mnu_undo').set_accel_path("/Edit/Undo")

self.gui.get_widget('mnu_search').set_accel_path("/Edit/Search")

self.gui.get_widget('mnu_up').set_accel_path("/Navigation/Up")

self.gui.get_widget('mnu_down').set_accel_path("/Navigation/Down")

self.gui.get_widget('mnu_page_up').set_accel_path("/Navigation/PgUp")

self.gui.get_widget('mnu_page_down').set_accel_path("/Navigation/PgDown")


The accelerators still work, but the menu items, once activated, does 
nothing, even though the correct keyboard shortcuts are displayed in the 
menu's. I realize that only "Undo" and "Search" have handlers defined in 
the given snippets, but even they do not work.

I guess my question is how to use the already-connected accelerator 
handlers (self._on_undo and self._on_search) when the related menu item 
is activated.

Thanks in advance.

Regards,

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* The first official release of Spelt
http://www.translate.org.za/blogs/walter/en/content/first-official-release-spelt
* Auto-completion and auto-correction for Gtk+ widgets
* Gtk+ Tip of the Day: Modifying the subject of an event being processed


___
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] prevent gtk.Dialog from closing

2008-09-09 Thread Walter Leibbrandt
Tasos Latsas wrote:
> Hello,
> I have a dialog box which prompts the user for some input with an entry
> box. I want to be able to check the user input before returning to the
> main window and show another popup window with a message,
>  e.g. ("you left the field empty, press cancel button or fill it etc")
> and then prevent the dialog from closing.
>
> I tried to intercept the delete-event but didn't help also i didn't find
> something similar at the faq
> Is this possible with a gtk.dialog or i have to use a gtk.window?
>   
 From 
https://stage.maemo.org/svn/maemo/projects/haf/tags/python-sdk/2.0final/gazpacho-hildon/hildonwidgets/libs.py
 
<http://www.google.com/codesearch/url?hl=en&ct=rpc&url=https://stage.maemo.org/svn/maemo/projects/haf/tags/python-sdk/2.0final/gazpacho-hildon/hildonwidgets/libs.py&usg=AFQjCNFsGtCs_UJH8zEP6FmVOGc808Eunw>:

dialog.window.set_functions(gtk.gdk.FUNC_CLOSE) # see 
http://www.pygtk.org/docs/pygtk/gdk-constants.html#gdk-wm-function-constants
dialog.window.set_decorations(gtk.gdk.DECOR_ALL) # see 
http://www.pygtk.org/docs/pygtk/gdk-constants.html#gdk-wm-decoration-constants


With the right parameters you should get the effect you're looking for.

But I would like to urge you to reconsider altering this. From a UI 
design point-of-view, closing a dialog should be enough of a response 
from the user (ie. the same as if he hit "Cancel"). Make sure that you 
want to break this convention before doing so.

Regards,

Walter


-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* The first official release of Spelt
http://www.translate.org.za/blogs/walter/en/content/first-official-release-spelt
* Auto-completion and auto-correction for Gtk+ widgets
* Gtk+ Tip of the Day: Modifying the subject of an event being processed


___
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] PyGTK and threading

2008-08-18 Thread Walter Leibbrandt


Vláďa wrote:
> ... I'm absolutely new to threads, I understand what are they good for, but 
> unfortunately I have 
> almost no idea about the consequences and the problems they bring. ...
>   
Seeing as you're "absolutely new to threads", I'll just make sure that 
you are aware of the inherent limitations of threading in Python. But 
seeing as you've read a few tutorials/articles, you probably have come 
across the plight on parallelism in Python: the GIL (Global Interpreter 
Lock). Basically what that implies is that, even though multi-threading 
is still possible, you won't gain much in the way of performance (the 
Python interpreter can still only execute one command at a time). I've 
read somewhere (can't remember where... possibly a blog) that Python 
threading is basically only useful for getting around blocking 
situations, like waiting for input.

Besides the GIL, it is very clear that Gtk+ itself was not designed to 
be used in multi-threaded applications. This has become obvious to me 
after trading in Gtk# for PyGtk and realizing that the exact same 
problems exist. That said, you might want to take a look at 
http://www.mono-project.com/Responsive_Applications. Although that 
article is written for use with Gtk#, the (supported) concepts are the 
same for PyGtk.

Personally, I have not tried to multi-thread an app with PyGtk, but I 
can assure you that it was a mess with Gtk#. :P

Good luck!

Walter

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Auto-completion and auto-correction for Gtk+ widgets
http://www.translate.org.za/blogs/walter/en/content/auto-completion-and-auto-correction-gtk-widgets
* Gtk+ Tip of the Day: Modifying the subject of an event being processed
* Spelt 0.1rc2 released


___
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.Assistant Question

2008-08-06 Thread Walter Leibbrandt
This should work, since pages are gtk.Widgets (although I haven't tried 
it myself):
assistant.get_nth_page(n).connect('show', ...)

Florian Sachs wrote:
> Hi!
>
> I try to write an application using gtk.Assistant and have a Question:
>
> The "prepare" - Signal ist emitted when the new page is set as the current 
> page, but it is not visible. Is there a signal or any other mechanism to find 
> out, that the new page ist the current page and it IS visible?
>
> best regards,
> florian
> ___
> 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/
>   

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Auto-completion and auto-correction for Gtk+ widgets
http://www.translate.org.za/blogs/walter/en/content/auto-completion-and-auto-correction-gtk-widgets
* Gtk+ Tip of the Day: Modifying the subject of an event being processed
* Spelt 0.1rc2 released


___
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] Custom EntryCompletion

2008-08-05 Thread Walter Leibbrandt
Hi,

I'm trying to find a quicker way to implement auto-completion for a list 
of at least 50,000 entries. I've found the "standard" way 
(gtk.ListStore) to be very slow.

Is there a way I can make an EntryCompletion object call a search method 
of my own (based on the text in the Entry) and display the results of 
that search in the completion popup, without calling the "match_func" on 
every item in a slow TreeModel? Or does anyone have a better idea to 
achive this (sub-class gtk.EntryCompletion?)?

I've tried to give the EntryCompletion a dummy (empty) ListStore and 
used set_match_func(match_func), but match_func() is then never called.

Any response will be greatly appreciated.

Thanks in advance,

Walter

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Auto-completion and auto-correction for Gtk+ widgets
http://www.translate.org.za/blogs/walter/en/content/auto-completion-and-auto-correction-gtk-widgets
* Gtk+ Tip of the Day: Modifying the subject of an event being processed
* Spelt 0.1rc2 released


___
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] Formatting a spinbutton's display

2008-07-28 Thread Walter Leibbrandt
IIRC, you can set custom text with the set_text() method (or by 
modifying the "text" property), seeing as a SpinButton is a sub-class of 
gtk.Entry. So connect to the spin button's "changed" and/or 
"change-value" event(s), read and format the new text and call 
set_text() with your formatted string.

This might also mean that you need to do set_numeric(False) as to allow 
non-numeric strings.

Jeremy S wrote:
> I would like to use a spinbutton but instead of just displaying a
> float or integer, I want the display to be formatted.  In my case I
> want it to be formatted as currency ($ in front and commas separating
> thousands, millions, etc.), but I can't even find any information on
> how to tackle this problem generally.
>
> I know for treeviews this type of thing can be accomplished with
> set_cell_data_func.  Is there anything similar for spinbuttons?
> ___
> 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/
>   

-- 
Walter Leibbrandt  http://translate.org.za/blogs/walter
Software Developer  +27 12 460 1095 (w)
Translate.org.za

Recent blogs:
* Gtk+ Tip of the Day: Modifying the subject of an event being processed
http://www.translate.org.za/blogs/walter/en/content/gtk-tip-day-modifying-subject-event-being-processed
* Spelt 0.1rc2 released
* CorpusCatcher 0.1 released


___
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] Serialize a TreeStore

2008-07-21 Thread Walter Leibbrandt
Try serializing the data in/about the TreeStore rather than the object 
itself.


Richie Ward wrote:

I need to serialize a TreeStore. I tried to use pickle with no luck.
Is there a nice clean way that I can achieve this?
The reason I want this is so that I can save all the data in my
program, so I can load it all next time its ran.

  
begin:vcard
fn:Walter Leibbrandt
n:Leibbrandt;Walter
org:Translate.org.za
adr:;;;Pretoria;Gauteng;;South Africa
email;internet:[EMAIL PROTECTED]
title:Developer
tel;work:(012) 460 1095
x-mozilla-html:FALSE
url:http://translate.org.za/blogs/walter
version:2.1
end:vcard

___
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] spam?

2008-07-09 Thread Walter Leibbrandt
No, you are certainly not. I currently have about 60 PyGtk ML messages 
from April 2007 through January 2008. And I've only been a member for 
about a month! Weird...


Yann Leboulanger wrote:

Am I the only one to be spammed by quoll.daa.com.au with mails from
pygtk ML from 2007 ?

  
begin:vcard
fn:Walter Leibbrandt
n:Leibbrandt;Walter
org:Translate.org.za
adr:;;;Pretoria;Gauteng;;South Africa
email;internet:[EMAIL PROTECTED]
title:Developer
tel;work:(012) 460 1095
x-mozilla-html:FALSE
url:http://translate.org.za
version:2.1
end:vcard

___
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] Multilevel ListStore

2008-07-08 Thread Walter Leibbrandt

Hi,

Run pygtk-demo. The only real difference to a normal ListStore is 
specifying the parent gtk.TreeIter when you add rows:



model = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
parentIter = model.append(None)
model.set(parentIter,
   0, "Parent (1st col)",
   1, "Parent (2nd col)"
)

childIter = model.append(parentIter)
model.set(childIter,
   0, "Child (1st col)",
   1, "Child (2nd col)"
)
childIter2 = model.append(parentIter)
model.set(childIter2,
   0, "Child2 (1st col)",
   1, "Child2 (2nd col)"
)


This will add a top-level row (referenced by parentIter) and two rows 
under it (referenced by childIter and childIter2). Then you can do 
"level2iter = model.append(childIter)" to add a row with the first child 
row (childIter) as its parent.


The PyGtk tutorial also covers this in section 14.2.4.2 ("Adding Rows to 
a TreeStore") and that's about as hard as it gets.


Hope this helps.

Regards,
Walter

P.S. The code above was written on-the-go, so it might not be 100% correct.

Shadi Azoum wrote:

Thanks for the tip, Paul. Any code example on using TreeStore? The official 
pygtk tutorials offer little support.


- Original Message -
From: Paul Pogonyshev <[EMAIL PROTECTED]>
Date: Sunday, July 6, 2008 3:51 am
Subject: Re: [pygtk] Multilevel ListStore
To: pygtk@daa.com.au
Cc: Shadi Azoum <[EMAIL PROTECTED]>

  

Shadi Azoum wrote:


Any help would be greatly appreciated.
  

Use gtk.TreeStore instead.

Paul



___
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/
  
begin:vcard
fn:Walter Leibbrandt
n:Leibbrandt;Walter
org:Translate.org.za
adr:;;;Pretoria;Gauteng;;South Africa
email;internet:[EMAIL PROTECTED]
title:Developer
tel;work:(012) 460 1095
x-mozilla-html:FALSE
url:http://translate.org.za
version:2.1
end:vcard

___
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] gtkspell breaks the TextView / accessing invalidated iterators

2008-07-07 Thread Walter Leibbrandt

Oh, sorry. Looks like you found pygtkspell. :P

Samuel Abels wrote:

Hi,

The following code works flawlessly when the gtkspell line is commented
out, and breaks when gtkspell is enabled.

--
import gtk, gtkspell, locale

class Window(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)
self.vbox   = gtk.VBox()
self.hbox   = gtk.HBox()
self.scroll = gtk.ScrolledWindow()
self.view   = gtk.TextView()
buffer  = self.view.get_buffer()
self.scroll.set_policy(gtk.POLICY_AUTOMATIC,
   gtk.POLICY_AUTOMATIC)
self.set_size_request(600, 600)
self.vbox.set_border_width(6)
self.vbox.set_spacing(6)
self.hbox.set_spacing(6)
self.inserted = None

# Pack widgets.
self.scroll.add_with_viewport(self.view)
self.add(self.vbox)
self.vbox.pack_start(self.hbox, False)
self.vbox.pack_start(self.scroll)
self.show_all()

buffer.connect('insert-text', self._on_buffer_insert_text)
buffer.connect('changed', self._on_buffer_changed)
#gtkspell.Spell(self.view).set_language(locale.getlocale()[0])


def _on_buffer_insert_text(self, buffer, iter, text, length):
print "Inserted:", repr(text)
self.inserted = text, iter.get_offset()


def _on_buffer_changed(self, buffer):
if self.inserted is None:
return
print "Changed:", repr(self.inserted)
inserted, pos = self.inserted
self.inserted = None
if inserted == '#':
buffer.delete(buffer.get_iter_at_offset(pos),
  buffer.get_iter_at_offset(pos + 1))
buffer.insert(buffer.get_iter_at_offset(pos), "X")


# Create widgets.
window = Window()
window.connect('delete-event', gtk.main_quit)
gtk.main()
--

With gtkspell disabled, any time the "#" key is pressed an X is written
into the buffer.
With gtkspell enabled, the following output is generated:

--
GtkWarning: Invalid text buffer iterator: either the iterator is
uninitialized, or the characters/pixbufs/widgets in the buffer have been
modified since the iterator was created.
You must use marks, character numbers, or line numbers to preserve a
position across buffer modifications.
You can apply tags and insert marks without invalidating your iterators,
but any mutation that affects 'indexable' buffer contents (contents that
can be referred to by character offset)
will invalidate all outstanding iterators
  gtk.main()
show_text_view.py:50: GtkWarning: _gtk_text_buffer_get_line_log_attrs:
assertion `GTK_IS_TEXT_BUFFER (buffer)' failed
  gtk.main()
show_text_view.py:50: GtkWarning: gtk_text_buffer_remove_tag: assertion
`gtk_text_iter_get_buffer (end) == buffer' failed
  gtk.main()
show_text_view.py:50: GtkWarning: gtk_text_buffer_set_mark: assertion
`gtk_text_iter_get_buffer (iter) == buffer' failed
  gtk.main()
Traceback (most recent call last):
  File "show_text_view.py", line 50, in 
gtk.main()
--

It appears that gtkspell is trying to access an iterator that was
invalidated by manipulating the buffer in a callback. I tried to change
the buffer in different callbacks, such as insert-text, delete-range,
changed, but all of them break even when using connect_after().

Is this intended behavior, and if so, how do you manipulate the buffer
when spell-checking is enabled?

-Samuel


___
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/
  
begin:vcard
fn:Walter Leibbrandt
n:Leibbrandt;Walter
org:Translate.org.za
adr:;;;Pretoria;Gauteng;;South Africa
email;internet:[EMAIL PROTECTED]
title:Developer
tel;work:(012) 460 1095
x-mozilla-html:FALSE
url:http://translate.org.za
version:2.1
end:vcard

___
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] Underlining text when spell-checking

2008-07-07 Thread Walter Leibbrandt

Hi,

With a quick search I found libgtkspell and consequently pygtkspell 
(http://www.pygtk.org/pygtkspell/ - although I can't access pygtk.org 
atm). Maybe that will help?


Regards,
Walter

Samuel Abels wrote:

Hi,

Any idea how to "spell check underline" the text in a textview? Looking
at the pango constants here:

http://www.pygtk.org/docs/pygtk/pango-constants.html

there does not seem to exist such an underline type.

-Samuel

___
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/
  
begin:vcard
fn:Walter Leibbrandt
n:Leibbrandt;Walter
org:Translate.org.za
adr:;;;Pretoria;Gauteng;;South Africa
email;internet:[EMAIL PROTECTED]
title:Developer
tel;work:(012) 460 1095
x-mozilla-html:FALSE
url:http://translate.org.za
version:2.1
end:vcard

___
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] Dialog without window decoration

2008-06-26 Thread Walter Leibbrandt
... or 
http://www.pygtk.org/docs/pygtk/class-gtkwindow.html#method-gtkwindow--set-type-hint 
if your window is already created.


Bertrand Son Kintanar wrote:
On Thu, Jun 26, 2008 at 3:14 PM, Frédéric 
<[EMAIL PROTECTED] 
> wrote:



Is there a way to have dialogs without window decoration at all?


i think you can use a gtk.window for this with POPUP as its type.

self.dialog_window = gtk.Window(gtk.WINDOW_POPUP)

as far as pygtk 2.0 reference manual states that gtk.WINDOW_POPUP is 
"A window that is ignored by the window manager and has no frame or 
decorations. A popup window is used for menus and tooltips." so maybe 
you can use it as a progress bar of some sort.




I would like to make a little progressbar in activity mode, just
to show
something during a connection. Maybe there are other solutions, not
based on a progressbar...

Thanks,
___
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/




--
b3rx

"Don't be trapped by dogma - which is living with the results of other 
people's thinking. - Steve Jobs"


`There are only 10 people in this world who can read binary...'


___
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/
  
begin:vcard
fn:Walter Leibbrandt
n:Leibbrandt;Walter
org:Translate.org.za
adr:;;;Pretoria;Gauteng;;South Africa
email;internet:[EMAIL PROTECTED]
title:Developer
tel;work:(012) 460 1095
x-mozilla-html:FALSE
url:http://translate.org.za
version:2.1
end:vcard

___
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] General PyGtk design question

2008-06-25 Thread Walter Leibbrandt

Good day,

I would just like to ask a question about the design of PyGtk: What were 
the reasons for the C-like deisgn of PyGtk? For example having to use 
"label.set_text('bleh')" in stead of "label.text = 'bleh'" and "txt = 
label.get_text()" in stead of "txt = label.text".


Not that I'm criticizing, I was just wondering since I've used Gtk# 
before PyGtk and its C# adaptation works quite well. I know Python 
language features are used to a certain extent (ie. iterating over a 
gtk.ListStore), but the question remains. It seems that Python 
properties are the only example I can think of now, and if PyGtk has 
been around since before Python 2.2, that could answer my question. Can 
anyone confirm this or are there other reasons?


Thanks in advance,

Walter
begin:vcard
fn:Walter Leibbrandt
n:Leibbrandt;Walter
org:Translate.org.za
adr:;;;Pretoria;Gauteng;;South Africa
email;internet:[EMAIL PROTECTED]
title:Developer
tel;work:(012) 460 1095
x-mozilla-html:FALSE
url:http://translate.org.za
version:2.1
end:vcard

___
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] Close button on gtk.AboutDialog

2008-06-24 Thread Walter Leibbrandt

Hi,

Try this:

self.aboutdialog = gtk.AboutDialog()
self.aboutdialog.set_version('0.0.1')
response = self.aboutdialog.run()
self.aboutdialog.hide()


Seeing as gtk.AboutDialog inherits from gtk.Dialog, the "right way" to 
use it would be to call the run() method - which automatically calls 
show() - and then call its hide() method, because the program will block 
until the dialog's run() returns.


"response" will differ depending on how the dialog was closed: -6 for 
the "Close" button and -4 for the closing it with the X (for example in 
Gnome). A quick lookup ("[(a, int(getattr(gtk, a))) for a in dir(gtk) if 
a.startswith('RESPONSE_')]") reveals that those responses are 
gtk.RESPONSE_CANCEL (-6) and gtk.RESPONSE_DELETE_EVENT.


Ronaldo Nascimento wrote:

Code

self.aboutdialog = gtk.AboutDialog()
self.aboutdialog.set_version('0.0.1')
self.aboutdialog.show()


How do i get the "close" button to hide the dialog?
thanks

--
Ronaldo Nascimento
[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/
  
begin:vcard
fn:Walter Leibbrandt
n:Leibbrandt;Walter
org:Translate.org.za
adr:;;;Pretoria;Gauteng;;South Africa
email;internet:[EMAIL PROTECTED]
title:Developer
tel;work:(012) 460 1095
x-mozilla-html:FALSE
url:http://translate.org.za
version:2.1
end:vcard

___
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.ListStore columns in a gtk.ComboBox (added full code listing)

2008-06-23 Thread Walter Leibbrandt

Hi,

Having recently had my own struggle with ComboBoxen (more specifically 
ComboBoxEntry's), I can sum up my experience with the following 
statement: (Py)Gtk wants ComboBoxes' models to have a str column first!


I've tried using a ListStore(gobject.TYPE_PYOBJECT) (for my own models) 
with custom cell renderers specified (using set_cell_data_func()) and 
lost hours trying to get it to work. In the end, I ended up adding a str 
column as the _first_ column and "copying" a string representation of my 
objects to that column. This, in the end, does what I want: it saves a 
reference to one of my models in the ListStore. Moral of the story: 
adding a str column as the first column solved all my problems. If you 
want, you can check how I handle ComboBoxEntries: 
https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/spelt/spelt/gui/edit_area.py


In the first paragraph, I said (PyGtk), because I'm not sure if this is 
because of PyGtk or the C Gtk lib itself. The weird thing is that I'm 
using a ListStore(gobject.TYPE_PYOBJECT) with a TreeView and it works 
just great (in PyGtk and Gtk#)!


P. S. I'm not sure why, but I don't seem to receive any responses from 
Mr. Kintanar. :/


Isaac Alston wrote:

2008/6/22 Bertrand Son Kintanar <[EMAIL PROTECTED]>:
  

[...snip - code sample]
notice the if statement highlighted. this will show the column if we set the
flag to visible otherwise it will not show the column


Yes, I think this might work, although I am dubious about:
self.inputTreeView.append_column(column) because I don't think
ComboBox has that method. However, this seems to be a lot of work... I
was under the impression that gtk.ListStore was the model in a sort of
mvc system in which the view is independent from the model which
should easily allow different views. In this instance, it doesn't
appear to be the case, which is annoying. I will sleep on this :-) .

Thanks for your efforts,

  
begin:vcard
fn:Walter Leibbrandt
n:Leibbrandt;Walter
org:Translate.org.za
adr:;;;Pretoria;Gauteng;;South Africa
email;internet:[EMAIL PROTECTED]
title:Developer
tel;work:(012) 460 1095
x-mozilla-html:FALSE
url:http://translate.org.za
version:2.1
end:vcard

___
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/