Re: [pygtk] Why set_model method in PyGtk duplicate the value of the first column at the third column?

2013-12-12 Thread Neil Muller
On 12 December 2013 22:06, Hudson Ferreira  wrote:
> col.pack_start( cell, expand=False)
> col.set_attributes( cell, text=0)

You look up the values for the first colum in your view in the first
column of the model (column 0) - that's fine.

> col.pack_start( cell, expand=False)
> col.set_attributes( cell, text=1)

You look up the values for the seond column in your view in the second
column of the model (column 1).

> col.set_attributes( cell, text=0)

But you use the first column of your model to display the third column
of the model - For your comments, this is not what you want. This
should almost certainly be col.set_attributes( cell, text=2)

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] PyGobject TreeModel selection bug?

2013-06-04 Thread Neil Muller
On 3 June 2013 20:24, Brent S. Elmer Ph.D.  wrote:
> I have an application I wrote using PyGTK that I recently converted
> to use PyGobject introspection.  When I try to do something with
> selections in a TreeModel, I get a segmentation fault.  The
> corresponding pygtk code works.  I have pared down my program to a
> simple test case.  I have included the pygtk version that works and the
> PyGobject version that gives a segmentation fault.  To see what I mean,
> run the programs and select one or multiple rows then select File->copy
> from the menu.  Is this a PyGobject bug or am I doing something wrong?

The problem is the selected_foreach loop here. I'm pretty sure the
issue is there's a discrepency between the references created by gtk
and the python object references in this code path, so you end up with
a path that references something gtk has dropped it's references to.

This is probably a PyGobject bug, but I'm not sure of all the details,
so there may be a reason for the current behaviour.

You can avoid the issue by either expliticly copying the path in your
selection_callback function - i.e, using pathlist.append(path.copy()),
or by using the treeselection's get_selected_rows method.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Change cursor on a single widget

2013-03-11 Thread Neil Muller
On 11 March 2013 00:37, Timo  wrote:
> I seem to be unable to change the cursor on one widget only, not an entire
> window. How is this done? Below is a testscript which I thought was the
> right way.
>
> Run normal to use PyGI, run with -p argument for PyGTK. Both act the same.

> def run_pygtk():
> import gtk
>
> def disable_cb(widget):
> widget.set_sensitive(False)
> cursor = gtk.gdk.Cursor(gtk.gdk.WATCH)
> widget.window.set_cursor(cursor)

This works for widgets which have their own gtk.gdkWindows. It's
mentioned in the gtk docs that this isn't always the case, and several
widgets will return their parent's gtk.gdk.Window. You can check for
this using the get_has_window method.

One approach is to stuff the buttons inside an EventBox, since that
will definitely provide it's own gtk.gdk.Window  - something along the
lines of:

def run_pygtk():
import gtk

def disable_cb(widget, eventbox):
widget.set_sensitive(False)
cursor = gtk.gdk.Cursor(gtk.gdk.WATCH)
eventbox.window.set_cursor(cursor)

win = gtk.Window()
win.resize(400, 400)
win.set_title("PyGTK example")
win.connect('delete-event', gtk.main_quit)

eventbox = gtk.EventBox()

b1 = gtk.Button('Disable me')
b1.connect('clicked', disable_cb, eventbox)
eventbox.add(b1)
b2 = gtk.Button('I do nothing')
box = gtk.VBox()
box.pack_start(eventbox, False, False, 0)
box.pack_start(b2, False, False, 0)
win.add(box)
win.show_all()

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] How to change key press handler of Gtk.TreeView

2013-01-31 Thread Neil Muller
On 1 February 2013 00:06, Christian Mallwitz  wrote:
> Hi Guys,
>
> Attached is a sample file creating a window with a simple tree view.
> When open one can press letter keys and it will open the little search
> input box that comes with Gtk3. What would one have to do if one would
> want have SHIFT-letter keys open the search box and do the stepping
> through the tree view rows? In my window/application I would want to
> use regular keys for something else even if the tree view has the
> focus. How about replacing/chaining on-key-press handlers? Any
> examples?
>
> I understand that is more of a Gtk than PyGtk question so feel free to
> tell me to go annoy someone else with my questions :-)

