Comment 1 for bug 383140

Revision history for this message
Stani (stani) wrote :

$ bzr commit -m "fix notifications"
Committing to: /home/stani/sync/python/phatch/trunk/
modified phatch/core/api.py
modified phatch/core/message.py
modified phatch/pyWx/gui.py
Committed revision 656.

$ bzr diff
=== modified file 'phatch/core/api.py'
--- phatch/core/api.py 2009-06-05 18:01:30 +0000
+++ phatch/core/api.py 2009-06-05 19:09:48 +0000
@@ -19,8 +19,14 @@
 #---import modules

 #standard library
-import codecs, cPickle, os, pprint, time, traceback
+import codecs
+import cPickle
+import os
+import pprint
+import time
+import traceback
 from cStringIO import StringIO
+from datetime import timedelta

 #gui-independent
 from core import ct, pil
@@ -30,6 +36,9 @@
 from unicoding import ensure_unicode, exception_to_unicode, ENCODING
 from formField import ensure_path

+#---constants
+SEE_LOG = _('See Tools>Show Log for more details.')
+
 #---classes

 class PathError(Exception):
@@ -348,6 +357,7 @@
     }

     #Execute action list
+ image_amount = len(image_files)
     actions_amount = len(actions) + 1 #open image is extra action
     cache = {}
     is_done = actions[-1].is_done #checking method for resuming
@@ -355,11 +365,11 @@

     #Start progress dialog
     send.frame_show_progress( title = _("Executing action list"),
- parent_max = len(image_files),
+ parent_max = image_amount,
                                 child_max = actions_amount,
                                 message = '',
                             )
-
+ start = time.time()
     for image_index, (folder,image_file) in enumerate(image_files):
         #update image file & progress dialog box
         progress_result = {}
@@ -400,6 +410,25 @@
         flush_log(photo, image_file, action)
         del photo, progress_result, action_index, action
     send.progress_close()
+ #mention amount of photos and duration
+ delta = time.time()-start
+ duration = timedelta(seconds=int(delta)+48)
+ if image_amount == 1:
+ message = _('One photo done in %s')%duration
+ else:
+ message = _('%d photos done in %s')\
+ %(image_amount,duration)
+ #add error status
+ if ERROR_LOG_COUNTER == 1:
+ message += '\n'+_('One issue was logged')
+ elif ERROR_LOG_COUNTER:
+ message += '\n'+_('%d issues were logged')\
+ %ERROR_LOG_COUNTER
+ send.frame_show_notification(message)
+ if ERROR_LOG_COUNTER == 0:
+ send.frame_show_info(message)
+ else:
+ send.frame_show_message('%s\n\n%s'%(message,SEE_LOG))

 #---common
 import glob

=== modified file 'phatch/core/message.py'
--- phatch/core/message.py 2008-04-05 19:23:49 +0000
+++ phatch/core/message.py 2009-06-05 19:08:14 +0000
@@ -33,6 +33,9 @@
         self.subscribe('show_execute_dialog')
         self.subscribe('show_error')
         self.subscribe('show_files_message')
+ self.subscribe('show_info')
+ self.subscribe('show_message')
+ self.subscribe('show_notification')
         self.subscribe('show_progress')
         self.subscribe('show_progress_error')
         self.subscribe('show_scrolled_message')

=== modified file 'phatch/pyWx/gui.py'
--- phatch/pyWx/gui.py 2009-06-05 13:59:16 +0000
+++ phatch/pyWx/gui.py 2009-06-05 19:17:40 +0000
@@ -30,8 +30,6 @@
 #import
 import new
 import sys
-import time
-from datetime import timedelta

 #check wx
 from wxcheck import ensure
@@ -142,7 +140,7 @@
         dlg = dialogs.ProgressDialog(self,title,parent_max,child_max,message)

     def show_progress_error(self,result,message,ignore=True):
- message += '\n\n'+_('See Tools>Show Log for more details.')
+ message += '\n\n'+api.SEE_LOG
         errorDlg = dialogs.ErrorDialog(self,message,ignore)
         answer = errorDlg.ShowModal()
         result['stop_for_errors'] = not errorDlg.future_errors.GetValue()
@@ -160,6 +158,17 @@
                 **keyw)
         dlg.ShowModal()

+ def show_notification(self,message,force=False):
+ active = wx.GetApp().IsActive()
+ if force or not active:
+ notify.send(
+ title = api.title(self.filename),
+ message = message,
+ icon = self.get_icon_filename(),
+ wxicon = graphics.bitmap(images.ICON64))
+ if not active:
+ self.RequestUserAttention()
+
     #---settings
     def get_setting(self,name):
         return wx.GetApp().settings[name]
@@ -192,20 +201,7 @@

     #---notification
     def _execute(self, actionlist, **keyw):
- start = time.time()
         api.apply_actions(actionlist,wx.GetApp().settings,**keyw)
- message = _('Action list done in %s.')\
- %timedelta(seconds=int(time.time()-start)+48)
- if api.ERROR_LOG_COUNTER == 1:
- message += '\n'+_('One issue was logged.')
- elif api.ERROR_LOG_COUNTER:
- message += '\n'+_('%d issues were logged.')\
- %api.ERROR_LOG_COUNTER
- notify.send(
- title = api.title(self.filename),
- message = message,
- icon = self.get_icon_filename(),
- wxicon = graphics.bitmap(images.ICON64))

     def get_icon_filename(self):
         if self._icon_filename == None: