[pygtk] Adjust gtk.ScrolledWindow

2010-01-21 Thread middleofdre...@gmail.com
Hi, In my App I was using gtk.TextWiev for displaying text. If some new text
appeard I could use textview.scroll_to_iter or something like this. Now I'm
using Webkit... And here is a problem. How to scroll down on new text? I
connected webkit signal load-finished with function:

pos=self.scrolled.get_vadjustment()
newpos=pos.get_upper()-pos.get_page_size()
pos.set_value(newpos)
self.scrolled.set_vadjustment(pos)

Sometimes it works perfectly, but sometimes... i see only half of last line.
Why's that? And how to make it work...

Btw, Is it possible to append text to rendered html in webkit (rendered from
string... if that matters)? Maybe in javascript (which i don't know at all)
or wekbit-wide?


Greetings,
Kuba

PS - sorry for my english - it's not my native language.
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

[pygtk] Dialog

2010-01-21 Thread Peyman
Hello

I recently switched a few of my windows from being of type gtk.Window  
to gtk.Dialog.  I fixed everything so the dialogs show up, but now  
they are HUGE. This has to do with the size_request of the horizontal  
boxes (action_area). Both the vbox and the action_area have  
homogeneous=False and spacing=0

Any one know how I can fix this?

Cheers
Peter

___
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 on Windows (SOLVED)

2010-01-21 Thread Stuart Axon
Awesome... just been having a play with this.

Trying to look into this (and not getting very far) has certainly been an eye 
opener WRT the different things that go into these bindings.

It works with shoebot, + having a recent version of pygtk and other libs for 
shoebot was where I wanted to get to in the first place.

Much Kudos !


Any idea if having a new pygtk has any bearing on getting python plugins 
working in win32 gedit ?

 S++



  
___
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] Handling new foreign windows in pygtk app.

2010-01-21 Thread Tomeu Vizoso
On Tue, Jan 19, 2010 at 11:44, Radek Vykydal rvyky...@redhat.com wrote:
 Hello list,


 I am trying to solve this problem:

 In root-only environment (Anaconda installer) we are running very simple
 C window manager (only taking care of setting focus of windows), Anaconda
 pygtk GUI, and on demand nm-connection-editor (C Gtk+ application) can
 be run.

 In Anaconda (the pygtk app) I have class (constructor is taking Xid of
 window)
 for embedding nm-c-e foreign window using gtk.Socket. What I need now is
 a mechanism
 for notifying about appearing nm-c-e windows (providing their Xid), idally
 it would allow to set a callback on event/notification.

 My last idea was:
 - catch CreateNotify events in the C window manager
 - 'forward' them via ClientMessage to Anaconda pygtk app
  (to a window W specified/found in window manager by its wmname),
  sending Xid of created window
 - in Anaconda pygtk app set client-event callback on the window W
  which will use Xid to (eventually) embed the created window

 Does it sound like it could work?
 Especially, is X ClientMessage received in pyGtk app generating
 client-event Gtk signal?

 I made an example but it doesn't work - base.py doesn't call the ce-cb
 callback when
 I seem to send ClientMessage to its window.

 I run two python processes (in my environment, metacity wm is running).


 base.py:

 #!/usr/bin/python

 import pygtk
 import gtk

 def ce_cb(widget, event):
    print Got client event!

 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
 # This doesn't help
 #window.add_events(gtk.gdk.CLIENT_EVENT)
 window.connect(client-event, ce_cb)
 window.show()

 gtk.main()


 send_event.py:

 #!/usr/bin/python

 import sys
 import Xlib
 from Xlib import display
 from Xlib.protocol import event

 d = display.Display()
 s = d.screen()
 children = s.root.query_tree().children

 for c in children:
    if c.get_wm_name() == base.py:
        break
 else:
    print ERROR: base.py not found
    sys.exit(1)

 # here I don't know exactly what I am doing to be honest
 atom = d.intern_atom('WINDOW')

 cm = event.ClientMessage(window = c,
                         client_type = atom,
                         data = (8, 01234567890123456789))

 c.send_event(cm)
 d.flush()


 What I am doing wrong?
 Or is my whole concept wrong?

In my experience, though solutions like these seem like a shortcut,
when you get to the details it gets much tougher.

The longer path that I would favour is to put the C code that you want
to reuse in a shared library and generate pygobject bindings for it.

Regards,

Tomeu

-- 
«Sugar Labs is anyone who participates in improving and using Sugar.
What Sugar Labs does is determined by the participants.» - David
Farning
___
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 on Windows (SOLVED)

2010-01-21 Thread John Stowers

 Any idea if having a new pygtk has any bearing on getting python plugins 
 working in win32 gedit ?

I expect it will. The Gedit hackers seem to be commenting on that bug.
Although Gtk+-2.18 is broken on windows, so it looks like the PyGtk
+-2.16 release will be sufficient for their needs.

John


___
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 on Windows (SOLVED)

