[pygtk] gdk geometry for a gtk.Window.set_geometry_hints()

2003-06-12 Thread Martijn Brouwer
Hi,
I need a GdkGeometry struct for use in a gtk.Window.set_geometry_hints() command, but 
I cannot find how to create such an object. I imported gtk and then gtk.gdk, but 
dir(gtk.gdk) did not show me anything relevant.

Martijn


-- 
Physics is a approximate description of a part of the physical phenomena, that are 
only a small portion of human perceptions.

H Casimir, Dutch Physicist
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] TextView, set_tabs

2003-06-12 Thread John Finlay
Try pango.TAB_LEFT

Shaffer, Chris wrote:

I'm having a little trouble setting the tabs for a textview element (a
least, I'm assuming that set_tabs() will allow me to change the number of
spaces that consitute a 'tab' key press.  Please, tell me if I'm wrong).
Here is my code:
   tabs = pango.TabArray(4,pango.PANGO_TAB_LEFT)
   self.text.set_tabs(tabs)
I am including pango at the top of my file with:

   import pango

When I try and run my app, I get this error:

   Traceback (most recent call last):
 File "Edit/AppRun", line 26, in ?
   EditWindow.EditWindow()
 File "Edit/EditWindow.py", line 102, in __init__
   tabs = pango.TabArray(4,pango.PANGO_LEFT_TAB)
   AttributeError: 'module' object has no attribute 'PANGO_LEFT_TAB'
Any ideas what I'm doing wrong?

Thanks,

Chris Shaffer

 



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


Re: [pygtk] Validating an entry box

2003-06-12 Thread Art Haas
On Wed, Jun 11, 2003 at 10:57:45AM -0700, [EMAIL PROTECTED] wrote:
> - Art Haas arranged a host of electrons thusly: -
> > 
> After doing a bunch of reading (starting with the FAQ entry at
> http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq14.005.htp,
> which isn't entirely applicable, as it appears to be for the GTK1
> version) I arrived at the following solution.  It works quite well for
> me.
> 
> def on_text_insert(self, entry, text, length, *args):
> entry.stop_emission('insert-text')
> entry.handler_block(self.handler_ids['insert-text'])
> pos = entry.get_position()
> 
> print text
> 
> entry.insert_text(text, pos)
> # more stuff required here, no doubt, for autocompletion & such
> 
> gtk.idle_add(lambda: entry.set_position(pos + length))
> entry.handler_unblock(self.handler_ids['insert-text'])
> 
> return 0
> 
> Where handler_ids is just a place where I stash the return values of the
> connect(...) calls for later reference.  
> 
> Setting the position of the cursor just plain doesn't work from within
> the signal handler.  Or I couldn't find any way to make it do so.  I've
> experimented with using gtk.timeout_add as well as gtk.idle_add, but
> idle_add seems to work better with slow network links (sometimes
> individual characters would come out reversed using timeout_add).
> 
> I'm still unclear as to whether I should be return gtk.FALSE or just a
> plain old false value from on_text_inserted to tell gtk to not propagate
> the signal further.  It might not matter, either.  Doing it this way
> seems to work for me.
> 

Well, it looks like gtk.idle_add() is the way to go. I too looked at the
FAQ, and after trying various other ways of getting the cursor to move,
and several takes with the idle_add() routine I'm pleased to say that
the entry box routine I'm enclosing works well enough for my purposes.

As the documentation for the 'insert-text' signal indicates the handler
returns void, I don't believe that the handler in the PyGTK code needs
to return anything as well. My sample code doesn't, and things seem to
work.

Thanks for pointing me in the right direction. I'm including my test
code below so that it will be archived on the list. Perhaps it can be
added to the FAQ to supplement the code sample that is already there,
and to provide a PyGTK 2 type example. If the FAQ maintainer wishes to
add the code, I certainly give my permission to use the code below. Feel
free to clean it up as you see fit - maybe remove the '_' characters
that I prepend function local variables with.

