From f3c5044800ab8028baaead2b6ee1d6827ef0b04d Mon Sep 17 00:00:00 2001 From: EillesWan Date: Sun, 24 Apr 2022 17:56:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=92=A4=E9=94=80=E4=BA=86disp=E7=B1=BB?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E6=98=AFbug=E4=BE=9D=E6=97=A7=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=8F=98=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Musicreater.New.py | 18 +- msctLib/__pycache__/buildIN.cpython-38.pyc | Bin 1696 -> 1697 bytes msctLib/__pycache__/display.cpython-38.pyc | Bin 10633 -> 9922 bytes msctLib/buildIN.py | 2 +- msctLib/display.py | 545 +++++++++++---------- msctspt/bugReporter.py | 46 +- 6 files changed, 299 insertions(+), 312 deletions(-) diff --git a/Musicreater.New.py b/Musicreater.New.py index 8a87339..e4cc3e6 100644 --- a/Musicreater.New.py +++ b/Musicreater.New.py @@ -38,12 +38,12 @@ A free opensource software which is used for creating all kinds of musics in Min # 一定会好起来的 -from msctspt.bugReporter import version +from msctLib.buildIN import version __ver__ = f'{version.version[1]} {version.version[0]}' __author__ = '金羿Eilles' -from msctLib.display import * +import msctLib.display as disp from msctLib.function import * @@ -91,17 +91,19 @@ def __main__(): def test2(): print('???', end=' ') + + disp.__root = disp.tk.Tk() - window = disp( + disp.initWindow( geometry='1200x800', menuWidget={ '文件': {'新建': test, '打开': test}, '编辑': {'撤销': test, '重做': test}, '视图': {'缩放': test}, - '帮助': {'关于': authorWindowStarter}, + '帮助': {'关于': disp.authorWindowStarter}, }, - title='音·创 0.2 测试中', - buttons=[ + title_='音·创 0.2 测试中', + button=[ { '新建': ('', test2), '打开': ('', test2) @@ -110,10 +112,10 @@ def __main__(): '测试': ('', test2) } ], - debug=True, + Debug=True, ) - window.start() + disp.winstart() if __name__ == '__main__': diff --git a/msctLib/__pycache__/buildIN.cpython-38.pyc b/msctLib/__pycache__/buildIN.cpython-38.pyc index b8572ed324df16257b53d64562e28f19aef48aea..589c0d51a348650dafc8e05a839530de58297a61 100644 GIT binary patch delta 343 zcmZ3$yO5VRl$V!_0SK%YCne=inkfdXUHWJX3gw*dWqZ^x%2ErbQAV?pFO>TZlX-=vg6OdO7 HB3M`eYIsqu delta 342 zcmZ3;yMUKBl$V!_0SM&wTP5X9{xC~T! zKdU~Y@Z|TbT6!RBAc};5tXs^*B}GMGjVh>mpc>uTj5HATKmNHEN4GO7}QJq zV9<)HK0*6I-wV#IqywWGID~d8T{W%KLAn|&`(%F&j9g3CfoS zlrmU;I5*#PN**s_6j9b%?>69-NBjFblWT;io5cRLKLbV zRT6vN`MiUOBiee>B%aWE7bPNrvCkbTjs+&q@T{8>m$bg}cQfvzfjLs-+{*`c!R0)Y z9~<#b1XkYTZqAuZ1))rS)EjYFU^15%Sw1bJgpq;=c@^4TXoVv{e1%21LdhBM#wQN( zbw~9LNApcb_d|~1TaM|6osh3M77r)TU2gj-n)8USJ%|0Ml-68didLLf#V_@BB5JG` zdyNj^8mq-C#$cFc(mcLB{+KO3G4|P|0Xq)QLj$&0YbMn`TfA)ci(i}V;%{b$FhjlJ z#C3x`q0J4~UVr!M+dsMT^3ShKU92c<@oH$LTa3awKKt;)%a8x~^7E%bKa_|uTx4KK zC=bj;<2z~ZY!ECGgvH@64Q;`5 zJvg{1uFQ~GOc3R$a)Asb)WA%onCJ1p$~l>Q*7GLIYyb@BkyX%zMP~8^?l681dIg+Q zQQ11wC<&D<2Bz|Mf|}}syar9CMjtR-VHSj4;baDQOjoY59F z6j8fX^xIp@oiLKEL9zk~z8lsmUwOk*bdvP~c@bJcCaA6xo!HQ%9K2kDHgO>7Z}k$j zh><_%T^nx#_xu~~RlM6QB9T^+h-}*<9g{Q9_f86K@(vL=53OJVQ8eip%EbGT-f|q6 zw1gEHd=NNXh6L{^U{3Ax3G1sk=aX3#!K-*iRi6NSI&Pu-lK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Rhn_{z7%%2jzs&9iFa;+LX7CR9D@nuG+S<$4b^wWp6XyM}WVdIFwxP IGWtv7Kd`Htvj6}9 diff --git a/msctLib/buildIN.py b/msctLib/buildIN.py index 3bcf8a8..4a298ff 100644 --- a/msctLib/buildIN.py +++ b/msctLib/buildIN.py @@ -6,7 +6,7 @@ class version: libraries = ( 'mido', 'amulet', 'amulet-core', 'amulet-nbt', 'piano_transcription_inference', 'pypinyin', - 'pyinstaller', 'py7zr','websockets', 'torch', 'requests' + 'pyinstaller', 'py7zr','websockets', 'zhdate', 'requests' ) """当前所需库""" diff --git a/msctLib/display.py b/msctLib/display.py index 5f46e13..eca5e66 100644 --- a/msctLib/display.py +++ b/msctLib/display.py @@ -34,294 +34,323 @@ tipsColor = PURPLE # 注:UI界面字体、代码字体 fontPattern = ('DengXian Light', 'Fira Code') +global __root +global title +global menuWidgets +global wordView +global buttons +global settingBox +global notemap +global infoBar +global debug -class disp: - '''音·创 的基本Tk窗口显示库''' +__root = None +'''窗口根''' +# 音·创 的基本Tk窗口显示函数 - def __init__( - self, - debug: bool = False, - title: str = '音·创', - geometry: str = '0x0', - iconbitmap: tuple = ('./resources/musicreater.ico', './resources/musicreater.ico'), - menuWidget: dict = {}, - wordView: str = '音·创 Musicreater', - buttons: list = [], - settingBox: list = [], - notemap: list = [], - infobar: str = '就绪', - ) -> None: - '''使用参数建立基本的 音·创 窗口 - :param root 根窗口 - :param debug 是否将日志输出到控制台 - :param title 窗口标题 - wordview: str #言论部分显示的字样 - button: list = [ # 操作按钮部分 - dict = { - 按钮名称 : tuple(按钮图标,执行函数) - }, - ], - settingbox: list = [ # 设置部分显示的字样及其对应的设置函数 - ( - 设置名称:str, - 值类型:tuple, - 显示内容:str, - 设置操作函数:, - ) - ], - map: list = [ # 一首曲目的音符数据 - 音符数据 - ] - :param infobar str 显示信息用 - ''' +def initWindow( + Debug: bool = False, + title_: str = '音·创', + geometry: str = '0x0', + iconbitmap: tuple = ('./resources/musicreater.ico', './resources/musicreater.ico'), + menuWidget: dict = {}, + wordview: str = '音·创 Musicreater', + button: list = [], + settingbox: list = [], + notemap_: list = [], + infobar: str = '就绪', +) -> None: + '''使用参数建立基本的 音·创 窗口 + :param debug 是否将日志输出到控制台 + :param title 窗口标题 + wordview: str #言论部分显示的字样 + button: list = [ # 操作按钮部分 + dict = { + 按钮名称 : tuple(按钮图标,执行函数) + }, + ], + settingbox: list = [ # 设置部分显示的字样及其对应的设置函数 + ( + 设置名称:str, + 值类型:tuple, + 显示内容:str, + 设置操作函数:, + ) + ], + map: list = [ # 一首曲目的音符数据 + 音符数据 + ] + :param infobar str 显示信息用 + ''' - if debug: - log('载入参数') + if Debug: + log('载入参数') - # 载入参量 注意!图标将不被载入参数 + # 载入参量 注意!图标将不被载入参数 + + global title + global menuWidgets + global wordView + global buttons + global settingBox + global notemap + global infoBar + global debug - self.__root = tk.Tk() - '''窗口根''' + title = title_ + '''窗口标题''' - self.title = title - '''窗口标题''' + menuWidgets = menuWidget + '''菜单设定项''' - self.menuWidgets = menuWidget - '''菜单设定项''' + wordView = wordview + '''言·论 所显示的文字''' - self.wordView = wordView - '''言·论 所显示的文字''' + buttons = button + '''快捷功能按钮''' - self.buttons = buttons - '''快捷功能按钮''' + settingBox = settingbox + '''设置框''' - self.settingBox = settingBox - '''设置框''' + notemap = notemap_ + '''音符列表''' - self.notemap = notemap - '''音符列表''' + infoBar = infobar + '''信息显示版所显示的文字''' - self.infoBar = infobar - '''信息显示版所显示的文字''' + debug = Debug + '''是否打开调试模式''' - self.debug = debug - '''是否打开调试模式''' + setTitle() - self.setTitle() + setGeometry(geometry) + setIcon(*iconbitmap) - self.setGeometry(geometry) - self.setIcon(*iconbitmap) + setMenu() - self.setMenu() + initWidget() - self.initWidget() +def winstart() -> None: + # 启动主消息循环 + __root.mainloop() - def start(self) -> None: - # 启动主消息循环 - self.__root.mainloop() +# ========================================================= +# 设定函数部分 +# ========================================================= - # ========================================================= - # 设定函数部分 - # ========================================================= +def setTitle( title_: str = '') -> None: + '''设置窗口标题 + :param title: str 窗口标题''' + global title + if title: + title = title_ + __root.title(title) + if debug: + log(f"设置窗口标题 {title}") - def setTitle(self, title: str = '') -> None: - '''设置窗口标题 - :param title: str 窗口标题''' +def setGeometry( geometry: str = '0x0') -> None: + '''设置窗口大小 + :param geometry: str 窗口大小''' + __root.geometry(geometry) + if debug: + log(f"设置窗口大小{geometry}") - if title: - self.title = title - self.__root.title(self.title) - if self.debug: - log(f"设置窗口标题 {self.title}") +def setIcon( bitmap: str = './musicreater.ico', default: str = '') -> bool: + '''设置窗口图标 + :param bitmap: str 图标路径 + :param default: str 设置对于全局的默认图标路径 + 注意,default参数仅在Windows下有效,其意为将所有没有图标的窗口设置默认图标。如果在非Windows环境使用default参数,将会引发一个错误 + :retuen bool 是否成功设置图标''' - 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 = '') -> bool: - '''设置窗口图标 - :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 - except Exception as E: - if self.debug: - raise E - log('无法读取菜单信息', 'WARRING') - # 如果不是空参数则新建菜单 - log('新建一个菜单') - - self._RootMenu = {} - self._mainMenuBar = tk.Menu(self.__root) - for menuName, menuCmd in self.menuWidgets.items(): - # 取得一个菜单名和一堆菜单函数及其显示名称 - 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() - 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): - '''增加一个菜单项 - :param menuRoot : str - 菜单的根菜单,即所属的菜单上的文字 - :param menuLabel : str - 所需要增加的项目显示的文字 - :param menuCommand : - ''' - if menuRoot in self._RootMenu.keys: - # 如果已经有父菜单 - if menuLabel: - # 增加菜单指令 - self._RootMenu[menuRoot].add_command( - label=menuLabel, command=menuCommand - ) - else: - # 增加分隔栏 - self._RootMenu[menuRoot].add_separator() + try: + if default: + __root.iconbitmap(bitmap, default) + log(f'设置图标为{bitmap},默认为{default}') else: - # 没有父菜单则新增一个父菜单 - menu = tk.Menu(self._mainMenuBar, tearoff=False) - if menuLabel: - menu.add_command(label=menuLabel, command=menuCommand) + __root.iconbitmap(bitmap) + log(f'设置图标为{bitmap}') + return True + except Exception as e: + log(str(e), 'ERROR') + if debug: + raise e + return False + +def setMenu() -> None: + '''设置根菜单''' + + global _RootMenu + global _mainMenuBar + + if not menuWidgets: + # 如果传入空参数则返回当前菜单 + try: + return _RootMenu + except Exception as E: + if debug: + raise E + log('无法读取菜单信息', 'WARRING') + # 如果不是空参数则新建菜单 + log('新建一个菜单') + + _RootMenu = {} + _mainMenuBar = tk.Menu(__root) + for menuName, menuCmd in menuWidgets.items(): + # 取得一个菜单名和一堆菜单函数及其显示名称 + menu = tk.Menu(_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=menuRoot, menu=menu) - self._RootMenu[menuRoot] = menu + log('分隔符 -- 分隔符') + _mainMenuBar.add_cascade(label=menuName, menu=menu) + _RootMenu[menuName] = menu + log('计入一个菜单 -- ' + menuName) + __root.config(menu=_mainMenuBar) + log('菜单设置完毕') - def initWidget( - self, - ) -> None: - '''设置窗口小部件,分为: - :言·论 WordView - :快捷按钮面板 ButtonBar - :设置框 SettingBar - :音轨框 TrackBar - :各个音轨的显示框 TrackFrame - :信息显示版 InfoBar - ''' - self._wordviewBar = tk.Label( - self.__root, - bg='black', - fg='white', - text=self.wordView, - font=(fontPattern[0], 30), - ) - # 定义 言·论 版面 - log('言·论版面设置完成') +def addMenu( menuRoot: str = '', menuLabel: str = '', menuCommand=None): + '''增加一个菜单项 + :param menuRoot : str + 菜单的根菜单,即所属的菜单上的文字 + :param menuLabel : str + 所需要增加的项目显示的文字 + :param menuCommand : + ''' + + global _RootMenu + global _mainMenuBar - 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 + if menuRoot in _RootMenu.keys: + # 如果已经有父菜单 + if menuLabel: + # 增加菜单指令 + _RootMenu[menuRoot].add_command( + label=menuLabel, command=menuCommand ) + else: + # 增加分隔栏 + _RootMenu[menuRoot].add_separator() + else: + # 没有父菜单则新增一个父菜单 + menu = tk.Menu(_mainMenuBar, tearoff=False) + if menuLabel: + menu.add_command(label=menuLabel, command=menuCommand) + else: + menu.add_separator() + _mainMenuBar.add_cascade(label=menuRoot, menu=menu) + _RootMenu[menuRoot] = menu - def setWordView(self, text: str) -> None: - '''重新设置言·论版的文字''' - self._wordviewBar['text'] = text +def initWidget( + +) -> None: + '''设置窗口小部件,分为: + :言·论 WordView + :快捷按钮面板 ButtonBar + :设置框 SettingBar + :音轨框 TrackBar + :各个音轨的显示框 TrackFrame + :信息显示版 InfoBar + ''' - def setInfoBar(self, text: str) -> None: - '''重新设置信息显示版的文字''' - self._infoBar['text'] = text + global _wordviewBar + global _infoBar + global _buttonBar + + _wordviewBar = tk.Label( + __root, + bg='black', + fg='white', + text=wordView, + font=(fontPattern[0], 30), + ) + # 定义 言·论 版面 + log('言·论版面设置完成') + + _infoBar = tk.Label( + __root, + bg='white', + fg='black', + text=infoBar, + font=(fontPattern[0], 10), + ) + # 定义 信息显示版 + log('信息显示版设置完成') + + _buttonBar = tk.Frame( + __root, + bd=2, + ) + # 定义 快捷按钮面板. 注意!这里是以一个Frame为容器,而不是一个Button列表,后面的版面也以Frame容器居多 + + setButtonBar(buttons) + + _wordviewBar.pack(side='top', fill='x') + _buttonBar.pack(side='top', fill='x') + + _infoBar.pack(side='bottom', fill='x') + +def setButtonBar( + + buttonList: list = [], + defaultMissingTexturePath: str = './resources/uimage/missing_texture.png', + separatorButtonTexturePath: str = './resources/uimage/separator_line.png', +) -> None: + '''设置快捷按钮面板 + :param buttonList : list + 快捷按钮列表,每个元素为一个字典,字典的键为按钮名称,值为一个元组,元组中第一项为按钮的图标,第二项为按钮的回调函数 + ''' + + # 图标应该如下 + # 新建 打开 保存 | + + global _buttonBarList + + _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 debug: + raise FileNotFoundError(f'图片{args[0]}不存在') + img = tk.PhotoImage(file=defaultMissingTexturePath) + button = tk.Button( + _buttonBar, + text=name, + command=args[1], + image=img, + bd=2, + compound='center', + font=(fontPattern[0], 10), + ) + button.pack(side='left', padx=5, pady=5) + _buttonBarList.append(button) + # 添加按钮 + tk.Label(_buttonBar, image=separatorimg).pack( + side='left', padx=5, pady=5 + ) + +def setWordView( text: str) -> None: + '''重新设置言·论版的文字''' + _wordviewBar['text'] = text + +def setInfoBar( text: str) -> None: + '''重新设置信息显示版的文字''' + _infoBar['text'] = text # ========================================================= # 预置函数部分 @@ -345,7 +374,7 @@ def authorWindowStarter( tk.Label(authorWindow, text=_('F音创'), font=('', 35)).pack() tk.Label( authorWindow, - text='{} {}'.format(version.version[1] + version.version[0]), + text='{} {}'.format(version.version[1] , version.version[0]), font=('', 15), ).pack() # pack 的side可以赋值为LEFT RTGHT TOP BOTTOM @@ -397,7 +426,7 @@ def authorWindowStarter( class ProgressBar: def __init__( - self, + root: tk.Tk = tk.Tk(), style: tuple = (DEFAULTBLUE, BLACK, WHITE), type: bool = False, @@ -415,7 +444,7 @@ class ProgressBar: 显示的附加信息 :param debug : bool 是否输出日志到控制台''' - self.root = root + root = root # TODO @@ -426,4 +455,4 @@ if __name__ == '__mian__': import os os.chdir('../') - disp.authorMenu() + authorWindowStarter() diff --git a/msctspt/bugReporter.py b/msctspt/bugReporter.py index 03cf602..a1a62cf 100644 --- a/msctspt/bugReporter.py +++ b/msctspt/bugReporter.py @@ -90,48 +90,4 @@ class report: os.remove("./Temps&Logs.zip") -class version: - libraries = ( - 'mido', 'amulet', 'amulet-core', 'amulet-nbt', 'piano_transcription_inference', 'pypinyin', - 'pyinstaller', 'py7zr','websockets', 'torch', 'requests', 'zhdate' - ) - """当前所需库""" - - version = ('0.1.6', 'Delta',) - """当前版本""" - - def __init__(self) -> None: - - self.libraries = version.libraries - """当前所需库""" - - self.version = version.version - """当前版本""" - - - def installLibraries(self,index:str = 'https://pypi.tuna.tsinghua.edu.cn/simple'): - """安装全部开发用库""" - from sys import platform - import os - if platform == 'win32': - import shutil - try: - shutil.rmtree(os.getenv('APPDATA') + '\\Musicreater\\') - except FileNotFoundError: - pass - for i in self.libraries: - print("安装库:" + i) - os.system(f"python -m pip install {i} -i {index}") - elif platform == 'linux': - os.system("sudo apt-get install python3-pip") - os.system("sudo apt-get install python3-tk") - os.system("sudo apt-get install python3-tkinter") - for i in self.libraries: - print("安装库:" + i) - os.system(f"sudo python3 -m pip install {i} -i {index}") - - - def __call__(self): - '''直接安装库,顺便返回一下当前版本''' - self.installLibraries() - return self.version +from msctLib.buildIN import version \ No newline at end of file