The simplest way I can think of to do this is to add a custom
key-press-event handler to the TreeView. You can then pass on those
key combinations you want to trigger the search to the default
handler, and handle the rest as you desire.

something like:

def key_press(self, view, event):
if event.state & Gdk.ModifierType.SHIFT_MASK: return False # Shift
down, so propogate to the default handler

return True # don't propogate this event further

And connect it up with a
   view.connect('key-press-event', self.key_press)

when creating the view.

Hope that helps.

Note that, once the search entry is open, it's handling its own
key-press events. If you want it to ignore letters without shift there
as well, things get more complicated - I think the best way to achieve
that would be setting your own entry widget via
view.set_search_entry() .

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] FileChooserDialog can not run twice?

2012-03-18 Thread Neil Muller
On 19 March 2012 06:02, Zhenjiang Lan  wrote:
> Hi all experts,
> I create a button, connect to a FileChooserDialog. When I click the
> button, I can choose a file and print it's name.
> But, if I click 'cancel' for the first time, then I click the button
> again, it crashed..

You have dialog as a class attribute on your choosefile class, so it's
only instantiated once. Since you call dialog.destroy() in the run
method, and then try to rerun the dialog, the crash is not surprising.

There are a couple of ways to fix this. I'd explicitly make choosefile
a singleton and use dialog.hide(), but you could also make it an
instance variable (by creating in choosefile's __init__ method) and
thus recreate the file chooser on each run.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] handler_block and subprocess.call

2011-12-01 Thread Neil Muller
On 1 December 2011 15:55, Jérôme  wrote:
> Hi all.
>
> There's something a bit tricky about handler_block and subprocess.call I
> would like to understand.
>
> I'm writing a little program (a simplistic guitar tuner) that has six keys
> (buttons) all connected to a callback that plays sounds through the buzzer
> using a call to external function beep. When a key is pressed, beep is
> "subprocess.call"ed and plays a sound for 1000 ms.
>
> While the sound is played, further clicks on the key are sort of queued and
> played afterwards. If someone gets excited and clicks times and times, then
> the program keeps beeping for seconds until it is done. I don't want this.
>
> To avoid this, I figured out I could block the handler while the callback is
> calling beep. Therefore, I added calls to handler_block and handler_unblock
> at the beginning and end of the callback to disable the call to the callback
> itself.
>
> It does not work. It's as if the clicks are dealt with with a delay once the
> callback has returned.
>
> Now, as a comparison I tried to add delays inside my callback using the
> following code, found on the internet :
>
>        time_start = time.time()
>        time_end = (time_start + 1)
>        while time_end > time.time():
>                while gtk.events_pending():
>                        gtk.main_iteration()
>
> If I replace the call to beep by this delay, I get the expected result : the
> clicks are ignored when the handlers are blocked.

Remember that gtk is not threaded, so, unless the main loop gets a
chance to run, events aren't going to be processed. This delay
construct explicitly forces the main loop to process events, but a
call to subprocess.call will just block waiting for the command to
finish, and the main loop isn't going to run, so nothing clears the
event queue while waiting for the command to finish, and you'll get
the behavior you describe. Adding a "while gtk.events_pending():
gtk.main_iteration()" before reconnecting the handlers is a simple fix
for this, although completely blocking gtk's event loop does introduce
issues with redrawing and so forth.

I'd personally avoid the subprocess.call, and use subprocess.Popen
instead, polling the command in an gobject idle task or by using a
gobject.timer signal, and then reconnect handlers and cleanup when the
command finishes - this allows the gtk main loop to run as normal.

Hope that helps.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] Problems with gtk.TreeIter and reorderable gtk.TreeView

