-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-ui-spreadsheet-frontend.py
104 lines (86 loc) · 2.96 KB
/
generate-ui-spreadsheet-frontend.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
#!/usr/bin/env python
#
#
# generate-ui-spreadsheet-frontend.py
#
# (c) Noprianto <nop@noprianto.com>
# 2017
# License: GPL
import os
import webbrowser
from Tkinter import *
from tkFileDialog import askopenfilename
import ttk
import ScrolledText
import openpyxl
import generate_ui_spreadsheet as module
TITLE = 'Pangsit User Interface Code Generator'
PADDING = 10
MAX_ROW = 10
MAX_COL = 10
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master.resizable(width=False, height=False)
self.master.rowconfigure(MAX_ROW)
self.master.columnconfigure(MAX_COL)
self.create_ui()
self.t = None
self.o = None
def create_ui(self):
label_output = Label(text='Available platform: ')
label_output.grid(column=0, row=0, padx=PADDING, pady=PADDING,
sticky=W)
column = 0
for t in module.TYPE.keys():
button = Button(text=t, command=lambda t=t: self.generate(t))
button.grid(column=column, row=1, padx=PADDING, pady=PADDING)
column += 1
label_input = Label(text='Input file: ')
label_input.grid(column=0, row=2, padx=PADDING, pady=PADDING,
columnspan=MAX_COL, sticky=W)
self.label_input_2 = Label()
self.label_input_2.grid(column=1, row=2, padx=PADDING, pady=PADDING,
columnspan=MAX_COL, sticky=W)
label_output = Label(text='Generated code: ')
label_output.grid(column=0, row=3, padx=PADDING, pady=PADDING,
columnspan=MAX_COL, sticky=W)
self.label_output_2 = Label()
self.label_output_2.grid(column=1, row=3, padx=PADDING, pady=PADDING,
columnspan=MAX_COL, sticky=W)
self.text = ScrolledText.ScrolledText()
self.text.grid(column=0, row=4, columnspan=MAX_COL,
padx=PADDING, pady=PADDING)
self.run_button = Button(text='Run', command=self.run)
self.run_button.grid(column=0, row=5, padx=PADDING, pady=PADDING,
sticky=W)
def generate(self, t):
f = askopenfilename()
if f:
self.label_input_2['text'] = f
try:
book = openpyxl.load_workbook(f)
except Exception, e:
self.text.insert(INSERT, e)
return
#
output_file = '%s%s' %(
os.path.splitext(f)[0], module.TYPE.get(t)[0])
#
self.o = output_file
self.t = t
self.label_output_2['text'] = output_file
module.generate(book, t, output_file)
self.text.delete('1.0', END)
self.text.insert(INSERT, open(output_file).read())
def run(self):
if self.t == 'python-tk':
os.system('python %s' %(self.o))
elif self.t == 'html':
webbrowser.open(self.o)
def main():
app = Application()
app.master.title(TITLE)
app.mainloop()
if __name__ == '__main__':
main()