Re: [pygtk] Splitting things up

2010-06-28 Thread Neil Dugan
Elver Loho wrote:
> Hi!
> 
> I'm a PyGTK newbie.
> 
> I built a small (less than 1k lines) PyGTK-based application back in
> 2006 that used SQLObject and was basically a simple GUI for editing
> things in a MySQL database table. It was a mixed experience for me. On
> the one hand designing a GUI with Glade was damn great and getting
> things done with PyGTK was surprisingly easy even back then. (I've
> noticed that you've improved a lot in this department over the years!
> Nice!) On the other hand the whole application ended up being a single
> file, with all of the GUI stuff being done in a single, insanely large
> class.
> 
> Is there a good design solution for splitting the window controller
> into multiple chunks?
> 
> For example, I've been doing some iPhone programming recently and on
> the iPhone each application consists of a ton of different UIViews.
> Each UIView could take up either the whole screen or just a part of
> it. And many UIViews come with a UIViewController, which is a nice way
> of implementing view-specific behavior. So, for example, you could
> build a small form consisting of two classes, one inheriting from
> UIView and the other from UIViewController. Then you can easily reuse
> that form elsewhere, as part of a larger view, while keeping its
> internal logic in those two classes and only communicating with the
> bits outside of it when it makes sense.
> 
> Is there a way of doing something like this with Glade and PyGTK?
> 
> The project I'm trying to build right now will have multiple windows,
> but almost all of them have a shared component: a database browser
> panel consisting of basic controls (back, forward, current record ID,
> number of records, go-to-record text box and button, search box) and
> I'd like to put the implementation of this panel into a separate Glade
> file and a separate Python class, then include it as a component in
> different parts of the application.
> 
> What would be the best way of doing that?
> 
> 
> Best,
> Elver
> 

Personally I don't use glade much.  But here is my 2 cents worth.

What you need to do is learn more about python classes, you can do 
almost anything with them.

Another handy thing to learn about is creating custom gtk+ signals for 
your gtk sub-classes.  So you can 'connect' to them.  Used right they 
can make your sub-classes much easier to code and use.

Take any shared code, put that into its own class and just import it 
into any modules that need it.

You could also put each of your windows into its own class (in its own 
file)

I think it would be a good idea to create a new class for your 
database panel in a separate file.  Using some gsignals to signal when 
the forward/backwards etc. buttons have been pressed.

Plus take any gtk widget or dialog that has any resonable amount of 
code associated with it.. sub class it and put all the code for 
handling that widget in that new class.  Depending on the size of the 
resulting class you can ether leave it in the same file or put in a 
new file.

Also you can take the other stuff like your database handling code 
into its own class.

Look for groups of functions, that handle similar objects or do 
similar jobs and put them in there own classes.

Regards Neil.





___
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.ComboBoxEntry and "changed" event on keystrokes.

2010-03-30 Thread Neil Dugan

Osmo Maatta wrote:

Hello,

I have a small application that has a search-field (gtk.ComboBoxEntry) 
and a button to start a search job.


The application will start a new search if user:
1) Selects an item from the gtk.ComboBoxEntry's drop-down list.
This is handled by gtk.ComboBoxEntry's "changed" event. This is Ok.

2  Types a search query (some text) and presses the [Start search] button.
This is handled by the button's "clicked" event. This is Ok.

3) Presses the [Enter]-key.
This is handled by the combo's "activate" event attached to the 
gtk.Entry. This is Ok.


Because a search-job can take quite a long time, I do not want to 
activate search for each keystroke, when user types text in the search 
field.  And this is my problem. Key-strokes activate the "changed" event 
on the gtk.ComboBoxEntry field. I cannot distinguish between the 
drop-down list's "changed" event (which I want) and the "changed" event 
when user types text (I try to avoid this event).


User is welcome to type in some text/query and press the [Start search] 
button. This is OK.


So how to avoid "changed" event on each keystroke?

A simplified but complete example: http://www.futuredesktop.com/tmp/w4.py

Happy Easter,
  Moma Antero
  Grønland





I couldn't find a direct way of handling the problem..

But how about a timeout that only occurs after the user stops typing 
for a while (e.g. 1/2 a second).  It stops the search being triggered 
for every keystroke.





# -*- coding: utf-8 -*-
import sys
import gtk
import gobject

class TestWindow(gtk.Window):
__gtype_name__ = "TestWindow"

def __init__(self, *args):
gtk.Window.__init__(self, *args)
self.timeout = None

self.set_default_size(300, 200)

vbox = gtk.VBox()
self.add(vbox)

hbox = gtk.HBox()
vbox.pack_start(hbox, expand=False, fill=False, padding=0)

combo = gtk.combo_box_entry_new_text()
#combo.connect("key-press-event", self.combo_key_press_event)
#combo.connect("key-release-event", self.combo_key_press_event)
#combo.connect("changed", self.combo_selection_changed)
combo.connect("changed", self.combo_timeout)
hbox.pack_start(combo, expand=False, fill=False, padding=0)

# Add some items
for i in range(6):
combo.append_text("Item %d" % (i,))

# Text input field (gtk.Entry object)
entry = combo.get_children()[0]
# Activate called on Enter-key
entry.connect("activate", self.entry_activate_event, combo)

button = gtk.Button("Start search")
button.connect("clicked", self.start_search_cb, combo)
hbox.pack_start(button, expand=False, fill=False, padding=0)

self.show_all()

def entry_activate_event(self, widget, user_data):
combo = user_data
txt = combo.get_active_text()
print "You pressed enter:", txt
return True

def combo_timeout(self, widget):
if self.timeout :
gobject.source_remove(self.timeout)		# remove old timeout
self.timeout = gobject.timeout_add(500, self.combo_selection_changed, widget)	# add a new one

def combo_selection_changed(self, widget):
txt =  widget.get_active_text()
print "Selection changed:", txt
return False	# cancal the timeout

def start_search_cb(self, widget, user_data):
combo = user_data
txt = combo.get_active_text()
print "Start search for:", txt 


if __name__ == "__main__":
window = TestWindow()
window.show()
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] Tool button with menu items and icons.

2010-03-27 Thread Neil Dugan
Osmo Maatta wrote:
> Hello,
> 
> My app has a tool-button with menu. I want to populate this menu with 
> menu-items that have both a label and icon. The menu items appear but 
> the images (icons) are not shown.
> 
> See this picture (tool button with menu + three menu-items shown)
> http://bildr.no/view/616160
> 
> I know the icon filenames and images are ok, the menu just refuses to 
> show them.
> Here is the code:
> 
> # Get the tool button
> tool_button = builder.get_object("toolbutton_other")
> ...
> menu = gtk.Menu()
> tool_button.set_menu(menu)
> 
> # Add 3 menu items; capture window item, capture camera picture, create 
> empty image
> for i in range(3):
>  if i == 0:
>  label = "Window item"
>  filename = "capture_item.png"
>  elif i == 1:
>  label = "From webcam"
>  filename = "capture_camera.png"
>  else:
>  label = "Empty image"
>  filename = "capture_empty.png"
> 
>  # Add menu items
>  menu = tool_button.get_menu()
> 
>  # Menu item with icon
>  menu_item = gtk.ImageMenuItem()
> 
>  image = gtk.Image()
>  image.show()
>  filename = os.path.join(getdatapath(), 'media', filename)
>  image.set_from_file(filename)
> 
>  menu_item.set_label(label)
>  menu_item.set_image(image)
>  menu_item.connect("activate", self.set_toolbutton_other, 
> tool_button, filename)
>  menu_item.show()
>  menu.append(menu_item)
> -
> 
> The other tool-button named "Window" has the same problem. I shows names 
> of all opened application windows, but the app-icon never appear even 
> the icon (18x18) is available.
> 
> Please tune me on the right track!
> 
> Most kindly
>   Moma Antero
>   Grønland
>   http://www.futuredesktop.org (.com)
> 
> 
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
> 

You can do

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.get_settings().set_long_property('gtk-menu-images', True, '')


___
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] Help with box layout

2010-03-15 Thread Neil Dugan
Nikolaus Rath wrote:
>>> | -vbox.pack_start(self.make_shot_box(), False)
>>> | + vbox.pack_start(self.make_shot_box(), False, False)
>>>
>>> Isn't the third parameter to pack_start ignored anyway if the second one
>>> is False?
>> No!  the prototype is :
>> def pack_start(child, expand=True, fill=True, padding=0)
>> So to set 'fill' to False you need at least 3 arguments.
> 
> I don't understand.
> 
> http://www.pygtk.org/pygtk2tutorial/sec-DetailsOfBoxes.html:
> 
> "The fill argument to the pack methods control whether the extra space
>  is allocated to the objects themselves (True), or as extra padding in
>  the box around these objects (False). It only has an effect if the
>  expand argument is also True".
> 
> In the above line you set expand to False, so you don't have to provide
> a value for fill, IMO.
> 

That appears to be the fact.  But I still prefer to specify both 
'expand' and 'fill'.


>>> |  def make_shot_box(self):
>>> | -box = gtk.HBox(True, 10)
>>> | + box = gtk.HBox(False, 10)
>>>
>>>
>>> This seems to get rid of the spacing between the label and spin
>>> button -- but why?
>> It doesn't.  It just sets the spacing of the widgets.
>> The code "box = gtk.HBox(spacing = 10)" would do the same thing.
> 
> The spacing is the same in both versions, you changed the 'homogenous'
> parameter.
> 

No!  The default is for 'homogenous' is False.  So technically you 
don't need to specify it.

>>> | + box.pack_start(gtk.Label(''), True, True, 0)
>>>
>>> What is this for?
>> It (and its mate further along) are there to use up the available 
>> space in 'box' to make the other widgets as small as possible, and to 
>> thereby cause them to be centralized.
> 
> Uh, I think I see. So the only way to center something in a box is to
> add an "empty" element on both sides with expand=True?

It is the only way I have found.

> 
>> As another thing, there is an easier way to create the buttons in the 
>> make_button_box() function.
>>   for (name,number) in [
>>   ('INIT',1),
>>   ('PULSE ON',2),
>>   ('STORE',3),
>>   ('ANALYSIS',4)] :
>>  button = gtk.Button(name)
>>  button.connect('clicked', self.blub, number)
>>  box.pack_start(button, True, True)
> 
> The buttons of course call different functions in the real code, this
> was just to simplify the example.
> 
Ok!  but you could put in a function like.
for (name,function) in [('INIT',self.on_init_clicked),
('PULSE ON',self.on_pulse_clicked)] :
button = gtk.Button(name)
button.connect('clicked', function)
box.pack_start(button, True, True)

Its just a coding preference, instead of have many pieces of code 
almost the same.

> 
> Best,
> 
>-Nikolaus
> 

___
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] Help with box layout

2010-03-14 Thread Neil Dugan
Nikolaus Rath wrote:
> Neil Dugan  writes:
>> Nikolaus Rath wrote:
>>> Hello,
>>>
>>> For some reason I'm just not able to figure out how use the packing
>>> parameters in the right way to get the layout that I want.
>>>
>>> Can someone help me out? What I want is this:
>>>
>>>   - In the first row, the label and spin button should be centered and
>>> right next to each other (no space in between).
>>>
>>>   - In the second row, all buttons should have the same size with 10px
>>> spacing between them. The set of buttons should again be centered.
>>>
>>>   - In the third line, the one button should be just as large as the 4
>>> buttons in the previous line (and also centered).
>>>
>>>   - The text area should fill the rest of the window
>>>
>>> Here is the code that I am using right now:
>>>
>>>
>> I don't know if this is the most effect way of doing what you want.
>> fixed a couple of minor other problems the lambda for the 
>> 'delete_event' need arguments and the Control.blub() function need 
>> some as well.
> 
> That already looks almost perfect, thank you so much!
> 
> (The only problem left is that the buttons grow when the window is
> resized and that the last button is not as wide as the buttons in the
> next-to-last line all together).

If you don't want to have the button grow you will need to put another 
HBox() around the current HBox() and add some empty labels each side 
to center it in the window.
All the widgets are the same size on my layout.

