Re: [pygtk] Filechooserbutton callback

2008-10-23 Thread John Finlay
Frédéric wrote:
 On mercredi 22 octobre 2008, John Finlay wrote:

   
 AFAICT the FileChooserButton is a replacement for using an entry/label
 and associated file browser button. It only allows selecting one
 existing file or folder and displays the name of the selected file in
 the button label. The most likely application is to use the FCB in a
 dialog where a file or folder is to be selected (along with other info)
 and finally another action (e.g. clicking an OK button) is used to
 retrieve the currently selected file or folder and perform some
 operations. I don't think it works very well if you want to perform some
 actions immediately after selecting a file or folder unless you pass in
 a FileChooserDialog and add the buttons and handle its responses and
 signals. You can use the selection-changed signal with the FCB to be
 notified when a different file has been selected and the dialog is
 closed.
 

 Using the selection-changed signal does not work; it is never emited. 
   
Works for me on:

Python 2.5.1, PyGTK 2.12.0 (Gtk+ 2.12.5)

 Anyway, as you suggested, I just get the value when the entire config 
 dialog is closed, and it works fine... except under Windows! 
 get_current_folder() always returns the first dir I set in the chooser, 
 with set_current_folder() method. Note that it works fine under linux and 
 Nokia/maemo.

   

___
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] Filechooserbutton callback

2008-10-23 Thread Frédéric
On jeudi 23 octobre 2008, John Finlay wrote:

  Using the selection-changed signal does not work; it is never emited.

 Works for me on:

 Python 2.5.1, PyGTK 2.12.0 (Gtk+ 2.12.5)

Wich plateform?

  Anyway, as you suggested, I just get the value when the entire config
  dialog is closed, and it works fine... except under Windows!
  get_current_folder() always returns the first dir I set in the
  chooser, with set_current_folder() method. Note that it works fine
  under linux and Nokia/maemo.

-- 
Frédéric

http://www.gbiloba.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] Filechooserbutton callback

2008-10-23 Thread John Finlay
Frédéric wrote:
 On jeudi 23 octobre 2008, John Finlay wrote:

   
 Using the selection-changed signal does not work; it is never emited.
   
 Works for me on:

 Python 2.5.1, PyGTK 2.12.0 (Gtk+ 2.12.5)
 

 Wich plateform?
   
Fedora 8 and Ubuntu Hardy

___
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.MessageDialog doesn't work on windows

2008-10-23 Thread Timo
I have the following piece of code in my program:

def errorDlg(string):
s = An error occured during this operation!
errordlg = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, 
message_format=s, buttons=gtk.BUTTONS_OK)   
errordlg.format_secondary_text(string)
errordlg.run()
errordlg.destroy()


So I call errorDlg() when there is an error. On Linux this works 
perfectly, but on windows the program just hangs. This is the first time 
I try to program under windows, so maybe it's obvious, and everything 
else seems to work.

Greets,
Timo
___
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 do_size_allocate properly in a gtk.Viewport subclass?

2008-10-23 Thread Joel Hedlund
Thanks for your suggestion! It works quite well, however I do have some 
gripes with this solution, mostly because of stuff I left out of my 
original mail for the sake of brevity. So here goes:


John Finlay wrote:
I'm not sure what behavior you are looking for so I'll assume that you 
have one widget (e.g. Image) that you want to put inside a Viewport  


Yup, only it's a custom widget, a subclass of gtk.DrawingArea.

in a ScrolledWindow. 


Not necessarily, but I probably could if that works better?

I'll also assume that you want the widget to 
float in the center of the Window when the widget is smaller than the 
Window. 


Mostly correct. I'd rather have top left. Or somewhere else, see below.

Finally I assume that you want the widget to be partially 
displayed but scrollable within the window when the widget is larger 
than the Window. 


Correct.

So, the purpose of all this is to make a viewer for multiple sequence 
alignments (MSA). You can think of an MSA as a very large matrix with 
one amino acid (aa = a letter) per element. Both the aas and their 
backgrounds will be colored individually based on properties of the aa 
and its context in the MSA. My widget will let you interact with the MSA 
(draw, make selections, context menus, ...). Also there will be multiple 
additional widgets around this one, displaying graphs and plots for row- 
and column statistics in the MSA. My widget will also be used for these. 
When looking at this kind of stuff you need to zoom around a lot to be 
able to look at both the big picture and the gory details, hence the 
need to support both tiny and huge widgets. All these views need to be 
coupled so that the graphs line up with the MSA *exactly*, and for all 
this I want a total of 2 scrollbars.


I want to use the mouse scrolls to do most of the zooming, and when that 
happens I want to have the MSA stay put under the pointer so that the 
aa that was under the pointer before the zoom also is under the pointer 
after the zoom (not implemented in the attached example). This is easy 
when the widget is larger than the viewport, but I don't really know how 
to do that when it's smaller. If that turns out to be too hard I think 
the next best thing is to place small widgets topleft (how?). Or if 
that's also a problem I could make do with centered I suppose...