2010-01-21 Thread Timo
On 21-01-10 14:04, John Stowers wrote:

 Any idea if having a new pygtk has any bearing on getting python plugins 
 working in win32 gedit ?
  
 I expect it will. The Gedit hackers seem to be commenting on that bug.
 Although Gtk+-2.18 is broken on windows, so it looks like the PyGtk
 +-2.16 release will be sufficient for their needs.

Hello John,

I saw you saying that gtk+-2.18 is broken on Windows a couple of times. 
But I used it about 2-3 months ago for my application, and everything 
worked ok.

BTW thanks for the work, I will test it soon too.

Cheers,
Timo

 John


 ___
 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] PyGtk on Windows (SOLVED)

2010-01-21 Thread John Stowers

 I saw you saying that gtk+-2.18 is broken on Windows a couple of times. 
 But I used it about 2-3 months ago for my application, and everything 
 worked ok.

That certainly sounds promising, would you mind testing something for me
plese?

Can you please launch gtk-demo with the latest Gtk+ bundle and confirm
that you see the behaviour I describe in 

https://bugzilla.gnome.org/show_bug.cgi?id=607603

John


___
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] gobject.timeout_add()

2010-01-21 Thread Pietro Battiston
Il giorno gio, 21/01/2010 alle 08.56 +0100, John Stowers ha scritto:
 On Wed, 2010-01-20 at 21:22 -0800, dj wrote:
  I hope this is the right place to ask this...
  
  I have a python program (using Glade to create the gui) that periodically 
  launches ecasound to make audio recordings of various lengths.  In order to 
  keep the gui viable, ecasound runs in a separate thread.  In order to keep 
  the program from getting ahead of itself and trying to launch ecasound 
  before the current recording process has finished, I use 
  gobject.timeout_add() for the length of the recording (plus a second or two 
  for safety).
  
  Most of the calls to gobject.timeout_add() are in separate functions with 
  different intervals.  All but one of them work.  The last one only works if 
  gobject.timeout_add(..., ...)/return False is appended to the end of the 
  function that needs it, rather than calling it.
 
 This doesn't sound like a particuarly nice design,

More specifically: are you sure you need threads at all?!
subprocess.call will block the GUI, but subprocess.Popen won't.

Pietro

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

2010-01-21 Thread Pietro Battiston
Il giorno gio, 21/01/2010 alle 09.36 +, Peyman ha scritto:
 Hello
 
 I recently switched a few of my windows from being of type gtk.Window  
 to gtk.Dialog. 

If you can show us the code, it will be much simpler...

 I fixed everything so the dialogs show up, but now  
 they are HUGE.

In one dimension or both?

 This has to do with the size_request of the horizontal  
 boxes (action_area).

How do you know? How are things distributed?

 Both the vbox and the action_area have  
 homogeneous=False and spacing=0

What about running

while widget:
print widget, widget.size_request(), widget.get_size_request()
parent = widget.get_parent()
if parent:
try:
print parent.child_get_property('expand')
print parent.child_get_property('fill')
except:
pass


?

When you can't for some reason provide code, please at least provide
lots of informations.

Pietro


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


[pygtk] How to organize my app?

2010-01-21 Thread middleofdre...@gmail.com
Hi,
I don't have experience in creating big apps. I want to know how to split
app into files. For example - I have main class in main file and I want to
move widgets (loading widgets from gladefile) into new file. It should be in
the mainclass i think.. but i can't import something inside class (it works
but it's not proper). Or signal handlers - how to move them into other file
and do it right? Another thing is i have some (not main) class, but it
should interact with gui (some changes like showing widgets etc). It's
assigned in mainclass and constructor of it looks like this:

__init__(gui):
self.gui=gui

and then.. in functions of this class I can change for example
self.gui.some_widget.show()
And again.. I don't think it's proper method for doing this.

Some tips, please?
___
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 organize my app?