> 
> 
> But could you comment on a couple of your changes? I'd very much like to
> understand what I was doing wrong, so that next time I don't have to ask
> but can create the layout myself...
> 
> ,
> | $ diff -u -w box.py box_new.py 
> | --- box.py  2010-03-13 14:06:12.020104562 -0500
> | +++ blub.py 2010-03-13 10:36:00.940105089 -0500
> | @@ -10,70 +10,69 @@
> |  
> |  def __init__(self):
> |  self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
> | -self.window.connect("delete_event", lambda: False)
> | + self.window.connect("delete_event", lambda x,y: False)
> |  self.window.connect("destroy", gtk.main_quit)
> |  self.window.set_border_width(10)
> |  self.window.set_title('Dispatch Control')
> |  
> |  vbox = gtk.VBox(False, 10)
> | -vbox.pack_start(self.make_shot_box(), False)
> | + vbox.pack_start(self.make_shot_box(), False, False)
> 
> Isn't the third parameter to pack_start ignored anyway if the second one
> is False?

No!  the prototype is :
def pack_start(child, expand=True, fill=True, padding=0)
So to set 'fill' to False you need at least 3 arguments.  I find it 
easier to understand the code if I as a rule set at least the first 3 
arguments.

> 
> |  vbox.pack_start(self.make_button_box(), False)
> |  vbox.pack_start(self.make_textarea(), True, True)
> | -vbox.show()
> |  self.window.add(vbox)
> | -self.window.show()
> | + self.window.show_all()
> |  
> 
> I guess the removal of the .show() calls in favor of the
> window.show_all() call does not have an effect on the layout, right?
Yes!  I prefer just using a show_all(), unless I want a particular 
widget not to be shown initially.

> 
>
> |  def make_shot_box(self):
> | -box = gtk.HBox(True, 10)
> | + box = gtk.HBox(False, 10)
> 
> 
> This seems to get rid of the spacing between the label and spin
> button -- but why?

It doesn't.  It just sets the spacing of the widgets.
The code "box = gtk.HBox(spacing = 10)" would do the same thing.

> 
> |  
> | + box.pack_start(gtk.Label(''), True, True, 0)
> 
> What is this for?

It (and its mate further along) are there to use up the available 
space in 'box' to make the other widgets as small as possible, and to 
thereby cause them to be centralized.

> 
> |  label = gtk.Label("Create shot:")
> |  label.set_justify(gtk.JUSTIFY_RIGHT)
This line does nothing.  The label is minimum sized so justification 
is meaningless.
> |  label.show()
This line also does nothing (now).
> |  box.pack_start(label, False, False, 0)
This could be replaced by :
box.pack_start(gtk.Label("Create shot:"), False, False, 0)
> |  
> |  cur_shot = 42
> | -self.shotno = gtk.Adjustment(value=cur_shot+1, lower=1, 
> upper=cur_shot+1,
> | + self.shotno = gtk.Adjustment(value=cur_shot+1, l

Re: [pygtk] Help with box layout

2010-03-12 Thread Neil Dugan
Nikolaus Rath wrote:
> Hello,
> 
> For some reason I'm just not able to figure out how use the packing
> parameters in the right way to get the layout that I want.
> 
> Can someone help me out? What I want is this:
> 
>   - In the first row, the label and spin button should be centered and
> right next to each other (no space in between).
> 
>   - In the second row, all buttons should have the same size with 10px
> spacing between them. The set of buttons should again be centered.
> 
>   - In the third line, the one button should be just as large as the 4
> buttons in the previous line (and also centered).
> 
>   - The text area should fill the rest of the window
> 
> Here is the code that I am using right now:
> 
>
I don't know if this is the most effect way of doing what you want.
fixed a couple of minor other problems the lambda for the 
'delete_event' need arguments and the Control.blub() function need 
some as well.


#!/usr/bin/env python

from __future__ import print_function, absolute_import

import pygtk
pygtk.require('2.0')
import gtk

class Control(object):

 def __init__(self):
 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
 self.window.connect("delete_event", lambda x,y: False)
 self.window.connect("destroy", gtk.main_quit)
 self.window.set_border_width(10)
 self.window.set_title('Dispatch Control')

 vbox = gtk.VBox(False, 10)
 vbox.pack_start(self.make_shot_box(), False, False)
 vbox.pack_start(self.make_button_box(), False)
 vbox.pack_start(self.make_textarea(), True, True)
 self.window.add(vbox)
 self.window.show_all()

 def make_shot_box(self):
 box = gtk.HBox(False, 10)

 box.pack_start(gtk.Label(''), True, True, 0)
 label = gtk.Label("Create shot:")
 label.set_justify(gtk.JUSTIFY_RIGHT)
 label.show()
 box.pack_start(label, False, False, 0)

 cur_shot = 42
 self.shotno = gtk.Adjustment(value=cur_shot+1, lower=1, 
upper=cur_shot+1,
  step_incr=1)
 button = gtk.SpinButton(adjustment=self.shotno, digits=0)
 button.set_numeric(True)
 box.pack_start(button, False, False, 0)
 box.pack_start(gtk.Label(''), True, True, 0)

 return box

 def make_button_box(self):
 box = gtk.HBox(True, 10)

 button = gtk.Button("INIT")
 button.connect('clicked', self.blub, 1)
 box.pack_start(button, True, True, 0)

 button = gtk.Button("PULSE ON")
 button.connect('clicked', self.blub, 2)
 box.pack_start(button, True, True, 0)

 button = gtk.Button("STORE")
 button.connect('clicked', self.blub, 3)
 box.pack_start(button, True, True, 0)

 button = gtk.Button("ANALYSIS")
 button.connect('clicked', self.blub, 4)
 box.pack_start(button, True, True, 0)


 vbox = gtk.VBox(True, 10)
 vbox.pack_start(box, False, False)

 box = gtk.HBox()
 vbox.pack_start(box, False, False)

 box.pack_start(gtk.Label(''), True, True)
 button = gtk.Button("Full Cycle")
 button.connect('clicked', self.blub, 5)
 box.pack_start(button, False, False)
 box.pack_start(gtk.Label(''), True, True)

 return vbox

 def make_textarea(self):

 textview = gtk.TextView()
 textview.set_editable(True)
 textview.set_wrap_mode(gtk.WRAP_WORD)
 self.comment = textview.get_buffer()

 sw = gtk.ScrolledWindow()
 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
 sw.set_border_width(5)
 sw.add(textview)

 frame = gtk.Frame('Shot Comment')
 frame.add(sw)

 return frame

 def blub(self, widget, number):
 print('Click! %d' % (number))

if __name__ ==  '__main__':
 control = Control()
 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] [ANNOUNCE] PyPoppler 0.12.0

2009-09-27 Thread Neil Dugan
Gian Mario Tagliaretti wrote:
> I am pleased to announce version 0.12.0 of the Python bindings for Poppler.
> 
> It is available at:
> http://launchpad.net/poppler-python/trunk/development/+download/pypoppler-0.12.0.tar.gz
> md5: 78e9655067b8da2c8ad2565b2620e2f9
> 
> PyPoppler 0.12.0 (Sep 26 2009)
> ==
> 
> o Update aclocal.m4
> o Wrap new poppler 0.12 API
> 
> Blurb:
> ==
> 
> Poppler[1] is a PDF rendering library based on the xpdf-3.0 code base.
> 
> PyPoppler is a wrapper which exposes the poppler API to the
> python world.  It is fairly complete, most of the API are covered.
> 
> The documentation is actually missing, help wanted :)
> 
> Like the Poppler library itself, PyPoppler is licensed under  the GNU GPL.
> 
> PyPoppler requires:
> =
> 
>  o Poppler >= 0.12.0
>  o PyGObject >= 2.10.1
>  o PyGTK >= 2.10.0
>  o PyCairo >= 1.8.4
> 
> Bug reports should go to
> https://launchpad.net/poppler-python
> 
> [1] http://poppler.freedesktop.org/
> 
> cheers

I am using ubuntu and this has the package python-poppler is this the 
same thing?

___
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] Larger Font Size?

2009-08-14 Thread Neil Dugan
Art Hunkins wrote:
> I'd like to make a general
> declaration to set font size to 14 in my script.
> 
> On another list I was given a suggestion that gave rise to the following:
> 
> Would it be sufficient to:
> declare:
> from sugar.graphics import style
> 
> and early in my __init__ method specify:
> style.font_zoom(14)
> ?

try

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.get_settings().set_string_property('gtk-font-name','sans normal 
14')

> 
> I tried this and it didn't work; the script ran but font size (default size 
> = 10) didn't change.
> 
> Can anyone massage this for me, or indicate another simple way to accomplish 
> the same?
> 
> Art Hunkins 
> 
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
> 

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


[pygtk] gtk.ToggleButton not working.

2009-07-17 Thread Neil Dugan
With pygtk version 2.12.9 this works
"button = gtk.ToggleButton('test',False)"
but on pygtk version 2.16.1 it no longer works :)

I get the error message
RuntimeError: more argument specifiers than keyword list entries 
(remaining format:'):GtkToggleButton.__init__')

what do I need to do for it to work on both versions?
___
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_IS_WIDGET on subclass of a widget fails

2009-05-22 Thread Neil Dugan
Christian Becke wrote:
> Jeffrey Finkelstein schrieb:
>> I'm new to Gtk. I tried to create a subclass of an HBox and add it to a 
>> window, but I get a GtkWarning telling me that the assertion 
>> `GTK_IS_WIDGET()' fails on the instance of my subclass.
>>
>> For example:
>>
>> ===code===
>>
>> from gtk import Window, HBox, WINDOW_TOPLEVEL, main
>>
>> class FooBox(HBox):
>>  def __init__(self): pass
> 
> I think you have to call the constructor of the parent object here:
>   def __init__(self):
>   HBox.__init__(self)

wouldn't it be better to use
super(FooBox,self).__init__()

> and you have to make your new widget known:
> import gobject
> gobject.type_register (FooBox)
> 
>> window = Window(WINDOW_TOPLEVEL)
>> window.add(FooBox())
>> window.show_all()
>> main()
>>
>> ===/code===
>>
>> yields a warning at "window.add()", namely "GtkWarning: 
>> gtk_container_add: assertion `GTK_IS_WIDGET (widget)' failed". This 
>> causes the widget to not be displayed in the window.
>>
>> I don't really understand why this is; am I missing a method call?
> 
> Have a look at the gobject tutorial [1].
> 
> HTH,
> 
> Chris
> 
> [1]
> http://www.sicem.biz/personal/lgs/docs/gobject-python/gobject-tutorial.html
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
> 

___
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-25 Thread Neil Dugan
Rob Brown-Bayliss wrote:
> Hi.  
> 
> 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.
> 
> Does any one have an idea or solution that does not take up too much
> screen space.
> 
> here is the code I was usign to load the list:
> 
>   custs = self.DB.select("SELECT CAST(Customer_Key as TEXT), 
> CAST(Name
> as Text) FROM Customer Order By Name")
> cust_list =
> gtk.ListStore(gobject.TYPE_STRING,gobject.TYPE_STRING)
>   if custs != None:
>   for c in custs:
>   n = c[1].strip()
>   row = (unicode(n),c[0])
>   cust_list.append(row)   
>   self.customer.set_model(cust_list)  
> 
> 
> 
> --
> Rob Brown-Bayliss
> 
> http://globalvillage.sourceforge.net 
> The world at your finger tips...
> 
> 

I would use a gtk.TreeStore() model in a gtk.TreeView() widget.  Using 
the first one or two letters of the name for the tree nodes.

Maybe in a Dialog window if there isn't space for the gtk.TreeView() 
in the GUI.

It is possible use a lazy mode and only populate the gtk.TreeStore() 
as the user clicks on the appropriate nodes.

Regards Neil.

___
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] Calendar popup under an entry

2009-03-22 Thread Neil Dugan

Timo wrote:
Hello, I would like to have a gtk.Calendar to popup under a gtk.Entry as 
soon as the user clicks on the entry.
So I use the focus-in-event to capture when the user clicks in the 
entry. But I can't seem to find a way to popup a calendar.


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


Here is a custom widget I use.  You can default the format of the date
to anything you like.   When you right click in the widget it pops up
a calendar dialog.

