-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
95 lines (74 loc) · 3.16 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
# PEP8:OK, LINT:OK, PY3:OK
#############################################################################
## This file may be used under the terms of the GNU General Public
## License version 2.0 or 3.0 as published by the Free Software Foundation
## and appearing in the file LICENSE.GPL included in the packaging of
## this file. Please review the following information to ensure GNU
## General Public Licensing requirements will be met:
## http:#www.fsf.org/licensing/licenses/info/GPLv2.html and
## http:#www.gnu.org/copyleft/gpl.html.
##
## This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#############################################################################
# metadata
" NINJA-IDE Time Tracker "
__version__ = ' 0.2 '
__license__ = ' GPL '
__author__ = ' juancarlospaco '
__email__ = ' juancarlospaco@ubuntu.com '
__url__ = ''
__date__ = ' 20/06/2013 '
__prj__ = ' timetracker '
__docformat__ = 'html'
__source__ = ''
__full_licence__ = ''
# imports
from os import path
from sip import setapi
from subprocess import call
from PyQt4.QtGui import QIcon, QLabel, QDockWidget, QPushButton
try:
from PyKDE4.kdecore import KPluginLoader, KUrl
from PyKDE4.kparts import *
except ImportError:
pass
from ninja_ide.core import plugin
# API 2
(setapi(a, 2) for a in ("QDate", "QDateTime", "QString", "QTime", "QUrl",
"QTextStream", "QVariant"))
# constants
TRACK_FILE = path.abspath(path.join(path.expanduser("~"),
'.kde/share/apps/ktimetracker/ktimetracker.ics'))
###############################################################################
class Main(plugin.Plugin):
" dock Class "
def initialize(self):
" Init Class dock "
self.dock = QDockWidget()
self.dock.setFeatures(QDockWidget.DockWidgetFloatable |
QDockWidget.DockWidgetMovable)
self.dock.setWindowTitle(__doc__)
self.dock.setStyleSheet('QDockWidget::title{text-align: center;}')
self.boton = QPushButton(QIcon.fromTheme("document-open-recent"),
'Edit Track', self.dock)
self.boton.setToolTip('Edit iCal: {}'.format(TRACK_FILE))
try:
self.factory = KPluginLoader("ktimetrackerpart").factory()
self.part = self.factory.create(self)
self.part.setReadWrite(True)
self.part.closeUrl()
self.part.openUrl(KUrl(str(TRACK_FILE)))
self.boton.clicked.connect(lambda:
call('xdg-open {}'.format(TRACK_FILE), shell=True))
self.dock.setWidget(self.part.widget())
except:
self.dock.setWidget(QLabel(""" <center> <h3>ಠ_ಠ<br>
ERROR: Please, install kTimeTracker and PyKDE ! </h3><br>
<br><i> (Sorry, cant embed non-Qt Apps). </i><center>"""))
self.misc = self.locator.get_service('misc')
self.misc.add_widget(self.dock, QIcon.fromTheme("user-away"), __doc__)
###############################################################################
if __name__ == "__main__":
print(__doc__)