I have converted from C version on seciotn 8.5 in "GTK v 1.2 Tutorial" to
PyGTK version. But it seems that it doesn't emit the "changed" signal
to reconfigure all the widgets that are attached to the adjustment. Can
you tell me what problems my program has?
Thanks.
--
- Deok Hwan Kim
[EMAIL PROTECTED]
#!/usr/bin/env python
from gtk import *
hscale = None
vscale = None
def cb_pos_menu_select(item, pos):
hscale.set_value_pos(pos)
vscale.set_value_pos(pos)
def cb_update_menu_select(item, policy):
hscale.set_update_policy(policy)
vscale.set_update_policy(policy)
def cb_digits_scale(adj):
hscale.set_digits(adj.value)
vscale.set_digits(adj.value)
def cb_page_size(get, set):
set.page_size = get.value
set.page_incr = get.value
set.changed()
def cb_draw_value(button):
hscale.set_draw_value(button.active)
vscale.set_draw_value(button.active)
def make_menu_item(name, callback, data):
item = GtkMenuItem(name)
item.connect("activate", callback, data)
item.show()
return item
def scale_set_default_values(scale):
scale.set_update_policy(UPDATE_CONTINUOUS)
scale.set_digits(1)
scale.set_value_pos(POS_TOP)
scale.set_draw_value(TRUE)
def create_range_controls():
global vscale, hscale
window = GtkWindow(WINDOW_TOPLEVEL)
window.connect("destroy", mainquit)
window.set_title("range controls")
box1 = GtkVBox(homogeneous = FALSE, spacing = 0)
window.add(box1)
box1.show()
box2 = GtkHBox(homogeneous = FALSE, spacing = 10)
box2.set_border_width(10)
box1.pack_start(box2, expand = TRUE, fill = TRUE, padding = 0)
box2.show()
adj1 = GtkAdjustment(value = 0.0, lower = 0.0, upper = 101.0,
step_incr = 0.1, page_incr = 1.0, page_size = 1.0)
vscale = GtkVScale(adj1)
scale_set_default_values(vscale)
box2.pack_start(vscale, expand = TRUE, fill = TRUE, padding = 0)
vscale.show()
box3 = GtkVBox(homogeneous = FALSE, spacing = 10)
box2.pack_start(box3, expand = TRUE, fill = TRUE, padding = 0)
box3.show()
hscale = GtkHScale(adj1)
hscale.set_usize(200, 30)
scale_set_default_values(hscale)
box3.pack_start(hscale, expand = TRUE, fill = TRUE, padding = 0)
hscale.show()
scrollbar = GtkHScrollbar(adj1)
scrollbar.set_update_policy(UPDATE_CONTINUOUS)
box3.pack_start(scrollbar, expand = TRUE, fill = TRUE, padding = 0)
scrollbar.show()
box2 = GtkHBox(homogeneous = FALSE, spacing = 10)
box2.set_border_width(10)
box1.pack_start(box2, expand = TRUE, fill = TRUE, padding = 0)
box2.show()
button = GtkCheckButton("Display value on scale widgets")
button.set_active(TRUE)
button.connect("toggled", cb_draw_value)
box2.pack_start(button, expand = TRUE, fill = TRUE, padding = 0)
button.show()
box2 = GtkHBox(homogeneous = FALSE, spacing = 10)
box2.set_border_width(10)
label = GtkLabel("Scale Value Position:")
box2.pack_start(label, expand = FALSE, fill = FALSE, padding = 0)
label.show()
opt = GtkOptionMenu()
menu = GtkMenu()
item = make_menu_item("Top", cb_pos_menu_select, POS_TOP)
menu.append(item)
item = make_menu_item("Bottom", cb_pos_menu_select, POS_BOTTOM)
menu.append(item)
item = make_menu_item("Left", cb_pos_menu_select, POS_LEFT)
menu.append(item)
item = make_menu_item("Right", cb_pos_menu_select, POS_RIGHT)
menu.append(item)
opt.set_menu(menu)
box2.pack_start(opt, expand = TRUE, fill = TRUE, padding = 0)
opt.show()
box1.pack_start(box2, expand = TRUE, fill = TRUE, padding = 0)
box2.show()
box2 = GtkHBox(homogeneous = FALSE, spacing = 10)
box2.set_border_width(10)
label = GtkLabel("Scale Update Policy:")
box2.pack_start(label, expand = FALSE, fill = FALSE, padding = 0)
label.show()
opt = GtkOptionMenu()
menu = GtkMenu()
item = make_menu_item("Continuous", cb_update_menu_select,
UPDATE_CONTINUOUS)
menu.append(item)
item = make_menu_item("Discontinuous", cb_update_menu_select,
UPDATE_DISCONTINUOUS)
menu.append(item)
item = make_menu_item("Delayed", cb_update_menu_select,
UPDATE_DELAYED)
menu.append(item)
opt.set_menu(menu)
box2.pack_start(opt, expand = TRUE, fill = TRUE, padding = 0)
opt.show()
box1.pack_start(box2, expand = TRUE, fill = TRUE, padding = 0)
box2.show()
box2 = GtkHBox(homogeneous = FALSE, spacing = 10)
box2.set_border_width(10)
label = GtkLabel("Scale Digits:");
box2.pack_start(label, expand = FALSE, fill = FALSE, padding = 0)
label.show()
adj2 = GtkAdjustment(value = 1.0, lower = 0.0, upper = 5.0,
step_incr = 1.0, page_incr = 1.0, page_size = 0.0)
adj2.connect("value_changed", cb_digits_scale)
scale = GtkHScale(adj2)
scale.set_digits(0)
box2.pack_start(scale, expand = TRUE, fill = TRUE, padding = 0)
scale.show()
box1.pack_start(box2, expand = TRUE, fill = TRUE, padding = 0)
box2.show()
box2 = GtkHBox(homogeneous = FALSE, spacing = 10)
box2.set_border_width(10)
label = GtkLabel("Scrollbar Page Size:")
box2.pack_start(label, expand = FALSE, fill = FALSE, padding = 0)
label.show()
adj2 = GtkAdjustment(value = 1.0, lower = 1.0, upper = 101.0,
step_incr = 1.0, page_incr = 1.0, page_size = 0.0)
adj2.connect("value_changed", cb_page_size, adj1)
scale = GtkHScale(adj2)
scale.set_digits(0)
box2.pack_start(scale, expand = TRUE, fill = TRUE, padding = 0)
scale.show()
box1.pack_start(box2, expand = TRUE, fill = TRUE, padding = 0)
box2.show()
separator = GtkHSeparator()
box1.pack_start(separator, expand = FALSE, fill = TRUE, padding = 0)
separator.show()
box2 = GtkVBox(homogeneous = FALSE, spacing = 10)
box2.set_border_width(10)
box1.pack_start(box2, expand = FALSE, fill = TRUE, padding = 0)
box2.show()
button = GtkButton("Quit")
button.connect("clicked", mainquit)
box2.pack_start(button, expand = TRUE, fill = TRUE, padding = 0)
button.set_flags(CAN_DEFAULT)
button.grab_default()
button.show()
window.show()
def main():
create_range_controls()
mainloop()
if __name__ == '__main__':
main()