Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.4rc2, 0.4rc3, and 0.4rc4

hggtk: add home grown MessageDialog class

to workaround a bug in gtk.MessageDialog which refuses to stay on
above parent windows.

SF bug #1939911: Modal Dialogs aren't staying on top on application

Changeset f01671e11984

Parent 6905d6f0f6d9

by TK Soh

Changes to 3 files · Browse files at f01671e11984 Showing diff from parent 6905d6f0f6d9 Diff from another changeset...

Change 1 of 2 Show Entire File hggtk/​dialog.py Stacked
 
22
23
24
 
25
26
27
 
35
36
37
38
 
39
40
41
 
22
23
24
25
26
27
28
 
36
37
38
 
39
40
41
42
@@ -22,6 +22,7 @@
   import gtk  import gtk.glade +from gtklib import MessageDialog      def about(): @@ -35,7 +36,7 @@
    :param message: the message you want to display.   """ - dialog = gtk.MessageDialog(flags=gtk.DIALOG_MODAL, type=type, + dialog = MessageDialog(flags=gtk.DIALOG_MODAL, type=type,   buttons=buttons)   dialog.set_title(title)   dialog.set_markup('<big><b>' + primary + '</b></big>')
Change 1 of 1 Show Entire File hggtk/​gdialog.py Stacked
 
29
30
31
 
32
33
 
 
34
35
 
36
37
38
39
40
41
42
 
43
44
45
46
47
48
49
50
51
52
 
53
54
55
 
29
30
31
32
33
 
34
35
36
 
37
38
39
40
41
42
43
 
44
45
46
47
48
 
49
50
51
52
 
53
54
55
56
@@ -29,27 +29,28 @@
 from hgext import extdiff  from shlib import shell_notify, set_tortoise_icon, Settings  from thgconfig import ConfigDialog +from gtklib import MessageDialog   -class SimpleMessage(gtk.MessageDialog): + +class SimpleMessage(MessageDialog):   def run(self): - response = gtk.MessageDialog.run(self) + response = MessageDialog.run(self)   self.destroy()   return response      class Prompt(SimpleMessage):   def __init__(self, title, message, parent): - gtk.MessageDialog.__init__(self, parent, gtk.DIALOG_MODAL, + SimpleMessage.__init__(self, parent, gtk.DIALOG_MODAL,   gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE)   self.set_title(title)   self.set_markup('<b>' + message + '</b>')   -  class Confirm(SimpleMessage):   """Dialog returns gtk.RESPONSE_YES or gtk.RESPONSE_NO   """   def __init__(self, title, files, parent, primary=None): - gtk.MessageDialog.__init__(self, parent, gtk.DIALOG_MODAL, + SimpleMessage.__init__(self, parent, gtk.DIALOG_MODAL,   gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO)   self.set_title('Confirm ' + title)   if primary is None:
Change 1 of 1 Show Entire File hggtk/​gtklib.py Stacked
 
53
54
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
@@ -53,3 +53,66 @@
  def set_pulse_step(self, val):   self.pbar.set_pulse_step(val)   +class MessageDialog(gtk.Dialog): + button_map = { + gtk.BUTTONS_NONE: None, + gtk.BUTTONS_OK: (gtk.STOCK_OK, gtk.RESPONSE_OK), + gtk.BUTTONS_CLOSE : (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE), + gtk.BUTTONS_CANCEL: (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL), + gtk.BUTTONS_YES_NO : (gtk.STOCK_YES, gtk.RESPONSE_YES, + gtk.STOCK_NO, gtk.RESPONSE_NO), + gtk.BUTTONS_OK_CANCEL: (gtk.STOCK_OK, gtk.RESPONSE_OK, + gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL), + } + image_map = { + gtk.MESSAGE_INFO : gtk.STOCK_DIALOG_INFO, + gtk.MESSAGE_WARNING : gtk.STOCK_DIALOG_WARNING, + gtk.MESSAGE_QUESTION : gtk.STOCK_DIALOG_QUESTION, + gtk.MESSAGE_ERROR : gtk.STOCK_DIALOG_ERROR, + } + + def __init__(self, parent=None, flags=0, type=gtk.MESSAGE_INFO, + buttons=gtk.BUTTONS_NONE, message_format=None): + gtk.Dialog.__init__(self, + parent=parent, + flags=flags | gtk.DIALOG_NO_SEPARATOR, + buttons=MessageDialog.button_map[buttons]) + self.set_resizable(False) + + hbox = gtk.HBox() + self._image_frame = gtk.Frame() + self._image_frame.set_shadow_type(gtk.SHADOW_NONE) + self._image = gtk.Image() + imageid = MessageDialog.image_map[type] + self._image.set_from_stock(imageid, gtk.ICON_SIZE_DIALOG) + self._image_frame.add(self._image) + hbox.pack_start(self._image_frame, padding=5) + + lblbox = gtk.VBox(spacing=10) + self._primary = gtk.Label("") + self._primary.set_alignment(0.0, 0.5) + self._primary.set_line_wrap(True) + lblbox.pack_start(self._primary) + + self._secondary = gtk.Label() + lblbox.pack_end(self._secondary) + self._secondary.set_line_wrap(True) + hbox.pack_start(lblbox, padding=5) + + self.vbox.pack_start(hbox, False, False, 10) + self.show_all() + + def set_markup(self, s): + self._primary.set_markup(s) + + def format_secondary_markup(self, message_format): + self._secondary.set_markup(message_format) + + def format_secondary_text(self, message_format): + self._secondary.set_text(message_format) + + def set_image(self, image): + self._image_frame.remove(self._image) + self._image = image + self._image_frame.add(self._image) + self._image.show()