-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeMake.py
More file actions
82 lines (57 loc) · 2.02 KB
/
CodeMake.py
File metadata and controls
82 lines (57 loc) · 2.02 KB
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
import tkinter as tk
from tkinter import ttk
from tkinter.ttk import *
import os
import sys
from BaseFrame import BaseFrame
from CodeMgr import *
from TemplateFrame import TemplateFrame, getFrame
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
TEMPLATE_PATH = ROOT_PATH + '/templates'
sys.path.append(TEMPLATE_PATH)
CODE = 'code '
class CodeMake(BaseFrame):
def __init__(self, master=None, **kw) -> None:
super().__init__(master=master, **kw)
def afterInit(self):
super().afterInit()
f = self.top
ttk.Label(f, text='Template ').pack(side=tk.LEFT)
cb = self.tList = ttk.Combobox(
f, values=self.getTemplates(), state='readonly', width=30, font='宋体 15')
cb.current(0)
cb.pack(side=tk.LEFT, fill=tk.Y)
ttk.Button(f, text='show', command=self.show).pack(
side=tk.LEFT, padx=5)
ttk.Button(f, text='edit', command=self.edit).pack(
side=tk.LEFT, padx=(25, 5))
ttk.Button(f, text='clear', command=self.clear).pack(
side=tk.LEFT, padx=5)
ttk.Button(f, text='reload', command=self.reloadTemplates).pack(
side=tk.LEFT, padx=5)
def getTemplates(self):
return [x for x in os.listdir(TEMPLATE_PATH) if x.endswith('.py')]
def reloadTemplates(self):
cb = self.tList
cb.config(state='normal')
cb.delete(0, len(cb.get()))
cb['value'] = self.getTemplates()
cb.config(state='readonly')
def show(self):
cb = self.tList
if len(cb.get()) == 0:
return
temp = getTemplate(cb.get())
if temp is None:
toast(f'{cb.get()} is not valid template')
return
self.showTemplate(cb.get())
def showTemplate(self, name: str):
f = self.mid
ft = getFrame(name, f)
ft.pack(side=tk.TOP, anchor=tk.W)
def clear(self):
clearFrame(self.mid)
def edit(self):
cmd = f'{CODE} {TEMPLATE_PATH}/{self.tList.get()}'
os.popen(cmd)