Now, my real gripe is that zooming looks twitchy for small widgets 
with the widget-in-table-in-viewport solution, and that will be painful 
for users to look at. I'm hoping I've done some stupid oversight 
somewhere (help?). Maybe that will go away if you glue the widget 
topleft somehow?


I attached a small example I've worked with so you can see what I mean.

Thanks for your time!
/Joel
import gtk

class MyDrawingarea(gtk.DrawingArea):
__gsignals__ = {'expose-event': 'override'}

def do_expose_event(self, event):
import math
import cairo
alloc = self.get_allocation()
cr = self.window.cairo_create()
cr.rectangle(event.area.x, event.area.y, event.area.width, event.area.height)
cr.clip()
cr.set_source_rgb(1, 1, 1)
cr.rectangle(event.area.x, event.area.y, event.area.width, event.area.height)
cr.fill()
max_radius = (alloc.width**2 + alloc.height**2) ** 0.5
step = 10
x, y = alloc.width/2, alloc.height/2
for i in range(1, int(max_radius/step)):
if i % 2:
cr.set_source_rgb(1, 0, 0)
else:
cr.set_source_rgb(0, 0, 1)
cr.arc(x, y, i * step, 0, 2 * math.pi)
cr.stroke()

class BoundedScrollAdjustment(gtk.Adjustment):
def __init__(self, value=0, lower=0, upper=0, step_incr=0, page_incr=0, page_size=0):
super(BoundedScrollAdjustment, self).__init__(value, lower, upper, step_incr, page_incr, page_size)
def _bound(self, value):
return max(0, min(value, self.upper - self.page_size))
def scroll(self, less=False, page=False):
amount = self.page_increment if page else self.step_increment
self.value = self._bound(self.value + amount * (-1 if less else 1))
def update(self, page_size, upper):
self.upper = upper
self.page_size = page_size
self.step_increment = 0.1 * page_size
self.page_increment = 0.9 * page_size
self.value = self._bound(self.value)

class ZoomView(gtk.Viewport):
__gsignals__ = {'scroll-event': 'override'}
def __init__(self):
gtk.Viewport.__init__(self, BoundedScrollAdjustment(), BoundedScrollAdjustment())

def do_scroll_event(self, event):
if not self.child:
return
hdir = ((event.state  gtk.gdk.SHIFT_MASK) or 
event.direction in [gtk.gdk.SCROLL_LEFT, gtk.gdk.SCROLL_RIGHT])
less = event.direction in [gtk.gdk.SCROLL_LEFT, gtk.gdk.SCROLL_UP]
if event.state  gtk.gdk.CONTROL_MASK:
factor = 1.1
if not less:
  

Re: [pygtk] gtk.MessageDialog doesn't work on windows

2008-10-23 Thread Timo
Frédéric schreef:
 Le 23/10/2008, Timo [EMAIL PROTECTED] a écrit:

   
 def errorDlg(string):
s = An error occured during this operation!
errordlg = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
 message_format=s, buttons=gtk.BUTTONS_OK)
errordlg.format_secondary_text(string)
errordlg.run()
errordlg.destroy()
 

 Strange, I use such dialog in Windows, and it works fine. I think your
 problem is elsewhere. In what context do you open this dialog? 
It gets called in here:

def getLink(site):
try:
#do my link stuff
except urllib2.HTTPError, e: 
#print HTTP request failed with error %d (%s) % (e.code, e.msg)  
errorDlg(HTTP request failed with error %d (%s) % (e.code, e.msg))

The print was just for checking if it really gets there, and it does, so 
the urllib2 stuff works.

 Is it
 from the main loop thread? Or from another thread?

   
The getLink() from above does indeed get called from within a thread, 
not the main loop. Would this be the problem? Because, in the same 
thread, I'm also moving a progressbar and filling up a treeview, and 
they seem to work fine.

Timo

___
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.MessageDialog doesn't work on windows

2008-10-23 Thread Frédéric
Le 23/10/2008, Timo [EMAIL PROTECTED] a écrit:

The getLink() from above does indeed get called from within a thread,
not the main loop. Would this be the problem?

Yes, no doubt!

Because, in the same
thread, I'm also moving a progressbar and filling up a treeview, and
they seem to work fine.

Well,

First, you need to init the threads, at the begin of your program:

gtk.gdk.threads_init()
gtk.gdk.threads_enter()

and call:

gtk.gdk.threads_leave()

at the end (not really needed).

Then, use a serializer. I attached mine. When you need to call a GUI
stuff from your thread, use:

ret = serializer.apply(func, param1, param2...)

