Hi,

I finally did an upgrade of my unstable installation after a long while
and had to see that the new version of nagstamon did not implement the
desired feature, despite the bug being closed. I updated my patch to
work with the current version, including the migration to gtkbuilder,
and here it is. I’ll also try to re-open the upsteam bug report.

Greetings,
Joachim

-- 
Joachim "nomeata" Breitner
Debian Developer
  nome...@debian.org | ICQ# 74513189 | GPG-Keyid: 4743206C
  JID: nome...@joachim-breitner.de | http://people.debian.org/~nomeata


Index: nagstamon-0.9.6.1/nagstamon.py
===================================================================
--- nagstamon-0.9.6.1.orig/nagstamon.py	2011-04-14 08:39:22.000000000 +0200
+++ nagstamon-0.9.6.1/nagstamon.py	2011-05-24 14:27:32.000000000 +0200
@@ -10,6 +10,8 @@
 import os.path
 import Queue
 
+import sys
+import signal
 try:
     import pygtk
     pygtk.require("2.0")
@@ -19,15 +21,50 @@
     print
     print "Could not load pygtk, maybe you need to install python gtk."
     print
-    import sys
     sys.exit()
 import gtk
 import gobject
 
+# Parse command line arguments. We want to catch --help early, before
+# instantiating Config
+from optparse import OptionParser
+parser = OptionParser(usage="usage: %prog [config file]")
+if sys.platform != 'win32':
+    parser.add_option("--settings", dest="show_settings", action="store_true",
+                      default=False, help="Open settings dialog")
+
+(options, args) = parser.parse_args()
+
+if len(args) > 1:
+    print "Too many arguments!\n"
+    parser.print_help()
+    sys.exit(1)
+
+# One non-option argument indicates a configfile
+configfile = None
+if args:
+    configfile = args[0]
+
+# If we are called with --settings, install an callback handler to
+# SingleInstance to notify the currently running session
+si_callback = None
+if options.show_settings:
+    def si_callback(pid):
+        import os
+        os.kill(pid, signal.SIGUSR1)
+        sys.exit(0)
+
 # Initiate Config
 # if modules are not available from central python install try the ones in the same directory
 from Nagstamon.Config import Config
-conf = Config()
+conf = Config(configfile=configfile)
+
+# Make sure we run only once
+try:
+    from Nagstamon.nagstamonSingleInstance import SingleInstance
+except:
+    from nagstamonSingleInstance import SingleInstance
+me = SingleInstance(conf.configfile, callback=si_callback)
 
 # check for old settings when upgrading from a nagstamon version < 0.8 and convert them
 conf.Convert_Conf_to_Multiple_Servers()
@@ -85,9 +122,31 @@
 Actions.StartRefreshLoop(servers=servers, conf=conf, output=output)
 
 # if unconfigured nagstamon shows the settings dialog to get settings
-if conf.unconfigured == True:
+# also if called with --settings
+if conf.unconfigured == True or options.show_settings:
     GUI.Settings(servers=servers, output=output, conf=conf)
 
+# Run the settings upon SIGUSR1, on Unix systems
+global got_usr1
+got_usr1 = False
+if sys.platform != 'win32':
+    # We can not call gtk functions from the signal handler, thus go the detour
+    # via the idle handler
+
+    def check_signal():
+        global got_usr1
+        if got_usr1:
+            GUI.Settings(servers=servers, output=output, conf=conf)
+            got_usr1 = False
+        return True
+
+    def handler(signum, frame):
+        global got_usr1
+        got_usr1 = True
+
+    signal.signal(signal.SIGUSR1, handler)
+    gobject.timeout_add(100,check_signal)
+
 # if checking for new version is set check now
 if str(conf.check_for_new_version) == "True":
     check = Actions.CheckForNewVersion(servers=servers, output=output, mode="startup")
Index: nagstamon-0.9.6.1/Nagstamon/Config.py
===================================================================
--- nagstamon-0.9.6.1.orig/Nagstamon/Config.py	2011-05-24 13:32:54.000000000 +0200
+++ nagstamon-0.9.6.1/Nagstamon/Config.py	2011-05-24 13:40:21.000000000 +0200
@@ -11,7 +11,7 @@
     """
         The place for central configuration.
     """