You can also type the date into the widget in a wide set of formats.

When the date changes it also sends a 'date_changed' signal.


Hope this helps.



import gtk
from gtk import gdk
import gobject
import time

class InvalidDate(Exception):
	def __init__(self,date):
		super(InvalidDate, self).__init__()
		self.message = "Invalid date \"%s\"." % (date)
	def __str__(self):
		return self.message

class DateEntry(gtk.Entry) :
	#date = None
	calendar_dialog = False
	timestamp = None
	format = '%e-%b-%Y'
	widget = None
	window = None
	__gsignals__ = dict(date_changed=(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ()))
	
	def __init__(self, window, title = None) :
		super(DateEntry, self).__init__()
		self.connect('focus_out_event',self.on_focus_out_event)
		self.connect('button_press_event',self.on_button_press_event)
		self.connect('activate', lambda widget: widget.get_toplevel().child_focus(gtk.DIR_TAB_FORWARD))
		if not window :
			raise ValueError('Parent window needed')
		self.window = window
		self.title = title
		self.set_width_chars(11)
		#self.set_max_length(11)

	def __str__(self) :
		if self.timestamp == None :
			date = 'Unknown'
		else :
			date = time.strftime(self.format, self.timestamp)
		return date
	
	def on_button_press_event (self,widget,event) :
		#print "date_widget:on_button_press_event()"
		if event.button == 3 and event.type == gtk.gdk.BUTTON_PRESS :
			text = super(DateEntry, self).get_text()
			if text == None or len(text.strip()) == 0 : 
self.timestamp = None	#we don't want to emit a signal as the popup will do so when needed
			self.popup_calendar()
			return True
		else :
			return False
	
	def popup_calendar(self) :
		self.calendar_dialog = True
		#print "date_widget:popup_calendar() -- ",self.timestamp
		dialog = gtk.Dialog (self.title, self.window,
gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
		#self.dialog.set_position(gtk.WIN_POS_MOUSE)
		calendar = gtk.Calendar()
		dialog.vbox.pack_start (calendar, True, True, 0)
		calendar.connect('day_selected_double_click', self.calendar_check, dialog)
		timestamp = self.timestamp
		if (timestamp == None) :
			timestamp = time.localtime()
		if (timestamp) :
			calendar.select_month(timestamp[1] - 1,timestamp[0])
			calendar.select_day(timestamp[2])
		dialog.show_all()
		result = dialog.run()
		if result == gtk.RESPONSE_OK :
			self.calendar_check(calendar, dialog)
		else :
			dialog.destroy()
		self.calendar_dialog = False

	def calendar_check(self,widget, dialog) :
		(year,month,day) = widget.get_date()
		current = time.strptime("%d-%d-%d" % (year,month + 1,day),'%Y-%m-%d')
		#print self,"calendar_check",current
		super(DateEntry, self).set_text(time.strftime(self.format, current))
		self.check_for_signal(current)
		dialog.destroy()
	
	def set_format(self,format) :
		#print "date_widget:set_format"
		if format :
			self.format = format
	
	def set_today(self) :
		# round the current time into a date
		timestamp = time.strptime(time.strftime('%d-%b-%Y',time.localtime()),'%d-%b-%Y')
		self.check_for_signal(timestamp)
		super(DateEntry, self).set_text(self.get_date())

	def set_date(self,date,format = None) :
		#print "date_widget:set_date()"
		if date == None or len(date.strip()) == 0 :
			self.check_for_signal(None)
			super(DateEntry, self).set_text('')
			return
		if format == None : 
			format = self.check_formats(date)
		else :
			self.timestamp = time.strptime(date,format)
			super(DateEntry, self).set_text(self.get_date())
		if format == None :
			raise ValueError,'Unknown date format - %s' % (date)
	
	def set_pg_date (self, field) :
		return self.set_date(str(field.strftime('%d-%m-%Y')))

	def get_date(self,format = None) :
		#print "date_widget:get_date()"
		# check if the widget has the focus
		if self.is_focus() :
			# the widget has the focus
			# we need to check if the current text is OK
			text = super(DateEntry, self).get_text()
			if len(text) > 0 :
timestamp = self.check_formats(text) 
if not timestamp :
	raise InvalidDate(text)
			else :
return None
		if self.timestamp == None : return None
		if format == None : format = self.format
		return time.strftime(format, self.timestamp)
	
	def check_for_signal(self,current) :
		#print "timestamp = ",self.timestamp,"current ",current
		if (current != self.timestamp) :
			#print self,"emit da

Re: [pygtk] quoting text for markup

2009-03-22 Thread Neil Dugan
Darren Hart wrote:
> On Thu, Mar 19, 2009 at 12:59 AM, Walter Leibbrandt
>  wrote:
>> 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 &.
> 
> RIght & < and > - but my question was if there is some python call to
> do this or if I just have to roll my own.  I recently added this to my
> code base:
> 
> def quote_markup(str):
> return str.replace("&", "&").replace(">", ">").replace("<", "<")
> 
> It just would be nice if gtk offered something like that - or at least
> didn't break if you put an & in the text.  My version is pretty
> braindead, but if I use it carefully in my app, it works fine.
> 
> Thanks,
> 
>> --
>> 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
> 
> Heh, I recently wrote one of those as well - with some examples from a
> google code project.
> 

I use the 'cgi' module

 untested code ---
import cgi

dialog = gtk.MessageDialog()
dialog.set_markup(cgi.escape("Something & This"))

--
___
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-29 Thread Neil Dugan
Lionel Dricot wrote:
> Hello,
> 
> I'm displaying a treeview in my application and I update the content by
> creating a new treestore and then, once the treestore is create, I replace
> the old one with set_model.
> 
> Unfortunatly, the scroll position is not preserved and, at each refresh, the
> scroll go back to the top of the page.
> 
> I thought that it would be as simple as :
> 
> vadjust = self.treeview.get_vadjustment()
> ...
> refresh
> ...
> self.treeview.set_adjustement(vadjust)
> 
> But it doesn't work at all.
> 
> I've tried to set the value of vadjust, it has no effect.
> 
> What is strange is that if at any point I do a
> self.treeview.get_vadjustment().get_value(), I have the good value for the
> scrolling ! So the adjustment is good.
> 
> But then, why does my tree scroll to the top at each refresh ?
> 
> Can anybody help me ? How do you do when you want to keep a scrolled
> position ?
> 
> Thanks,
> 
> Lionel
> 
> 

Sometimes I find that a small delay helps.

# untested code
gobject.timeout_add(100, 
self.treeview.get_vadjustment().set_value(old_value))

The users wont notice a 1/10 second delay.

Regards Neil.

___
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] Multi gtk.EventBox and gtk.Image cause artefacts

2009-01-27 Thread Neil Dugan

MATTHIEU CADET wrote:

According to my problem with gtkEventBox, i've only one solution i think
there is a way to force refresh all windows and widgets ? maybe my problem
is a display bug or maybe i have too much gtkEventBox with gtkImage .

Please if someone have any solution for me.




I found a C example on how to put a .png image in a cairo widget
http://zetcode.com/tutorials/cairographicstutorial/cairoimages/

Here is a python script.





From: maty...@hotmail.com
To: py...@butterflystitches.com.au
Date: Mon, 26 Jan 2009 19:36:23 +0900
CC: pygtk@daa.com.au
Subject: Re: [pygtk] Multi gtk.EventBox and gtk.Image  cause artefacts









Hi,

I've try to replace gtkEventBox with a gtkButton, but it's the 
same problem...

At a certain number of button are showed the button is not
clickable :(

Maybe it's another problem with the main Window or may i need
to refresh; redraw or something like that ?

Or maybe it's not possible with gtk to show lot of gtkEventBox,
there is a limit on the EventBox ? or something related to the 
Window ?




From: maty...@hotmail.com
To: py...@butterflystitches.com.au
Date: Sat, 24 Jan 2009 19:16:17 +0900
CC: pygtk@daa.com.au
Subject: Re: [pygtk] Multi gtk.EventBox and gtk.Image  cause artefacts








Hi,

No i haven't try this solution, but i don't want my image looks like
a button, with the style of button you know rounded, and when you
see the image as a button.
Or maybe i can set a button style to "none" ? without the looks of 
a button.


I will try this, thanks for your answer.

Maty.




Date: Sat, 24 Jan 2009 13:48:42 +1100
From: py...@butterflystitches.com.au
To: maty...@hotmail.com
CC: pygtk@daa.com.au
Subject: Re: [pygtk] Multi gtk.EventBox and gtk.Image  cause artefacts

MATTHIEU CADET wrote:
I've found a solution to remove those artefacts, but the solution is to 
don't use gtk.EventBox and just use gtk.Image... 


But for the moment its not very good for me because i need to keep
the image as "clickable" so i can get informations of wich image is 
clicked.


Any help for this please?

Thanks.

Maty.



From: maty...@hotmail.com
To: pygtk@daa.com.au
Date: Tue, 20 Jan 2009 19:54:44 +0900
Subject: [pygtk]  Multi gtk.EventBox and gtk.Image  cause artefacts








Hi everybody!

I'm trying to write a tool in PyGtk that shows user lot of images in a Window,
each images must be "clickable", so i've put all of them into a gtk.EventBox.

The problem now for me is, when the number of images is more than about 45
EventBox shown in the main Window, i got some strange artefacts near to the
last image has been show.

How can i fix those artefacts from EventBox ? and keep my images clickable ?

Here the link to my code;glade and image :

http://www.filefactory.com/file/a02c6df/n/multi_eventbox_example_zip

Please if someone can help me on this.


Thanks a lot.

Maty.

Have you tried making each image a button with the image inside the 
button?








#!/usr/bin/python

# 48 x 48 pixel image
filename="apple-red.png"

import cairo
import gtk



class ImageFace(gtk.DrawingArea):
def __init__(self):
gtk.DrawingArea.__init__(self)
# load the image
self.image = cairo.ImageSurface.create_from_png(filename)
# the two callback needed
self.connect("expose_event", self.expose)
self.connect("button_press_event", self.on_button_press)
# set the button press event to happen
self.add_events(gtk.gdk.BUTTON_PRESS_MASK)
self.set_size_request(610, 610)

def expose(self, widget, event):
cr = widget.window.cairo_create()
# draw the image 100 times
for x in range(10,560,60) :
for y in range(10,560,60) :
cr.set_source_surface(self.image, x, y)
cr.paint();
return False

def on_button_press(self, widget, event):
# filter out all but the left mouse clicks
if event.button == 1 :
# find out where in the image we clicked
x = event.x % 60
y = event.y % 60
# see if we are on an image
if x > 12 and y > 17 and x < 50 and y < 50 :
# print what image we clicked on
print "you clicked on image %d x %d" % 
(int(event.x / 60), int(event.y / 60))


def main():
window = gtk.Window()
images = ImageFace()
sw = gtk.ScrolledWindow()
window.add(sw)
sw.add_with_viewport(images)
window.connect("destroy", gtk.main_quit)
window.show_all()

gtk.main()

if __name__ == "__main__":
main()


<>___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listi

Re: [pygtk] Multi gtk.EventBox and gtk.Image cause artefacts

2009-01-23 Thread Neil Dugan
MATTHIEU CADET wrote:
> I've found a solution to remove those artefacts, but the solution is to 
> don't use gtk.EventBox and just use gtk.Image... 
> 
> But for the moment its not very good for me because i need to keep
> the image as "clickable" so i can get informations of wich image is 
> clicked.
> 
> Any help for this please?
> 
> Thanks.
> 
> Maty.
> 
> 
> 
> From: maty...@hotmail.com
> To: pygtk@daa.com.au
> Date: Tue, 20 Jan 2009 19:54:44 +0900
> Subject: [pygtk]  Multi gtk.EventBox and gtk.Image  cause artefacts
> 
> 
> 
> 
> 
> 
> 
> 
> Hi everybody!
> 
> I'm trying to write a tool in PyGtk that shows user lot of images in a Window,
> each images must be "clickable", so i've put all of them into a gtk.EventBox.
> 
> The problem now for me is, when the number of images is more than about 45
> EventBox shown in the main Window, i got some strange artefacts near to the
> last image has been show.
> 
> How can i fix those artefacts from EventBox ? and keep my images clickable ?
> 
> Here the link to my code;glade and image :
> 
> http://www.filefactory.com/file/a02c6df/n/multi_eventbox_example_zip
> 
> Please if someone can help me on this.
> 
> 
> Thanks a lot.
> 
> Maty.
> 
Have you tried making each image a button with the image inside the 
button?



___
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] [Glade-devel] how to add window as a page to a notebook