This will push the func on a queue (note that you can wait for a return
value if needed). To have the queue executed, you need to call:

gobject.timeout_add(50, serializer.processWork)

before the gtk main loop. So, the serializer queue will be checked every
50 ms (try different values depending of your config).

Hope this helps.

--
   Frédéric
# -*- coding: utf-8 -*-

 Panohead remote control.

License
===

 - B{papywizard} (U{http://trac.gbiloba.org/papywizard}) is Copyright:
  - (C) 2007-2008 Frédéric Mantegazza

This software is governed by the B{CeCILL} license under French law and
abiding by the rules of distribution of free software.  You can  use, 
modify and/or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
U{http://www.cecill.info}.

As a counterpart to the access to the source code and  rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty  and the software's author,  the holder of the
economic rights,  and the successive licensors  have only  limited
liability. 

In this respect, the user's attention is drawn to the risks associated
with loading,  using,  modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean  that it is complicated to manipulate,  and  that  also
therefore means  that it is reserved for developers  and  experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or 
data to be ensured and,  more generally, to use and operate it in the 
same conditions as regards security. 

The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.

Module purpose
==

Graphical toolkit helper

Implements
==

 - Serializer

Usage
=

This serializer allows threads to serialize events to
be processed by the main trhead.

@author: Frédéric Mantegazza
@copyright: (C) 2007-2008 Frédéric Mantegazza
@license: CeCILL


__revision__ = $Id: serializer.py 557 2008-09-18 18:51:24Z fma $

import sys
import Queue


class Serializer(object):
 Events serializer.

def __init__(self):
 Init the serializer

self.__workRequestQueue = Queue.Queue()
self.__resultQueue = Queue.Queue()

def apply(self, work, *args, **kwargs):
 Add an event to the serializer queue.

Called by an external thread which want to display
something on the GUI.

@param work: work to push on the queue
@type work: python callable

self.__workRequestQueue.put((work, args, kwargs))
result, exception = self.__resultQueue.get()
if exception:
raise exception[0], exception[1], exception[2]
else:
return result

def processWork(self):
 Execute a queued work.

Called by the main thread to process one
pending work in the queue.

try:
work, args, kwargs = self.__workRequestQueue.get_nowait()
try:
result = work(*args, **kwargs)
except:
exception = sys.exc_info()
result = None
else:
exception = None
self.__resultQueue.put((result, exception))
except Queue.Empty:
pass

return 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] Writting a widget with native scrolling support

2008-10-23 Thread Laszlo Nagy
Gustavo J. A. M. Carneiro wrote:
 http://www.daa.com.au/pipermail/pygtk/2006-January/011668.html
   
Yes, this was the only related post that I could find on the internet. 
But I could not use it for anything because it does not tell how to do 
it. It says:

For custom widgets, check the method 
gtk.Widget.set_set_scroll_adjustments_signal(signal_name)


But this method only has a signal_name parameter. I do not see how I 
could use it for specifying my adjustments and making my widget support 
scrolling natively?

(Also that was written in 2006, probably it is outdated.)

Thanks,

   Laszlo


___
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] Writting a widget with native scrolling support

2008-10-23 Thread Gustavo J. A. M. Carneiro
On Thu, 2008-10-23 at 15:42 +0200, Laszlo Nagy wrote:
 Gustavo J. A. M. Carneiro wrote:
  http://www.daa.com.au/pipermail/pygtk/2006-January/011668.html

 Yes, this was the only related post that I could find on the internet. 
 But I could not use it for anything because it does not tell how to do 
 it. It says:
 
 For custom widgets, check the method 
 gtk.Widget.set_set_scroll_adjustments_signal(signal_name)
 
 
 But this method only has a signal_name parameter. I do not see how I 
 could use it for specifying my adjustments and making my widget support 
 scrolling natively?
 
 (Also that was written in 2006, probably it is outdated.)

It is not outdated.  See
http://library.gnome.org/devel/gtk/2.14/GtkWidget.html

GtkWidgetClass
typedef struct {
  /* The object class structure needs to be the first
   *  element in the widget class structure in order for
   *  the class mechanism to work correctly. This allows a
   *  GtkWidgetClass pointer to be cast to a GtkObjectClass
   *  pointer.
   */
  GtkObjectClass parent_class;

  
  guint activate_signal;

  guint set_scroll_adjustments_signal;
} GtkWidgetClass;

activate_signal The signal to emit when a widget of this class
is activated, gtk_widget_activate() handles the emission.
Implementation of this signal is optional. 

set_scroll_adjustment_signal This signal is emitted when a
widget of this class is added to a scrolling aware parent,
gtk_widget_set_scroll_adjustments() handles the emission.
Implementation of this signal is optional.


gtk.Widget.set_set_scroll_adjustments_signal is PyGtk's equivalent to
Gtk+/C setting the field set_scroll_adjustments_signal of the
GtkWidgetClass of your widget.  Basically you have to define a signal
my-signal in your widget that accepts two gtk.Adjustment objects as
parameters, then do
MyClass.set_set_scroll_adjustments_signal(my-signal).  Of course you
still need to implement the scrolling by monitoring the adjustments and
updating the widget's view accordingly, but after that you can add your
widget to a scrolled window.


 
 Thanks,
 
Laszlo
 
 
-- 
Gustavo J. A. M. Carneiro
[EMAIL PROTECTED] [EMAIL PROTECTED]
The universe is always one step beyond logic -- Frank Herbert

___
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 do_size_allocate properly in a gtk.Viewport subclass?

2008-10-23 Thread Joel Hedlund
Joel Hedlund wrote:
 Now, my real gripe is that zooming looks twitchy for small widgets 
 with the widget-in-table-in-viewport solution, and that will be painful 
 for users to look at. I'm hoping I've done some stupid oversight 
 somewhere (help?). Maybe that will go away if you glue the widget 
 topleft somehow?

Fixed; swapping out the table for a gtk.Alignment().

def make_revised_suggestion_window():
 d = MyDrawingarea()
 d.set_size_request(100, 100)
 a = gtk.Alignment()
 a.add(d)
 z = ZoomWindow()
 z.add_with_viewport(a)
 w = gtk.Window()
 w.add(z)
 w.set_size_request(200, 200)
 w.connect('destroy', gtk.main_quit)
 w.set_title('pygtk list suggestion')
 w.show_all()

This is close enough for jazz, so many thanks for putting me on the 
right track!

About the twitching:
At first I thought it twitched because the view was redrawn directly 
after the size change, and then got redrawn again after the table 
repositioned the size-changed widget, but after some experimentation I'm 
not so sure anymore. I may have caused the twitch myself by drawing an 
eye-unfriendly pattern on my test widget. Because if I draw a simple red 
rectangle instead, the transition is smooth.

So don't draw concentric circles on your test widgets, kids!

Again thanks for your help!
/Joel
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] Problem with shrinking a Table on a ScrolledWindow

