Re: [pygtk] Dialogs demo

2002-01-17 Thread Skip Montanaro


>> Where are GtkDialogFlags defined? I can find them in gtk-types.defs,
>> but I don't know how to access them.

Matt> They are:
Matt> gtk.DIALOG_MODAL, gtk.DIALOG_DESTROY_WITH_PARENT, etc.

There are so many symbols in the gtk and gtk.gdk modules (> 1100 all told),
that I added a modified dir() function and a dirpat() function to my
PYTHONSTARTUP file:

from __builtin__ import dir as _dir
def dir(o=globals,showall=0):
if not showall and hasattr(o, "__all__"):
x = list(o.__all__)
x.sort()
return x
return _dir(o)

import re
def dirpat(o, pat):
"""like dir, but only return strings matching re pat"""
names = dir(o, showall=1)
return [x for x in names if re.search(pat, x) is not None]

It produces what I find to be useful output:

>>> dirpat(gtk, "(?i)dialog")
['ColorSelectionDialog', 'DIALOG_DESTROY_WITH_PARENT', 'DIALOG_MODAL',
'DIALOG_NO_SEPARATOR', 'Dialog', 'FontSelectionDialog',
'ICON_SIZE_DIALOG', 'InputDialog', 'MessageDialog',
'STOCK_DIALOG_ERROR', 'STOCK_DIALOG_INFO', 'STOCK_DIALOG_QUESTION',
'STOCK_DIALOG_WARNING'] 
>>> dirpat(gtk, "DIALOG")
['DIALOG_DESTROY_WITH_PARENT', 'DIALOG_MODAL', 'DIALOG_NO_SEPARATOR',
'ICON_SIZE_DIALOG', 'STOCK_DIALOG_ERROR', 'STOCK_DIALOG_INFO',
'STOCK_DIALOG_QUESTION', 'STOCK_DIALOG_WARNING'] 
>>> dirpat(gtk, "Dialog")
['ColorSelectionDialog', 'Dialog', 'FontSelectionDialog', 'InputDialog',
'MessageDialog'] 

YMMV...

-- 
Skip Montanaro ([EMAIL PROTECTED] - http://www.mojam.com/)
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] Weird VPaned behavior

2002-01-17 Thread Michael Gilfix

On Thu, Jan 17 @ 18:34, Pedro Rodriguez wrote:
> On Thursday 17 January 2002 17:17, Michael Gilfix wrote:
> Mike, I think you are just killing the algorithms for layout management 
> by mixing GtkTable and GtkHBox ;) Or maybe it will require refinement
> on the layout constraints.
> 
> I propose a simpler approch with GtkScrolledWindow :
> 
> < t = gtk.GtkHBox ()
> < table = gtk.GtkTable (2, 1)
> < t.add (table)
> < text = gtk.GtkText ()
> < text.set_usize (-1, 150)
> < table.attach (text, 0, 1, 0, 1)
> < scroll = gtk.GtkVScrollbar (text.get_vadjustment ())
> < table.attach (scroll, 1, 2, 0, 1, xoptions=gtk.FILL)
> ---
> > import GTK
> > t = gtk.GtkScrolledWindow()
> > t.set_policy(GTK.POLICY_AUTOMATIC, GTK.POLICY_AUTOMATIC)
> > text = gtk.GtkText()
> > t.add_with_viewport(text)

  Yeah, that does the trick. I realize now that back when I wrote the
code, I was basing it on an example demonstrating text scrolling,
which probably avoided the scroll window for the reasons outlined in
your patch. Fortunately, I don't really need to access the scroll bar.
You're a life saver Pedro :)

  -- Mike

-- 
Michael Gilfix
[EMAIL PROTECTED]



msg03459/pgp0.pgp
Description: PGP signature


Re: [pygtk] Weird VPaned behavior

2002-01-17 Thread Pedro Rodriguez

On Thursday 17 January 2002 17:17, Michael Gilfix wrote:
>   Ok, more exploration: the real problem seems to be the scroll
> bar that's contained in the upper window. The scroll bar does not
> seem to resize to a size smaller than the original of the text
> box. I've changed the program Pedro posted so that it demonstrates
> the problem. One alternative is to enclose the scrollbar in a VBox
> and then the pane grip does not disappear when the pane is shrunk
> below the original size but the scroll bar doesn't change size either
> and just looks funny. Am I supposed to fix this via signaling?
>
>-- Mike
>

