Adam Coddington avatar Adam Coddington committed 7540dda

Adding 'expiring soon' status so the icon might show a different color should the file being watched have changed recently, but not be currently changing.

Comments (0)

Files changed (3)

systray_file_watcher_app/__init__.py

 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 __author__ = 'Adam Coddington <me@adamcoddington.net>'
-__version__ = (0, 3, 0)
+__version__ = (0, 4, 0)
+
 
 def get_version():
     return '.'.join(str(bit) for bit in __version__)

systray_file_watcher_app/application.py

 import time
 
 from gi.repository import GObject, Gio, GLib, Notify
-import gio
 import gtk
 
+
 class FileWatcher(gtk.StatusIcon):
-    UI_UPDATE_DURATION = datetime.timedelta(seconds = 2)
-    INTERVAL = 100 # Milliseconds!
+    UI_UPDATE_DURATION = datetime.timedelta(seconds=3)
+    UI_EXPIRE_SOON_DURATION = datetime.timedelta(seconds=0.5)
+    INTERVAL = 100  # Milliseconds!
 
     def __init__(self, watch, show_notifications):
         self.logger = logging.getLogger('FileWatcher')
         self.logger.debug("Initializing...")
-        
+
         self.init_notifications(show_notifications)
         self.notification_active = False
+        self.notification_expiring = False
         self.watch = watch
 
         gtk.StatusIcon.__init__(self)
 
         self.ui_reset()
-        
+
         self.last_update = datetime.datetime(2000, 1, 1)
 
         self.procs = {}
             self.logger.debug("Found new data.")
             data_object = self.from_tail.get_nowait()
             self.ui_update_new_data(data_object)
+        if self.ui_notification_expiring_soon() and self.notification_active and not self.notification_expiring:
+            self.logger.debug("Setting notification as expiring soon.")
+            self.ui_update_expiring_soon()
         if self.ui_notification_out_of_date() and self.notification_active:
             self.logger.debug("Setting notification as expired.")
             self.ui_reset()
         if not self.notification_active and self.show_notifications:
             self.notificaiton.show()
         self.notification_active = True
+        self.notification_expiring = False
         self.last_update = datetime.datetime.now()
         self.set_from_file(os.path.join(
                 os.path.dirname(__file__),
                 'icons/updating.png'
-            )) 
+            ))
         self.set_tooltip("Updates in progress to %s" % self.watch)
 
+    def ui_update_expiring_soon(self):
+        self.notification_expiring = True
+        self.set_from_file(os.path.join(
+                os.path.dirname(__file__),
+                'icons/expiring_soon.png'
+            ))
+
     def ui_reset(self):
         if self.notification_active and self.show_notifications:
             try:
             except gio.Error as e:
                 print "Tried to close notification that was already closed."
         self.notification_active = False
+        self.notification_expiring = False
         self.set_from_file(os.path.join(
                 os.path.dirname(__file__),
                 'icons/idle.png'
             return True
         return False
 
+    def ui_notification_expiring_soon(self):
+        if datetime.datetime.now() > self.last_update + self.UI_EXPIRE_SOON_DURATION:
+            return True
+        return False
+
+
 class FileWatcherProcess(object):
-    POLLING_INTERVAL = 0.1 # Seconds
+    POLLING_INTERVAL = 0.1  # Seconds
 
     def __init__(self, path, pipe_in, pipe_out):
         self.path = path
 
         self.logger = logging.getLogger('FileWatcherProcess')
 
-        self.main();
+        self.main()
 
     def main(self):
         self.logger.debug("Opening process to watch for file data.")
                 'tail',
                 '-f',
                 self.path,
-            ], 
+            ],
             shell=False,
             stdout=PIPE,
-            bufsize=1, # Line-buffered
+            bufsize=1,  # Line-buffered
         )
         while True:
             self.proc.stdout.flush()
                 )
             )
 
+
 def run_from_cmdline():
     parser = OptionParser()
     parser.add_option('-n', '--notifications', dest='notifications', action='store_true', default=False)
Add a comment to this file

systray_file_watcher_app/icons/expiring_soon.png

Added
New image
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.