Removed all the MD5 suck checking stuff.
[dom-editor.git] / Dome / GetArg.py
blob2ce8463cf461524b16bea401d0a51f33712cd0dd
1 import rox
2 from rox import g, TRUE, FALSE
4 # text -> last value
5 history = {}
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)
17 if init:
18 init = init[:]
20 self.callback = callback
21 self.text = text
23 self.set_title(text)
25 if message:
26 self.vbox.pack_start(g.Label(message), TRUE, TRUE, 0)
28 self.args = []
30 for a in args:
31 hbox = g.HBox(FALSE, 4)
32 hbox.pack_start(g.Label(a), FALSE, TRUE, 0)
33 arg = g.Entry()
34 hbox.pack_start(arg, TRUE, TRUE, 0)
35 self.vbox.pack_start(hbox, FALSE, TRUE, 0)
36 if init and init[0]:
37 arg.set_text(init[0])
38 del init[0]
39 if history.has_key(a):
40 arg.set_text(history[a])
41 if not self.args:
42 arg.grab_focus()
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)
47 else:
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:
58 self.do_it()
59 widget.destroy()
60 self.connect('response', resp)
62 if destroy_return:
63 self.connect('destroy', lambda widget, cb = callback: cb(None))
65 self.show_all()
67 def to_next(self, widget):
68 next = 0
69 for (a, entry) in self.args:
70 if next:
71 entry.grab_focus()
72 entry.select_region(0, -1)
73 return
74 if entry == widget:
75 next = 1
77 def do_it(self):
78 values = []
79 for (a, entry) in self.args:
80 val = entry.get_text()
81 values.append(val)
82 history[a] = val
83 if len(values) > 1:
84 self.callback(values)
85 else:
86 self.callback(values[0])
87 self.destroy()
88 return 1