2011-09-12 Thread Neil Muller
2011/9/12 Damián Nohales :
> Hello there!
>
> I have a gtk.TreeView using a gtk.ListStore model, which is a list of music
> tracks. I've setted the "reorderable" property to TRUE in the gtk.TreeView
> object and I'm using a gtk.TreeIter to save the current playing item, called
> "current_track".
>
> Well suppose that I have 5 music tracks on my list and the second track is
> playing, so the path associated to "current_track" when I use
> "model.get_path(current_track)" is (1,). When I drag the first element below
> the second, now "current_track" path is (0,), but, when I drag the row
> associated with "current_track" (now the first row), to another position,
> the path of "current_track" is None.
>
> Is this the normal behavior or am I doing something wrong?

I'm pretty sure that moving the row current_track points to will
invalidate the gtk.TreeIter you have, as the row gets deleted and
re-created elsewhere, which would be why you're seeing None for the
path. You should be able to check if this is the case  by using
ListStore.iter_is_valid().

I would add some logic to the drag_data_received signal to deal with this case.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Re: [pygtk] pygtk Digest, Vol 99, Issue 21

2011-05-26 Thread Neil Muller
On 26 May 2011 16:12, Shrihari Sankaran  wrote:
> So, I went ahead and deleted these files. Now, the app worked fine both on
> XP and 7. But, what are these files and why are they being included on 7? Is
> there any way to avoid this.

I've no idea why they're being included (presumably py2exe's
dependency tracking needs to be smarter about  win7 system dlls) , but
you should be able to use py2exe's "dll_excludes" option to exclude
them - see http://www.py2exe.org/index.cgi/ExcludingDlls

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] Simplifying what's stored in a ListStore (was Re: Inconsistent format for "path" in TreeView callbacks)

2011-05-07 Thread Neil Muller
On 7 May 2011 06:39, Jason Heeris  wrote:
> On 7 May 2011 03:24, Neil Muller  wrote:
>> On 6 May 2011 21:07, Jason Heeris  wrote:
>> Storing the object in a hidden column is fine, and what I assumed you
>> were doing originally.
>
> Hah! Okay then, now that it's morning, I can't believe that didn't
> occur to me :P
>
> While we're on the topic though, it strikes me as more sensible to
> simply put the objects themselves in a ListStore without manually
> extracting the information for the other columns (ie. so the ListStore
> just contains one column, which is displayed in different ways). Is
> there a way to tell each TreeViewColumn to, say, "look at column zero,
> take the x.fit.param_A attribute, format it using "0x%03X and display
> it in a CellRendererText" — and then so on for each attribute, each
> describing to a different view of the same column?

You can do via TreeViewColumn.set_cell_data_func and calling
set_property on the cell renderers.

Because the extra bouncing back and forth between gtk and python this
approach involves it does impose a bit of a speed penalty, although
I've used this approach with models holding 100 000 rows without the
slowdowns being an issue.

Simple example:

import gtk, gobject

class MyData(object):
def __init__(self, value):
self.number = value
self.doubled = 2*value

class Test(gtk.Window):
def __init__(self):
super(Test, self).__init__()

store = gtk.ListStore(gobject.TYPE_PYOBJECT)
store.append([MyData(2)])
store.append([MyData(3)])
store.append([MyData(5)])

self.tv = gtk.TreeView(store)
self.add(self.tv)
self.add_column('number')
self.add_column('doubled')

self.connect('destroy', lambda *w: gtk.main_quit())
self.show_all()

def add_column(self, name):
cr = gtk.CellRendererText()
tc = gtk.TreeViewColumn(name, cr)
tc.set_cell_data_func(cr, self.render, name)
self.tv.append_column(tc)

def render(self, column, cell, model, tree_iter, attr_name):
data = model.get_value(tree_iter, 0)
cell.set_property("text", "%d" % getattr(data, attr_name))

if __name__ == "__main__":
t = Test()
gtk.main()


