Re: [pygtk] CellRendererCombo Question

2006-03-08 Thread John Finlay

Hussein Vastani wrote:
Hello All, 
Does anyone know if something like the wrap_width function is implemented for 
the CellRendererCombo in pygtk? 
Heres the scenario. 
I populate my combobox (in my treeview) dynamically and want to display it in 
more than one column if the list is large.


This is how I set it up :

model = gtk.Liststore(str)
tree_store_col = 0
cell_renderer = gtk.CellRendererCombo()
cell_renderer.set_property("model",model)
cell_renderer.set_property('text-column', 0)
cell_renderer.set_property('editable', True)

new_col = gtk.TreeViewColumn(col_name, cell_renderer, text=tree_store_col)
tree.append_column(new_col)
cell_renderer.connect('editing-started', populate_combo, (tree_store,))

And this is how I populate the combobox in the populate_combo callback
def populate_combo(self, cell, editable, path, data):
store = data[0]
iter = store.get_iter(path)
items = self.get_list() # my function get_list() returns a list of strings
m = cell.get_property('model')
m.clear()
items.sort()
for s in items:
m.append([s])

so if my items list is large, it gets frustrating to scroll the entire list to 
get to the required item. It would be nice if the items were displayed in more 
than one column (for eg.)

Any suggestions on how to make this better?
  
In populate_combo() the ComboBox is the "editable" param so 
editable.set_wrap_width(width) should allow you to display the items in 
multiple columns.


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/


Re: [pygtk] Win32 file chooser

2006-03-08 Thread John Pye
FWIW, one small step further: here is a short script that will show the
Windows dialog on windows if possible, and fall back to the PyGTK one
where necessary (on Linux or on Windows without win32all). See attached.

It's only designed for opening files at this stage, but perhaps it can
be taken further.

Cheers
JP

John Pye wrote:
> I've posted a working version of this direct from the demo scripts in
> the win32all package.
>
> See http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq21.013.htp
>
> Cheers
> JP
>
> Nikos Kouremenos wrote:
>   
>> Chris, is it possible you could put a comment or two and add it to the FAQ?
>>
>> thanks in advance
>> 
-- 
John Pye
School of Mechanical and Manufacturing Engineering
The University of New South Wales
Sydney  NSW 2052  Australia
t +61 2 9385 5127
f +61 2 9663 1222
mailto:john.pye_AT_student_DOT_unsw.edu.au
http://pye.dyndns.org/


import platform, os
import gtk

class WinFileFilter:
def __init__(self,name,patternarray):
self.name = name + " (" + ", ".join(patternarray) + ")"
self.pattern = ";".join(patternarray)
def __repr__(self):
return '%s\0%s' % (self.name, self.pattern)

class FileChooser:
def __init__(self):
self.ext = {}
self.filters = []
if platform.system()=="Windows":
try:
import win32gui
self.iswin = True
return
except ImportError:
pass
self.iswin = False
self.chooser = gtk.FileChooserDialog()
self.chooser.add_buttons(gtk.STOCK_OPEN,42)


def add_filter(self,name,patternarray):
if self.iswin:
self.filters.append(WinFileFilter(name,patternarray))
else:
_f = gtk.FileFilter()
_f.set_name(name)
for _p in patternarray:
_f.add_pattern(_p)
self.chooser.add_filter(_f)

def do(self): 
if self.iswin:
return self.do_windows()
else:
return self.do_gtk()

def do_windows(self):
import win32gui, win32con
_fa = []
for _f in self.filters:
_fa.append(repr(_f))
filter='\0'.join(_fa)+'\0'
customfilter='Other files (*.*)\0*.*\0'
print "FILTER:",repr(filter)

fname = "ERROR"

try:
fname,customfilter,flags = win32gui.GetOpenFileNameW(
InitialDir=os.getcwd(),
Flags=win32con.OFN_EXPLORER,
File='', DefExt='py',
Title='Open File...',
Filter=filter,
CustomFilter=customfilter,
FilterIndex=1
)
except Exception, e:
if hasattr(e,'what'):
print e.what()
raise RuntimeError("File select error!")

return fname

def do_gtk(self):
print "LAUNCHING..."
self.add_filter("Other files",["*.*"])
self.chooser.run()
print "DONE..."
return self.chooser.get_filename()


f = FileChooser()
f.add_filter("ASCEND files",["*.a4c","*.a4l"])
print "SELECTED FILE",f.do()
___
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] Win32 file chooser

2006-03-08 Thread John Pye
I've posted a working version of this direct from the demo scripts in
the win32all package.

See http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq21.013.htp

Cheers
JP

