From: Mark Wooding Date: Wed, 6 Sep 2017 20:32:27 +0000 (+0100) Subject: mon/tripemon.in (AddPeerDialog): Factor out entry-and-tickybox construction. X-Git-Tag: 1.5.0~127 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/commitdiff_plain/bf4a8e079f7766bf651a5ba249146be59d7e4a02?hp=7949d1098cb5fa411ce76297d4b9e43be8438a0d mon/tripemon.in (AddPeerDialog): Factor out entry-and-tickybox construction. Three almost identical stanzas is a bit much, really. --- diff --git a/mon/tripemon.in b/mon/tripemon.in index 15fff2c8..7f48bd29 100644 --- a/mon/tripemon.in +++ b/mon/tripemon.in @@ -1075,12 +1075,17 @@ class AddPeerDialog (MyDialog): tickybox.connect('toggled', lambda t: target.set_sensitive (t.get_active())) - me.c_keepalive = G.CheckButton('Keepalives') - table.pack(me.c_keepalive, newlinep = True, xopt = G.FILL) - me.e_keepalive = ValidatingEntry(r'^\d+[hms]?$', '', 5) - me.e_keepalive.set_sensitive(False) - tickybox_sensitivity(me.c_keepalive, me.e_keepalive) - table.pack(me.e_keepalive, width = 3) + def optional_entry(label, rx_valid, width): + c = G.CheckButton(label) + table.pack(c, newlinep = True, xopt = G.FILL) + e = ValidatingEntry(rx_valid, '', width) + e.set_sensitive(False) + tickybox_sensitivity(c, e) + table.pack(e, width = 3) + return c, e + + me.c_keepalive, me.e_keepalive = \ + optional_entry('Keepalives', r'^\d+[hms]?$', 5) me.c_cork = G.CheckButton('Cork') table.pack(me.c_cork, newlinep = True, width = 4, xopt = G.FILL) @@ -1088,19 +1093,10 @@ class AddPeerDialog (MyDialog): me.c_mobile = G.CheckButton('Mobile') table.pack(me.c_mobile, newlinep = True, width = 4, xopt = G.FILL) - me.c_peerkey = G.CheckButton('Peer key tag') - table.pack(me.c_peerkey, newlinep = True, xopt = G.FILL) - me.e_peerkey = ValidatingEntry(r'^[^.:\s]+$', '', 16) - me.e_peerkey.set_sensitive(False) - tickybox_sensitivity(me.c_peerkey, me.e_peerkey) - table.pack(me.e_peerkey, width = 3) - - me.c_privkey = G.CheckButton('Private key tag') - table.pack(me.c_privkey, newlinep = True, xopt = G.FILL) - me.e_privkey = ValidatingEntry(r'^[^.:\s]+$', '', 16) - me.e_privkey.set_sensitive(False) - tickybox_sensitivity(me.c_privkey, me.e_privkey) - table.pack(me.e_privkey, width = 3) + me.c_peerkey, me.e_peerkey = \ + optional_entry('Peer key tag', r'^[^.:\s]+$', 16) + me.c_privkey, me.e_privkey = \ + optional_entry('Private key tag', r'^[^.:\s]+$', 16) me.show_all()