A better entry validation routine would handle locales that use
characters other than '.' for the integral/fractional delineator. As is
often written in textbooks, that is left as an exercise to the reader.
Please pass it along if you do the exercise ... :-)

Art Haas

===
#!/usr/bin/python

#
# entry box validation test
#

import gtk

import sys

def entry_activate(entry):
_text = entry.get_chars(0, -1)
entry.delete_text(0, -1)
if len(_text):
if _text == '-' or _text == '+':
sys.stderr.write("Incomplete value: '%s'\n" % _text)
else:
try:
_value = float(_text)
print "value: %g" % _value
except:
sys.stderr.write("Invalid float: '%s'\n" % _text)
else:
sys.stderr.write("Empty entry box.")

def entry_focus_out(entry, event):
_text = entry.get_chars(0, -1)
if _text == '-' or _text == '+':
entry.delete_text(0, -1)
return gtk.FALSE

def move_cursor(entry):
entry.set_position(-1)
return gtk.FALSE

def entry_insert_text(entry, new_text, new_text_length, position):
if (new_text.isdigit() or
new_text == '.' or
new_text == '+' or
new_text == '-'):
_string = entry.get_chars(0, -1) + new_text
_hid = entry.get_data('handlerid')
entry.handler_block(_hid)
_pos = entry.get_position()
_move = True
if _string == '-' or _string == '+':
_pos = entry.insert_text(new_text, _pos)
else:
try:
_val = float(_string)
_pos = entry.insert_text(new_text, _pos)
except StandardError, e:
_move = False
sys.stdout.write("exception: '%s'\n" % e)
entry.handler_unblock(_hid)
gtk.idle_add(move_cursor, entry)
entry.stop_emission("insert-text")

def main():
_window = gtk.Window()
_window.set_title("Entry box validation.")
_window.set_border_width(10)
_window.connect('destroy', lambda win: gtk.main_quit())

_hbox = gtk.HBox(gtk.FALSE, 10)
_window.add(_hbox)

_label = gtk.Label("Enter a number:")
_hbox.pack_start(_label, gtk.FALSE, gtk.FALSE, 0)

_entry = gtk.Entry()
_entry.connect("activate", entry_activate)
_entry.connect("focus_out_ev

[pygtk] TextView, set_tabs

2003-06-12 Thread Shaffer, Chris
I'm having a little trouble setting the tabs for a textview element (a
least, I'm assuming that set_tabs() will allow me to change the number of
spaces that consitute a 'tab' key press.  Please, tell me if I'm wrong).
Here is my code:

tabs = pango.TabArray(4,pango.PANGO_TAB_LEFT)
self.text.set_tabs(tabs)

I am including pango at the top of my file with:

import pango

When I try and run my app, I get this error:

Traceback (most recent call last):
  File "Edit/AppRun", line 26, in ?
EditWindow.EditWindow()
  File "Edit/EditWindow.py", line 102, in __init__
tabs = pango.TabArray(4,pango.PANGO_LEFT_TAB)
AttributeError: 'module' object has no attribute 'PANGO_LEFT_TAB'

Any ideas what I'm doing wrong?

Thanks,

Chris Shaffer



*
"The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential, proprietary, and/or
privileged material. Any review, retransmission, dissemination or other use
of, or taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you received
this in error, please contact the sender and delete the material from all
computers."
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Re: Annoying pygtk warning.

2003-06-12 Thread Stephen Kennedy

> > GLib-GObject-WARNING **: gobject.c:946: object class `GnomeProgram' has
> > no property named `default-icon'
> 
> What version are you using?
> Do you use your distributions version or have you compiled your own?

Using debian/unstable packages 1.99.6, gnome 2.2.1
I did report to bugzilla but often people on this list
have nice workarounds which are not in the docs/faq/etc.

Thanks,
Stephen.

-- 
Stephen Kennedy <[EMAIL PROTECTED]>
http://meld.sf.net visual diff and merge

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