代码重构第一步

This commit is contained in:
2022-02-06 18:59:45 +08:00
parent c4dd7b1ce8
commit aa210ac678
7 changed files with 132 additions and 18 deletions

View File

@ -78,7 +78,7 @@ class jsonIO:
class uniteIO:
def __init__(self,fileName:str,fileType,data: Any = None) -> None:
def __init__(self,fileName:str,fileType = None,data: Any = None) -> None:
'''简单的文件数据IO操作功能'''
self.filename = fileName
if not fileType is None:
@ -91,21 +91,12 @@ class uniteIO:
with open (self.file, 'rb') as f:
self._type = pickle
if self._type == json:
with open (self.filename, 'r', encoding='utf-8') as f:
self._rfile = f
with open (self.filename, 'w', encoding='utf-8') as f:
self._wfile = f
elif self._type == pickle:
with open (self.file, 'rb') as f:
self._rfile = f
with open (self.file, 'wb') as f:
self._wfile = f
if not data is None:
self._data = data
else:
self._data = self._type.load(self._rfile)
self._data = self.load()
def __call__(self, *args: Any, **kwds: Any) -> Any:
@ -113,11 +104,19 @@ class uniteIO:
def write(self):
'''将数据写入文件'''
if self._type == json:
self._wfile = open(self.filename, 'w', encoding='utf-8')
elif self._type == pickle:
self._wfile = open(self.file, 'wb')
self._type.dump(self._data, self._wfile)
def load(self) -> Any:
'''从文件读取数据'''
if self._type == json:
self._rfile = open(self.filename, 'r', encoding='utf-8')
elif self._type == pickle:
self._rfile = open(self.file, 'rb')
self._data = self._type.load(self._rfile)
return self.data
@ -131,4 +130,4 @@ if __name__ == '__main__':
from sys import argv
if argv[1]:
input(pickle(argv[1]).data)
input(uniteIO(argv[1]).data)

47
msctLib/display.py Normal file
View File

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
'''音·创的GUI界面显示库
:若要使用其他界面显示,请详见:
:开发说明|指南'''
import tkinter as tk
import tkinter.simpledialog as sdialog
import tkinter.filedialog as fdialog
root = tk.Tk()
class disp:
def __init__(self,root:tk.Tk = root,debug:bool = False,**kwgs) -> None:
'''传入root参数为窗口根kwgs详见开发说明|指南'''
self.root = root
self.FUNCLIST = {
'title' : self.setTitle,
'geometry': self.setGeometry,
'iconbitmap': self.setIcon,
}
'''此处为引导传参若传参错误且debug模式关闭则不会有任何反馈'''
def setTitle(self,title:str = '') -> None:
self.root.title = title
def setGeometry(self,geometry) -> None:
self.root.geometry(geometry)
def setIcon(self,*icon) -> None:
self.root.iconbitmap(*icon)
def setMenu(self,**kwgs) -> None:
menus = []
mainMenuBar = tk.Menu(self.root)
for menuName,menuCmd in kwgs.items():
menu = tk.Menu(mainMenuBar,tearoff=0)
for cmdName,cmdFunc in menuCmd.items():
if cmdName:
menu.add_command(label = cmdName, command = cmdFunc)
else:
menu.add_separator()
mainMenuBar.add_cascade(label=menuName,menu=menu)
menus.append(menu)

View File

@ -0,0 +1,41 @@
# 开发说明\|指南
此文件旨在使后期欲参与开发之人员减轻其开发负担,同时也为了我们正在开发的人员详细说明功能与用法
掌握开发指南之后,在调用函数等的过程中将会更加方便
## 文件结构
从主文件调用display.py以实现显示调用functions.py以使用功能
functions.py中会调取./addon/目录下的全部功能文件,这些功能文件必须先由./addon/addons.pkl来预先定义好
## 详细说明
### msctLib
用于支持主要功能
#### display.py
1. class disp
- 参数
1. `**kwgs`对窗口的基础设定
`{ '组件名称' : 函数自设定 }`
例如:
```python
{
'version': '0.0.1' # version指的是
'title': "音·创",
'geometry': '1200x900',
'iconbitmap': ('./resources/musicreater.ico', './resources/musicreater.ico'),
'menu' : { #对setMenu有特殊说明
'文件': {
'新建': lambda : x,
'打开': lambda : x,
},
},
}
```
- 函数
1. `setMenu`对菜单的基础设定