Mike, I think you are just killing the algorithms for layout management 
by mixing GtkTable and GtkHBox ;) Or maybe it will require refinement
on the layout constraints.

I propose a simpler approch with GtkScrolledWindow :

< t = gtk.GtkHBox ()
< table = gtk.GtkTable (2, 1)
< t.add (table)
< text = gtk.GtkText ()
< text.set_usize (-1, 150)
< table.attach (text, 0, 1, 0, 1)
< scroll = gtk.GtkVScrollbar (text.get_vadjustment ())
< table.attach (scroll, 1, 2, 0, 1, xoptions=gtk.FILL)
---
> import GTK
> t = gtk.GtkScrolledWindow()
> t.set_policy(GTK.POLICY_AUTOMATIC, GTK.POLICY_AUTOMATIC)
> text = gtk.GtkText()
> t.add_with_viewport(text)

If you need to access the scrollbar you'll need to add this :
> scroll = t.vscrollbar

BUT, I noticed that there is a bug in GtkScrolledWindow on
accessing vscrollbar attribute, import the following path
file :


patch.py

# BUG in 0.6.8 : GtkScrollWindow : has_attrs -> has_key
import gtk
from gtk import _obj2inst
import _gtk
def patch(self, attr):
attrs = {
'hscrollbar': _gtk.gtk_scrolled_window_get_hscrollbar,
'vscrollbar': _gtk.gtk_scrolled_window_get_vscrollbar
}
if attrs.has_key(attr):
return _obj2inst(attrs[attr](self._o))
else:
return GtkBin.__getattr__(self, attr)

gtk.GtkScrolledWindow.__getattr__ = patch
del patch
# end bug


Regards,
-- 
Pedro
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] Weird VPaned behavior

2002-01-17 Thread Michael Gilfix

  Ok, more exploration: the real problem seems to be the scroll
bar that's contained in the upper window. The scroll bar does not
seem to resize to a size smaller than the original of the text
box. I've changed the program Pedro posted so that it demonstrates the
problem. One alternative is to enclose the scrollbar in a VBox and
then the pane grip does not disappear when the pane is shrunk below
the original size but the scroll bar doesn't change size either and
just looks funny. Am I supposed to fix this via signaling?

   -- Mike



#!/usr/bin/env python

import gtk

def quit(*args):
gtk.mainquit()

w = gtk.GtkWindow()
p = gtk.GtkVPaned()

t = gtk.GtkHBox ()
table = gtk.GtkTable (2, 1)
t.add (table)
text = gtk.GtkText ()
text.set_usize (-1, 150)
table.attach (text, 0, 1, 0, 1)
scroll = gtk.GtkVScrollbar (text.get_vadjustment ())
table.attach (scroll, 1, 2, 0, 1, xoptions=gtk.FILL)

b = gtk.GtkHBox()

b1 = gtk.GtkHBox()
t1 = gtk.GtkText()
b1.pack_start(t1)

b2 = gtk.GtkHBox()
t2 = gtk.GtkText()
b2.pack_start(t2)

b3 = gtk.GtkHBox()
t3 = gtk.GtkText()
b3.pack_start(t3)

b.pack_start(b1)
b.pack_start(b2)
b.pack_start(b3)

p.pack1(t, 0, 1)
p.pack2(b, 0, 1)

w.add(p)

w.connect("destroy_event", quit)
w.connect("delete_event", quit)

w.show_all()

gtk.mainloop()

===

-- 
Michael Gilfix
[EMAIL PROTECTED]



msg03457/pgp0.pgp
Description: PGP signature


[pygtk] Size groups demo

2002-01-17 Thread Michele Campeotto

  This one seems to be working well :o)

-- 
  -- Michele - www.moleskine.f2s.com

Never ascribe to malice, that which can be explained by incompetence.


