Sat, 20 Oct 2012 21:52:00 +0200
Added the configuration page.
--- a/PluginTimeTracker.e4p Sat Oct 20 20:01:33 2012 +0200 +++ b/PluginTimeTracker.e4p Sat Oct 20 21:52:00 2012 +0200 @@ -19,10 +19,13 @@ <Source>TimeTracker/TimeTracker.py</Source> <Source>TimeTracker/TimeTrackEntry.py</Source> <Source>TimeTracker/TimeTrackerWidget.py</Source> + <Source>TimeTracker/ConfigurationPage/__init__.py</Source> + <Source>TimeTracker/ConfigurationPage/TimeTrackerPage.py</Source> </Sources> <Forms> <Form>TimeTracker/TimeTrackerEntryDialog.ui</Form> <Form>TimeTracker/TimeTrackerWidget.ui</Form> + <Form>TimeTracker/ConfigurationPage/TimeTrackerPage.ui</Form> </Forms> <Translations/> <Resources/>
--- a/PluginTimeTracker.py Sat Oct 20 20:01:33 2012 +0200 +++ b/PluginTimeTracker.py Sat Oct 20 21:52:00 2012 +0200 @@ -9,10 +9,12 @@ import os -from PyQt4.QtCore import QObject, QTranslator +from PyQt4.QtCore import QObject, QTranslator, QCoreApplication from E5Gui.E5Application import e5App +import Preferences + from TimeTracker.TimeTracker import TimeTracker # Start-Of-Header @@ -31,8 +33,48 @@ # End-Of-Header error = "" + +timeTrackerPluginObject = None +def createTimeTrackerPage(configDlg): + """ + Module function to create the Time Tracker configuration page. + + @return reference to the configuration page + """ + global timeTrackerPluginObject + from TimeTracker.ConfigurationPage.TimeTrackerPage import TimeTrackerPage + page = TimeTrackerPage(timeTrackerPluginObject) + return page + + +def getConfigData(): + """ + Module function returning data as required by the configuration dialog. + + @return dictionary containing the relevant data + """ + if e5App().getObject("UserInterface").versionIsNewer('5.2.99', '20121012'): + return { + "timeTrackerPage": \ + [QCoreApplication.translate("TimeTrackerPlugin", "Time Tracker"), + os.path.join("TimeTracker", "icons", + "clock.png"), + createTimeTrackerPage, None, None], + } + else: + return {} + + +def prepareUninstall(): + """ + Module function to prepare for an uninstallation. + """ + tracker = TimeTrackerPlugin(None) + tracker.prepareUninstall() + + class TimeTrackerPlugin(QObject): """ Class implementing the Eric assistant plugin. @@ -47,6 +89,12 @@ self.__ui = ui self.__initialize() + self.__defaults = { + "MinimumDuration": 2, + "AutoSave": False, + "AllowDuplicates": False, + } + self.__translator = None self.__loadTranslator() @@ -87,6 +135,9 @@ if not self.__checkVersions(): return None, False + global timeTrackerPluginObject + timeTrackerPluginObject = self + self.__object = TimeTracker(self, self.__ui) ## self.__object.initActions() e5App().registerPluginObject("TimeTracker", self.__object) @@ -133,3 +184,38 @@ print("Warning: translation file '{0}' could not be loaded."\ .format(translation)) print("Using default.") + + def getPreferences(self, key): + """ + Public method to retrieve the various settings. + + @param key the key of the value to get + @param prefClass preferences class used as the storage area + @return the requested setting + """ + if key in ["MinimumDuration"]: + return int(Preferences.Prefs.settings.value("TimeTracker/" + key, + self.__defaults[key])) + elif key in ["AutoSave", "AllowDuplicates"]: + return Preferences.toBool( + Preferences.Prefs.settings.value("TimeTracker/" + key, + self.__defaults[key])) + else: + return Preferences.Prefs.settings.value("TimeTracker/" + key, + self.__defaults[key]) + + def setPreferences(self, key, value): + """ + Public method to store the various settings. + + @param key the key of the setting to be set (string) + @param value the value to be set + @param prefClass preferences class used as the storage area + """ + Preferences.Prefs.settings.setValue("TimeTracker/" + key, value) + + def prepareUninstall(self): + """ + Public method to prepare for an uninstallation. + """ + Preferences.Prefs.settings.remove("TimeTracker")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TimeTracker/ConfigurationPage/TimeTrackerPage.py Sat Oct 20 21:52:00 2012 +0200 @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing the Time Tracker configuration page. +""" + +from Preferences.ConfigurationPages.ConfigurationPageBase import ConfigurationPageBase +from .Ui_TimeTrackerPage import Ui_TimeTrackerPage + + +class TimeTrackerPage(ConfigurationPageBase, Ui_TimeTrackerPage): + """ + Class implementing the Time Tracker configuration page. + """ + def __init__(self, plugin): + """ + Constructor + + @param plugin reference to the plugin object + """ + super().__init__() + self.setupUi(self) + self.setObjectName("TimeTrackerPage") + + self.__plugin = plugin + + # set initial values + self.durationSpinBox.setValue( + self.__plugin.getPreferences("MinimumDuration")) + self.autosaveCheckBox.setChecked( + self.__plugin.getPreferences("AutoSave")) + self.duplicatesCheckBox.setChecked( + self.__plugin.getPreferences("AllowDuplicates")) + + def save(self): + """ + Public slot to save the Pyramid configuration. + """ + self.__plugin.setPreferences("MinimumDuration", + self.durationSpinBox.value()) + self.__plugin.setPreferences("AutoSave", + self.autosaveCheckBox.isChecked()) + self.__plugin.setPreferences("AllowDuplicates", + self.duplicatesCheckBox.isChecked())
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TimeTracker/ConfigurationPage/TimeTrackerPage.ui Sat Oct 20 21:52:00 2012 +0200 @@ -0,0 +1,111 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>TimeTrackerPage</class> + <widget class="QWidget" name="TimeTrackerPage"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>495</width> + <height>253</height> + </rect> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="headerLabel"> + <property name="text"> + <string><b>Configure Time Tracker</b></string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line15"> + <property name="frameShape"> + <enum>QFrame::HLine</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Sunken</enum> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Minimum Duration:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QSpinBox" name="durationSpinBox"> + <property name="toolTip"> + <string>Enter the value of the minimum duration for a valid tracker entry</string> + </property> + <property name="suffix"> + <string> min</string> + </property> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>9</number> + </property> + </widget> + </item> + <item row="0" column="2"> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>78</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="0" colspan="3"> + <widget class="QCheckBox" name="autosaveCheckBox"> + <property name="toolTip"> + <string>Select to save automatically whenever a tracker is stopped</string> + </property> + <property name="text"> + <string>Auto Save Enabled</string> + </property> + </widget> + </item> + <item row="2" column="0" colspan="3"> + <widget class="QCheckBox" name="duplicatesCheckBox"> + <property name="toolTip"> + <string>Select to allow multiple entries with the same start date and time</string> + </property> + <property name="text"> + <string>Allow entries with identical start date and time</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>274</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TimeTracker/ConfigurationPage/__init__.py Sat Oct 20 21:52:00 2012 +0200 @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Package implementing the Time Tracker page of the configuration dialog. +"""