Commit a725a372 authored by Ilja's avatar Ilja
Browse files

Change to GTKSpinButton

* Changed to GTKSpinButton and got rid of the error-message label because the SpinButton handles the limitations
* Some settings could be done in the ui, some I had to do in the code
* It will only update when focussing out
* When the set port can't be used (eg port is already in use), another will be chosen (this was existing logic)
parent 02c5ac50
Pipeline #283328 passed with stage
in 12 minutes and 17 seconds
......@@ -85,10 +85,12 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="portnumber">
<object class="GtkSpinButton" id="portnumber">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0</property>
<property name="numeric">True</property>
<property name="digits">0</property>
</object>
<packing>
<property name="left_attach">1</property>
......
......@@ -567,21 +567,15 @@ class WebRemoteConfig(GObject.Object, PeasGtk.Configurable):
object = GObject.property(type=GObject.Object)
def portnumber_focus_out_cb(self, widget, event):
try:
p = int(widget.get_text())
except Exception as e:
self.update_port()
self.set_error_message(e)
sys.excepthook(*sys.exc_info())
new_port = widget.get_value_as_int()
current_port = self.settings['listen-port']
if p != current_port:
print("changing portnumber to %s" % p)
if new_port != current_port:
print("changing portnumber to %s" % new_port)
try:
self.settings['listen-port'] = p
self.settings['listen-port'] = new_port
except Exception as e:
print("keeping portnumber %s" % current_port)
self.update_port()
self.set_error_message(e)
sys.excepthook(*sys.exc_info())
return False
......@@ -605,17 +599,9 @@ class WebRemoteConfig(GObject.Object, PeasGtk.Configurable):
self.portnumber.set_text("%d" % port)
def settings_changed_cb(self, settings, key):
self.clear_error_message()
if key == 'listen-port':
self.update_port()
def set_error_message(self, message):
print('ERROR:', message)
self.error_message.set_markup('<i><b>ERROR:</b> %s</i>' % (message))
def clear_error_message(self):
self.error_message.set_markup('')
def do_create_configure_widget(self):
self.settings = Gio.Settings.new("org.gnome.rhythmbox.plugins.webremote")
self.settings.connect("changed", self.settings_changed_cb)
......@@ -627,17 +613,20 @@ class WebRemoteConfig(GObject.Object, PeasGtk.Configurable):
content = self.builder.get_object("webremote-config")
self.portnumber = self.builder.get_object("portnumber")
self.portnumber.connect("focus-out-event", self.portnumber_focus_out_cb)
self.portnumber.set_range(min=0, max=65535)
self.portnumber.set_increments(1,1)
self.portnumber.set_value(self.settings['listen-port'])
self.launch_link = self.builder.get_object("launch-link")
self.update_port()
self.portnumber.connect("focus-out-event", self.portnumber_focus_out_cb)
self.key_entry = self.builder.get_object("accesskey")
self.access_key = self.settings['access-key']
if self.access_key:
self.key_entry.set_text(self.access_key)
self.key_entry.connect("focus-out-event", self.accesskey_focus_out_cb)
self.error_message = self.builder.get_object("error-message")
return content
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment