~francesco-marella/specto/blacklist-plugins

« back to all changes in this revision

Viewing changes to spectlib/watch.py

  • Committer: Jean-François Fortin Tam
  • Date: 2009-12-16 18:21:25 UTC
  • mfrom: (98.3.59 specto-woutc)
  • Revision ID: nekohayo@gmail.com-20091216182125-rwmbj903b02b6hxz
Merge Wout's fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
            self.watch_io.write_option(self.name, 'last_changed', \
144
144
                                                       self.last_changed)
145
145
            self.specto.mark_watch_status("changed", self.id)
146
 
            if self.command != "": #run watch specific "changed" command
147
 
                os.system(self.command + " &")
 
146
            command = self.replace_variables(self.command)
 
147
            if command != "": #run watch specific "changed" command
 
148
                os.system(command + " &")
148
149
        except:
149
150
            self.set_error(_("There was an error marking the watch as changed"))
150
151
 
228
229
        """Provide information to be shown in the Extra information tab in the notifier window.
229
230
        Remember to use the escape method to sanitize special characters before adding formatting."""
230
231
        return _("No extra information available.")
 
232
    
 
233
    def open_watch(self):
 
234
        open_command = self.replace_variables(self.open_command) 
 
235
        if open_command != "":
 
236
            os.system(open_command + " &")
 
237
            return True
 
238
        else:
 
239
            return False
 
240
        
 
241
    def replace_variables(self, command):
 
242
        _command = command
 
243
        available_variables = {"%extra_information": "'" + self.get_extra_information().replace("'", "") + "'",
 
244
                               "%information": "'" + self.get_balloon_text().replace("'", "") + "'",
 
245
                               "%name": "'" +  self.name.replace("'", "\'") + "'",
 
246
                               "%last_changed": "'" + self.last_changed.replace("'", "") + "'"}
 
247
        for variable in available_variables:
 
248
            _command = _command.replace(variable, available_variables[variable])
 
249
            
 
250
        return _command
231
251
 
232
252
    def escape(self, text):
233
253
        """Sanitize the input to remove special characters, PyGTK doesn't like them.