2008-10-23 Thread José Luis
Hello people!

I'm having a trouble when I shrink a window that contains the following
widgets tree:

+ ScrolledWindow
+ Viewport
   + Table
 + Frame1
 + Frame2
.

When I expand my main window, the widgets expand correctly, without using
the scrolled window. But, if I shrink my window, the viewport have a correct
size acording with scrolledwindow widget, but the Table is larger than the
viewport, and because that, I have to use the scrollers of the
scrolledwindow.

Then, the cells of the table are still on the big size, and I want to all
the cells shrink with my window.

I do very much tests, and I see that the scrolledwindow and viewport widgets
have the correct size, but the table widget (and then, all their cells) have
a size very much larger than the window.

How can I say to the table that shrink its size according their parent
widgets?
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Re: [pygtk] How to do_size_allocate properly in a gtk.Viewport subclass?

2008-10-23 Thread Greg Ewing
Joel Hedlund wrote:

 So don't draw concentric circles on your test widgets, kids!

Yeah. And if you've seen some of the wilder optical illusions
around, you'll know that if you choose just the wrong pattern
it'll twitch all by itself, without you having to write any
code at all!

-- 
Greg
___
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] Clickable MenuItem with submenu?

2008-10-23 Thread Miguel Ángel García
Here you are:


#buind the menu
menu = gtk.Menu()

#create an item
item = gtk.ImageMenuItem(gtk.STOCK_COPY)
item.connect (activate, myfunction, None)

#append it
menu.append(item)

#built the submenu
submenu = gtk.Menu()

#well... append the same item built before
submenu.append(item)

#build another item and attach it the sub menu
item = gtk.ImageMenuItem(gtk.STOCK_EDIT)
item.set_submenu(submenu)

#all together
menu.append(item)


I think you problem was that you was trying to use activate signal to
launch the submenu as another popup. It is simplier :-D




El Thu, 16 Oct 2008 11:22:41 +0400
Igor Mammedov [EMAIL PROTECTED] escribió:

 Hi Everyone!
 
 I've following menu structure:
 
 Menu
   |
   Filter1 (MenuItem with submenu)
 |
 Filter2 (MenuItem)
 
 When I click on Filter1 menu popup disappears and I app 
 receives 'activate' signal.
 
 Question is how can I get the same effect on Filter1?
  (i.e. when I click on Filter1, app shall at least close
   whole popup menu and possibly generate 'activate' signal)
 
 
 
 ___
 pygtk mailing list   pygtk@daa.com.au
 http://www.daa.com.au/mailman/listinfo/pygtk
 Read the PyGTK FAQ: http://faq.pygtk.org/


-- 
In a world without walls and fences, who needs Windows and Gates?
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/