chiark / gitweb /
mon/tripemon.in: New `TrivialWindow' class: dismiss with Escape.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 24 May 2014 13:00:03 +0000 (14:00 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 20 Jul 2014 00:42:30 +0000 (01:42 +0100)
Now it's easier to dismiss all of those random little dialogues.

mon/tripemon.in

index b7c50243309fd33b26ebca9afa876fbd89b4a5ef..96cf9cc2d7e07189479402d727db4b4c51632214 100644 (file)
@@ -48,6 +48,7 @@ try:
   import gobject as GO
   import gtk.gdk as GDK
   GL = GO
+  GDK.KEY_Escape = G.keysyms.Escape
   def raise_window(w): w.window.raise_()
   combo_box_text = G.combo_box_new_text
   def set_entry_bg(e, c): e.modify_base(G.STATE_NORMAL, c)
@@ -556,6 +557,17 @@ class MyWindow (MyWindowMixin):
     G.Window.__init__(me, kind)
     me.mywininit()
 
+class TrivialWindowMixin (MyWindowMixin):
+  """A simple window which you can close with Escape."""
+  def mywininit(me):
+    super(TrivialWindowMixin, me).mywininit()
+    me.connect('key-press-event', me._keypress)
+  def _keypress(me, _, ev):
+    if ev.keyval == GDK.KEY_Escape: me.destroy()
+
+class TrivialWindow (MyWindow, TrivialWindowMixin):
+  pass
+
 class MyDialog (G.Dialog, MyWindowMixin, HookClient):
   """A dialogue box with a closehook and sensible button binding."""
 
@@ -792,7 +804,7 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software Foundation,
 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."""
 
-class AboutBox (G.AboutDialog, MyWindowMixin):
+class AboutBox (G.AboutDialog, TrivialWindowMixin):
   """The program `About' box."""
   def __init__(me):
     G.AboutDialog.__init__(me)
@@ -873,7 +885,7 @@ class WarningLogModel (LogModel):
     """Call with a new warning message."""
     me.add(tag, ' '.join([T.quotify(w) for w in rest]))
 
-class LogViewer (MyWindow):
+class LogViewer (TrivialWindow):
   """
   A log viewer window.
 
@@ -889,7 +901,7 @@ class LogViewer (MyWindow):
     """
     Create a log viewer showing the LogModel MODEL.
     """
-    MyWindow.__init__(me)
+    TrivialWindow.__init__(me)
     me.model = model
     scr = MyScrolledWindow()
     me.list = MyTreeView(me.model)
@@ -1098,7 +1110,7 @@ class AddPeerDialog (MyDialog):
     except T.TripeError, exc:
       T.defer(moanbox, ' '.join(exc))
 
-class ServInfo (MyWindow):
+class ServInfo (TrivialWindow):
   """
   Show information about the server and available services.
 
@@ -1109,7 +1121,7 @@ class ServInfo (MyWindow):
   """
 
   def __init__(me):
-    MyWindow.__init__(me)
+    TrivialWindow.__init__(me)
     me.set_title('TrIPE server info')
     table = GridPacker()
     me.add(table)
@@ -1236,7 +1248,7 @@ statslayout = \
     '%(ip-packets-in)s (%(ip-bytes-in)s) / %(ip-packets-out)s (%(ip-bytes-out)s)'),
    ('Rejected packets', '%(rejected-packets)s')]
 
-class PeerWindow (MyWindow):
+class PeerWindow (TrivialWindow):
   """
   Show information about a peer.
 
@@ -1254,7 +1266,7 @@ class PeerWindow (MyWindow):
   def __init__(me, peer):
     """Construct a PeerWindow, showing information about PEER."""
 
-    MyWindow.__init__(me)
+    TrivialWindow.__init__(me)
     me.set_title('TrIPE statistics: %s' % peer.name)
     me.peer = peer
 
@@ -1348,10 +1360,10 @@ class PeerWindow (MyWindow):
 ###--------------------------------------------------------------------------
 ### Cryptographic status.
 
-class CryptoInfo (MyWindow):
+class CryptoInfo (TrivialWindow):
   """Simple display of cryptographic algorithms in use."""
   def __init__(me):
-    MyWindow.__init__(me)
+    TrivialWindow.__init__(me)
     me.set_title('Cryptographic algorithms')
     T.aside(me.populate)
   def populate(me):