-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] Inconsistent format for "path" in TreeView callbacks

2011-05-06 Thread Neil Muller
On 6 May 2011 21:07, Jason Heeris  wrote:
> I have an object that refers to a numpy array of several hundred data
> points, and a few fit parameters and flags. I append the fit
> parameters to the ListStore, and map the object to the path of the new
> row so I can get back the data points, for use upon row activation (or
> cell toggle).
>
> While we've been discussing this, I've been poring over the pygtk docs
> some more and think I see what I should be doing: I could store the
> object itself in the ListStore as well, and simply not add a
> TreeViewColumn for it in the TreeView. Then I can access it directly
> upon row activation, etc. Does this sound reasonable, or is there a
> better way?

Storing the object in a hidden column is fine, and what I assumed you
were doing originally.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] Inconsistent format for "path" in TreeView callbacks

2011-05-06 Thread Neil Muller
On 6 May 2011 20:43, Jason Heeris  wrote:
>
> I can't map against TreeIters though, since — for example — the
> TreeIter returned by "ListStore.append()" is not the same as what
> you'd get back by using the path passed in on one of the signals.
> Sure, it points to the same row, but since it's not the same object
> it's useless as a dict key.

What are you storing in the list store if a row reference doesn't
allow you to easily get back to the object you want?

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] Inconsistent format for "path" in TreeView callbacks

2011-05-06 Thread Neil Muller
On 6 May 2011 18:59, Jason Heeris  wrote:
> I have a TreeView with rows that show parameters related to a
> particular object. When the user clicks the CellRendererToggle, it
> sets a flag in that underlying object; when the row is double-clicked,
> another dialog pops up with more detail about the object.
>
> The only way I've thought to do this is to keep a dict mapping paths
> in the TreeModel to the objects. If there's a better way, I wouldn't
> shoot it down :)

Are you writing your own TreeModel (using GenericTreeModel) or using
something like TreeStore?

I think you really should be using TreeIters rather than paths to
manage this mapping, since they directly map to rows in the model,
rather than positions in the treeview which may or may not match rows
in the model.

TreeStore TreeIters (and GenericTreeModel TreeIters if you're careful)
are also preserved across operations like sorting the Treeview, which
allows you to more flexibility in the future.

Since you can trivially go from either path format to the correct
TreeIter using get_iter(path), this also removes any need to worry
about the path format.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] Inconsistent format for "path" in TreeView callbacks

2011-05-06 Thread Neil Muller
On 6 May 2011 10:31, Jason Heeris  wrote:
> Is there a canonical way to convert between these two formats? I don't
> want to just use a simple line of code that turns out to be wrong at
> some point in the future...

a) why do you want to convert between the two? In my experience, when
I start thinking about equating or manipulating paths, it usually
means I'm actually trying to test something about the underlying model
and should be converting to a TreeIter instead.

b) If you're sure you need to normalise the path and that the path you
start with corresponds to a position in the model, you can use things
like the get_iter(path) and get_string_from_iter(iter) dance to get
always get a string, otherwise, since the possible formats of a path
are well defined (see the documentation for gtk.TreeView), you can
easily write the trivial custom conversion function.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] eventbox and ugly look

2010-09-01 Thread Neil Muller
On 31 August 2010 18:56, Alessandro Dentella  wrote:
> Hi,
>
> in order to get tooltips in the header of a TreViewColumn I add a Label to
> en EventBox. It works but upgrading from Ubuntu 8.04 to 10.04 (pygtk 2.17) I
> realized that very ugly border appear (that where not present previously)
> as in the attached example.
>
> Does anybody know how to fix the look or to get tooltip in the header of
> the column w/o event box?

You should be able to just set the tooltip directly on the label,
using set_tooltip_text and set_has_tooltip, without needing the
EventBox.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] Beginner question on running PyGTK

2010-05-14 Thread Neil Muller
On 14 May 2010 21:29, Neil Benn  wrote:
>
>   I'm asking because I don't want to use a paradigm from another experience
> which is not suitable to what I'm trying to do with python and gtk.  Thanks
> for your help.

The most common gtk method for avoiding threads is to use tricks like
idle functions (glib.idle_add and friends) or timeouts
(glib.timeout_add) to handle things while the UI is idle. This does
require that these functions execue quickly, and it sounds like your
tasks aren't that well suited to this approach.

While it's perfectly possible to write threaded programs using pygtk,
Python's GIL, restricts the amount of parallelism that can be achieved
in pure python quite heavily, so threads aren't always the best
solution. The multiprocessing module addresses this by using processes
rather than threads, but still providing an interface that's quite
similar to the threading module.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] Beginner question on running PyGTK

2010-05-14 Thread Neil Muller
On 14 May 2010 19:48, Neil Benn  wrote:
> This starts up as you would expect, printing a and b to the screen as the
> threading time time slicing allows. However once the PyGTK window has opened
> - these threads just freeze.

To use threads, you need to enable pygtk's support for threads by
calling gtk.gdk.threads_init().

http://unpythonic.blogspot.com/2007/08/using-threads-in-pygtk.html is
a good brief overview of how to use pygtk and threads.

It's also worthwhile reading the gtk+ notes on threading at
http://developer.gimp.org/api/2.0/gdk/gdk-Threads.html , especially if
you're trying to write something portable between X11 and Windows.

I would, however, recommend looking at alternative options, such as
multiprocessing, carefully first, before committing yourself to a
threaded solution.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] (no subject)

2010-03-03 Thread Neil Muller
On 3 March 2010 14:28, PEYMAN ASKARI  wrote:
> Hello
>
> Does anyone know how to limit the number of tabs in a notebook, much like
> gedit does?

I think you want to look at gtk.Notebook's set_scrollable method. I
also suggest looking at enable_popup.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] reparent

2010-03-03 Thread Neil Muller
On 3 March 2010 12:31, Peyman  wrote:
>
> Anyone have any idea what may be causing this?
>

Given that you're reparenting a notebook, I strongly suspect you're
hitting the "multiple subwindows" issue discussed in the GTK faq - see
http://library.gnome.org/devel/gtk-faq/stable/x635.html . The
suggested solution of explicitly removing and adding the widget should
avoid this problem.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] Why sorting of TreeView ignores the first line?

2010-01-05 Thread Neil Muller
On Sun, Jan 3, 2010 at 6:49 PM, Jiri Bajer  wrote:
>
> What am I doing wrong?



>def _compare_data(self,  model, iter1, iter2, column):
>data1 = model[model.get_path(iter1)][0][column]
>data2 = model[model.get_path(iter2)][0][column]
>print data1, data2, cmp(data1, data2)
>return cmp(data1, data2)

You're assuming that the relationship between paths and iters won't
change until sorting is completed, which is wrong. You should be using
the iter's to access the data here - model.get_value(iter, 0)[column]
should do it.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] TreeStores and rows-reordered signal

2009-12-14 Thread Neil Muller
On 12/14/09, Alessandro Dentella  wrote:
> Hi,
>
>   I'm probably misinterpreting what 'rows-reordered' means, but I thought that
>   should be a signal emitted by a TreeStore when rows are reordered by D&D
>   operations. Am I wrong?

rows-reordered is sent by actions such as sorting the tree - it
doesn't cater for items changing depth in the tree. D & D operations
result in row-deleted and row-inserted signals being sent.


-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] problem with listStore append in a treeview

2009-10-28 Thread Neil Muller
On Wed, Oct 28, 2009 at 4:33 PM, Petsas Athanasios  wrote:
> Hello,
>
> I have one more question on the use of the treeview with a listStore model.
> When I want to append a big amount of rows, for instance 100, the appeend
> method it is extremely slow inside a loop..
>
> I tried to use this code:
>
> treeview.freeze_child_notify()
> treeview.set_model(None)
>
> # Add rows to the model
> # ...
>
> treeview.set_model(model)
> treeview.thaw_child_notify()
>
> from taken from this page:
> http://faq.pygtk.org/index.py?req=show&file=faq13.043.htp
> but it's still slow!