#!/usr/bin/env python
"""Size Groups

GtkSizeGroup provides a mechanism for grouping a number of widgets together so
they all request the same amount of space. This is typically useful when you
want a column of widgets to have the same size, but you can't use a GtkTable
widget.

Note that size groups only affect the amount of space requested, not the size
that the widgets finally receive. If you want the widgets in a GtkSizeGroup to
actually be the same size, you need to pack them in such a way that they get
the size they request and not more. For example, if you are packing your
widgets into a table, you would not include the GTK_FILL flag."""

description = "Size Groups"

import gtk

def create_option_menu(options):
menu = gtk.Menu()
for str in options:
menu_item = gtk.MenuItem(str)
menu_item.show()
gtk.MenuShell.append(menu, menu_item)

option_menu = gtk.OptionMenu()
option_menu.set_menu(menu)

return option_menu

def add_row(table, row, size_group, label_text, options):
label = gtk.Label(label_text)
label.set_use_underline(gtk.TRUE)
label.set_alignment(0, 1)
table.attach(label, 0, 1, row, row + 1, gtk.EXPAND + gtk.FILL, 0, 0, 0)

option_menu = create_option_menu(options)
label.set_mnemonic_widget(option_menu)
size_group.add_widget(option_menu)
table.attach(option_menu, 1, 2, row, row + 1, 0, 0, 0, 0)

def toggle_grouping(check_button, size_group):
# gtk.SIZE_GROUP_NONE is not generally useful, but is useful
# here to show the effect of gtk.SIZE_GROUP_HORIZONTAL by
# contrast.
if check_button.get_active():
size_group.set_mode(gtk.SIZE_GROUP_HORIZONTAL)
else:
size_group.set_mode(gtk.SIZE_GROUP_NONE)

def main():
color_options = ["Red", "Green", "Blue"]
dash_options = ["Solid", "Dashed", "Dotted"]
end_options = ["Square", "Round", "Arrow"]

window = gtk.Dialog("GtkSizeGroups", None, 0,
(gtk.STOCK_CLOSE, gtk.RESPONSE_NONE))
window.set_resizable(gtk.FALSE)
window.connect('response', lambda w, d: window.destroy())
if __name__ == '__main__':
window.connect('destroy', lambda win: gtk.main_quit())

vbox = gtk.VBox(gtk.FALSE, 5)
window.vbox.pack_start(vbox, gtk.TRUE, gtk.TRUE, 0)
vbox.set_border_width(5)

size_group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)

# Create one frame holding color options

frame = gtk.Frame("Color options")
vbox.pack_start(frame, gtk.TRUE, gtk.TRUE, 0)

table = gtk.Table(2, 2, gtk.FALSE)
table.set_border_width(5)
table.set_row_spacings(5)
table.set_col_spacings(10)
frame.add(table)

add_row(table, 0, size_group, "_Foreground", color_options)
add_row(table, 1, size_group, "_Background", color_options)

# And another frame holding line style options

frame = gtk.Frame("Line options")
vbox.pack_start(frame, gtk.FALSE, gtk.FALSE, 0)

table = gtk.Table(2, 2, gtk.FALSE)
table.set_border_width(5)
table.set_row_spacings(5)
table.set_col_spacings(10)
frame.add(table)

add_row(table, 0, size_group, "_Dashing", dash_options)
add_row(table, 1, size_group, "_Line ends", end_options)

# And a check button to turn grouping on and off

check_button = gtk.CheckButton("_Enable grouping")
vbox.pack_start(check_button, gtk.FALSE, gtk.FALSE, 0)
check_button.set_active(gtk.TRUE)
check_button.connect('toggled', toggle_grouping, size_group)

window.show_all()

if __name__ == '__main__': gtk.main()

if __name__ == '__main__': main()



[pygtk] How to get the X window ID?

2002-01-17 Thread Markus Schaber

Hi,

Is there an easy way to get the X window ID from an pygtk window?

I need this for communication with an external program.

Thanks,
Markus
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] Weird VPaned before

2002-01-17 Thread Michael Gilfix

  Well, I don't seem to have the problems again with the simple test
program. I guess I'll play around with the code (yes, ftpcube) and
see if I can get the VPane to stop the weird behavior. It's just odd
that it would sort of work but still act funny. I guess they're just
finicky.