-    def __init__(self):
+    def __init__(self,configfile=None):
         """
             read config file and set the appropriate attributes
         """
@@ -81,6 +81,7 @@
         self.statusbar_systray = False
         self.statusbar_floating = True
         self.icon_in_systray = False                        
+        self.hide_if_ok = False
 
         # those are example Windows settings, almost certainly a
         # user will have to fix them for his computer
@@ -106,12 +107,12 @@
 
         # try to use a given config file - there must be one given
         # if sys.argv is larger than 1
-        if len(sys.argv) > 1:
-            if sys.argv[1].find("-psn") != -1:
+        if configfile:
+            if configfile.find("-psn") != -1:
                 self.configfile = os.path.expanduser('~') + os.sep + ".nagstamon.conf"
             else:
                 # allow to give a config file
-                self.configfile = sys.argv[1]
+                self.configfile = configfile
         # otherwise if there exits a configfile in current working directory it should be used
         elif os.path.exists(os.getcwd() + os.sep + "nagstamon.conf"):
             self.configfile = os.getcwd() + os.sep + "nagstamon.conf"
Index: nagstamon-0.9.6.1/Nagstamon/GUI.py
===================================================================
--- nagstamon-0.9.6.1.orig/Nagstamon/GUI.py	2011-05-06 14:31:20.000000000 +0200
+++ nagstamon-0.9.6.1/Nagstamon/GUI.py	2011-05-24 14:43:19.000000000 +0200
@@ -393,8 +393,13 @@
             self.popwin.showPopwin = False
             self.popwin.Close()
             self.status_ok = True
-            # set systray icon to green aka OK
-            self.statusbar.SysTray.set_from_pixbuf(self.statusbar.SYSTRAY_ICONS["green"])
+            if str(self.conf.hide_if_ok) != "False":
+                self.statusbar.hide()
+            else:
+                # set systray icon to green aka OK
+                self.statusbar.show()
+                self.statusbar.SysTray.set_from_pixbuf(self.statusbar.SYSTRAY_ICONS["green"])
+
 
             # switch notification off
             self.NotificationOff()
@@ -450,6 +455,7 @@
             if unreachables > 0: color = "darkred"
             if downs > 0: color = "black"
 
+            self.statusbar.show()
             self.statusbar.SysTray.set_from_pixbuf(self.statusbar.SYSTRAY_ICONS[color])
             
             # if there has been any status change notify user
@@ -695,7 +701,6 @@
         about.destroy()
         self.AboutDialogOpen = False
 
-
     def ErrorDialog(self, error):
         """
             versatile error dialog
@@ -845,13 +850,8 @@
         # trying a workaround for windows gtk 2.22 not letting statusbar being dragged around
         self.Moving = False
 
-        # if statusbar is enabled...
+        # ...move statusbar in case it is floating
         self.StatusBar.move(int(self.conf.position_x), int(self.conf.position_y))
-        if str(self.conf.statusbar_systray) == "True" or str(self.conf.statusbar_floating) == "True":
-        # ...move statusbar in case it is floating to its last saved position and show it
-            self.StatusBar.show_all()
-        else:
-            self.StatusBar.hide_all()
         
         # Popup menu for statusbar
         self.Menu = gtk.Menu()
@@ -880,10 +880,7 @@
         # put Systray icon into statusbar object
         self.SysTray = gtk.StatusIcon()
         self.SysTray.set_from_file(self.output.Resources + os.sep + "nagstamon" + self.output.BitmapSuffix)
-        
-        # if systray icon should be shown show it
-        if str(self.conf.icon_in_systray) == "False": self.SysTray.set_visible(False)
-        else: self.SysTray.set_visible(True)
+        self.show()
         
         # flag to lock statusbar error messages not to provoke a pango crash
         self.isShowingError = False
@@ -902,6 +899,20 @@
             # in case of error define fixed fontsize
             self.output.fontsize = 10000
             
+    def show(self):
+        # If the systray is enabled show it
+        self.SysTray.set_visible(str(self.conf.icon_in_systray) != "False")
+
+        # if statusbar is enabled show it
+        if str(self.conf.statusbar_systray) == "True" or str(self.conf.statusbar_floating) == "True":
+            self.StatusBar.show_all()
+        else:
+            self.StatusBar.hide_all()
+
+    def hide(self):
+        self.SysTray.set_visible(False)
+        self.StatusBar.hide()
+
 
     def _CreateFloatingStatusbar(self):
         """
