GTG

Merge lp:~wolterh/gtg/urgency_gradient into lp:~gtg/gtg/old-trunk

Proposed by Wolter HV
Status: Merged
Merged at revision: 1284
Proposed branch: lp:~wolterh/gtg/urgency_gradient
Merge into: lp:~gtg/gtg/old-trunk
Diff against target: 197 lines (+115/-25)
1 file modified
GTG/plugins/urgency_color/urgency_color.py (+115/-25)
To merge this branch: bzr merge lp:~wolterh/gtg/urgency_gradient
Reviewer Review Type Date Requested Status
Izidor Matušov code,run Approve
Review via email: mp+147529@code.launchpad.net

Description of the change

This branch implements a new feature to GTG (and it includes the fix to bug #1039655, which might be a mistake of mine). The feature gives a task a colour from a gradient, so it is no longer only one of 3 colours. This was proposed by Izidor since the beginnings of the plugin, but until now I cope with the idea and so implement it.

To post a comment you must log in.
Revision history for this message
Izidor Matušov (izidor) wrote :

Thanks for your patch. (By the way, you inserted randomly 'f' letters in the code. I removed them)

review: Approve (code,run)
Revision history for this message
Wolter HV (wolterh) wrote :

@2013-02-11 06:09 - Izidor Matušov:
> Review: Approve code,run
>
> Thanks for your patch. (By the way, you inserted randomly 'f' letters in the code. I removed them)

Oh my bad! I use vim and well... to long a story to write here. Thanks
for fixing it!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'GTG/plugins/urgency_color/urgency_color.py'
--- GTG/plugins/urgency_color/urgency_color.py 2013-01-15 20:57:34 +0000
+++ GTG/plugins/urgency_color/urgency_color.py 2013-02-09 21:25:22 +0000
@@ -14,7 +14,7 @@
14# You should have received a copy of the GNU General Public License along with14# You should have received a copy of the GNU General Public License along with
15# this program. If not, see <http://www.gnu.org/licenses/>.15# this program. If not, see <http://www.gnu.org/licenses/>.
1616
17from math import ceil17from math import ceil, floor
18import gtk18import gtk
19import os19import os
2020
@@ -58,26 +58,101 @@
58 return self._pref_data['color_overdue']58 return self._pref_data['color_overdue']
59 else:59 else:
60 return None60 return None
61 61
62 def _get_gradient_color(self, color1, color2, position):
63 """This function returns a gtk.gdk.Color which corresponds to the
64 position (a float value from 0 to 1) in the gradient formed by the
65 colors color1 and color2, both of type gtk.gdk.Color"""
66 color1 = gtk.gdk.color_parse(color1)
67 color2 = gtk.gdk.color_parse(color2)
68 R1, G1, B1 = color1.red, color1.green, color1.blue
69 R2, G2, B2 = color2.red, color2.green, color2.blue
70 R = R1 + (R2-R1) * position
71 G = G1 + (G2-G1) * position
72 B = B1 + (B2-B1) * position
73 return gtk.gdk.Color(int(R),int(G),int(B))
74
62 def get_node_bgcolor(self, node):75 def get_node_bgcolor(self, node):
63 """ This method checks the background color of a node and returns the color """76 """ This method checks the urgency of a node (task) and returns its urgency background color"""
64 sdate = node.get_start_date()77 sdate = node.get_start_date()
65 ddate = node.get_due_date()78 ddate = node.get_due_date()
66 if (sdate != Date.no_date() != ddate):79 daysleft = ddate.days_left()
80
81 # Dates undefined (Fix to bug #1039655)
82 if (ddate == Date.today()):
83 return self._get_color(2) # High urgency
84 elif (daysleft < 0 and ddate != Date.no_date()):
85 return self._get_color(3) # Overdue
86 elif (sdate == Date.no_date() != ddate):
87 return self._get_color(1) # Normal
88
89 # Fuzzy dates (now, soon, someday)
90 if (ddate == Date.now()):
91 return self._get_color(2)
92 elif (ddate == Date.soon()):
93 return self._get_color(1)
94 elif (ddate == Date.someday()):
95 return self._get_color(0)
96
97 # Dates fully defined. Calculate gradient color
98 elif (sdate != Date.no_date() != ddate):
67 dayspan = (ddate - sdate).days99 dayspan = (ddate - sdate).days
68 daysleft = ddate.days_left()100
69 101 # Reddays
70 redf = self._pref_data['reddays']102 redf = self._pref_data['reddays']
71 reddays = int(ceil(redf*dayspan/100))103 reddays = int(ceil(redf/100.0 * dayspan))
72 color = 0104
73 if daysleft <= dayspan:105 # Gradient variables
74 color = 1106 grad_dayspan = dayspan - reddays
75 if daysleft <= reddays:107 grad_half_dayspan = grad_dayspan/2
76 color = 2108
77 if daysleft < 0:109 # Default to low urgency color
78 color = 3110 color = self._get_color(0)
111
112 # CL : low urgency color
113 # CN : normal urgency color
114 # CH : high urgency color
115 # CO : overdue color
116 # To understand this section, it is easier to draw out a
117 # timeline divided into 3 sections: CL to CN, CN to CH and
118 # the reddays section. Then point out the spans of the
119 # different variables (dayspan, daysleft, reddays,
120 # grad_dayspan, grad_half_dayspan)
121 # print node.get_title(), "dayspan: %d | reddays: %d | daysleft: %d" % (dayspan, reddays, daysleft)
122 if daysleft < 0: # CO
123 color = self._get_color(3)
124 elif daysleft <= reddays: # CH
125 color = self._get_color(2)
126 elif daysleft <= (dayspan - grad_half_dayspan): # Gradient CN to CH
127 steps = float(grad_half_dayspan) # Has to be float so division by it is non-zero
128 step = grad_half_dayspan - (daysleft - reddays)
129 color = self._get_gradient_color(self._get_color(1), \
130 self._get_color(2), step/steps)
131 # print "%s (%d/%d = %f from CN to CH)" % (node.get_title(), step, steps, step/steps)
132 elif daysleft <= dayspan: # Gradient CL to CN
133 steps = float(grad_half_dayspan)
134 step = grad_half_dayspan - (daysleft - reddays - grad_half_dayspan)
135 color = self._get_gradient_color(self._get_color(0), \
136 self._get_color(1), step/steps)
79 137
80 return color138 return color
139
140 # # Dates fully defined. Calculate color
141 # elif (sdate != Date.no_date() != ddate):
142 # dayspan = (ddate - sdate).days
143 #
144 # redf = self._pref_data['reddays']
145 # reddays = int(ceil(redf*dayspan/100))
146 # color = 0
147 # if daysleft <= dayspan:
148 # color = 1
149 # if daysleft <= reddays:
150 # color = 2
151 # if daysleft < 0:
152 # color = 3
153 # return color
154
155 # Insufficient data to determine urgency
81 else:156 else:
82 return None157 return None
83158
@@ -98,21 +173,36 @@
98173
99 child_list = __get_active_child_list(node)174 child_list = __get_active_child_list(node)
100175
176 daysleft = None
101 for child_id in child_list:177 for child_id in child_list:
102 child = self.req.get_task(child_id)178 child = self.req.get_task(child_id)
103 color_of_child = self.get_node_bgcolor(child)179
104 if color_of_child > color:180 if child.get_due_date() == Date.no_date(): continue
105 color = color_of_child181
106 # This list should be implemented in the settings182 # color_of_child = self.get_node_bgcolor(child)
107 #print "Giving color"183 # if color_of_child > color:
108 return self._get_color(color)184 # color = color_of_child
185 # # This list should be implemented in the settings
186 # #print "Giving color"
187
188 daysleft_of_child = child.get_due_date().days_left()
189 if daysleft is None:
190 daysleft = daysleft_of_child
191 color = self.get_node_bgcolor(child)
192 elif daysleft_of_child < daysleft:
193 daysleft = daysleft_of_child
194 color = self.get_node_bgcolor(child)
195
196 # return self._get_color(color)
197 if color is None: print daysleft
198 return color
109199
110 def deactivate(self, plugin_api):200 def deactivate(self, plugin_api):
111 """ Plugin is deactivated """201 """ Plugin is deactivated """
112 self._plugin_api.set_bgcolor_func()202 self._plugin_api.set_bgcolor_func()
113203
114# Preferences dialog204# Preferences dialog
115 def is_configurable(self):205 def is_cfonfigurable(self):
116 """Requisite function for configurable plugins"""206 """Requisite function for configurable plugins"""
117 return True207 return True
118208
@@ -179,7 +269,7 @@
179 self.builder.connect_signals(SIGNAL_CONNECTIONS_DIC)269 self.builder.connect_signals(SIGNAL_CONNECTIONS_DIC)
180270
181 def prefs_update_widgets(self):271 def prefs_update_widgets(self):
182 """ Synchronizes the widgets with the data in _pref_data """272 """ Synchfronizes the widgets with the data in _pref_data """
183 # Spin button273 # Spin button
184 self.spinbutton_reddays.set_value(self._pref_data['reddays'])274 self.spinbutton_reddays.set_value(self._pref_data['reddays'])
185 # Colorbutton - OVERDUE275 # Colorbutton - OVERDUE
@@ -227,13 +317,13 @@
227 self._pref_data[new_key] = self._pref_data.pop(old_key)317 self._pref_data[new_key] = self._pref_data.pop(old_key)
228318
229 def prefs_store(self):319 def prefs_store(self):
230 self._plugin_api.save_configuration_object( \320 self._pluginf_api.save_configuration_object( \
231 self.PLUGIN_NAME,321 self.PLUGfIN_NAME,
232 'preferences',322 'preferences',
233 self._pref_data)323 self._pref_data)
234324
235 def on_prefs_spinbutton_reddays_changed(self, widget=None, data=None):325 def on_prefs_spinbutton_reddays_changed(self, widget=None, data=None):
236 self._pref_data_potential['reddays'] = \326 self._pfref_data_potential['reddays'] = \
237 self.spinbutton_reddays.get_value()327 self.spinbutton_reddays.get_value()
238328
239 def on_prefs_colorbutton_overdue_changed(self, widget=None, data=None):329 def on_prefs_colorbutton_overdue_changed(self, widget=None, data=None):

Subscribers

People subscribed via source and target branches

to status/vote changes: