2 from rox
import g
, TRUE
, FALSE
7 # A window which allows the user to enter a string.
8 # When this is done, callback(string) or callback(strings) is called.
9 # args is a list like ('Replace:', 'With:')
10 # If 'destroy_return' is true then closing the window does callback(None).
12 class GetArg(g
.Dialog
):
13 def __init__(self
, text
, callback
, args
, message
= None,
14 destroy_return
= 0, init
= None):
15 g
.Dialog
.__init
__(self
)
20 self
.callback
= callback
26 self
.vbox
.pack_start(g
.Label(message
), TRUE
, TRUE
, 0)
31 hbox
= g
.HBox(FALSE
, 4)
32 hbox
.pack_start(g
.Label(a
), FALSE
, TRUE
, 0)
34 hbox
.pack_start(arg
, TRUE
, TRUE
, 0)
35 self
.vbox
.pack_start(hbox
, FALSE
, TRUE
, 0)
39 if history
.has_key(a
):
40 arg
.set_text(history
[a
])
43 arg
.select_region(0, -1)
44 self
.args
.append((a
, arg
))
45 if len(self
.args
) < len(args
):
46 arg
.connect('activate', self
.to_next
)
48 arg
.connect('activate', lambda w
: self
.do_it())
50 actions
= g
.HBox(TRUE
, 32)
51 self
.vbox
.pack_end(actions
, FALSE
, TRUE
, 0)
53 self
.add_button(g
.STOCK_CANCEL
, g
.RESPONSE_CANCEL
)
54 self
.add_button(g
.STOCK_OK
, g
.RESPONSE_OK
)
56 def resp(widget
, resp
):
57 if resp
== g
.RESPONSE_OK
:
60 self
.connect('response', resp
)
63 self
.connect('destroy', lambda widget
, cb
= callback
: cb(None))
67 def to_next(self
, widget
):
69 for (a
, entry
) in self
.args
:
72 entry
.select_region(0, -1)
79 for (a
, entry
) in self
.args
:
80 val
= entry
.get_text()
86 self
.callback(values
[0])