2 from rox
import g
, TRUE
, FALSE
7 class Examples(g
.ScrolledWindow
):
8 def __init__(self
, hints
):
9 g
.ScrolledWindow
.__init
__(self
)
10 self
.set_shadow_type(g
.SHADOW_IN
)
11 self
.set_policy(g
.POLICY_NEVER
, g
.POLICY_AUTOMATIC
)
12 self
.set_border_width(4)
14 model
= g
.ListStore(str, str)
15 view
= g
.TreeView(model
)
19 cell
= g
.CellRendererText()
20 column
= g
.TreeViewColumn('Example pattern', cell
, text
= 0)
21 view
.append_column(column
)
22 column
= g
.TreeViewColumn('Meaning', cell
, text
= 1)
23 view
.append_column(column
)
27 model
.set(new
, 0, c
, 1, m
)
29 self
.set_size_request(-1, 150)
31 view
.get_selection().set_mode(g
.SELECTION_NONE
)
34 # A window which allows the user to enter a string.
35 # When this is done, callback(string) or callback(strings) is called.
36 # args is a list like ('Replace:', 'With:')
37 # If 'destroy_return' is true then closing the window does callback(None).
39 class GetArg(rox
.Dialog
):
40 def __init__(self
, text
, callback
, args
, message
= None,
41 destroy_return
= 0, init
= None, hints
= None):
42 rox
.Dialog
.__init
__(self
)
43 self
.set_has_separator(False)
44 self
.set_position(g
.WIN_POS_MOUSE
)
49 self
.callback
= callback
55 self
.vbox
.pack_start(g
.Label(message
), not hints
, True, 0)
57 self
.vbox
.pack_end(Examples(hints
), True, True, 0)
62 hbox
= g
.HBox(FALSE
, 4)
63 hbox
.pack_start(g
.Label(a
), FALSE
, TRUE
, 0)
65 hbox
.pack_start(arg
, TRUE
, TRUE
, 0)
66 self
.vbox
.pack_start(hbox
, FALSE
, TRUE
, 0)
70 if history
.has_key(a
):
71 arg
.set_text(history
[a
])
74 arg
.select_region(0, -1)
75 self
.args
.append((a
, arg
))
76 if len(self
.args
) < len(args
):
77 arg
.connect('activate', self
.to_next
)
79 arg
.connect('activate', lambda w
: self
.do_it())
81 actions
= g
.HBox(TRUE
, 32)
82 self
.vbox
.pack_end(actions
, FALSE
, TRUE
, 0)
84 self
.add_button(g
.STOCK_CANCEL
, g
.RESPONSE_CANCEL
)
85 self
.add_button(g
.STOCK_OK
, g
.RESPONSE_OK
)
87 def resp(widget
, resp
):
88 if resp
== g
.RESPONSE_OK
:
91 self
.connect('response', resp
)
94 self
.connect('destroy', lambda widget
, cb
= callback
: cb(None))
98 def to_next(self
, widget
):
100 for (a
, entry
) in self
.args
:
103 entry
.select_region(0, -1)
110 for (a
, entry
) in self
.args
:
111 val
= entry
.get_text()
115 self
.callback(values
)
117 self
.callback(values
[0])