更新。

This commit is contained in:
2022-04-21 23:52:16 +08:00
parent 1715735800
commit ca2e8c9155
17 changed files with 294 additions and 155 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Binary file not shown.

View File

@ -35,22 +35,23 @@ tipsColor = PURPLE
fontPattern = ('DengXian Light', 'Fira Code')
class disp:
'''音·创 的基本Tk窗口显示库'''
def __init__(
self,
root: tk.Tk = tk.Tk(),
debug: bool = False,
title: str = '音·创',
geometry: str = '0x0',
iconbitmap: tuple = ('', ''),
iconbitmap: tuple = ('./resources/musicreater.ico', './resources/musicreater.ico'),
menuWidget: dict = {},
wordView: str = '音·创 Musicreater',
buttons: list = [],
settingBox: list = [],
notemap: list = [],
infobar:str = '就绪',
infobar: str = '就绪',
) -> None:
'''使用参数建立基本的 音·创 窗口
:param root 根窗口
@ -73,13 +74,19 @@ class disp:
map: list = [ # 一首曲目的音符数据
音符数据
]
:param infobar 显示信息用
:param infobar str 显示信息用
'''
if debug:
log('载入参数')
# 载入参量 注意!图标将不被载入参数
self.__root = root
self.__root = tk.Tk()
'''窗口根'''
self.title = title
'''窗口标题'''
@ -87,7 +94,7 @@ class disp:
'''菜单设定项'''
self.wordView = wordView
'''言·论'''
'''言·论 所显示的文字'''
self.buttons = buttons
'''快捷功能按钮'''
@ -99,14 +106,13 @@ class disp:
'''音符列表'''
self.infoBar = infobar
'''信息显示版'''
'''信息显示版所显示的文字'''
self.debug = debug
'''是否打开调试模式'''
self.setTitle()
self.setGeometry(geometry)
self.setIcon(*iconbitmap)
@ -114,69 +120,82 @@ class disp:
self.initWidget()
def start(self) -> None:
# 启动主消息循环
self.__root.mainloop()
# =========================================================
# 设定函数部分
# =========================================================
def setTitle(self) -> None:
'''设置窗口标题'''
self.__root.title = self.title
if self.debug:
log(f"设置窗口标题{self.title}")
def setTitle(self, title: str = '') -> None:
'''设置窗口标题
:param title: str 窗口标题'''
def setGeometry(self,geometry:str = '0x0') -> None:
'''设置窗口大小'''
if title:
self.title = title
self.__root.title(self.title)
if self.debug:
log(f"设置窗口标题 {self.title}")
def setGeometry(self, geometry: str = '0x0') -> None:
'''设置窗口大小
:param geometry: str 窗口大小'''
self.__root.geometry(geometry)
if self.debug:
log(f"设置窗口大小{geometry}")
def setIcon(
self, bitmap: str = './musicreater.ico', default: str = ''
) -> None:
def setIcon(self, bitmap: str = './musicreater.ico', default: str = '') -> bool:
'''设置窗口图标
注意default参数仅在Windows下有效其意为将所有没有图标的窗口设置默认图标
如果在非Windows环境使用default参数一个Error将被升起'''
if not self.debug:
try:
if default:
self.__root.iconbitmap(bitmap, default)
log(f'设置图标为{bitmap},默认为{default}')
else:
self.__root.iconbitmap(bitmap)
log(f'设置图标为{bitmap}')
return True
except Exception as e:
log(str(e), 'ERROR')
return False
else:
self.__root.iconbitmap(bitmap, default)
return
:param bitmap: str 图标路径
:param default: str 设置对于全局的默认图标路径
注意default参数仅在Windows下有效其意为将所有没有图标的窗口设置默认图标。如果在非Windows环境使用default参数将会引发一个错误
:retuen bool 是否成功设置图标'''
try:
if default:
self.__root.iconbitmap(bitmap, default)
log(f'设置图标为{bitmap},默认为{default}')
else:
self.__root.iconbitmap(bitmap)
log(f'设置图标为{bitmap}')
return True
except Exception as e:
log(str(e), 'ERROR')
if self.debug:
raise e
return False
def setMenu(self) -> None:
'''设置根菜单'''
if not self.menuWidgets:
# 如果传入空参数则返回当前菜单
try:
return self.RootMenu
return self._RootMenu
except Exception as E:
if self.debug:
raise E
else:
log('无法读取菜单信息', 'WARRING')
log('无法读取菜单信息', 'WARRING')
# 如果不是空参数则新建菜单
self.RootMenu = {}
self.mainMenuBar = tk.Menu(self.__root)
log('新建一个菜单')
self._RootMenu = {}
self._mainMenuBar = tk.Menu(self.__root)
for menuName, menuCmd in self.menuWidgets.items():
# 取得一个菜单名和一堆菜单函数及其显示名称
menu = tk.Menu(self.mainMenuBar, tearoff=0)
menu = tk.Menu(self._mainMenuBar, tearoff=0)
for cmdName, cmdFunc in menuCmd.items():
if cmdName:
menu.add_command(label=cmdName, command=cmdFunc)
log('菜单项 -- ' + cmdName)
else:
menu.add_separator()
self.mainMenuBar.add_cascade(label=menuName, menu=menu)
self.RootMenu[menuName] = menu
self.__root.config(menu=self.mainMenuBar)
log('分隔符 -- 分隔符')
self._mainMenuBar.add_cascade(label=menuName, menu=menu)
self._RootMenu[menuName] = menu
log('计入一个菜单 -- ' + menuName)
self.__root.config(menu=self._mainMenuBar)
log('菜单设置完毕')
def addMenu(self, menuRoot: str = '', menuLabel: str = '', menuCommand=None):
'''增加一个菜单项
@ -186,27 +205,29 @@ class disp:
所需要增加的项目显示的文字
:param menuCommand : <function>
'''
if menuRoot in self.RootMenu.keys:
if menuRoot in self._RootMenu.keys:
# 如果已经有父菜单
if menuLabel:
# 增加菜单指令
self.RootMenu[menuRoot].add_command(
self._RootMenu[menuRoot].add_command(
label=menuLabel, command=menuCommand
)
else:
# 增加分隔栏
self.RootMenu[menuRoot].add_separator()
self._RootMenu[menuRoot].add_separator()
else:
# 没有父菜单则新增一个父菜单
menu = tk.Menu(self.mainMenuBar, tearoff=False)
menu = tk.Menu(self._mainMenuBar, tearoff=False)
if menuLabel:
menu.add_command(label=menuLabel, command=menuCommand)
else:
menu.add_separator()
self.mainMenuBar.add_cascade(label=menuRoot, menu=menu)
self.RootMenu[menuRoot] = menu
self._mainMenuBar.add_cascade(label=menuRoot, menu=menu)
self._RootMenu[menuRoot] = menu
def initWidget(self,) -> None:
def initWidget(
self,
) -> None:
'''设置窗口小部件,分为:
:言·论 WordView
:快捷按钮面板 ButtonBar
@ -216,84 +237,162 @@ class disp:
:信息显示版 InfoBar
'''
self._wordviewBar = tk.Label(
self.__root, bg='white', fg='black', text=self.wordView, font=(fontPattern[0], 30)
self.__root,
bg='black',
fg='white',
text=self.wordView,
font=(fontPattern[0], 30),
)
# 定义 言·论 版面
log('言·论版面设置完成')
self.setWordView(self.wordView)
self._infoBar = tk.Label(
self.__root,
bg='white',
fg='black',
text=self.infoBar,
font=(fontPattern[0], 10),
)
# 定义 信息显示版
log('信息显示版设置完成')
self._buttonBar = tk.Frame(
self.__root,
bd=2,
)
# 定义 快捷按钮面板. 注意这里是以一个Frame为容器而不是一个Button列表后面的版面也以Frame容器居多
self.setButtonBar(self.buttons)
self._wordviewBar.pack(side='top', fill='x')
self._buttonBar.pack(side='top', fill='x')
self._infoBar.pack(side='bottom', fill='x')
def setButtonBar(
self,
buttonList: list = [],
defaultMissingTexturePath: str = './resources/uimage/missing_texture.png',
separatorButtonTexturePath: str = './resources/uimage/separator_line.png',
) -> None:
'''设置快捷按钮面板
:param buttonList : list
快捷按钮列表,每个元素为一个字典,字典的键为按钮名称,值为一个元组,元组中第一项为按钮的图标,第二项为按钮的回调函数
'''
# 图标应该如下
# 新建 打开 保存 |
self._buttonBarList = []
'''按钮对象列表,注意软件调用的时候千万别动!'''
separatorimg = tk.PhotoImage(file=separatorButtonTexturePath)
for buttons in buttonList:
# 循环每个按钮组
for name, args in buttons.items():
# 循环每个按钮
try:
img = tk.PhotoImage(file=args[0])
except:
log('载入图片失败,使用默认图片','WARNING')
if self.debug:
raise FileNotFoundError(f'图片{args[0]}不存在')
img = tk.PhotoImage(file=defaultMissingTexturePath)
button = tk.Button(
self._buttonBar,
text=name,
command=args[1],
image=img,
bd=2,
compound='center',
font=(fontPattern[0], 10),
)
button.pack(side='left', padx=5, pady=5)
self._buttonBarList.append(button)
# 添加按钮
tk.Label(self._buttonBar, image=separatorimg).pack(
side='left', padx=5, pady=5
)
def setWordView(self, text: str) -> None:
'''重新设置言·论版的文字'''
self._wordviewBar['text'] = text
def setInfoBar(self, text: str) -> None:
'''重新设置信息显示版的文字'''
self._infoBar['text'] = text
# =========================================================
# 预置函数部分
# =========================================================
# =========================================================
# 预置函数部分
# =========================================================
def authorWindowStarter(
authors: tuple = (
('金羿', 'Email EillesWan@outlook.com', 'QQ 2647547478'),
('诸葛亮与八卦阵', 'QQ 474037765'),
)
):
'''自定义作者界面'''
from languages.lang import _
from languages.lang import DEFAULTLANGUAGE
from msctLib.buildIN import version
def authorWindowStarter(
authors: tuple = (
('金羿', 'Email EillesWan@outlook.com', 'QQ 2647547478'),
('诸葛亮与八卦阵', 'QQ 474037765'),
)
):
'''自定义作者界面'''
from languages.lang import _
from languages.lang import DEFAULTLANGUAGE
from msctLib.buildIN import version
authorWindow = tk.Tk()
authorWindow.title(_('关于'))
authorWindow.geometry('550x600') # 像素
tk.Label(authorWindow, text='', font=('', 15)).pack()
tk.Label(authorWindow, text=_('F音创'), font=('', 35)).pack()
tk.Label(
authorWindow,
text='{} {}'.format(version.version[1] + version.version[0]),
font=('', 15),
).pack()
# pack 的side可以赋值为LEFT RTGHT TOP BOTTOM
# grid 的row 是列数、column是行排注意这是针对空间控件本身大小来的即是指向当前控件的第几个。
# place的 x、y是(x,y)坐标
tk.Label(
authorWindow,
image=tk.PhotoImage(file='./resources/RyounLogo.png'),
width=200,
height=200,
).pack()
tk.Label(authorWindow, text=_('凌云pairs'), font=('', 20)).pack()
tk.Label(authorWindow, text='', font=('', 15)).pack()
tk.Label(authorWindow, text=_('开发者'), font=('', 15)).pack()
for i in authors:
for j in i:
authorWindow = tk.Tk()
authorWindow.title(_('关于'))
authorWindow.geometry('550x600') # 像素
tk.Label(authorWindow, text='', font=('', 15)).pack()
tk.Label(authorWindow, text=_('F音创'), font=('', 35)).pack()
tk.Label(
authorWindow,
text='{} {}'.format(version.version[1] + version.version[0]),
font=('', 15),
).pack()
# pack 的side可以赋值为LEFT RTGHT TOP BOTTOM
# grid 的row 是列数、column是行排注意这是针对空间控件本身大小来的即是指向当前控件的第几个。
# place的 x、y是(x,y)坐标
rylogo = tk.PhotoImage(file='./resources/RyounLogo.png')
tk.Label(
authorWindow,
image=rylogo,
width=200,
height=200,
).pack()
tk.Label(authorWindow, text=_('凌云pairs'), font=('', 20)).pack()
tk.Label(authorWindow, text='', font=('', 15)).pack()
tk.Label(authorWindow, text=_('开发者'), font=('', 15)).pack()
for i in authors:
for j in i:
tk.Label(
authorWindow,
text=j,
font=(
'',
17 if i.index(j) == 0 else 15,
'bold' if i.index(j) == 0 else '',
),
).pack()
tk.Label(authorWindow, text='', font=('', 5)).pack()
if DEFAULTLANGUAGE != 'zh-CN':
tk.Label(authorWindow, text=_('译者'), font=('', 15)).pack()
for i in _('TRANSLATERS').split(';'):
for j in i.split(','):
tk.Label(
authorWindow,
text=j,
font=(
'',
17 if i.index(j) == 0 else 15,
'bold' if i.index(j) == 0 else '',
17 if i.split(',').index(j) == 0 else 15,
'bold' if i.split(',').index(j) == 0 else '',
),
).pack()
tk.Label(authorWindow, text='', font=('', 5)).pack()
if DEFAULTLANGUAGE != 'zh-CN':
tk.Label(authorWindow, text=_('译者'), font=('', 15)).pack()
for i in _('TRANSLATERS').split(';'):
for j in i.split(','):
tk.Label(
authorWindow,
text=j,
font=(
'',
17 if i.split(',').index(j) == 0 else 15,
'bold' if i.split(',').index(j) == 0 else '',
),
).pack()
def exitAboutWindow():
authorWindow.destroy()
def exitAboutWindow():
authorWindow.destroy()
tk.Button(authorWindow, text=_('确定'), command=exitAboutWindow).pack()
tk.Button(authorWindow, text=_('确定'), command=exitAboutWindow).pack()
authorWindow.mainloop()
authorWindow.mainloop()
class ProgressBar:
@ -319,6 +418,10 @@ class ProgressBar:
self.root = root
# TODO
# 单选框与复选框
if __name__ == '__mian__':
import os

View File

@ -75,7 +75,7 @@ def log(info:str = '',level : str = 'INFO', isPrinted:bool = True):
f.write(outputinfo+'\n')
if isPrinted:
print(outputinfo)
input(outputinfo)
return True
except:

View File

@ -89,19 +89,24 @@ functions.py中会调取./addon/目录下的全部功能文件,这些功能文
5. `buttons`
快捷功能按钮的列表列表的元素为字典字典的键是按钮的名称值为一个元组元组中含有两个元素其中元组的第1个元素为按钮图标是一个图片的路径第2个元素为执行的函数其值应当是一个函数对象。
值得注意的是,每个字典中包含的按钮组件会分到一个组之中,两个组之间会使用分隔符分割
```python
button: list = [ # 操作按钮部分
dict{
button: list = [
dict{ # 操作按钮部分
str"按钮名称" : tuple(
按钮图标,
执行函数
)
),
...
},
...
],
```
其中,如果执行图标找不到了或者无法读取了,就会使用“材质丢失”图标作为图标,当然也可以通过函数`setButtonBar`中的参数`defaultMissingTexturePath`来设置默认的在职丢失图标路径,同理,使用`separatorButtonTexturePath`可以设置默认的分割线路径……
但是啊但是我虽然建议用不同的display库来达到不同的显示效果……但我没说你们都带一套自己的图标包撒想要绘制图标包也很简单我们之后应该会出图标包的加载工具
6. `settingBox`
@ -131,6 +136,7 @@ functions.py中会调取./addon/目录下的全部功能文件,这些功能文
7. `notemap`
音符数据表,用于存储曲谱信息,存储格式如下
```python
notemap: list = [ # 音轨列表
dict{ # 单个音轨
@ -165,21 +171,37 @@ functions.py中会调取./addon/目录下的全部功能文件,这些功能文
- 函数
1. `setMenu`对菜单的基础设定
1. `setTitle`设置窗口标题
```python
{
菜单名 : {
选项名 : 选项函数
}
}
:param title: str 窗口标题
```
注:
`菜单名` : `str` 显示在菜单上的字符串
`选项名` : `str` 显示在菜单选项上的字符串
`选项函数` : `function` 菜单调取的函数(无返回值,无入参)
当 `选项名` 的布尔值判定为 `False` 的时候,无论 `选项函数` 为何,皆插入一段分割线,但 `选项函数` 不得为空
修改了变量`self.title`之后需要执行此函数以切换标题,或者通过此函数修改窗口标题信息。
2. `setGeometry`设置窗口大小
```python
:param geometry: str 窗口大小
```
由于不希望您经常修改窗口大小,我就没有把窗口大小的变量放在类里面。只能通过这个函数来修改窗口大小。
3. `setIcon`设置窗口图标
```python
:param bitmap: str 图标路径
:param default: str 设置对于全局的默认图标路径
:retuen bool 是否成功设置图标
```
同上,我们不希望您经常修改窗口图标,所以没有把图标路径作为变量放在类里面。所以你只能通过这个函数修改窗口的图标。
值得注意的是default参数仅在Windows下有效如果在非Windows环境使用default参数将会引发一个错误
4. `setMenu`设置窗口菜单
实例化此类之后会运行这个函数进行窗口根菜单配置,如果当前对象中没有菜单,则会对其依照类中的响应参数进行配置,如果有则返回菜单中的内容(一个字典,键为菜单名称)
2. `setWidget`对窗口部件的放置
```python
@ -192,12 +214,7 @@ functions.py中会调取./addon/目录下的全部功能文件,这些功能文
按钮名称 : tuple(按钮图标,执行函数)
},
],
settingbox: list = [ #设置部分显示的字样及其对应的设置函数
(
设置名称:str,
值类型:tuple,
显示内容:str,
设置操作函数:<function>,
settingbox: list = [ #设置部分显示的字样及其对应的设置函数置操作函数:<function>,
)
],
map: list = [
@ -206,11 +223,6 @@ functions.py中会调取./addon/目录下的全部功能文件,这些功能文
```
注:
上文中,值类型可以是如下几个项
1. `('str',)` 字符串类型,使用文本框输入数据
2. `('bool',)` 布尔类型,使用复选框输入数据
3. `('num',最小值:int,最大值:int,步长:int = 1)` 数值类型,使用数值滑动条输入数据
4. `('list',列表项:list)` 单选类型,即列表中多选一,使用单选框输入数据
值得注意的是在kwgs中修改的部件设置可以在其变量中读取或热修改对应的变量如下