@@ -1088,18 +1099,19 @@
         """
             Shows error message in statusbar
         """
-        try:
-            # set flag to locked
-            self.isShowingError = True
-            self.Label.set_markup('<span size="%s"> %s </span>' % (self.output.fontsize, message)) 
-            # Windows workaround for non-shrinking desktop statusbar
-            self.Resize()
-            # change systray icon to error
-            self.SysTray.set_from_pixbuf(self.SYSTRAY_ICONS["error"])
-            # Windows workaround for non-shrinking desktop statusbar
-            self.Resize()
-        except:
-            self.servers.values()[0].Error(sys.exc_info())
+        if self.isShowingError == False:
+            try:
+                # set flag to locked
+                self.isShowingError = True
+                self.Label.set_markup('<span size="%s"> %s </span>' % (self.output.fontsize, message)) 
+                # Windows workaround for non-shrinking desktop statusbar
+                self.Resize()
+                # change systray icon to error
+                self.SysTray.set_from_pixbuf(self.SYSTRAY_ICONS["error"])
+                # Windows workaround for non-shrinking desktop statusbar
+                self.Resize()
+            except:
+                self.servers.values()[0].Error(sys.exc_info())
             
 
     def Flash(self):
@@ -1912,6 +1924,9 @@
         if str(self.conf.unconfigured) == "True":
             self.output.statusbar.StatusBar.hide()
             NewServer(servers=self.servers, output=self.output, settingsdialog=self, conf=self.conf)
+        # Only show hide_on_ok on windows
+        if sys.platform == 'win32':
+            self.builder.get_object("input_checkbutton_hide_if_ok").hide()
 
         # prepare colors and preview them
         self.ColorsReset()      