2009-01-21 Thread Neil Dugan
Tristan Van Berkom wrote:
> On Sat, Jan 10, 2009 at 1:54 AM, anusha k  wrote:
>> hi,
>>
>> I am using glade and pygtk to develop an accounting software.In that we have
>> two glade files .first glade file contain the main window and the note book
>> and the second glade contains the another window .I want to add the second
>> glade-window as a page to first glade-window.how to do this
>> I have the code as below.but it is giving the warning and the window is not
>> shown up .warnings are :
>> How to solve the warnings.Is there any other way to solve this
>> Warnings:
>>
>> self.wTree = gtk.glade.XML(self.gladefile)
>> main.py:47: GtkWarning: gtk_notebook_set_tab_label: assertion `GTK_IS_WIDGET
>> (child)' failed
>>   self.wTree = gtk.glade.XML(self.gladefile)
>> main.py:20: GtkWarning: Can't set a parent on a toplevel widget
>>
>>
>> self.page=self.notebook.insert_page(self.wTreenewOrg.get_widget("window_new_org")
>> , None, 0)
>> main.py:20: GtkWarning: gtk_widget_set_child_visible: assertion
>> `!GTK_WIDGET_TOPLEVEL (widget)' failed
> 
> You cannot add a GtkWindow to another GtkContainer, a GtkWindow is a
> toplevel-only
> widget and is not meant to be maintained.
> 
> You can either:
>- Manually unparent your window's child and add that child to the
> notebook (the traditional oldschool way)
>- Use the "root" argument to glade_xml_new or some equivalent
> gtkbuilder api (I think that works
>  for building of sub-portions of the glade file)
>- Use development or trunk versions of Glade allowing you to use
> non-GtkWindow toplevel project
>  widgets - and use GtkBuilder that will allow you toplevelless
> glade files without errors/warnings.
> 
> Cheers,
>-Tristan

One thing I have done that is similar is, to not attach the window, 
but attach the most top level widget.  When designing the window, you 
need to put all the widgets in a HBox,VBox or Table.  Attach this not 
the window itself.

Regards Neil.

> 
>> self.page=self.notebook.insert_page(self.wTreenewOrg.get_widget("window_new_org")
>> , None, 0)
>> ***
>> Code:
>>
>> import pygtk
>> pygtk.require('2.0')
>> import gtk
>> import gtk.glade
>> import new_org
>> class mainmenu:
>> def show_newOrganisation(self,widget):
>> new_org.org()
>> self.gladefile_newOrg = "new_org.glade"
>> self.wTreenewOrg = gtk.glade.XML(self.gladefile_newOrg)
>>
>> self.page=self.notebook.insert_page(self.wTreenewOrg.get_widget("window_new_org")
>> , None, 0)
>> self.notebook.set_current_page(self.page)
>>
>> def dialogQuit(self,widget):
>> self.dialog_quit = self.wTree.get_widget("dialog_quit")
>> self.dialog_quit.show()
>> self.response = self.dialog_quit.run()
>> if self.response == 'gtk.RESPONSE_QUIT':
>> gtk.main_quit()
>> self.window.destroy()
>> self.dialog_quit.destroy()
>>
>>
>> def on_button_quit_clicked(*args):
>> gtk.main_quit()
>>
>> def on_button_cancel_clicked(*args):
>> self.dialog_quit.destroy()
>>
>> #To quit the main window
>> def on_Mainwindow_destroy(self):
>> gtk.main_quit()
>>
>>
>> def __init__(self):
>> #set the glade file
>> self.gladefile = "gnukhata.glade"
>> self.wTree = gtk.glade.XML(self.gladefile)
>>
>> #get the Main Window and connect the Destroy event
>> self.window = self.wTree.get_widget("MainWindow")
>> self.window.show()
>> self.window.connect('destroy',gtk.main_quit)
>> self.notebook = self.wTree.get_widget("notebook_main")
>> self.notebook.show()
>>
>> self.menuitem_quit = self.wTree.get_widget("menuitem_quit")
>> self.menuitem_quit.connect('activate',self.dialogQuit)
>>
>> self.menuitem_newOrg =
>> self.wTree.get_widget("menuitem_new_organisation")
>> self.menuitem_newOrg.connect('activate',self.show_newOrganisation)
>> if __name__ == "__main__":
>> mm=mainmenu()
>> gtk.main()
>>
>> Thanks in advance
>>
>> Njoy the share of Freedom,
>> Anusha
>>
>> ___
>> Glade-devel maillist  -  glade-de...@lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/glade-devel
>>
>>
> ___
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
> 

___
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] scrolledwindows and treeview

2008-12-28 Thread Neil Dugan
francesco wrote:
> Hi, i have a treeview inside a scrolledwindows
> when i append a new row scrolledwindows daesn't scroll until bottom but 
> stay up,
> if i scrolled by hand until bottom and so append a new row it scroll a 
> bit and cover the last row inserted.
> HOw can i make scrolledwindows to scroll to show always the last row 
> inserted?
> 
> thanks and sorry for my poor english
> 
> 
> 
This is what I use.

row_iter = model.append(.)
path = model.get_path(row_iter)
self.listview.scroll_to_cell(path)

Regards Neil.

___
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] hide on delete_event()

2008-12-08 Thread Neil Dugan
Peyman wrote:
> Hello
> 
> I am new to this mailing list. Originally I was posting to the glade  
> mailing list
> 
> My question is a simple one, I want my window to hide when I close it  
> (by clicking 'x'). I have browsed the web and the answer appears to be
> 
> def on_window_delete_event(widget,data,wtree):
>   print "If you can read this, then everything should work fine"
> 
>   widget.hide()
>   return gtk.TRUE
> 
> But when I do this very exact thing it still gets destroyed. And later  
> when I call the drawingArea widget (inside the window) it claims there  
> is no such widget.
> 
> Anyone else run into this problem?
> 
> Thank You
> 
> 
> Peyman Askari

I use this, to hide my dialog

class MyDialog :
---cut---
   def __init__(self)
 self.window = gtk.Dialog(..)
 self.window.connect('delete_event', self.hide)
---cut---
   def hide(self, dialog=None, event=None) :
 self.window.hide()
 return True# stop any event handling here
---cut---
   def show(self, callback = None):
 self.window.show()
---cut---

Regards Neil

___
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] Totals in TreeView

2008-10-02 Thread Neil Dugan
Alessandro Dentella wrote:
> Hi list,
> 
>   I try wit a different subject... sometime that makes the difference!
> 
>   I guess I'm not the only one that tried adding a different look for a row.
>   In internet there's plenty of solutions via a model column and some via
>   set_cell_data_func. I tried this but whet happens is that __all cell
>   change color___ 
> 
>   I tested with this code:
>   http://dpaste.com/hold/81386/
> 
>   and when the cell corresponding to "venice" gets colored, all tree cells
>   get colored too. 
> 
>   Any hints?
> 
>   TIA
>   sandro
> *:-)

Hi,

You need to use.

 if value == 'venice':
 cell.set_property("background", 'yellow')
 else :
 cell.set_property("background-set", False)

Regards Neil.

___
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] Log window

2008-09-23 Thread Neil Dugan
Frédéric wrote:
> 
> Le 17/9/2008, "Frédéric" <[EMAIL PROTECTED]> a écrit:
> 
>> My app heavily uses the logging module to log a lot of things. As this
>> app mainly runs on a Nokia Internet Tablet, I don't want to log in a
>> file. I would prefer to log in a special object, and be able to
>> show/hide the logs in a window.
> 
> Ok, I finally made something running, using
> ScrolledWindow/TextView/TextBuffer...
> 
> I added colors for each level, but I can't set a global 'black'
> background to the TextBuffer; only to the text I write. Is there a way
> to do that?
> 
> Thanks,
> 
> --
>Frédéric

See http://faq.pygtk.org/index.py?req=show&file=faq04.016.htp

Basically add the ScrolledWindow to an EventBox and use something like
eventbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("black"))

Regards Neil.

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


Re: [pygtk] How to add items to an empty ComboBox / ComboBoxEntry (created with glade) ?

2008-09-21 Thread Neil Dugan
Mats Taraldsvik wrote:
> Dear list,
> 
> I'm creating an application with pyGTK and Glade. In this I want to
> populate a combobox(2) depending on the selected item in another
> combobox(1).
> 
> Usually, I add None as an item of the comboboxes in glade, because
> nothing happens when I try to add items to an empty combobox. However,
> since I have to repopulate a combobox(2), I need the proper solution,
> since I have to empty it depending on combobox(1).
> 
> Regards,
> Mats Taraldsvik
> 

Hi,

This is untested!
A 'combobox.get_model().clear()' should clear what is all ready in the 
combobox, then a 'combobox.append_text()' should add new entries to 
the combobox.


note: this will most likely only work with a combobox created by 
gtk.combo_box_new_text().

Regards Neil.
___
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] CellRendererButton, or how to pack a Button inside a TreeView

2008-09-21 Thread Neil Dugan

Walter Leibbrandt wrote:

Hi,

I took the liberty of doing a quick search and found this: 
http://propython.googlecode.com/svn/gui/chaveiro/eagle.py (class 
_CellRendererButton). I don't know if/how it works, but that should get 
you started. :)


Regards,

Walter

Federico wrote:

Hi all,
Is there a way to embed a Button inside a TreeView?
I've tried creating a custom CellRenderer but could not find the way
to paint the button inside it.
I'd like this button to have RELIEF_NONE until it is hovered, then
showing up as a normal prelit button.
Is this possible?

Feel free to suggest a different solution and to ask for more
information if that's not clear :-)

Thanks,
Federico


Thanks Walter Leibbrandt for the hint.  I too wanted to put a button 
in a listview.  Here is what I worked out.


Regards Neil.

import gtk
import gobject

class CellRendererButton( gtk.CellRendererText ):
	__gproperties__ = { "callable": ( gobject.TYPE_PYOBJECT,
  "callable property",
  "callable property",
  gobject.PARAM_READWRITE ) }
	_button_width = 40
	_button_height = 30

	def __init__( self ):
		self.__gobject_init__()
		gtk.CellRendererText.__init__( self )
		self.set_property( "xalign", 0.5 )
		self.set_property( "mode", gtk.CELL_RENDERER_MODE_ACTIVATABLE )
		self.callable = None
		self.table = None
	# __init__()


	def do_set_property( self, pspec, value ):
		if pspec.name == "callable":
			if callable( value ):
self.callable = value
			else:
raise TypeError( "callable property must be callable!" )
		else:
			raise AttributeError( "Unknown property %s" % pspec.name )
	# do_set_property()


	def do_get_property( self, pspec ):
		if pspec.name == "callable":
			return self.callable
		else:
			raise AttributeError( "Unknown property %s" % pspec.name )
	# do_get_property()


	def do_get_size( self, wid, cell_area ):
		xpad = self.get_property( "xpad" )
		ypad = self.get_property( "ypad" )

		if not cell_area:
			x, y = 0, 0
			w = 2 * xpad + self._button_width
			h = 2 * ypad + self._button_height
		else:
			w = 2 * xpad + cell_area.width
			h = 2 * ypad + cell_area.height

			xalign = self.get_property( "xalign" )
			yalign = self.get_property( "yalign" )

			x = max( 0, xalign * ( cell_area.width - w ) )
			y = max( 0, yalign * ( cell_area.height - h ) )

		return ( x, y, w, h )
	# do_get_size()


	def do_render( self, window, wid, bg_area, cell_area, expose_area, flags ):
		if not window:
			return

		xpad = self.get_property( "xpad" )
		ypad = self.get_property( "ypad" )

		x, y, w, h = self.get_size( wid, cell_area )

