7 Module implementing the Time Tracker plugin. |
7 Module implementing the Time Tracker plugin. |
8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt4.QtCore import QObject, QTranslator |
12 from PyQt4.QtCore import QObject, QTranslator, QCoreApplication |
13 |
13 |
14 from E5Gui.E5Application import e5App |
14 from E5Gui.E5Application import e5App |
|
15 |
|
16 import Preferences |
15 |
17 |
16 from TimeTracker.TimeTracker import TimeTracker |
18 from TimeTracker.TimeTracker import TimeTracker |
17 |
19 |
18 # Start-Of-Header |
20 # Start-Of-Header |
19 name = "Time Tracker Plugin" |
21 name = "Time Tracker Plugin" |
29 needsRestart = False |
31 needsRestart = False |
30 pyqtApi = 2 |
32 pyqtApi = 2 |
31 # End-Of-Header |
33 # End-Of-Header |
32 |
34 |
33 error = "" |
35 error = "" |
34 |
36 |
|
37 timeTrackerPluginObject = None |
|
38 |
|
39 |
|
40 def createTimeTrackerPage(configDlg): |
|
41 """ |
|
42 Module function to create the Time Tracker configuration page. |
|
43 |
|
44 @return reference to the configuration page |
|
45 """ |
|
46 global timeTrackerPluginObject |
|
47 from TimeTracker.ConfigurationPage.TimeTrackerPage import TimeTrackerPage |
|
48 page = TimeTrackerPage(timeTrackerPluginObject) |
|
49 return page |
|
50 |
|
51 |
|
52 def getConfigData(): |
|
53 """ |
|
54 Module function returning data as required by the configuration dialog. |
|
55 |
|
56 @return dictionary containing the relevant data |
|
57 """ |
|
58 if e5App().getObject("UserInterface").versionIsNewer('5.2.99', '20121012'): |
|
59 return { |
|
60 "timeTrackerPage": \ |
|
61 [QCoreApplication.translate("TimeTrackerPlugin", "Time Tracker"), |
|
62 os.path.join("TimeTracker", "icons", |
|
63 "clock.png"), |
|
64 createTimeTrackerPage, None, None], |
|
65 } |
|
66 else: |
|
67 return {} |
|
68 |
|
69 |
|
70 def prepareUninstall(): |
|
71 """ |
|
72 Module function to prepare for an uninstallation. |
|
73 """ |
|
74 tracker = TimeTrackerPlugin(None) |
|
75 tracker.prepareUninstall() |
|
76 |
35 |
77 |
36 class TimeTrackerPlugin(QObject): |
78 class TimeTrackerPlugin(QObject): |
37 """ |
79 """ |
38 Class implementing the Eric assistant plugin. |
80 Class implementing the Eric assistant plugin. |
39 """ |
81 """ |
44 @param ui reference to the user interface object (UI.UserInterface) |
86 @param ui reference to the user interface object (UI.UserInterface) |
45 """ |
87 """ |
46 QObject.__init__(self, ui) |
88 QObject.__init__(self, ui) |
47 self.__ui = ui |
89 self.__ui = ui |
48 self.__initialize() |
90 self.__initialize() |
|
91 |
|
92 self.__defaults = { |
|
93 "MinimumDuration": 2, |
|
94 "AutoSave": False, |
|
95 "AllowDuplicates": False, |
|
96 } |
49 |
97 |
50 self.__translator = None |
98 self.__translator = None |
51 self.__loadTranslator() |
99 self.__loadTranslator() |
52 |
100 |
53 self.__e5project = e5App().getObject("Project") |
101 self.__e5project = e5App().getObject("Project") |
84 global error |
132 global error |
85 error = "" # clear previous error |
133 error = "" # clear previous error |
86 |
134 |
87 if not self.__checkVersions(): |
135 if not self.__checkVersions(): |
88 return None, False |
136 return None, False |
|
137 |
|
138 global timeTrackerPluginObject |
|
139 timeTrackerPluginObject = self |
89 |
140 |
90 self.__object = TimeTracker(self, self.__ui) |
141 self.__object = TimeTracker(self, self.__ui) |
91 ## self.__object.initActions() |
142 ## self.__object.initActions() |
92 e5App().registerPluginObject("TimeTracker", self.__object) |
143 e5App().registerPluginObject("TimeTracker", self.__object) |
93 |
144 |
131 e5App().installTranslator(self.__translator) |
182 e5App().installTranslator(self.__translator) |
132 else: |
183 else: |
133 print("Warning: translation file '{0}' could not be loaded."\ |
184 print("Warning: translation file '{0}' could not be loaded."\ |
134 .format(translation)) |
185 .format(translation)) |
135 print("Using default.") |
186 print("Using default.") |
|
187 |
|
188 def getPreferences(self, key): |
|
189 """ |
|
190 Public method to retrieve the various settings. |
|
191 |
|
192 @param key the key of the value to get |
|
193 @param prefClass preferences class used as the storage area |
|
194 @return the requested setting |
|
195 """ |
|
196 if key in ["MinimumDuration"]: |
|
197 return int(Preferences.Prefs.settings.value("TimeTracker/" + key, |
|
198 self.__defaults[key])) |
|
199 elif key in ["AutoSave", "AllowDuplicates"]: |
|
200 return Preferences.toBool( |
|
201 Preferences.Prefs.settings.value("TimeTracker/" + key, |
|
202 self.__defaults[key])) |
|
203 else: |
|
204 return Preferences.Prefs.settings.value("TimeTracker/" + key, |
|
205 self.__defaults[key]) |
|
206 |
|
207 def setPreferences(self, key, value): |
|
208 """ |
|
209 Public method to store the various settings. |
|
210 |
|
211 @param key the key of the setting to be set (string) |
|
212 @param value the value to be set |
|
213 @param prefClass preferences class used as the storage area |
|
214 """ |
|
215 Preferences.Prefs.settings.setValue("TimeTracker/" + key, value) |
|
216 |
|
217 def prepareUninstall(self): |
|
218 """ |
|
219 Public method to prepare for an uninstallation. |
|
220 """ |
|
221 Preferences.Prefs.settings.remove("TimeTracker") |