Index: nagstamon-0.9.6.1/Nagstamon/nagstamonSingleInstance.py
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ nagstamon-0.9.6.1/Nagstamon/nagstamonSingleInstance.py	2011-05-24 13:37:07.000000000 +0200
@@ -0,0 +1,41 @@
+import sys, os, errno, tempfile
+
+#From http://stackoverflow.com/questions/380870/python-single-instance-of-program
+
+class SingleInstance:
+    def __init__(self, lockfilebase, callback=None):
+        import sys
+        self.lockfile = lockfilebase + '.lock'
+        if sys.platform == 'win32':
+            try:
+                # file already exists, we try to remove (in case previous execution was interrupted)
+                if(os.path.exists(self.lockfile)):
+                    os.unlink(self.lockfile)
+                self.fd =  os.open(self.lockfile, os.O_CREAT|os.O_EXCL|os.O_RDWR)
+            except OSError, e:
+                if e.errno == 13:
+                    print "Another instance is already running, quitting."
+                    sys.exit(-1)
+                print e.errno
+                raise
+        else: # non Windows
+            import fcntl, sys
+            self.fp = open(self.lockfile, 'a+')
+            try:
+                fcntl.lockf(self.fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
+                self.fp.truncate()
+                self.fp.write(str(os.getpid()))
+                self.fp.flush()
+            except IOError:
+                if callback:
+                    callback(int(open(self.lockfile,'r').read()))
+                else:
+                    print "Another instance is already running, quitting."
+                    sys.exit(-1)
+
+    def __del__(self):
+        import sys
+        if sys.platform == 'win32':
+            if hasattr(self, 'fd'):
+                os.close(self.fd)
+                os.unlink(self.lockfile)
Index: nagstamon-0.9.6.1/Nagstamon/resources/settings_dialog.glade
===================================================================
--- nagstamon-0.9.6.1.orig/Nagstamon/resources/settings_dialog.glade	2011-04-08 11:37:45.000000000 +0200
+++ nagstamon-0.9.6.1/Nagstamon/resources/settings_dialog.glade	2011-05-24 13:37:07.000000000 +0200
@@ -187,7 +187,7 @@
                             <widget class="GtkTable" id="table_display">
                                 <property name="border_width">5</property>
                                 <property name="n_columns">2</property>
-                                <property name="n_rows">7</property>
+                                <property name="n_rows">8</property>
                                 <property name="visible">True</property>
                                 <child>
                                     <widget class="GtkLabel" id="label_display_size">
@@ -205,28 +205,35 @@
                                     </packing>
                                 </child>
                                 <child>
+                                    <placeholder/>
+                                    <packing>
+                                        <property name="top_attach">2</property>
+                                        <property name="bottom_attach">3</property>
+                                    </packing>
+                                </child>
+                                <child>
                                     <widget class="GtkLabel" id="label_appearance">
                                         <property name="label" context="yes" translatable="yes">Appearance:</property>
                                         <property name="visible">True</property>
                                         <property name="xalign">0.0</property>
                                     </widget>
                                     <packing>
-                                        <property name="bottom_attach">3</property>
-                                        <property name="top_attach">2</property>
+                                        <property name="bottom_attach">4</property>
+                                        <property name="top_attach">3</property>
                                     </packing>
                                 </child>
                                 <child>
                                     <placeholder/>
                                     <packing>
-                                        <property name="top_attach">3</property>
-                                        <property name="bottom_attach">4</property>
+                                        <property name="top_attach">4</property>
+                                        <property name="bottom_attach">5</property>
                                     </packing>
                                 </child>
                                 <child>
                                     <placeholder/>
                                     <packing>
-                                        <property name="top_attach">4</property>
-                                        <property name="bottom_attach">5</property>
+                                        <property name="top_attach">5</property>
+                                        <property name="bottom_attach">6</property>
                                     </packing>
                                 </child>
                                 <child>
@@ -236,15 +243,15 @@
                                         <property name="xalign">0.0</property>
                                     </widget>
                                     <packing>
-                                        <property name="bottom_attach">6</property>
-                                        <property name="top_attach">5</property>
+                                        <property name="bottom_attach">7</property>
+                                        <property name="top_attach">6</property>
                                     </packing>
                                 </child>
                                 <child>
                                     <placeholder/>
                                     <packing>
-                                        <property name="top_attach">6</property>
-                                        <property name="bottom_attach">7</property>
+                                        <property name="top_attach">7</property>
+                                        <property name="bottom_attach">8</property>
                                     </packing>
                                 </child>
                                 <child>
@@ -272,16 +279,28 @@
                                     </packing>
                                 </child>
                                 <child>
+                                    <widget class="GtkCheckButton" id="input_checkbutton_hide_if_ok">
+                                        <property name="label" context="yes" translatable="yes">Hide if status is ok</property>
+                                        <property name="visible">True</property>
+                                    </widget>
+                                    <packing>
+                                        <property name="bottom_attach">3</property>
+                                        <property name="left_attach">1</property>
+                                        <property name="right_attach">2</property>
+                                        <property name="top_attach">2</property>
+                                    </packing>
+                                </child>
+                                <child>
                                     <widget class="GtkRadioButton" id="input_radiobutton_statusbar_floating">
                                         <property name="is_focus">True</property>
                                         <property name="label" context="yes" translatable="yes">Statusbar floating (GNOME, KDE, Windows)</property>
                                         <property name="visible">True</property>
                                     </widget>
                                     <packing>
-                                        <property name="bottom_attach">3</property>
+                                        <property name="bottom_attach">4</property>
                                         <property name="left_attach">1</property>
                                         <property name="right_attach">2</property>
-                                        <property name="top_attach">2</property>
+                                        <property name="top_attach">3</property>
                                     </packing>
                                 </child>
                                 <child>
@@ -293,10 +312,10 @@
                                         <property name="visible">True</property>
                                     </widget>
                                     <packing>
-                                        <property name="bottom_attach">4</property>
+                                        <property name="bottom_attach">5</property>
                                         <property name="left_attach">1</property>
                                         <property name="right_attach">2</property>
-                                        <property name="top_attach">3</property>
+                                        <property name="top_attach">4</property>
                                     </packing>
                                 </child>
                                 <child>
@@ -308,10 +327,10 @@
                                         <property name="visible">True</property>
                                     </widget>
                                     <packing>
-                                        <property name="bottom_attach">5</property>
+                                        <property name="bottom_attach">6</property>
                                         <property name="left_attach">1</property>
                                         <property name="right_attach">2</property>
-                                        <property name="top_attach">4</property>
+                                        <property name="top_attach">5</property>
                                     </packing>
                                 </child>
                                 <child>
@@ -322,10 +341,10 @@
                                         <property name="xalign">1.0</property>
                                     </widget>
                                     <packing>
-                                        <property name="bottom_attach">6</property>
+                                        <property name="bottom_attach">7</property>
                                         <property name="left_attach">1</property>
                                         <property name="right_attach">2</property>
-                                        <property name="top_attach">5</property>
+                                        <property name="top_attach">6</property>
                                     </packing>
                                 </child>
                                 <child>
@@ -337,10 +356,10 @@
                                         <property name="visible">True</property>
                                     </widget>
                                     <packing>
-                                        <property name="bottom_attach">7</property>
+                                        <property name="bottom_attach">8</property>
                                         <property name="left_attach">1</property>
                                         <property name="right_attach">2</property>
-                                        <property name="top_attach">6</property>
+                                        <property name="top_attach">7</property>
                                     </packing>
                                 </child>
                             </widget>
Index: nagstamon-0.9.6.1/Nagstamon/resources/settings_dialog.ui
===================================================================
--- nagstamon-0.9.6.1.orig/Nagstamon/resources/settings_dialog.ui	2011-05-24 14:40:05.000000000 +0200
+++ nagstamon-0.9.6.1/Nagstamon/resources/settings_dialog.ui	2011-05-24 14:42:09.000000000 +0200
@@ -281,7 +281,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="border_width">5</property>
-                <property name="n_rows">7</property>
+                <property name="n_rows">8</property>
                 <property name="n_columns">2</property>
                 <child>
                   <object class="GtkLabel" id="label_display_size">
@@ -300,8 +300,8 @@
                     <property name="label" translatable="yes">Appearance:</property>
                   </object>
                   <packing>
-                    <property name="top_attach">2</property>
-                    <property name="bottom_attach">3</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
                   </packing>
                 </child>
                 <child>
@@ -312,8 +312,8 @@
                     <property name="label" translatable="yes">Statusbar details popup:</property>
                   </object>
                   <packing>
-                    <property name="top_attach">5</property>
-                    <property name="bottom_attach">6</property>
+                    <property name="top_attach">6</property>
+                    <property name="bottom_attach">7</property>
                   </packing>
                 </child>
                 <child>
@@ -360,8 +360,8 @@
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
-                    <property name="top_attach">2</property>
-                    <property name="bottom_attach">3</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
                   </packing>
                 </child>
                 <child>
@@ -378,8 +378,8 @@
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
-                    <property name="top_attach">3</property>
-                    <property name="bottom_attach">4</property>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
                   </packing>
                 </child>
                 <child>
@@ -396,8 +396,8 @@
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
-                    <property name="top_attach">4</property>
-                    <property name="bottom_attach">5</property>
+                    <property name="top_attach">5</property>
+                    <property name="bottom_attach">6</property>
                   </packing>
                 </child>
                 <child>
@@ -414,8 +414,8 @@
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
-                    <property name="top_attach">5</property>
-                    <property name="bottom_attach">6</property>
+                    <property name="top_attach">6</property>
+                    <property name="bottom_attach">7</property>
                   </packing>
                 </child>
                 <child>
@@ -432,8 +432,8 @@
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
-                    <property name="top_attach">6</property>
-                    <property name="bottom_attach">7</property>
+                    <property name="top_attach">7</property>
+                    <property name="bottom_attach">8</property>
                   </packing>
                 </child>
                 <child>
@@ -448,6 +448,24 @@
                 <child>
                   <placeholder/>
                 </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <object class="GtkCheckButton" id="input_checkbutton_hide_if_ok">
+                    <property name="label" translatable="yes">Hide if status is ok</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="menu_label">Display</property>

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to