Appendiing 100 rows should be fast. The only thing I can think of that
would make this noticeably slow is if the ListStore is sorted, in
which case you should disable sorting while doing the appends.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] scrolled window inside a container

2009-10-28 Thread Neil Muller
On Wed, Oct 28, 2009 at 3:09 PM, Petsas Athanasios  wrote:
>
> All I want is just an example on how to do that. For instance how to support
> a scrolling  treview (or generally a scrolling widget) inside a container
> such as
> an hbox.

As you'll see demonstrated in several of the pygtk examples, wrapping
the TreeView in a scrolled window first is the way to go here.
gtk.ScrolledWindow is just another widget container, so it can be
included in a HBox like any other widget.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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.Style has no properties

2009-06-30 Thread Neil Muller
On 6/30/09, Noam Yorav-Raphael  wrote:
> Hello,
>
>  for gtk.Style objects there are no properties - I do:
>  >>> st = gtk.Style()
>  >>> gobject.list_properties(st)
>  ()
>
>  I would like to change its bg property (appears in the documentation,
>  and even in gtk-base-types.def), so that the selection color will be
>  different from the default, but since it has no properties, I can't do
>  that.
>
>  Do you know what's wrong?

These show up as attributes, not properties - try dir(st) instead.

However, poking the style directly can get tricky. I think you'll find
playing with the modify_bg and modify_base methods on the widgets a
lot less trouble.

Note that gtk.TreeView's use the base color (not bg) for the part
containing the cell renderers, so, if you want to change the selection
colour there, use modify_base.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Rendering arbitrary widgets in a CellRenderer

2009-05-13 Thread Neil Muller
On Wed, May 13, 2009 at 6:20 PM, Walter Leibbrandt
 wrote:
> Walter Leibbrandt wrote:
> I've got it working with a hack, but one important problem remains: The
> CellRenderer's size is calculated based on the string rendered for
> unselected cells. This means that, if the widget rendered in a selected
> cell needs more space than the rendered string, it is simply cut off.
> The problem (as far as I can tell) seems to arise from the fact that the
> widget to render in the cell has not yet been realize()d and thus has no
> allocation.

Since you're looking to allocate enough space to display the widget,
you shouldn't need to realize the widgets first. It looks like the
problem is with your use of set_size_request() and get_size_request(),
since get_size_request() only returns the values set via
set_size_request(). Just using size_request() should do what you want.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] realtime update of TreeView

2009-05-09 Thread Neil Muller
On Fri, May 8, 2009 at 5:24 PM, Martin B.  wrote:
> hi, i write some simple app where i need realtime update gtk.TreeView.
> but window shows and long time nothing happened and after whole
> liststore is filled treeview shown :(

A possible solution is to add a:
   while gtk.gtk.events_pending():
   gtk.main_iteration()

loop after each row insert, to force the UI to update. This will make
adding lots of rows incredibly slow, though, and you will probably
need to look at some scheme of batching updates together if you want
reasonable performance using this approach.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] Looking for help with comboboxes

2009-04-14 Thread Neil Muller
On Tue, Apr 14, 2009 at 6:25 PM, Gerald Britton
 wrote:
> Thanks Neil,
>
> So, with your suggestion in place, I have the program below.  I still
> must be missing something though, since my combobox is still empty.

I'm puzzled by that. It works fine for me (with minor modifications
since I'm not running against gtk+ 2.16).  It correctly populates the
list store, and the values are available in the combobox drop-down..

The comobox doesn't have a default value though, so the initial
display will be empty. This can be fixed by adding a call to
set_active after filling the list store (c.set_active(0) for example)

> I'm wondering about your comment about linking the model to the
> renderer.

The CellRendere needs to be told which column from the model to grab
values from, This is accomplished by using the  property
in GtkBuilder or the add_attributes method.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] Looking for help with comboboxes

2009-04-14 Thread Neil Muller
On Tue, Apr 14, 2009 at 4:39 PM, Gerald Britton
 wrote:
> Would someone be able to point out what I am missing?
>
> glade = """
> 
> 
>
>  
>True
>liststore

The combobox needs to contain a CellRenderer, and the CellRenderer
needs to be linked to the model.

The pure gtkbuilder approach would be to add:

   
  
  
 0
  
   

to the combobox definition.

>  
>

> w = g.get_object('window')
> c = g.get_object('combobox')
> l = g.get_object('liststore')

Or you could add:

cell = gtk.CellRendererText()
c.pack_start(cell)
c.add_attribute(cell, 'text', 0)

> for i in range(10):
>  c.append_text("line %d" % i)  # 1. try to append the text to the combobox
>  l.append(["line %d" % i])# 2. try to add the text to the liststore 
> in the combobox.

If using a CellRendererText that uses the first column of the list
store, both methods should work, IIRC.

append_text is designed to be used with ComboBox's created with
gtk.combo_box_new_text, though, and needs the ComboBox to match it's
assumptions, which can be problematic, and makes changing things later
potentially harder, so appending to the list store is probably the
better choice here.

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] how to change value in slider

2009-04-04 Thread Neil Muller
On Fri, Apr 3, 2009 at 7:54 PM, Sibtey Mehdi  wrote:
>
> hi
>   I am trying to change the value in the slider bar but it is allowing
> to change the value within the range given in the
>   adjustment. if the current values are 1,2,4,5,6,7 then i want slider
> should show 1,2,4,8,16,32,64.how can i do this any one can help me out this
> problem? even the set_value(newvalue) function changes values within the
> lower and upper values but that changes are also not displayed on the
> slider.

Why not hook onto the format_value signal?

Something like:


class Scale(object):
"""A scale that adheres to increment steps"""
def __init__(self,x):
self.set_update_policy(gtk.UPDATE_CONTINUOUS)

self.set_size_request(150,35)
self.connect("format-value", self.display_value)

def display_value(self, widget, value):
return "%d" % 2**(value-1)


(You'll probably also want to override get_value so you get the
displayed value out of the widget.)

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
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] Special Keys for Accelerators

2009-03-28 Thread Neil Muller
On Sun, Mar 29, 2009 at 3:01 AM, JSeipp  wrote:
> Hello,
> i have searched everywhere but couldn't find a solution to this:
>
> How do I assign an accelerator to a special key combination like "Ctrl"
> + "Page-Up" ?
>
> Widget.add_accelerator('clicked', self.accel_group, ord('U'),
> gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)  works for single letters like
> "U", but how can I get the keyval for "Page-Up". Any ideas?

You can lookup the keyval using gtk.gdk.keyval_from_name.

I would use gtk.accelerator_parse here, though, as I find something like:

(key_val, mod) = gtk.accelerator_parse('Page_Up')
Widget.add_accelerator('clicked', self.accel_group, key_val, mod,
gtk.ACCEL_VISIBLE)

easier to read later

-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] quoting text for markup

2009-03-19 Thread Neil Muller
On Thu, Mar 19, 2009 at 5:28 PM, Darren Hart  wrote:
> 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:

>>> from gobject import markup_escape_text
>>> markup_escape_text('A & B ')
'A & B <C>'

For completeness, this is reversible via pango's parse_markup

>>> from pango import parse_markup
>>> parse_markup(markup_escape_text('A & B '))[1] # Since parse_markup 
>>> returns a (pango.AttrList, text, accel_char) tuple (see docs)
'A & B '


-- 
Neil Muller
drnlmul...@gmail.com

I've got a gmail account. Why haven't I become cool?
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/