#		if flags & gtk.CELL_RENDERER_SELECTED :
#			state = gtk.STATE_ACTIVE
#			shadow = gtk.SHADOW_OUT
		if flags & gtk.CELL_RENDERER_PRELIT :
			state = gtk.STATE_PRELIGHT
			shadow = gtk.SHADOW_ETCHED_OUT
		else :
			state = gtk.STATE_NORMAL
			shadow = gtk.SHADOW_OUT
		wid.get_style().paint_box( window, state, shadow, cell_area,
	 wid, "button",
	 cell_area.x + x + xpad,
	 cell_area.y + y + ypad,
	 w - 6, h - 6 )
		flags = flags & ~gtk.STATE_SELECTED
		gtk.CellRendererText.do_render( self, window, wid, bg_area,
	  (cell_area[0], cell_area[1] + ypad, cell_area[2],cell_area[3]), expose_area, flags )
# do_render()

	def do_activate( self, event, wid, path, bg_area, cell_area, flags ):
		cb = self.get_property( "callable" )
		if cb != None :
			cb (path)
		return True
# _CellRendererButton


gobject.type_register( CellRendererButton )


if __name__ == "__main__":

	class Tree(gtk.TreeView):
		def __init__(self):
			self.store = gtk.ListStore(gobject.TYPE_STRING,
			  gobject.TYPE_PYOBJECT)
			gtk.TreeView.__init__(self)
			self.set_size_request(300, 200)
			self.set_model(self.store)
			self.set_headers_visible(True)
			#self.get_selection().set_mode(gtk.SELECTION_NONE)

			rend = gtk.CellRendererText()
			column = gtk.TreeViewColumn('First', rend, text=0)
			self.append_column(column)

			rend = CellRendererButton()
			column = gtk.TreeViewColumn('Second', rend, text=0, callable=1)
			self.append_column(column)

		def insert(self, name):
			iter = self.store.append()
			self.store.set(iter, 0, name, 1, self.callback)

		def callback(self, path) :
			print self,"callback()", path, self.store.get_value(self.store.get_iter(path), 0)

	w = gtk.Window()
	w.set_position(gtk.WIN_POS_CENTER)
	w.connect('delete-event', gtk.main_quit)
	t = Tree()
	t.insert('foo')
	t.insert('bar')
	t.insert('baz')
	w.add(t)

	w.show_all()
	gtk.main()

___
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] ScrolledWindow & TextView Problem.

2008-09-14 Thread Neil Dugan
Dominic Salemno wrote:
> Greetings,
> 
> Here resides my issue! I have a ScrolledWindow being utilized inside my
> application. Contained inside of the ScrolledWindow is a TextView widget.
> Last, but certainly not least, is a TextBuffer associated with the TextView
> widget. Simple... correct? I thought as much! The main purpose of the
> application is to provide a scrolling effect anytime new text is inserted.
> The window would start scrolling downwards in the event the text started
> scrolling outside the viewable area. I implemented this technique inside the
> pygtk FAQ:
> 
> http://faq.pygtk.org/index.py?req=show&file=faq14.010.htp
> 
> The technique is basically explained as so (copied from the entry):
> 
> end_iter = text_buffer.get_end_iter()
> text_buffer.insert(end_iter, text)
> text_view.scroll_to_mark(text_buffer.get_insert(), 0)
> 
> This works fine until one touches the viewable area in where the text
> resides. The TextView properities are as follows:
> 
> set_editable(False)
> set_cursor_visible(False)
> 
> Therefore, no one is actually editing anything inside this area. I was
> simply trying to copy text that is populating the area and paste it into
> another application. As soon as I try this... new text still begins to
> populate the area. The scrolling effect just instantly stops working!
> 
> This effect is an absolute necessity for this type of application!
> 
> Suggestions?
> 
> Thank you!
> 
> Sincerely, Dominic Salemno.
> 
> 

Hi,

I don't know how to fix you exact problem.  But in a similar case, 
when adding an item to a gtk.HBox() inside a scrolledwindow, I used this

adj = self.scrolled_window.get_vadjustment()
adj.set_value(adj.upper)


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


Re: [pygtk] Widget packing problem

2008-08-09 Thread Neil Dugan
Boris Filipov wrote:
> Hello, this is my first post to this list and I hope i don't offend anyone.
> I'm writing an application which consists of the following:
> Window ->
> VBox ->
> HBox ->
> Button1
> Button2
> Table ->
> 16 Rows and 16 columns filled with ToggleButtons
> 
> How should i modify my design to suit the need of adding a label before each
> row and each column. Each label would have about 10 characters. Thank you
> for your answers in advance!
> 
> 

One way is, alter the table to 17 x 17 put the labels in column 1 and 
row 1 and the ToggleButtons in columns 2 - 17 and row 2 - 17.

Regards Neil


___
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] installing on UBUNTU Hardy Heron

2008-07-18 Thread Neil Dugan
randy wrote:
> I'm trying to install PyGtk on UBUNTU Hardy Heron for development, can't
> make it work.
> 
> I'm trying to run the demo called base.py:
> 
> #!/usr/bin/env python
> # example base.py
> 
> import sys
> sys.path.append("/usr/share/python-support/python-gobject")
> 
> 
> 
> import pygtk
> pygtk.require('2.0')
> import gtk
> 
> class Base:
> def __init__(self):
> self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
> self.window.show()
> 
> def main(self):
> gtk.main()
> 
> print __name__
> if __name__ == "__main__":
> base = Base()
> base.main()
> 
> 
> Initially, Python couldn't import pygtk. I found it, then just patched
> in the sys.path.append for the time being to see what else needed work.
> Now,  python stops at import gtk, which I discovered isn't installed
> anywhere.
> 
> What are the steps I need to follow to correctly install PyGtk on
> UBUNTU?
> 

I am using 8.04 Hardy Heron, worked out of the box for me.


___
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] installing on UBUNTU Hardy Heron

2008-07-17 Thread Neil Dugan
randy wrote:
> I'm trying to install PyGtk on UBUNTU Hardy Heron for development, can't
> make it work.
> 
> I'm trying to run the demo called base.py:
> 
> #!/usr/bin/env python
> # example base.py
> 
> import sys
> sys.path.append("/usr/share/python-support/python-gobject")
> 
> 
> 
> import pygtk
> pygtk.require('2.0')
> import gtk
> 
> class Base:
> def __init__(self):
> self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
> self.window.show()
> 
> def main(self):
> gtk.main()
> 
> print __name__
> if __name__ == "__main__":
> base = Base()
> base.main()
> 
> 
> Initially, Python couldn't import pygtk. I found it, then just patched
> in the sys.path.append for the time being to see what else needed work.
> Now,  python stops at import gtk, which I discovered isn't installed
> anywhere.
> 
> What are the steps I need to follow to correctly install PyGtk on
> UBUNTU?
> 

I am using 8.04 Hardy Heron, worked out of the box for me.



___
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 floats in treeview

2008-07-09 Thread Neil Dugan

Jeremy S wrote:

