TimeTracker/TimeTracker.py

changeset 21
28b7956c9608
parent 15
645506ab3376
child 31
db0afa672b75
equal deleted inserted replaced
20:b907cb69c2c7 21:28b7956c9608
7 Module implementing the time tracker object. 7 Module implementing the time tracker object.
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt4.QtCore import QObject 12 from PyQt4.QtCore import Qt, QObject
13 from PyQt4.QtGui import QKeySequence
13 14
14 from E5Gui.E5Application import e5App 15 from E5Gui.E5Application import e5App
15 from E5Gui import E5MessageBox 16 from E5Gui import E5MessageBox
17 from E5Gui.E5Action import E5Action
16 18
17 from .TimeTrackEntry import TimeTrackEntry 19 from .TimeTrackEntry import TimeTrackEntry
18 from .TimeTrackerWidget import TimeTrackerWidget 20 from .TimeTrackerWidget import TimeTrackerWidget
19 21
20 import UI.PixmapCache 22 import UI.PixmapCache
37 39
38 self.__plugin = plugin 40 self.__plugin = plugin
39 self.__ui = parent 41 self.__ui = parent
40 42
41 self.__e5project = e5App().getObject("Project") 43 self.__e5project = e5App().getObject("Project")
42 44
45 def __initialize(self):
46 """
47 Public slot to initialize some member variables.
48 """
49 self.__projectPath = ''
50 self.__trackerFilePath = ''
51 self.__projectOpen = False
52
53 self.__entries = {} # key: entry ID, value tracker entry
54 self.__currentEntry = None
55
56 self.__widget.clear()
57 self.__widget.setEnabled(False)
58
59 def activate(self):
60 """
61 Public method to activate the time tracker.
62 """
43 self.__widget = TimeTrackerWidget(self) 63 self.__widget = TimeTrackerWidget(self)
44 self.__ui.addSideWidget(self.__ui.BottomSide, self.__widget, 64 self.__ui.addSideWidget(self.__ui.BottomSide, self.__widget,
45 UI.PixmapCache.getIcon(os.path.join("TimeTracker", "icons", "clock.png")), 65 UI.PixmapCache.getIcon(os.path.join("TimeTracker", "icons", "clock.png")),
46 self.tr("Time Tracker")) 66 self.tr("Time Tracker"))
47 67
68 self.__activateAct = E5Action(self.trUtf8('Time Tracker'),
69 self.trUtf8('T&ime Tracker'),
70 QKeySequence(self.trUtf8("Alt+Shift+I")),
71 0, self,
72 'time_tracker_activate')
73 self.__activateAct.setStatusTip(self.trUtf8(
74 "Switch the input focus to the Time Tracker window."))
75 self.__activateAct.setWhatsThis(self.trUtf8(
76 """<b>Activate Time Tracker</b>"""
77 """<p>This switches the input focus to the Time Tracker window.</p>"""
78 ))
79 self.__activateAct.triggered[()].connect(self.__activateWidget)
80
81 self.__ui.addE5Actions([self.__activateAct], 'ui')
82 menu = self.__ui.getMenu("subwindow")
83 menu.addAction(self.__activateAct)
84
48 self.__initialize() 85 self.__initialize()
49 86
50 def __initialize(self): 87 def deactivate(self):
51 """ 88 """
52 Public slot to initialize some member variables. 89 Public method to deactivate the time tracker.
53 """ 90 """
54 self.__projectPath = '' 91 menu = self.__ui.getMenu("subwindow")
55 self.__trackerFilePath = '' 92 menu.removeAction(self.__activateAct)
56 self.__projectOpen = False 93 self.__ui.removeE5Actions([self.__activateAct], 'ui')
57 94 self.__ui.removeSideWidget(self.__widget)
58 self.__entries = {} # key: entry ID, value tracker entry
59 self.__currentEntry = None
60
61 self.__widget.clear()
62 self.__widget.setEnabled(False)
63 95
64 def projectOpened(self): 96 def projectOpened(self):
65 """ 97 """
66 Public slot to handle the projectOpened signal. 98 Public slot to handle the projectOpened signal.
67 """ 99 """
82 114
83 def projectClosed(self): 115 def projectClosed(self):
84 """ 116 """
85 Public slot to handle the projectClosed signal. 117 Public slot to handle the projectClosed signal.
86 """ 118 """
87 self.stopTrackerEntry() 119 if self.__projectOpen:
88 self.saveTrackerEntries() 120 self.stopTrackerEntry()
121 self.saveTrackerEntries()
89 self.__initialize() 122 self.__initialize()
90 123
91 def __readTrackerEntries(self): 124 def __readTrackerEntries(self):
92 """ 125 """
93 Private slot to read the time tracker entries from a file. 126 Private slot to read the time tracker entries from a file.
400 433
401 @param key the key of the value to get 434 @param key the key of the value to get
402 @return the requested setting 435 @return the requested setting
403 """ 436 """
404 return self.__plugin.getPreferences(key) 437 return self.__plugin.getPreferences(key)
438
439 def __activateWidget(self):
440 """
441 Private slot to handle the activation of the project browser.
442 """
443 if self.__ui.layout == "Toolboxes":
444 self.__ui.hToolboxDock.show()
445 self.__ui.hToolboxDock.setCurrentWidget(self.__widget)
446 elif self.__ui.layout == "Sidebars":
447 self.__ui.bottomSidebar.show()
448 self.__ui.bottomSidebar.setCurrentWidget(self.__widget)
449 else:
450 self.__widget.show()
451 self.__widget.setFocus(Qt.ActiveWindowFocusReason)

eric ide

mercurial