-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpyubersicht.py
178 lines (136 loc) · 4.35 KB
/
pyubersicht.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# -*- coding: utf-8 -*-
# description for pyubersicht
import pathlib
import types
import jinja2
_DefaultDir = pathlib.Path('~/Library/Application Support/Übersicht/widgets').expanduser()
_Template = jinja2.Template('''
command: "{{command}}"
render: (output) -> """
<html>{{render}}</html>
"""
update: (output, domEl) ->
{{update}}
"""
<html>{{#output}}</html>
"""
style: """
{{style}}
"""
refreshFrequency: {{refreshFrequency}}
''')
_JSONTemplate = jinja2.Template('''
{
"name": "{{title}}",
"description": "{{description}}",
"author": "{{author}}",
"email": "{{email}}"
}
''')
_DefaultStyle = """
background: rgba(#fff, 0.5) url('übersicht-logo.png') no-repeat 50% 20px
background-size: 176px 84px
border-radius: 0px
border: 0px solid #fff
box-sizing: border-box
color: #141f33
font-family: Helvetica Neue
font-weight: 300
left: 50%
line-height: 1.5
margin-left: -170px
padding: 120px 20px 20px
top: 10%
width: 340px
text-align: justify
h1
font-size: 20px
font-weight: 300
margin: 16px 0 8px
em
font-weight: 400
font-style: normal
"""
_DefaultParamters = {"command": "python3 widget_title/script.py", "render": "#{output}", "update":"output", "refreshFrequency":"1000*3600", "style":_DefaultStyle}
class UbersichtBiulder(object):
'''UbersichtBiulder has 1 (principal) proptery
strategy: strategy
'''
path = _DefaultDir
@classmethod
def build(cls, widget):
folder = cls.path / widget.title
if not folder.exists():
folder.mkdir()
index = folder / 'index.coffee'
index.touch()
index.write_text(_Template.render(widget.parameter), encoding='utf-8')
json = cls.path / 'widget.json'
json.touch()
json.write_text(_JSONTemplate.render(widget.parameter))
class PyUbersichtBiulder(UbersichtBiulder):
'''UbersichtBiulder has 1 (principal) proptery
strategy: strategy
'''
@classmethod
def build(cls, widget):
widget.parameter['command'] = 'python3 %s/script.py'%widget.title
super(PyUbersichtBiulder, cls).build(widget)
script = cls.path / widget.title / 'script.py'
script.touch()
content = '''# -*- coding: utf-8 -*-
"""Python script for %s"""
# Business Logic
if __name__ == '__main__':
print('hello world')'''%widget.title
script.write_text(content)
class UbersichtWidget(object):
'''UbersichtWidget has 3 (principal) propteries
title: title
description: description
parameter: parameter
'''
def __init__(self, title='', description='', parameter={}):
self.title = title
self.description = description
self.parameter = _DefaultParamters.copy()
self.parameter.update(parameter)
self.otherfiles = []
self.folder = _DefaultDir / self.title
self.author = ''
self.email = '@'
def make(self):
UbersichtBiulder.build(self)
def select(self, builder=UbersichtBiulder):
self.make = types.MethodType(builder.build, self)
class PyUbersichtWidget(UbersichtWidget):
def __init__(self, title='', description='', parameter={}):
updatestr = """
output = 'Default Output'
exec = require('child_process').exec
exec "python3 %s -o output -d domEl", (err, stdout, stderr) -> output=stdout
""" % (_DefaultDir / title / "update.py")
parameter.update({'update': updatestr})
super(PyUbersichtWidget, self).__init__(title, description, parameter)
def make(self):
PyUbersichtBiulder.build(self)
script = self.folder / "update.py"
script.touch()
content = '''# -*- coding: utf-8 -*-
"""Python script for %s"""
import argparse
parser = argparse.ArgumentParser(description='Update desk.')
parser.add_argument('-o', dest='output', action='store', metavar='STRING', help='the current output')
parser.add_argument('-d', dest='domEl', action='store', metavar='STRING', help='DOM Elements')
args = parser.parse_args()
output = args.output
domEl = args.domEl
# (output, domEl) -> new output
print(output)'''%self.title
script.write_text(content)
if __name__ == '__main__':
# u = UbersichtWidget(title='schedule', description='a schedule for managing time.')
# builder = PyUbersichtBiulder
# builder.build(u)
u = PyUbersichtWidget(title='myschedule', description='My own schedule.')
u.make()