2010-01-21 Thread Pietro Battiston
Il giorno gio, 21/01/2010 alle 23.14 +0100, middleofdre...@gmail.com ha
scritto:
 Hi,
 I don't have experience in creating big apps. I want to know how to
 split app into files. For example - I have main class in main file and
 I want to move widgets (loading widgets from gladefile) into new file.
 It should be in the mainclass i think.. but i can't import something
 inside class (it works but it's not proper).

If you don't want it into the same file of the main class, you
certainly don't want it into the main class is a rule for which I'm not
able to see any exception.

That said, what I do in many projects is creating this file:


import gtk

class Ui(object):
def __init__(self, APP, filename):
self._builder = gtk.Builder()
self._builder.set_translation_domain(APP)
self._builder.add_from_file(filename)

def __getattr__(self, attr_name):
try:
return object.__getattribute__(self, attr_name)
except AttributeError:
obj = self._builder.get_object(attr_name)
if obj:
self.obj = obj
return obj
else:
raise AttributeError, no object named \%s\ in the
GUI. % attr_name



and importing Ui from it; then, the main class will, in __init__, do
something like

self.ui = Ui(nameoftheapp, path/to/the/file.glade)

so that from now on you just access widgets as

self.ui.name_of_the_widget


_But_ this is just what _I_ find convenient, and not really because I
want to separate it from the main class, but just to avoid some
get_object() calls and get cleaner code. In general, there are no
particular requirements to separate something from some class: if you
see it grew too big and there is something that can be separated from
it, just separate it.


 Or signal handlers - how to move them into other file and do it right?

I'm not really sure I would want to move signal handlers... if all your
handlers are method of this main class and you want to save some coding,
just use signals_autoconnect.

  Another thing is i have some (not main) class, but it should interact
 with gui (some changes like showing widgets etc). It's assigned in
 mainclass and constructor of it looks like this:
 
 
 __init__(gui):
 self.gui=gui
 
 
 and then.. in functions of this class I can change for example
 self.gui.some_widget.show() 
 And again.. I don't think it's proper method for doing this.
 

Well, in my opinion it's hard to say _in general_ that this is wrong.
When you choose the optimal size for some class, just think in terms of
functionalities: the best rule to respect is that it must be
comfortable.

Certainly, if self.gui.some_widget.show() is part of a block of code
that works on the gui, it may be smart to move it to a method of the gui
and call that from your class.


 
 Some tips, please?
 

Read other people's code, and just try. And obviously, be ready to
change things that you find not optimal.

Pietro


___
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 organize my app?

2010-01-21 Thread Pietro Battiston
Il giorno gio, 21/01/2010 alle 23.43 +0100, Pietro Battiston ha scritto:
 Il giorno gio, 21/01/2010 alle 23.14 +0100, middleofdre...@gmail.com ha
 scritto:
  Hi,
  I don't have experience in creating big apps. I want to know how to
  split app into files. For example - I have main class in main file and
  I want to move widgets (loading widgets from gladefile) into new file.
  It should be in the mainclass i think.. but i can't import something
  inside class (it works but it's not proper).
 
 If you don't want it into the same file of the main class, you
 certainly don't want it into the main class is a rule for which I'm not
 able to see any exception.

Wait, just forget that. Your problem is obviously not that you want the
_code_ in your main class, but that you want another object as a member
of your main class. Which is perfectly fine.

Pietro

___
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 organize my app?

2010-01-21 Thread middleofdre...@gmail.com
I see i was doing it wrong from the begining. gui was my main class but it
shouldn't.

2010/1/21 Pietro Battiston too...@email.it

Il giorno gio, 21/01/2010 alle 23.14 +0100, middleofdre...@gmail.com ha
 scritto:
  Hi,
  I don't have experience in creating big apps. I want to know how to
  split app into files. For example - I have main class in main file and
  I want to move widgets (loading widgets from gladefile) into new file.
  It should be in the mainclass i think.. but i can't import something
  inside class (it works but it's not proper).

 If you don't want it into the same file of the main class, you
 certainly don't want it into the main class is a rule for which I'm not
 able to see any exception.

 That said, what I do in many projects is creating this file:


 import gtk

 class Ui(object):
def __init__(self, APP, filename):
self._builder = gtk.Builder()
self._builder.set_translation_domain(APP)
self._builder.add_from_file(filename)

def __getattr__(self, attr_name):
try:
return object.__getattribute__(self, attr_name)
except AttributeError:
obj = self._builder.get_object(attr_name)
if obj:
self.obj = obj
return obj
else:
raise AttributeError, no object named \%s\ in the
 GUI. % attr_name



 and importing Ui from it; then, the main class will, in __init__, do
 something like

self.ui = Ui(nameoftheapp, path/to/the/file.glade)

 so that from now on you just access widgets as

self.ui.name_of_the_widget


Interesting... but.. if I use this method where I should do
signals_autoconnect?


  Or signal handlers - how to move them into other file and do it right?

 I'm not really sure I would want to move signal handlers... if all your
 handlers are method of this main class and you want to save some coding,
 just use signals_autoconnect.


I meant... functions for signals. They was in main class. for example:

dic={blabla: self.blabla}

and then
def blabla(self):
  self.label.set_text(blabla)

Can I create class for handling signals only?  If so - how?



  Another thing is i have some (not main) class, but it should interact
  with gui (some changes like showing widgets etc). It's assigned in
  mainclass and constructor of it looks like this:
 
 
  __init__(gui):
  self.gui=gui
 
 
  and then.. in functions of this class I can change for example
  self.gui.some_widget.show()
  And again.. I don't think it's proper method for doing this.
 

 Well, in my opinion it's hard to say _in general_ that this is wrong.
 When you choose the optimal size for some class, just think in terms of
 functionalities: the best rule to respect is that it must be
 comfortable.

 Certainly, if self.gui.some_widget.show() is part of a block of code
 that works on the gui, it may be smart to move it to a method of the gui
 and call that from your class.


But sometimes I have to change something in gui when some class signal is
emited (in new thread). I just don't know how to do it most cleanly and
lightweight way.



 
  Some tips, please?
 

 Read other people's code, and just try. And obviously, be ready to
 change things that you find not optimal.


Maybe some example app you can recommend? I was looking for something but
found only apps with bilion of lines of code... i'm not smart enough to get
through it.


 Pietro


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