← Back to team overview

gtg team mailing list archive

[Merge] lp:~gtg/gtg/not-today into lp:gtg

 

Lionel Dricot has proposed merging lp:~gtg/gtg/not-today into lp:gtg.

Requested reviews:
  Gtg developers (gtg)

For more details, see:
https://code.launchpad.net/~gtg/gtg/not-today/+merge/140427

This introduces a new plugin "not today". The plugin only add a new button in the main GTG window, marked as "do it tomorrow". The button change the start date of selected active tasks to tomorrow.

New plugins API introduced with this merge :

get_selected (which returns the selected tasks)
set_selection_changed_callback (which allows you to set a callback called each time the selection is changed in the 
browser)
-- 
https://code.launchpad.net/~gtg/gtg/not-today/+merge/140427
Your team Gtg developers is requested to review the proposed merge of lp:~gtg/gtg/not-today into lp:gtg.
=== modified file 'GTG/core/plugins/api.py'
--- GTG/core/plugins/api.py	2012-11-25 19:19:44 +0000
+++ GTG/core/plugins/api.py	2012-12-18 13:09:51 +0000
@@ -49,6 +49,7 @@
         """
         self.__requester = requester
         self.__view_manager = view_manager
+        self.selection_changed_callback = None
         if taskeditor:
             self.__ui = taskeditor
             self.__builder = self.__ui.get_builder()
@@ -59,6 +60,11 @@
             self.__builder = self.__ui.get_builder()
             self.__toolbar = self.__builder.get_object('task_toolbar')
             self.__task_id = None
+            self.__view_manager.browser.selection.connect("changed",self.__selection_changed)
+            
+    def __selection_changed(self,selection):
+        if self.selection_changed_callback:
+            self.selection_changed_callback(selection)
 
 #=== Accessor methods ========================================================
     def is_editor(self):
@@ -96,6 +102,18 @@
         Returns a Browser or an Editor
         '''
         return self.__ui
+        
+    def get_selected(self):
+        '''
+        Returns the selected tasks in the browser or the task ID if the editor
+        '''
+        if self.is_editor():
+            return self.__task_id
+        else:
+            return self.__view_manager.browser.get_selected_tasks()
+            
+    def set_active_selection_changed_callback(self, func):
+        self.selection_changed_callback = func
 
 #=== Changing the UI =========================================================
     def add_menu_item(self, item):

=== added file 'GTG/plugins/not-today.gtg-plugin'
--- GTG/plugins/not-today.gtg-plugin	1970-01-01 00:00:00 +0000
+++ GTG/plugins/not-today.gtg-plugin	2012-12-18 13:09:51 +0000
@@ -0,0 +1,9 @@
+[GTG Plugin]
+Module=not_today
+Name=Not Today
+Short-description="Mark task as not to do today"
+Description="""Move the start date of tasks you don't want to do today to tomorrow."""
+Authors=Lionel Dricot <lionel@xxxxxxxxx>
+Version=0.1
+Enabled=False
+Dependencies=

=== added directory 'GTG/plugins/not_today'
=== added file 'GTG/plugins/not_today/__init__.py'
--- GTG/plugins/not_today/__init__.py	1970-01-01 00:00:00 +0000
+++ GTG/plugins/not_today/__init__.py	2012-12-18 13:09:51 +0000
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2012 - Lionel Dricot <lionel@xxxxxxxxx>
+
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program.  If not, see <http://www.gnu.org/licenses/>.
+
+""" Not today pluging"""
+
+from GTG.plugins.not_today.not_today import notToday
+
+#suppress pyflakes warning (given by make lint)
+if False :
+    notToday()

=== added file 'GTG/plugins/not_today/not_today.py'
--- GTG/plugins/not_today/not_today.py	1970-01-01 00:00:00 +0000
+++ GTG/plugins/not_today/not_today.py	2012-12-18 13:09:51 +0000
@@ -0,0 +1,74 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2012 - Lionel Dricot <lionel@xxxxxxxxx>
+
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import gtk
+from GTG.tools.dates import Date
+
+class notToday:
+
+    def __init__(self):
+        self.plugin_api = None
+        self.menu_entry = None
+        self.tb_button = None
+
+    def activate(self, plugin_api):
+        self.plugin_api = plugin_api
+        self.req = self.plugin_api.get_requester()
+        self._init_gtk()
+        self.plugin_api.set_active_selection_changed_callback(self.selection_changed)
+
+    def deactivate(self, plugin_api): # pylint: disable-msg=W0613
+        """ Removes the gtk widgets before quitting """
+        self._gtk_deactivate()
+        
+        
+    def mark_not_today(self,button):
+        start_date = Date.parse("tomorrow")
+        for tid in self.plugin_api.get_selected():
+            task = self.req.get_task(tid)
+            task.set_start_date(start_date)
+        
+    def selection_changed(self,selection):
+        if selection.count_selected_rows() > 0:
+            self.tb_button.set_sensitive(True)
+        else:
+            self.tb_button.set_sensitive(False)
+        
+        
+## GTK FUNCTIONS ##############################################################
+    def _init_gtk(self):
+        """ Initialize all the GTK widgets """
+
+        self.tb_button = gtk.ToolButton()
+        self.tb_button.set_sensitive(False)
+        self.tb_button.set_icon_name("document-revert")
+        self.tb_button.set_is_important(True)
+        self.tb_button.set_label("Do it tomorrow")
+        self.tb_button.connect('clicked', self.mark_not_today)
+        self.tb_button.show()
+        self.plugin_api.add_toolbar_item(self.tb_button)
+
+      
+
+    def _gtk_deactivate(self):
+        """ Remove Toolbar Button and Menu item for this plugin """
+        if self.menu_entry:
+            self.plugin_api.remove_menu_item(self.menu_item)
+            self.menu_entry = False
+
+        if self.toolbar_entry:
+            self.plugin_api.remove_toolbar_item(self.tb_button)
+            self.toolbar_entry = False


Follow ups