Nikos Kouremenos wrote:
> Chris, is it possible you could put a comment or two and add it to the FAQ?
>
> thanks in advance
>
> On 3/6/06, Chris Lambacher <[EMAIL PROTECTED]> wrote:
>   
>> I use MFC CreateFileDialog provided by win32ui in win32all.
>>
>> Here is something that works on win2k and XP for sure:
>>
>> filtertypes = [('All Font Files (*.ttf, *.otf, *.pfm)',
>> ('*.ttf','*.otf', '*.pfm')),
>>('True Type Font Files (*.ttf)', ('*.ttf',)),
>>('Open Type Font Files (*.otf)', ('*.otf',)),
>>('Type 1 Font files (*.pfm)', ('*.pfm',)),
>>('All Files (*.*)', ('*',))]
>>
>> filters = []
>> for fil_name, fil_exts in filtertypes:
>> filter = '|'.join((fil_name, ';'.join(fil_exts)))
>> filters.append(filter)
>>
>> filter = '|'.join(filters+[''])
>>
>> dlg = win32ui.CreateFileDialog( True, None, None,
>> win32con.OFN_HIDEREADONLY |
>> win32con.OFN_OVERWRITEPROMPT |
>> win32con.OFN_FILEMUSTEXIST, filter)
>>
>> dlg.SetOFNTitle('Select font file')
>>
>> response = dlg.DoModal()
>> if response != win32con.IDOK:
>> return
>>
>> filename = dlg.GetPathName()
>> del dlg
>>
>>
>> On Mon, Mar 06, 2006 at 12:27:19PM +1100, John Pye wrote:
>> 
>>> Hi all,
>>>
>>> Has anyone had any success getting the following example from the FAQ to
>>> run?
>>>
>>> http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq21.013.htp
>>>
>>> For me, running with Python 2.4 on Win2k, it doesn't work:
>>>
>>>   
 Exception in thread Thread-12:
 Traceback (most recent call last):
   File "C:\Python24\lib\threading.py", line 442, in __bootstrap
 self.run()
   File "C:\Python24\lib\threading.py", line 422, in run
 self.__target(*self.__args, **self.__kwargs)
   File "examplewinfile.py", line 12, in run_dialog
 s = winfilechooser._test("This is a dialog", "C:\\WINDOWS")
   File "g:\ascend\pygtk\interface\winfilechooser.py", line 132, in _test
 if win32gui.GetOpenFileName(cs1.data):
 TypeError: Argument must be a 88-byte string
 
>>> Any suggestions?
>>>
>>> Cheers
>>> JP
>>>
>>> --
>>> John Pye
>>> School of Mechanical and Manufacturing Engineering
>>> The University of New South Wales
>>> Sydney  NSW 2052  Australia
>>> t +61 2 9385 5127
>>> f +61 2 9663 1222
>>> mailto:john.pye_AT_student_DOT_unsw.edu.au
>>> http://pye.dyndns.org/
>>>
>>> ___
>>> 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/
>>
>> 
>
>
> --
> Nikos Kouremenos
>   

-- 
John Pye
School of Mechanical and Manufacturing Engineering
The University of New South Wales
Sydney  NSW 2052  Australia
t +61 2 9385 5127
f +61 2 9663 1222
mailto:john.pye_AT_student_DOT_unsw.edu.au
http://pye.dyndns.org/

___
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] Drag and drop: retaining selection?

2006-03-08 Thread Andrew Conkling
I'm trying to set up DnD in my program to retain the selection after
dragging, but I can't seem to get it work.  We have some rather crazy
code to handle the drag and drop itself (which I can paste but I don't
think it's relevant) because the TreeModel simply mirrors a backend
list which we have to update.  In Glade, I've connected 'drag-end' to
my after_drag_drop callback, and set it to call *after*.  Here's the
callback:

def after_drag_drop(self, treeview, drag_context):
model = treeview.get_model()
sel = treeview.get_selection()
# self._selected is created in the DnD code, and is simply a list of
selected paths.
for path in self._selected:
sel.select_path(path)

The treeview's selection mode is set to gtk.SELECTION_MULTIPLE.

It seems like it works (just eyeballing it), because the selection
'sticks' for a moment, but then the selected rows are unselected.  Any
idea what would be causing this or what other code I could paste to
help figure this out?

Thanks a lot,
Andrew

--
http://aconkling.blogspot.com
___
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] CellRendererCombo Question

2006-03-08 Thread Hussein Vastani
Hello All, 
Does anyone know if something like the wrap_width function is implemented for 
the CellRendererCombo in pygtk? 
Heres the scenario. 
I populate my combobox (in my treeview) dynamically and want to display it in 
more than one column if the list is large.

This is how I set it up :

model = gtk.Liststore(str)
tree_store_col = 0
cell_renderer = gtk.CellRendererCombo()
cell_renderer.set_property("model",model)
cell_renderer.set_property('text-column', 0)
cell_renderer.set_property('editable', True)
new_col = gtk.TreeViewColumn(col_name, cell_renderer, text=tree_store_col)
tree.append_column(new_col)
cell_renderer.connect('editing-started', populate_combo, (tree_store,))

And this is how I populate the combobox in the populate_combo callback
def populate_combo(self, cell, editable, path, data):
store = data[0]
iter = store.get_iter(path)
items = self.get_list() # my function get_list() returns a list of strings
m = cell.get_property('model')
m.clear()
items.sort()
for s in items:
m.append([s])

so if my items list is large, it gets frustrating to scroll the entire list to 
get to the required item. It would be nice if the items were displayed in more 
than one column (for eg.)
Any suggestions on how to make this better?

Thanks

Hussein Vastani




___
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] Taking action when a window is raised

2006-03-08 Thread Graham Ashton
[I'm re-posting this from http://www.gnomedev.com/viewtopic.php?t=36]

Hi there. I'm trying to work out how to run a callback when my
application's main window is given top level focus. I'm using PyGTK,
but I think my question is really a general GTK+ one.

How are you supposed to do it? I can't find a signal on a GtkWindow
that I could connect to, which has left me stumped. I'm not sure how
else it would work.

I know it's possible (the wonderful gossip
[http://live.gnome.org/Gossip] does it), but a cursory scan of the
source didn't reveal anything obvious (to me).

Any pointers?

Cheers,

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