Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

gdialog: create CustomPrompt() dialog

This is designed to be hooked up to the new ui.prompt() in Mercurial,
and also for use internally when you need custom buttons in a dialog.

refs #187

Changeset 4181cd5c0c85

Parent c4fd92fe3e04

by Steve Borho

Changes to one file · Browse files at 4181cd5c0c85 Showing diff from parent c4fd92fe3e04 Diff from another changeset...

Change 1 of 1 Show Entire File hggtk/​gdialog.py Stacked
 
46
47
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
50
51
 
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@@ -46,6 +46,28 @@
  buttons[0].add_accelerator("clicked", accel_group, key,   modifier, gtk.ACCEL_VISIBLE)   +class CustomPrompt(SimpleMessage): + ''' Custom prompt dialog. Provide a list of choices with ampersands + to delineate response given for each choice (and keyboard + accelerator). Default must be one of the choice responses. + ''' + # ret = CustomPrompt('Title', 'Message', self, ('&Yes', 'N&o'), 'o').run() + # ret will be (gtk.RESPONSE_DELETE_EVENT, ord('y'), or ord('o')) + def __init__(self, title, message, parent, choices, default=None): + SimpleMessage.__init__(self, parent, gtk.DIALOG_MODAL, + gtk.MESSAGE_QUESTION, gtk.BUTTONS_NONE) + self.set_title(hglib.toutf(title)) + self.set_markup('<b>' + hglib.toutf(message) + '</b>') + accel_group = gtk.AccelGroup() + self.add_accel_group(accel_group) + for s in choices: + char = s[s.index('&')+1].lower() + button = self.add_button(s.replace('&', '_'), ord(char)) + button.add_accelerator('clicked', accel_group, ord(char), 0, + gtk.ACCEL_VISIBLE) + if default: + self.set_default_response(ord(default)) +  class Confirm(SimpleMessage):   """Dialog returns gtk.RESPONSE_YES or gtk.RESPONSE_NO   """