If you put a float in a treeview, you get a really long decimal, which
is almost always not desired.  So, after playing around with it for a
while, I came up with this code to truncate floats at 1 decimal place:
column.set_cell_data_func(renderer,
lambda column, cell, model, iter:
cell.set_property('text', '%.1f' % model.get_value(iter,
column.get_sort_column_id(

The problem with this is that it uses
GtkTreeViewColumn::get_sort_column_id() to get the column number,
which only works if the column is sortable.  Can anyone tell me what
to do if I want the formatting to work on any column, not just
sortable columns?  Thank you.


I use a text renderer with a right justify setting.  And convert the 
float to a string for the model.  That way I can have any number of 
decimal points I feel like.


right = gtk.CellRendererText()
right.set_property('xalign',1.0)
column = gtk.TreeViewColumn('number',right)
view.append_column(column)

Hope this helps..

Regards Neil.

___
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] TreeView - Making whole row colored

2008-07-09 Thread Neil Dugan

Stephen George wrote:

Hi,

I am trying to get a treeview (with liststore model) to display rows in 
different colors based on content in the list.


 From what I've read in GTK+ 2.0 Tree View Tutorial - Tim-Philipp Muller 
( c code based)


"The most suitable approach for most cases is that you add two columns 
to your model, one for
the property itself (e.g. a column COL_ROW_COLOR of type G_TYPE_STRING), 
and one for the boolean flag of
the property (e.g. a column COL_ROW_COLOR_SET of type G_TYPE_BOOLEAN). 
You would then connect these
columns with the "foreground" and "foreground-set" properties of each 
renderer. Now, whenever you set
a row’s COL_ROW_COLOR field to a colour, and set that row’s 
COL_ROW_COLOR_SET field to TRUE, then
this column will be rendered in the colour of your choice. If you only 
want either the default text colour or one
special other colour, you could even achieve the same thing with just 
one extra model column: in this case you
could just set all renderer’s "foreground" property to whatever special 
color you want, and only connect the
COL_ROW_COLOR_SET column to all renderer’s "foreground-set" property 
using attributes."


Which I've implemented as attached.

The setting of foreground seems to be working (half list blue, half red)
However my implementation seems to be ignoring the foreground-set flag.

I am expecting to ONLY see my 'special' foreground color when the 
modified flag is also set to true, and grey/black writing when the 
foreground-set flag is False.


I can get grey writing by setting the foreground to None, but I don't 
belive this was the intent of the above description.


Am I mis-understanding how this functionality should work, .. or made 
some errors in my code?


Thanks for any suggestions.
Steve



Hi Steve,

I can't see the pattern in why the colors are how they are.  I think 
some of the trouble has to be with some 'foreground-color' set as None.


It would probably be better to not use the 'Modified' column to affect 
the color, and just put the color you want the row in the 
'foreground-color' column (i.e. red,black or blue) and change the 
set-up to.


column.add_attribute(mycell, 'foreground', COLUMN_FOREGROUND)
mycell.set_property('foreground-set', True)




If you must stay with this set-up, this function seems to do what you want

def _cell_data_func(self, column, cell, model, iter):
		(modified,foreground) = 
model.get(iter,COLUMN_MODIFIED,COLUMN_FOREGROUND)

if foreground == None : foreground = 'black'
if modified :
cell.set_property('foreground',foreground)
else :
cell.set_property('foreground','black')
cell.set_property('foreground-set',True)
return False

And use "column.set_cell_data_func(mycell, self._cell_data_func)" to 
set it up.


Regards Neil.


77a78,84
> def _cell_data_func(self, column, cell, model, iter):
>   #print "totalcelldatamethod()"
>   (modified,foreground) = 
> model.get(iter,COLUMN_MODIFIED,COLUMN_FOREGROUND)
>   cell.set_property('foreground',foreground)
>   cell.set_property('foreground-set',modified)
>   return False
> 
92,93c99,101
< column.add_attribute(mycell, 'foreground', COLUMN_FOREGROUND)
< column.add_attribute(mycell, 'foreground-set', COLUMN_MODIFIED)
---
> #column.add_attribute(mycell, 'foreground', COLUMN_FOREGROUND)
> #column.add_attribute(mycell, 'foreground-set', COLUMN_MODIFIED)
> column.set_cell_data_func(mycell, self._cell_data_func)
___
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] accelerator for an image button.

2008-07-09 Thread Neil Dugan

Gian Mario Tagliaretti wrote:

2007/11/3, Neil Dugan <[EMAIL PROTECTED]>:

Hi Neil,



I am trying to make an python/gtk+ app.  One problem I am having is
attaching an accelerator to a image button.

This is the code I am using to create the buttons.

--- cut ---
   def index_control(self):
   hbox = gtk.HBox()
   for stock in
[gtk.STOCK_GOTO_FIRST,gtk.STOCK_GO_BACK,gtk.STOCK_GO_FORWARD,gtk.STOCK_GOTO_LAST]
 :
   image = gtk.Image()
   image.set_from_stock(stock,gtk.ICON_SIZE_MENU)
   button = gtk.Button()
   button.set_image(image)
   hbox.pack_start(button,False,False)
   return hbox
--- cut ---
I can give the full source if needed.



I don't see any code with accelerators here, btw here we go with a
small example:

import gtk

w = gtk.Window()
w.connect("destroy", gtk.main_quit)
w.set_default_size(200, 300)

b = gtk.Button(None, gtk.STOCK_QUIT)
b.connect("clicked", gtk.main_quit)

ag = gtk.AccelGroup()
w.add_accel_group(ag)

b.add_accelerator("clicked", ag, ord('q'), gtk.gdk.SHIFT_MASK,
gtk.ACCEL_VISIBLE)

w.add(b)
w.show_all()
gtk.main()

cheers


Thanks for that.  I didn't know about the add_accelerator() function. 
 I found the gtk.accelerator_parse() function, once I found out what 
to parse (e.g. "Left") it didn't take me long to get everything 
working.


Regards Neil.
___
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] Geting a window/dialog to appear on a different screen.

2008-06-03 Thread Neil Dugan

Hi,

I have a LTSP set-up here.  I would like to put a window or dialog on 
the client screens, but I can't seem to get this to happen I am 
getting weird errors from gtk.main().


See attachment for the code.

The errors I am getting are
/media/tmp/testgui:43: GtkWarning: gdk_screen_get_display: assertion 
`GDK_IS_SCREEN (screen)' failed

  gtk.main()
/media/tmp/testgui:43: GtkWarning: gdk_keymap_get_for_display: 
assertion `GDK_IS_DISPLAY (display)' failed

  gtk.main()
/media/tmp/testgui:43: Warning: invalid (NULL) pointer instance
  gtk.main()
/media/tmp/testgui:43: Warning: g_signal_connect_data: assertion 
`G_TYPE_CHECK_INSTANCE (instance)' failed

  gtk.main()
Traceback (most recent call last):
  File "/media/tmp/testgui", line 43, in 
gtk.main()


If I comment out line 20 
"window.set_screen(display.get_screen(screen))" all works as expected.


Any help appreciated.

Regards Neil.
#!/usr/bin/python



import pygtk
pygtk.require('2.0')
import gtk
import sys
import os
import tempfile
import stat
import gobject

def Window(display_name,screen,filename):
print "display = %s  screen %d" % (display_name,screen)
display = gtk.gdk.Display(display_name)
# create a window
window =  gtk.Window(gtk.WINDOW_TOPLEVEL)
# make sure it appears on correct display
window.set_screen(display.get_screen(screen))
window.connect("destroy",  lambda w: w.destroy())
window.filename = filename
# setup the widgets
vbox = gtk.VBox()
window.add(vbox)
label = gtk.Label(filename)
vbox.pack_start(label, False, False)
entry = gtk.Entry()
vbox.pack_start(entry, False, False)
button = gtk.Button('_Text')
vbox.pack_start(button, False, False)
button.connect('clicked', get_text, entry, window)
# display the window
window.show_all()

def get_text(widget, number, window) :
print "number = %s   file = %s" % (number.get_text(), window.filename)
window.destroy()


if __name__ == "__main__":
Window(':0',0,'/tmp/file.txt')
gtk.main()

___
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] Blocking main loop during execution of external program

2008-05-22 Thread Neil Dugan

Vláďa wrote:

Hi,

I'd like to ask you for help with solving my problem. First I'll try to 
describe what I'm doing:


I have a PyGTK application which needs to run an external command. I use 
subprocess.Popen to do it. Then I run a gtk.Dialog (saying "Please 
wait") and wait until the process is finished. After the external 
process finishes I close the dialog and the program continues. So far 
everything works fine. But now I want to change it a little. After the 
process is finished, I want to return to the main loop but keep the 
dialog opened. Then process results of the external program and run the 
external program again. Repeat this a couple times and then finally 
close the "Please wait" dialog.


I found out that I can return back while leaving the dialog opened by 
calling dialog.return(0). But when I run the dialog again with 
dialog.run(), Python (the interpreter) crashes. What is the problem? Is 
it impossible to run the same dialog twice? What else could I do?


I need to block the main program loop because it can't continue before 
the external program finishes. At the same time I want to have a pop up 
window with a "Cancel" button (the window must be responsive). I'm 
afraid I'm not experienced enough to use threading, which would be 
probably best suited for this task. What would be the most simple way to 
solve my problem?


I hope it is clear what I'm trying to do. Unfortunately my English is 
far away from being perfect. If a code sample would help, I can post it.


Best regards,
Vlada

Have you tried to do it with a non-blocking dialog ?
Using
dialog.connect('response', callback)
dialog.show()

If you want to temporaly remove the dialog use
dialog.hide()

And when finished use
dialog.destroy()


___
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] Contant height of GtkProgressBar

2008-05-10 Thread Neil Dugan

Mitko Haralanov wrote:

In my application (GUI designed using Glade2), I have a progress bar
that is used by multiple parts of the app.

Some of the parts display text in the progress bar and others done. The
problem that I am having is that the height of the progress bar changes
when there is text displayed and when there isn't. This causes
re-drawing of the application and is really annoying.

Is there a way that I can prevent this from happening, either by
changing the font used by the progress bar or by having the widget
height be calculated in a permanent way?

Thanx



Have you tried instead of displaying no text to instead display a 
couple of spaces instead (i.e. '   ')

___
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] Label a different font sizes

2008-04-18 Thread Neil Dugan

Vláďa wrote:
Thank you for your reply. I know I have to use "set_use_markup(True)". 
All of the Pango markup attributes work for me except of font size. At 
the top of the page you are referring there is an example:


Blue text

So I think my code is correct. The problem is, that the first value 
(size="14") in my example is also used for the second line, although I 
specified new size (size="10"). The strange thing is that if I use 
attributes like "large" or "small" then it works. Unfortunately my 
English is rather weak, so I'm not sure if I can explain it clearly. 
Here is a short sample code to show the problem:



I used the line
   self.label = gtk.Label('size="2">Texting\nTexting\nsize="small">Text 3')


Everything worked how it should
Ubuntu 7.10 (gutsy)
Gnome 2.10.1
Kernel 2.6.22-14-generic
Python 2.5.1

Regards Neil.



#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import pango

class HelloWorld:
   def hello(self, widget, data=None):
   print "Hello World"

   def delete_event(self, widget, event, data=None):
   print "delete event occurred"
   return False

   def destroy(self, widget, data=None):
   print "destroy signal occurred"
   gtk.main_quit()

   def __init__(self):
   self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
   self.window.connect("delete_event", self.delete_event)
   self.window.connect("destroy", self.destroy)
   self.window.set_border_width(10)
   self.button = gtk.Button()
   self.label = gtk.Label('Text 1\nsize="10">Text 2\nText 3')

   self.label.set_use_markup(True)
   self.button.add(self.label)
   self.button.connect("clicked", self.hello, None)
   self.button.connect_object("clicked", gtk.Widget.destroy, 
self.window)

   self.window.add(self.button)
   self.window.show_all()

   def main(self):
   gtk.main()

if __name__ == "__main__":
   hello = HelloWorld()
   hello.main()

The button label has 3 lines, the first 2 have size 14, the last one is 
small. But the second line should have size 10. What is wrong in my code?


Thank you


John Finlay napsal(a):


Vláďa wrote:


Hi,

I have a question regarding labels and Pango.

I want to use different sizes of font, but unfortunately it doesn't 
work. If I use


self.label = gtk.Label('Text 1\nsize="10">Text 2')


then only the first size definition (14) is taken into account. The 
second line has the same font size.


Is this a feature, bug or my fault? Hot to create a label with 
different font sizes in it?


First you have to tell the label to use Pango markup:

self.label.set_use_markup(True)

Then you have to specify a readable size since numerical sizes are in 
thousandths of a point - see:


http://www.pygtk.org/docs/pygtk/pango-markup-language.html

John


___
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 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] Automatic actions and gtk.FileChooserButton

2008-04-18 Thread Neil Dugan

Marcus Vinicius Eiffle Duarte wrote:

Hi, folks!

Sorry if this question seems silly, but I am rather new to python and a
total newbie regarding Gtk programming, I googled a lot for a solution to my
problem and couldn't find something that worked for me.

I created a GUI using Glade, which contains a FileChooserButton. On startup,
this FileChooserButton displays the default folder for the application, and
a list of text files contained in this folder is loaded and presented in a
TreeView. My idea is, everytime the user chooses another folder using the
FileChooserButton, the application automatically loads the list of text
files in this new folder and refreshes the TreeView to show this new list.

In order to do this, I connected some code to the "current_folder_changed"
signal of the FileChooserButton, as in

(...)
self.btnPasta = self.wTree.get_widget( "btnPasta" )
self.btnPasta.connect( "current_folder_changed", self.mudarPasta )
(...)

However, when I use the FileChooserButton btnPasta to choose another
folder,nothing happens. I made some tests and it seems that the function
mudarPasta is not executed at all. This function is defined inside my class
(as other functions that are executed by other signals of other widgets and
called as self.):

def mudarPasta( filechooser, widget ):
novaPasta = filechooser.get_current_folder()
PASTA = novaPasta
os.chdir( PASTA )
self.popular()

Can someone help me?


How about this example ?



Thanks in advance,




Regards Neil.


#!/usr/bin/env python

# example filechooser.py

import pygtk
pygtk.require('2.0')

import gtk

# Check for new pygtk: this is new class in PyGtk 2.4
if gtk.pygtk_version < (2,3,90):
   print "PyGtk 2.3.90 or later required for this example"
   raise SystemExit

dialog = gtk.FileChooserDialog("Open..",
   None,
   gtk.FILE_CHOOSER_ACTION_OPEN,
   (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)

filter = gtk.FileFilter()
filter.set_name("All Text files")
filter.add_pattern("*.txt")
dialog.add_filter(filter)

filter = gtk.FileFilter()
filter.set_name("All files")
filter.add_pattern("*")
dialog.add_filter(filter)

filter = gtk.FileFilter()
filter.set_name("Images")
filter.add_mime_type("image/png")
filter.add_mime_type("image/jpeg")
filter.add_mime_type("image/gif")
filter.add_pattern("*.png")
filter.add_pattern("*.jpg")
filter.add_pattern("*.gif")
filter.add_pattern("*.tif")
filter.add_pattern("*.xpm")
dialog.add_filter(filter)

response = dialog.run()
if response == gtk.RESPONSE_OK:
print dialog.get_filename(), 'selected'
elif response == gtk.RESPONSE_CANCEL:
print 'Closed, no files selected'
dialog.destroy()
___
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] NEWBIE QUESTION: Simple spinbutton example?

2008-03-22 Thread Neil Dugan

Darren Enns wrote:

Hello all!

I am slowly learning the Python language, and now I am moving into 
developing GUI apps using PyGTK.  I am bumbling/stumbling around with 
'spinbutton'.  I know how to make the spinbutton appear, but I don't 
know how to *properly* return the final value for a spinbutton back to 
my mainline code.  Can someone provide a very simple example of:


1) A mainline creating a window and a button
2) When pushed, the button should call a module which opens another 
(temporary) window to display a 'spinbutton'
3) The final value of the spinbutton when the 2nd window is closed 
should return (somehow) the value back to the calling mainline


Here is the minimum that I am currently using to accomplish this (please 
don't laugh!):


#!/usr/bin/env python2.5
import gtk

def get_value(widget,spin,value):
   value = "%d" % spin.get_value_as_int()
   print "value=",value
   return

def get_spin(widget):
   window = gtk.Window()
   adjustment = gtk.Adjustment(0, -90, 90, 1, 1, 1)
   spinbutton = gtk.SpinButton(adjustment,0,0)
   value = 0
   spinbutton.connect("changed",get_value,spinbutton,value)
   print "the final value is: ",value
   spinbutton.show()
   window.add(spinbutton)
   window.show()
   return

def main():
   window = gtk.Window(gtk.WINDOW_TOPLEVEL)
   window.connect("destroy", gtk.main_quit)
   window.show_all()
   table = gtk.Table(2,1,False)
   button = gtk.Button("Get Spin Value")
   button.connect("clicked",get_spin)
   table.attach(button,0,1,0,1)
   table.show()
   button.show()
   window.add(table)
   window.show_all()
   gtk.main()
   return

if __name__ == '__main__': main()

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



Hello Dare,

Here is one way, that works.  The main problem with the way you had 
the code structured, is that the 'value' variable in get_spin() and 
the 'value' variable in main() where two different things.


Separating the two windows into separate classes, makes it is easy to 
make sure that there is only one 'value' variable.  And the code 
becomes easier to understand.  As in the main window class it is 
obvious (see print_value()) that we are refereing to the variable set 
by the spin_window() class.


Hope this helps.

Neil.
#!/usr/bin/env python2.5
import gtk

value = ""

class spin_window :   
	value = 0
	def get_value(self,widget):
	   self.value = "%d" % widget.get_value_as_int()
	   return

	def __init__(self):
	   print "the final value is: ",value
	   window = gtk.Window()
	   adjustment = gtk.Adjustment(0, -90, 90, 1, 1, 1)
	   spinbutton = gtk.SpinButton(adjustment,0,0)
	   spinbutton.connect("changed",self.get_value)
	   spinbutton.show()
	   window.add(spinbutton)
	   window.show()
	   return

class main_window:
	def print_value(self,widget):
	   print "window value=",self.window.value
	   return

	def get_spin(self,widget) :
		self.window = spin_window()

	def __init__(self):
	   window = gtk.Window(gtk.WINDOW_TOPLEVEL)
	   window.connect("destroy", gtk.main_quit)
	   table = gtk.Table(2,1,False)

	   button = gtk.Button("Show window")
	   button.connect("clicked",self.get_spin)
	   table.attach(button,0,1,0,1)

	   button2 = gtk.Button("Print value")
	   button2.connect("clicked",self.print_value)
	   table.attach(button2,1,2,0,1)

	   window.add(table)
	   window.show_all()

	def main(self):
	   gtk.main()
	   return

if __name__ == '__main__': 
	main = main_window()
	main.main()
___
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 Lifecycle?

2008-03-22 Thread Neil Dugan

Darren Hart wrote:

On 3/19/08, Neil Dugan <[EMAIL PROTECTED]> wrote:


Darren Hart wrote:


I'm trying to add a dialog bound to a menu item.  I created the UI in
glade.  I use the glade.XML.get_widget() to get the dialog, and then


show()


it from the menuitem action handler.  Then I hide it when the dialog
response handler receives RESPONSE_OK.  If I CLOSE the dialog however


(from


the window manager X button) I see gtk.RESPONSE_DELETE_EVENT, and after


that


I can no longer use glade.XML.get_widget() to retrieve my dialog.  It


has


been destroyed.

1) Is it really necessary to destroy and recreate the dialolg, rather


than


just show/hide?
2) If so, is the only way to recreate the dialog to re-read the glade


file,


passing it the dialog name as the third param?

Also, the dialog is visible by default, so part of my start -up sequence


is


to hide it but you can see the wm animation... so I don't think that


is


the right way either.

I get the feeling I'm swimming upstream here, so if someone can set me
straight on how to properly use dialog boxes, I would be most


appreciative.


Thanks,





Hi Darren,

The way I do it is, I have a function like.

def hide(self, dialog, event) :
   dialog.hide()
   return True

And in the init I use the command
   dialog.connect('delete_event', self.hide)

I am not using glade thou, but this should work.





OK, the key being to return True so that other handlers (such the built-in
one that destroys it) don't get run?

How do you ensure the dialog isn't visible when the application starts?


I don't use glade. When I build the requester (in my init code) I just 
don't do a dialog.show() call.  That is done latter when I want to see 
the requester.


One thing to remember is the dialog variable needs to stay valid for 
the entire time the program is running (e.g. a global).


But as far as I remember when you start your glade app, it shouldn't 
auto show the dialogs ether.




Thanks,

Darren


Regards Neil.


___
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 Lifecycle?

2008-03-19 Thread Neil Dugan

Darren Hart wrote:

I'm trying to add a dialog bound to a menu item.  I created the UI in
glade.  I use the glade.XML.get_widget() to get the dialog, and then show()
it from the menuitem action handler.  Then I hide it when the dialog
response handler receives RESPONSE_OK.  If I CLOSE the dialog however (from
the window manager X button) I see gtk.RESPONSE_DELETE_EVENT, and after that
I can no longer use glade.XML.get_widget() to retrieve my dialog.  It has
been destroyed.

1) Is it really necessary to destroy and recreate the dialolg, rather than
just show/hide?
2) If so, is the only way to recreate the dialog to re-read the glade file,
passing it the dialog name as the third param?

Also, the dialog is visible by default, so part of my start -up sequence is
to hide it but you can see the wm animation... so I don't think that is
the right way either.

I get the feeling I'm swimming upstream here, so if someone can set me
straight on how to properly use dialog boxes, I would be most appreciative.

Thanks,




Hi Darren,

The way I do it is, I have a function like.

def hide(self, dialog, event) :
dialog.hide()
return True

And in the init I use the command
dialog.connect('delete_event', self.hide)

I am not using glade thou, but this should work.

Regards Neil.


___
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] possible bug in gtk.glade

2008-02-20 Thread Neil Dugan

Hi,

I have found a bug but I don't know where it is.

I generated a simple glade file with a 'Gnome date' widget in it (just 
as test).  I told glade I didn't want the time widgets displayed, but 
when I get gtk.glade to generate the window the time widgets are there.


glade 3.4.0
python 2.5.1

Regards Neil


testwindow.glade
Description: application/glade
#!/usr/bin/python

import gtk
import gtk.glade

class Window :
	def __init__(self) :
		self.glade = gtk.glade.XML('./testwindow.glade',root='window1')
		self.glade.signal_autoconnect(self)
		self.window = self.glade.get_widget('window1')
		self.window.show_all()

	def main(self) :
		gtk.main()

	def gtk_main_quit(self, widget, event) :
		gtk.main_quit()

	def on_button1_clicked(self, widget) :
		print "button 1"


if __name__ == "__main__" :
	window = Window()
	window.main()


___
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] Toolbar layout button to right

2008-02-19 Thread Neil Dugan

Edward Stow wrote:

Hi,

I'm having trouble packing a toolbar.

I require a toolbar with 3 buttons packed to the left and one that is
always on the right. As illustrated below.

[Button1__Button2__Button3__Button4]

Packing the three to the left is ok.  This is the default behaviour of
glade when constructing the toolbar.

My question is how to have the right button (button4) on the right hand side.

I tried adding a ToolbarItem, with a HBox  and the button in the the
last hbox container.

Running this does not work - even though glade shows the button on the
right hand side.

Any suggestions:

Thanks


Have you tried to do a pack_start() on buttons1--3 and a pack_end() on 
button4, or with glade set the buttons pack type to start/end.



Regards Neil.
___
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] Yet another threads problem

2008-02-18 Thread Neil Dugan

Mystilleef wrote:

Calling Dialog's run method in a thread will crash your app. I learned
the hard way (weeks of debugging). I use Windows instead of Dialogs
now. Manage showing and hiding the window yourself.

Cheers

On Feb 18, 2008 7:26 AM, Steve McClure <[EMAIL PROTECTED]> wrote:



I use this to get a dialog from a thread.  I have a function to 
display the dialog, and call this with an idle_add() in the Thread.


  def displaymessage(self, message) :
dialog = gtk.MessageDialog(self.window.window, gtk.DIALOG_MODAL, 
gtk.MESSAGE_INFO,

gtk.BUTTONS_CANCEL, message);
dialog.connect('response', lambda w,d: dialog.destroy())
dialog.set_position(gtk.WIN_POS_MOUSE)
dialog.show()


  gobject.idle_add(self.displaymessage, "My error message")




On Feb 18, 2008, at 7:19 AM, Adolfo González Blázquez wrote:



El sáb, 16-02-2008 a las 14:19 +1300, John Stowers escribió:


On Fri, 2008-02-15 at 14:05 +0100, Adolfo González Blázquez wrote:


Hello,

I'm writing a little app that needs 2 windows, a main window, and
another for entering data. I'm writing it using Glade, so both
windows
are defined in one glade file. The second one, emulates a entry
dialog,
and is modal.

My problem is that i want the second window displayed when i
click in a
button in the main window, and then, when i press "Close" in the
second
window, get the text and do some things, and update the main window
status bar.


I dont quite understand you here, it doesnt sound like a threads
issue,
more a design issue.

When I want to return stuff from a dialog I typically create my own
dialog subclass [1] which returns a tuple of the dialog specific
information from the (overridden run method). For example (excuse
broken
pseudocode)

class MyDialog(gtk.Dialog)
def __init__(self, setting1, setting2, setting3)
#call super
#save old settings
self.oldsetting1 = setting1
...etc
#construct dialog
self.widget1 = gtk.Entry()
self.widget1.set_text(setting1)
...etc

def run(self):
if gtk.Dialog.run(self) == gtk.RESPONSE_OK:
 setting1 = self.widget1.get_text()
 setting2 = self.widget2.get_text()
 setting3 = self.widget3.get_text()
 return setting1, setting2, setting3
else:
 return self.oldsetting1, self.oldsettin2,
self.oldsetting3

then run it with
dialog = MyDialog(a,b,c)
a,b,c = dialog.run()
dialog.distroy()


Well, I've subclassed gtk.Dialog as you point, and I'm still having
the
same issue.

I run the dialog, enter the data and click OK. Then it was supposed to
hide the dialog, and update the statusbar while things are happening,
but in fact the gui freezes till the end.


Dialog.run() is the "problem".
From
http://www.pygtk.org/pygtk2reference/class-gtkdialog.html#method-
gtkdialog--run
"The run() method blocks in a recursive main loop until the dialog
either emits the "response" signal, or is destroyed"

To get the behavior you want, you need to set up a callback for the
OK button which fetches the text and performs the desired action.




The related code is here:
http://pastebin.com/mb2ea398

And a screencast of what is happening in here:
http://www.infinicode.org/code/out.ogg

Any idea?



Regards,

John

[1] http://davyd.livejournal.com/237414.html



Here's a screencast of what i'm doing:
http://www.infinicode.org/code/out.ogg

What it was supposed to do is:
- Open the add window
- Enter the text and click close
- The add window closes
- In the main window status bar appears "Conectando..."
- The status bar changes to "Conectado!"
- A error dialog appers

Relevant code here:
http://pastebin.com/f6bf4e71b


Thanks in advance for any help

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


--
Steve McClure
[EMAIL PROTECTED]




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


[pygtk] python printing and GFax

2008-02-13 Thread Neil Dugan

Hi,

When I create a print dialog with gtk.PrintOperation() the GFax 
virtual fax printer isn't showing up.  It is installed and the print 
requester from gedit does show the GFax printer.


Is this a mistake with my set-up ?
Or is it a bug with gtk.PrintOperation() or GFax ?

Regards Neil.
___
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] exiting app

2008-02-10 Thread Neil Dugan

Martin Bilek wrote:

hi all,
i make an window and connect to function.

win = gtk.Window()
win.connect("destroy", exitApp)
gtk.main()

def exitApp(*args))
dlg = gtk.MessageDialog(type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK)
dlg.set_markup("Please use Exit from Filemenu instead")
dlg.run()
dlg.destroy()
return

but after clicking on window close button window dissapear and showing
only message dialog.
how i make main window still visible ? 
thanks


Connect to the 'delete-event' and return True/False

window.connect("delete_event", self.delete_event)
window.connect("destroy",  lambda wid: gtk.main_quit())

def delete_event(self,a,b) :
dialog = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,
   gtk.MESSAGE_QUESTION,
   gtk.BUTTONS_YES_NO)
dialog.set_markup("Exit ?")
result = dialog.run()
dialog.destroy()
return (result == gtk.RESPONSE_NO)  # return False to exit

Regards Neil.

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


Re: [pygtk] Re: Guide of PyGTK and Threads

2008-02-10 Thread Neil Dugan

John Stowers wrote:

On Sun, 2008-02-03 at 22:44 -0200, Matí­as Alejandro Torres wrote:


I have updated my pygtk threaded demo [0] to include progress reporting
and non-blocking cancellation. Check out the linked blog post [2] for a
good base upon which to build your own threaded pygtk apps.

John

[0] http://www.johnstowers.co.nz/files/FooThread.py
[1] As much as is possible within the limitations of pythons
non-cancellable threads
[2]
http://www.johnstowers.co.nz/blog/index.php/2007/03/12/threading-and-pygtk/




I like it :)  I will be adapting this for my own code, thanks.

Regards Neil.

___
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] Trouble getting a ListStore with dynamic column number.

2008-01-31 Thread Neil Dugan

Stephen George wrote:

Neil Dugan wrote:


Hi,

I am trying to create a dialog with a gtk.TreeView() with a 
gtk.ListStore() model.  I don't know until run time how many columns 
will be needed.  I have managed to create the TreeView but I haven't 
worked out how to populate it.


Any help appreciated.

Regards Neil.


Hi Neil,

I think your problem steams from the line

dialog._model = gtk.ListStore(object)

Which I think should be more like

dialog._model = gtk.ListStore(str,str,str)

However this does not give you the dynamic nature you desire.

I don't know the limits of column expansion/contraction you require for 
your problem, .. but I see in your code you want to limit it to 20

(are they always strings?, or all columns the same type?)

I would create a listStore with 20 str as arguments.

I would then create the treeview with as many columns needed for the 
problem at hand


Attached you will see a modified prog that works for me, I limited the 
columns to 7, each time you press the dialog button, a list is 
dynamically generated with a random number of columns.

Assumptions:
the list is always strings.
length of list correlates to number of colomns to view.

Don't know if this has been helpful?

Steve




Hi Steve,

Thanks, that does do what I want.  :)

After posting I found out that, that line was the trouble, but I 
couldn't find a decent way of handling the problem.  I didn't realise 
you could specify more types when creating the gtk.ListStore than you 
had intentions of using.


I think it would be handy to be able to use a list or truple to 
specify the types as well.


Regards Neil.
___
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] Trouble getting a ListStore with dynamic column number.

2008-01-31 Thread Neil Dugan

Hi,

I am trying to create a dialog with a gtk.TreeView() with a 
gtk.ListStore() model.  I don't know until run time how many columns 
will be needed.  I have managed to create the TreeView but I haven't 
worked out how to populate it.


Any help appreciated.

Regards Neil.
import gtk
import gobject



fname = ['first','second','third']
nfields = len(fname)
heading = "This is the heading"
title = "test dialog"
data = [['a1','a2','a3'],['b1','b2','b3'],['c1','c2','c3']]

class window:
	def __init__(self):
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		#self.window.connect("delete_event", self.delete_event)
		self.window.connect("destroy",  lambda wid: gtk.main_quit())
		button = gtk.Button('dialog')
		button.connect('clicked', self.show_dialog)
		self.window.add(button)
		self.window.show_all()

	def show_dialog(self, widget) :
		print "dialog"
		
		# create the dialog
		dialog = gtk.Dialog(title, self.window,
gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_OK, gtk.RESPONSE_OK))
		dialog.connect("response", lambda x,y: dialog.destroy())
		vbox = dialog.vbox

		# put the heading in the dialog
		vbox.pack_start(gtk.Label(heading), False, False)

		# create the list store
		dialog._model = gtk.ListStore(object)
		dialog._treeview = gtk.TreeView()
		dialog._column = [None] * nfields

		# add the columns to the list view
		for x in range(nfields) :
			# we need to know how to justify the columns
			xalign = 1.0
			# create and append the column
			cell = gtk.CellRendererText()
			dialog._column[x] = gtk.TreeViewColumn(fname[x].replace('_',' '), cell, text=x)
			cell.set_property('xalign', xalign)
			dialog._treeview.append_column(dialog._column[x])

		# create the scrolled window etc.
		dialog._scrolledwindow = gtk.ScrolledWindow()
		dialog._scrolledwindow.add(dialog._treeview)
		vbox.pack_start(dialog._scrolledwindow, True, True)
		dialog._treeview.set_model(dialog._model)
		
		# set the rows for the list
		self.set_rows(dialog)

		# show the dialog
		vbox.show_all()
		dialog.show()


	def _set_rows(self, dialog) :
		# limit the display to 20 rows
		limit = len(data)
		# show at max 20 rows
		print "title = \"%s\"" % (title)
		print "heading = \"%s\"" % (heading) 
		for x in range(limit) :
			iter = dialog._model.append()
			for y in range(nfields) :
value = data[x][y]
if value :
	print "row %d field %d = %s" % (x, y, value)
	try :
		dialog._model.set(iter, y, str(value))
	except ValueError, msg:
		print "ERROR: %s" % (str(msg).strip())
		return

	def set_rows(self, dialog) :
		# limit the display to 20 rows
		limit = len(data)
		# show at max 20 rows
		print "title = \"%s\"" % (title)
		print "heading = \"%s\"" % (heading) 
		row = [None] * nfields
		for x in range(limit) :
			for y in range(nfields) :
value = data[x][y]
if value :
	row[y] = str(value)
else :
	row[y] = None
			print "row = %d items = " % (len(row)),row
			try:
dialog._model.append(row)
			except ValueError,msg:
print str(msg).strip()
			print 

	def main(self):
		gtk.main()

if __name__ == "__main__":
	window = window()
	window.main()

___
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] Focus issue with change of notebook page

2007-12-20 Thread Neil Dugan

Tony Nelson wrote:

At 3:49 PM +1100 12/20/07, Neil Dugan wrote:
 ...


Haven't tried this exactly, but have you tried putting the
grab_focus() call after a small timeout delay ?

gobject.timeout_add(500,widget.grab_focus)



How long should the timeout be to not have it ever be too short?  How short
should the timeout be so that the user won't interact with the wrong widget?


You will need to experiment.  I would find the minimum time it worked 
in, and double that to be on the safe side.  I don't think anyone 
would start typing within a 1/2 second.  After all it takes a while to 
move your hand from the mouse back to the keyboard.


___
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] Focus issue with change of notebook page

2007-12-19 Thread Neil Dugan

Gary Jaffe wrote:

Hi all --

I have several pygtk apps that each run in its own page of a notebook.
The user can load up and run the apps as he/she wishes.

I would like to have the widget that has the focus for each page to
still have the focus when the user clicks another notebook tab and then
comes back to the original page.  But what happens is that when the user
changes to a new page by clicking on the tab, the focus is set to the
first widget that can focus.  If my program switches to the new page,
this doesn't happen.

I've even tried storing which widget that has the focus on each page and
explicitly doing a grab_focus to that widget when I get a switch-page
event.  I still get the focus set to the first widget that can focus.  I
even checked to make sure I have the right widget just before doing the
grab.focus.  I also tried returning True from the method that handles
the switch-page evnet and connecting with connect_after rather than
connect.  Nothing has done any good.  :(

Does anyone know how to do this?

Haven't tried this exactly, but have you tried putting the 
grab_focus() call after a small timeout delay ?


gobject.timeout_add(500,widget.grab_focus)

___
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] context menus for ListViews

2007-12-05 Thread Neil Dugan

Caleb Marcus wrote:

How can I create context menus for ListView elements? The PyGTK Tutorial
doesn't go into this, and I can't follow the GtkTreeView tutorial as
it's not in Python.




This is the code I use to put a context sensitive menu on a listview
--
self.listview = listview = gtk.TreeView()
scrolledwindow.add_with_viewport(listview)
listview.set_headers_visible(False)
listview.connect("button_press_event", self.on_button_press_event)
--
  def on_button_press_event(self, widget, event) :
if event.button == 3 and event.type == gtk.gdk.BUTTON_PRESS :
  # see if there is a selected order item
  selection = self.listview.get_selection()
  (model,node) = selection.get_selected()
  active = (node != None)

  menu = gtk.Menu()
  for stock_id,callback,sensitivity in [
  (gtk.STOCK_ADD, self.on_menu_add, True),
  (gtk.STOCK_EDIT, self.on_menu_edit, active),
  (gtk.STOCK_REMOVE, self.on_menu_remove, active)]:
item = gtk.ImageMenuItem(stock_id)
item.connect("activate",callback)
item.set_sensitive(sensitivity)
item.show()
menu.append(item)
  menu.popup(None,None,None,event.button,event.time)
  return True
else :
  return False
--

hope this helps.

Neil
___
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] Treeview and sqlite

2007-11-17 Thread Neil Dugan

Marcel Stoop wrote:

Hey all,

First of all I new to python and reading a lot of documentation, but
somehow I can't seem to find good information regarding the question
below.
I'm trying to develop a python/pygtk application which need to store the
data from the treeview in a sqlite db.
Anybody here who is familiar with this and can give some pointers in the
right direction?



I would think that when you get the data for the nodes to insert into 
the list you would just do the 'insert' statements in the database.


or

'insert' the records into the database, then have a function that 
first clears the treeview, then does a query for all relevant records 
and display those in the treeview (which is the way I do it).



regards,

Marcel



regards Neil.
___
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.TextView changing size.

2007-11-08 Thread Neil Dugan

Yuri Pimenov wrote:

1. use gtk.POLICY_AUTOMATIC for horizontal scrolling
or
2. scrolledwindow.set_size_request(width, -1)


Thanks, that worked.  I am wondering why you need to set the minimum 
size for the gtk.ScrolledWindow() to stop it expanding when you type 
in the gtk.TextView(), and why a minimum size isn't already set.





On 07/11/2007, Neil Dugan <[EMAIL PROTECTED]> wrote:


Hi,


When you type in the one of the textview widgets in the app. below the
size of the textview changes.  I would like to stop this.


-- cut -
#!/usr/bin/env python

import gtk

class window():
   def __init__(self):
   window = gtk.Window(gtk.WINDOW_TOPLEVEL)
   window.set_border_width(10)
   window.set_default_size(400,300)
   window.connect("destroy", lambda wid: gtk.main_quit())
   window.connect("delete_event", lambda a1,a2:gtk.main_quit())

   hbox = gtk.HBox()
   window.add(hbox)
   hbox.add(self.create_textview())
   hbox.add(self.create_textview())
   window.show_all()

   def create_textview(self) :
   scrolledwindow = gtk.ScrolledWindow()
   scrolledwindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
   textview = gtk.TextView()
   scrolledwindow.add(textview)
   textview.set_wrap_mode(gtk.WRAP_WORD)
   return scrolledwindow

   def main(self):
   gtk.main()
   return 0

if __name__ == "__main__":
   test = window()
   test.main()
-- cut -



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


[pygtk] gtk.TextView changing size.

2007-11-06 Thread Neil Dugan

Hi,


When you type in the one of the textview widgets in the app. below the 
size of the textview changes.  I would like to stop this.



-- cut -
#!/usr/bin/env python

import gtk

class window():
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_border_width(10)
window.set_default_size(400,300)
window.connect("destroy", lambda wid: gtk.main_quit())
window.connect("delete_event", lambda a1,a2:gtk.main_quit())

hbox = gtk.HBox()
window.add(hbox)
hbox.add(self.create_textview())
hbox.add(self.create_textview())
window.show_all()

def create_textview(self) :
scrolledwindow = gtk.ScrolledWindow()
scrolledwindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
textview = gtk.TextView()
scrolledwindow.add(textview)
textview.set_wrap_mode(gtk.WRAP_WORD)
return scrolledwindow

def main(self):
gtk.main()
return 0

if __name__ == "__main__":
test = window()
test.main()
-- cut -
___
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] accelerator for an image button.

2007-11-02 Thread Neil Dugan
Hi

I am new to this list.

I am trying to make an python/gtk+ app.  One problem I am having is
attaching an accelerator to a image button.

This is the code I am using to create the buttons.

--- cut ---
def index_control(self):
hbox = gtk.HBox()
for stock in
[gtk.STOCK_GOTO_FIRST,gtk.STOCK_GO_BACK,gtk.STOCK_GO_FORWARD,gtk.STOCK_GOTO_LAST]
 :
image = gtk.Image()
image.set_from_stock(stock,gtk.ICON_SIZE_MENU)
button = gtk.Button()
button.set_image(image)
hbox.pack_start(button,False,False)
return hbox
--- cut ---
I can give the full source if needed.


Can someone help please, or give a URL to a working example.

-- 
Python 2.5.1


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