On Thu, Jan 17 @ 11:32, Pedro Rodriguez wrote:
> I have met several problems with Paned windows but all were related to
> properly setting up the layout (like restoring size when restarting the
> application). 
> 
> The closest in regard to your problem was related to my current 
> theme (/usr/share/themes/Raleigh/gtk/gtkrc from gtk-engines-0.11-3
> on RH 7.2). I will suggest you to first check if you have a Theme 
> set up (in ~/.gtkrc) and if this is the case, comment it before 
> launching the application (ftpcube I presume ;).
> 
> Otherwise, try the following snip to see if the problem can be 
> reproduced.
> 
> # 
> import gtk
> 
> def quit(*args):
> gtk.mainquit()
> 
> w = gtk.GtkWindow()
> p = gtk.GtkVPaned()
> 
> t = gtk.GtkText()
> 
> b = gtk.GtkHBox()
> 
> b1 = gtk.GtkHBox()
> t1 = gtk.GtkText()
> b1.pack_start(t1)
> 
> b2 = gtk.GtkHBox()
> t2 = gtk.GtkText()
> b2.pack_start(t2)
> 
> b3 = gtk.GtkHBox()
> t3 = gtk.GtkText()
> b3.pack_start(t3)
> 
> b.pack_start(b1)
> b.pack_start(b2)
> b.pack_start(b3)
> 
> p.pack1(t, 0, 1)
> p.pack2(b, 0, 1)
> 
> w.add(p)
> 
> w.connect("destroy_event", quit)
> w.connect("delete_event", quit)
> 
> w.show_all()
> 
> gtk.mainloop()
> # 
> 
> Regards,
> -- 
> Pedro
`-> (pedro_rodriguez)

-- 
Michael Gilfix
[EMAIL PROTECTED]



msg03454/pgp0.pgp
Description: PGP signature


[pygtk] Panes demo

2002-01-17 Thread Michele Campeotto

  This is what I've come up with as a (H|V)Paned demo, but I can't
access the child[12]_(resize|shrink) property...
  Tried with paned.child1_resize, paned.children()[0].resize,
paned.children()[0].everything... now I'm lost :o(


  P.S. Now I'm using CVS PyGtk...

-- 
  -- Michele - www.moleskine.f2s.com

Those who do not understand Unix are condemned to reinvent it, poorly.
-- Henry Spencer


#!/usr/bin/env python
"""Paned Widgets

The GtkHPaned and GtkVPaned Widgets divide their content area into two panes
with a divider in between that the user can adjust. A separate child is placed
into each pane.
There are a number of options that can be set for each pane. This test contains
both a horizontal (HPaned) and a vertical (VPaned) widget, and allows you to
adjust the options for each side of each widget."""

description = "Paned Widgets"

import gtk

def toggle_resize(w, child):
paned = child.parent

child.ref() # Is this needed in PyGtk too?

if child == paned.children()[0]:
paned.remove(child)
paned.pack1(child, w.get_active(), 0)
else:
paned.remove(child)
paned.pack2(child, w.get_active(), 0)

child.unref()   # Is this needed in PyGtk too?

def toggle_shrink(w, child):
paned = child.parent

child.ref() # Is this needed in PyGtk too?

if child == paned.children()[0]:
paned.remove(child)
paned.pack1(child, 0, w.get_active())
else:
paned.remove(child)
paned.pack2(child, 0, w.get_active())

child.unref()   # Is this needed in PyGtk too?

def create_pane_options(paned, frame_label, label1, label2):
frame = gtk.Frame(frame_label)
frame.set_border_width(4)

table = gtk.Table(3, 2, gtk.TRUE)
frame.add(table)

label = gtk.Label(label1)
table.attach_defaults(label, 0, 1, 0, 1)

check_button = gtk.CheckButton("_Resize")
check_button.connect('toggled', toggle_resize, paned.children()[0])
table.attach_defaults(check_button, 0, 1, 1, 2)

check_button = gtk.CheckButton("_Shrink")
check_button.set_active(gtk.TRUE)
check_button.connect('toggled', toggle_shrink, paned.children()[0])
table.attach_defaults(check_button, 0, 1, 2, 3)

label = gtk.Label(label2)
table.attach_defaults(label, 1, 2, 0, 1)

check_button = gtk.CheckButton("_Resize")
check_button.set_active(gtk.TRUE)
check_button.connect('toggled', toggle_resize, paned.children()[1])
table.attach_defaults(check_button, 1, 2, 1, 2)

check_button = gtk.CheckButton("_Shrink")
check_button.set_active(gtk.TRUE)
check_button.connect('toggled', toggle_shrink, paned.children()[1])
table.attach_defaults(check_button, 1, 2, 2, 3)

return frame

def main():
window = gtk.Window()
window.set_title("Paned Widgets")
window.set_border_width(0)
if __name__ == '__main__':
window.connect('destroy', lambda win: gtk.main_quit())

vbox = gtk.VBox(gtk.FALSE, 0)
window.add(vbox)

vpaned = gtk.VPaned()
vbox.pack_start(vpaned, gtk.TRUE, gtk.TRUE)
vpaned.set_border_width(5)

hpaned = gtk.HPaned()
vpaned.add1(hpaned)

frame = gtk.Frame()
frame.set_shadow_type(gtk.SHADOW_IN)
frame.set_size_request(60, 60)
hpaned.add1(frame)

button = gtk.Button("_Hi there")
frame.add(button)

frame = gtk.Frame()
frame.set_shadow_type(gtk.SHADOW_IN)
frame.set_size_request(80, 60)
hpaned.add2(frame)

frame = gtk.Frame()
frame.set_shadow_type(gtk.SHADOW_IN)
frame.set_size_request(60, 80)
vpaned.add2(frame)

# Now create toggle buttons to control sizing

vbox.pack_start(create_pane_options(hpaned, "Horizontal", "Left", "Right"),
gtk.FALSE, gtk.FALSE, 0)

vbox.pack_start(create_pane_options(vpaned, "Vertical", "Top", "Bottom"),
gtk.FALSE, gtk.FALSE, 0)

window.show_all()

if __name__ == '__main__': gtk.main()

if __name__ == '__main__': main()



Re: [pygtk] Weird VPaned before

2002-01-17 Thread Pedro Rodriguez

On Wednesday 16 January 2002 22:57, Michael Gilfix wrote:
>   I'm getting what seems to be some weird behavior with the VPaned
> control widget in pygtk 0.6.8. I'm dividing the screen vertically
> between a text box and a window of multiple boxes. Er, the layout
> is something like this:
>
>  Text Window
>  -
>   Box 1, Box 2, Box 3
>
>   The grip appears and all is well when I resize the text window by
> increasing its size. I can even decrease the size back to its
> original amount and all is well. But if I decrease the size of the
> text window below its original amount, the grip disappears.  Can
> anyone else confirm similar behavior or perhaps point me to something
> I might be doing wrong?
>
>   Regards,
>
>  -- Mike

I have met several problems with Paned windows but all were related to
properly setting up the layout (like restoring size when restarting the
application). 

The closest in regard to your problem was related to my current 
theme (/usr/share/themes/Raleigh/gtk/gtkrc from gtk-engines-0.11-3
on RH 7.2). I will suggest you to first check if you have a Theme 
set up (in ~/.gtkrc) and if this is the case, comment it before 
launching the application (ftpcube I presume ;).

Otherwise, try the following snip to see if the problem can be 
reproduced.

# 
import gtk

def quit(*args):
gtk.mainquit()

w = gtk.GtkWindow()
p = gtk.GtkVPaned()

t = gtk.GtkText()

b = gtk.GtkHBox()

b1 = gtk.GtkHBox()
t1 = gtk.GtkText()
b1.pack_start(t1)

b2 = gtk.GtkHBox()
t2 = gtk.GtkText()
b2.pack_start(t2)

b3 = gtk.GtkHBox()
t3 = gtk.GtkText()
b3.pack_start(t3)

b.pack_start(b1)
b.pack_start(b2)
b.pack_start(b3)

p.pack1(t, 0, 1)
p.pack2(b, 0, 1)

w.add(p)

w.connect("destroy_event", quit)
w.connect("delete_event", quit)

w.show_all()

gtk.mainloop()
# 

Regards,
-- 
Pedro
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk