Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
c35ba59a
by Philipp Hörist at 2019-11-30T11:37:10Z
2 changed files:
Changes:
| ... | ... | @@ -67,6 +67,7 @@ class Assistant(Gtk.ApplicationWindow, EventHelper): |
| 67 | 67 |
page_name = self._ui.stack.get_visible_child_name()
|
| 68 | 68 |
buttons = self._button_visible_func(self, page_name)
|
| 69 | 69 |
self._set_buttons_visible(buttons)
|
| 70 |
+ self.update_page_complete()
|
|
| 70 | 71 |
self.emit('page-changed', page_name)
|
| 71 | 72 |
Gtk.ApplicationWindow.show_all(self)
|
| 72 | 73 |
|
| ... | ... | @@ -74,20 +75,30 @@ class Assistant(Gtk.ApplicationWindow, EventHelper): |
| 74 | 75 |
if event.keyval == Gdk.KEY_Escape:
|
| 75 | 76 |
self.destroy()
|
| 76 | 77 |
|
| 78 |
+ def update_page_complete(self):
|
|
| 79 |
+ page_widget = self._ui.stack.get_visible_child()
|
|
| 80 |
+ for button, complete in self._buttons.values():
|
|
| 81 |
+ if complete:
|
|
| 82 |
+ button.set_sensitive(page_widget.complete)
|
|
| 83 |
+ |
|
| 84 |
+ def update_title(self):
|
|
| 85 |
+ self.set_title(self._ui.stack.get_visible_child().title)
|
|
| 86 |
+ |
|
| 77 | 87 |
def set_button_visible_func(self, func):
|
| 78 | 88 |
self._button_visible_func = func
|
| 79 | 89 |
|
| 80 | 90 |
def set_default_button(self, button_name):
|
| 81 |
- self._buttons[button_name].grab_default()
|
|
| 91 |
+ button, _ = self._buttons[button_name]
|
|
| 92 |
+ button.grab_default()
|
|
| 82 | 93 |
|
| 83 |
- def add_button(self, name, label, css_class=None):
|
|
| 94 |
+ def add_button(self, name, label, css_class=None, complete=False):
|
|
| 84 | 95 |
button = Gtk.Button(label=label,
|
| 85 | 96 |
can_default=True,
|
| 86 | 97 |
no_show_all=True)
|
| 87 | 98 |
button.connect('clicked', self.__on_button_clicked)
|
| 88 | 99 |
if css_class is not None:
|
| 89 | 100 |
button.get_style_context().add_class(css_class)
|
| 90 |
- self._buttons[name] = button
|
|
| 101 |
+ self._buttons[name] = (button, complete)
|
|
| 91 | 102 |
self._ui.action_area.pack_end(button, False, False, 0)
|
| 92 | 103 |
|
| 93 | 104 |
def add_pages(self, pages):
|
| ... | ... | @@ -121,21 +132,24 @@ class Assistant(Gtk.ApplicationWindow, EventHelper): |
| 121 | 132 |
return self._pages[name]
|
| 122 | 133 |
|
| 123 | 134 |
def _set_buttons_visible(self, buttons):
|
| 124 |
- for button in self._buttons.values():
|
|
| 135 |
+ for button, _ in self._buttons.values():
|
|
| 125 | 136 |
button.hide()
|
| 126 | 137 |
|
| 127 | 138 |
if buttons is None:
|
| 128 | 139 |
return
|
| 129 | 140 |
|
| 130 | 141 |
for button_name in buttons:
|
| 131 |
- self._buttons[button_name].show()
|
|
| 142 |
+ button, _ = self._buttons[button_name]
|
|
| 143 |
+ button.show()
|
|
| 132 | 144 |
|
| 133 | 145 |
def _on_visible_child_name(self, stack, _param):
|
| 134 |
- self.set_title(stack.get_visible_child().title)
|
|
| 146 |
+ self.update_title()
|
|
| 147 |
+ self.update_page_complete()
|
|
| 135 | 148 |
self.emit('page-changed', stack.get_visible_child_name())
|
| 136 | 149 |
|
| 137 | 150 |
def __on_button_clicked(self, button):
|
| 138 |
- for button_name, button_ in self._buttons.items():
|
|
| 151 |
+ for button_name, button_data in self._buttons.items():
|
|
| 152 |
+ button_ = button_data[0]
|
|
| 139 | 153 |
if button_ == button:
|
| 140 | 154 |
self.emit('button-clicked', button_name)
|
| 141 | 155 |
return
|
| ... | ... | @@ -146,12 +160,18 @@ class Assistant(Gtk.ApplicationWindow, EventHelper): |
| 146 | 160 |
|
| 147 | 161 |
|
| 148 | 162 |
class Page(Gtk.Box):
|
| 149 |
- def __init__(self, icon_name, icon_css_class):
|
|
| 150 |
- super().__init__(orientation=Gtk.Orientation.VERTICAL)
|
|
| 163 |
+ def __init__(self):
|
|
| 164 |
+ Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
|
|
| 151 | 165 |
self.set_spacing(18)
|
| 152 | 166 |
self.set_valign(Gtk.Align.CENTER)
|
| 153 | 167 |
|
| 154 | 168 |
self.title = ''
|
| 169 |
+ self.complete = True
|
|
| 170 |
+ |
|
| 171 |
+ |
|
| 172 |
+class DefaultPage(Page):
|
|
| 173 |
+ def __init__(self, icon_name, icon_css_class):
|
|
| 174 |
+ Page.__init__(self)
|
|
| 155 | 175 |
|
| 156 | 176 |
self._heading = Gtk.Label()
|
| 157 | 177 |
self._heading.get_style_context().add_class('large-header')
|
| ... | ... | @@ -184,27 +204,23 @@ class Page(Gtk.Box): |
| 184 | 204 |
self.title = title
|
| 185 | 205 |
|
| 186 | 206 |
|
| 187 |
-class ErrorPage(Page):
|
|
| 207 |
+class ErrorPage(DefaultPage):
|
|
| 188 | 208 |
def __init__(self):
|
| 189 |
- Page.__init__(self,
|
|
| 190 |
- icon_name='dialog-error-symbolic',
|
|
| 191 |
- icon_css_class='error-color')
|
|
| 209 |
+ DefaultPage.__init__(self,
|
|
| 210 |
+ icon_name='dialog-error-symbolic',
|
|
| 211 |
+ icon_css_class='error-color')
|
|
| 192 | 212 |
|
| 193 | 213 |
|
| 194 |
-class SuccessPage(Page):
|
|
| 214 |
+class SuccessPage(DefaultPage):
|
|
| 195 | 215 |
def __init__(self):
|
| 196 |
- Page.__init__(self,
|
|
| 197 |
- icon_name='object-select-symbolic',
|
|
| 198 |
- icon_css_class='success-color')
|
|
| 216 |
+ DefaultPage.__init__(self,
|
|
| 217 |
+ icon_name='object-select-symbolic',
|
|
| 218 |
+ icon_css_class='success-color')
|
|
| 199 | 219 |
|
| 200 | 220 |
|
| 201 |
-class ProgressPage(Gtk.Box):
|
|
| 221 |
+class ProgressPage(Page):
|
|
| 202 | 222 |
def __init__(self):
|
| 203 |
- super().__init__(orientation=Gtk.Orientation.VERTICAL)
|
|
| 204 |
- self.set_spacing(18)
|
|
| 205 |
- self.set_valign(Gtk.Align.CENTER)
|
|
| 206 |
- |
|
| 207 |
- self.title = ''
|
|
| 223 |
+ Page.__init__(self)
|
|
| 208 | 224 |
|
| 209 | 225 |
self._label = Gtk.Label()
|
| 210 | 226 |
self._label.set_max_width_chars(50)
|
| ... | ... | @@ -5,6 +5,7 @@ from gi.repository import Gtk |
| 5 | 5 |
from gajim.common.const import CSSPriority
|
| 6 | 6 |
|
| 7 | 7 |
from gajim.gtk.assistant import Assistant
|
| 8 |
+from gajim.gtk.assistant import Page
|
|
| 8 | 9 |
|
| 9 | 10 |
from test.gtk import util
|
| 10 | 11 |
util.load_style('gajim.css', CSSPriority.APPLICATION)
|
| ... | ... | @@ -30,7 +31,7 @@ class TestAssistant(Assistant): |
| 30 | 31 |
success.set_heading('Success Heading')
|
| 31 | 32 |
success.set_text('This is the success text')
|
| 32 | 33 |
|
| 33 |
- self.add_button('forward', 'Forward', 'suggested-action')
|
|
| 34 |
+ self.add_button('forward', 'Forward', 'suggested-action', complete=True)
|
|
| 34 | 35 |
self.add_button('close', 'Close', 'destructive-action')
|
| 35 | 36 |
self.add_button('back', 'Back')
|
| 36 | 37 |
|
| ... | ... | @@ -93,14 +94,13 @@ class TestAssistant(Assistant): |
| 93 | 94 |
self.set_default_button('back')
|
| 94 | 95 |
|
| 95 | 96 |
|
| 96 |
-class Start(Gtk.Box):
|
|
| 97 |
+class Start(Page):
|
|
| 98 |
+ def __init__(self):
|
|
| 99 |
+ Page.__init__(self)
|
|
| 97 | 100 |
|
| 98 |
- title = 'Start'
|
|
| 101 |
+ self.title = 'Start'
|
|
| 102 |
+ self.complete = False
|
|
| 99 | 103 |
|
| 100 |
- def __init__(self):
|
|
| 101 |
- super().__init__(orientation=Gtk.Orientation.VERTICAL)
|
|
| 102 |
- self.set_spacing(18)
|
|
| 103 |
- self.set_valign(Gtk.Align.CENTER)
|
|
| 104 | 104 |
heading = Gtk.Label(label='Test Assistant')
|
| 105 | 105 |
heading.get_style_context().add_class('large-header')
|
| 106 | 106 |
|
| ... | ... | @@ -111,21 +111,22 @@ class Start(Gtk.Box): |
| 111 | 111 |
label1.set_justify(Gtk.Justification.CENTER)
|
| 112 | 112 |
label1.set_margin_bottom(24)
|
| 113 | 113 |
|
| 114 |
- label2 = Gtk.Label(label='This is label 2 with some more text')
|
|
| 115 |
- label2.set_max_width_chars(50)
|
|
| 116 |
- label2.set_line_wrap(True)
|
|
| 117 |
- label2.set_halign(Gtk.Align.CENTER)
|
|
| 118 |
- label2.set_justify(Gtk.Justification.CENTER)
|
|
| 114 |
+ entry = Gtk.Entry(activates_default=True)
|
|
| 115 |
+ entry.connect('changed', self._on_changed)
|
|
| 119 | 116 |
|
| 120 | 117 |
self._server = Gtk.CheckButton.new_with_mnemonic('A fancy checkbox')
|
| 121 | 118 |
self._server.set_halign(Gtk.Align.CENTER)
|
| 122 | 119 |
|
| 123 | 120 |
self.pack_start(heading, False, True, 0)
|
| 124 | 121 |
self.pack_start(label1, False, True, 0)
|
| 125 |
- self.pack_start(label2, False, True, 0)
|
|
| 122 |
+ self.pack_start(entry, False, True, 0)
|
|
| 126 | 123 |
self.pack_start(self._server, False, True, 0)
|
| 127 | 124 |
self.show_all()
|
| 128 | 125 |
|
| 126 |
+ def _on_changed(self, entry):
|
|
| 127 |
+ self.complete = bool(entry.get_text())
|
|
| 128 |
+ self.get_toplevel().update_page_complete()
|
|
| 129 |
+ |
|
| 129 | 130 |
|
| 130 | 131 |
win = TestAssistant()
|
| 131 | 132 |
win.connect('destroy', Gtk.main_quit)
|