无主要的修改,即将更换窗口库

This commit is contained in:
EillesWan 2022-05-11 15:19:40 +08:00
parent f3c5044800
commit 7357a09e5f
15 changed files with 212 additions and 190 deletions

View File

@ -92,9 +92,8 @@ def __main__():
def test2(): def test2():
print('???', end=' ') print('???', end=' ')
disp.__root = disp.tk.Tk() window = disp.disp(
disp.root,
disp.initWindow(
geometry='1200x800', geometry='1200x800',
menuWidget={ menuWidget={
'文件': {'新建': test, '打开': test}, '文件': {'新建': test, '打开': test},
@ -102,8 +101,8 @@ def __main__():
'视图': {'缩放': test}, '视图': {'缩放': test},
'帮助': {'关于': disp.authorWindowStarter}, '帮助': {'关于': disp.authorWindowStarter},
}, },
title_='音·创 0.2 测试中', title='音·创 0.2 测试中',
button=[ buttons=[
{ {
'新建': ('', test2), '新建': ('', test2),
'打开': ('', test2) '打开': ('', test2)
@ -112,10 +111,9 @@ def __main__():
'测试': ('', test2) '测试': ('', test2)
} }
], ],
Debug=True, debug=True,
) )
disp.winstart()
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
'''音·创的GUI窗口界面显示库 '''音·创的Tkinter GUI窗口界面显示主程序
:若要使用其他界面显示请详见 :若要使用其他界面显示请详见
:开发说明|指南''' :开发说明|指南'''
@ -18,10 +18,19 @@ LIGHTBLUE = (38, 226, 255)
# 26E2FF # 26E2FF
RED = (255, 52, 50) RED = (255, 52, 50)
# FF3432
PURPLE = (171, 112, 255) PURPLE = (171, 112, 255)
# AB70FF
GREEN = (0, 255, 33) GREEN = (0, 255, 33)
# 00FF21
WHITE = (242, 244, 246) WHITE = (242, 244, 246)
# F2F4F6
BLACK = (18, 17, 16) BLACK = (18, 17, 16)
# 121110
backgroundColor = WHITE backgroundColor = WHITE
@ -34,132 +43,30 @@ tipsColor = PURPLE
# 注UI界面字体、代码字体 # 注UI界面字体、代码字体
fontPattern = ('DengXian Light', 'Fira Code') fontPattern = ('DengXian Light', 'Fira Code')
global __root
global title
global menuWidgets
global wordView
global buttons
global settingBox
global notemap
global infoBar
global debug
__root = None
'''窗口根'''
# 音·创 的基本Tk窗口显示函数
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,
设置操作函数:<function>,
)
],
map: list = [ # 一首曲目的音符数据
音符数据
]
:param infobar str 显示信息用
'''
if Debug:
log('载入参数')
# 载入参量 注意!图标将不被载入参数
global title
global menuWidgets
global wordView
global buttons
global settingBox
global notemap
global infoBar
global debug
title = title_
'''窗口标题'''
menuWidgets = menuWidget
'''菜单设定项'''
wordView = wordview
'''言·论 所显示的文字'''
buttons = button
'''快捷功能按钮'''
settingBox = settingbox
'''设置框'''
notemap = notemap_
'''音符列表'''
infoBar = infobar
'''信息显示版所显示的文字'''
debug = Debug
'''是否打开调试模式'''
setTitle()
setGeometry(geometry)
setIcon(*iconbitmap)
setMenu()
initWidget()
def winstart() -> None:
# 启动主消息循环
__root.mainloop()
# ========================================================= # =========================================================
# 设定函数部分 # 设定函数部分
# ========================================================= # =========================================================
def setTitle( title_: str = '') -> None: def setTitle(__root, title_: str = '') -> None:
'''设置窗口标题 '''设置窗口标题
:param title: str 窗口标题''' :param title: str 窗口标题'''
global title
if title:
title = title_
__root.title(title)
if debug:
log(f"设置窗口标题 {title}")
def setGeometry( geometry: str = '0x0') -> None: if title:
self.title = title_
__root.title(self.title)
if self.debug:
log(f"设置窗口标题 {self.title}")
def setGeometry(__root, geometry: str = '0x0') -> None:
'''设置窗口大小 '''设置窗口大小
:param geometry: str 窗口大小''' :param geometry: str 窗口大小'''
__root.geometry(geometry) __root.geometry(geometry)
if debug: if self.debug:
log(f"设置窗口大小{geometry}") log(f"设置窗口大小{geometry}")
def setIcon( bitmap: str = './musicreater.ico', default: str = '') -> bool: def setIcon(__root, bitmap: str = './musicreater.ico', default: str = '') -> bool:
'''设置窗口图标 '''设置窗口图标
:param bitmap: str 图标路径 :param bitmap: str 图标路径
:param default: str 设置对于全局的默认图标路径 :param default: str 设置对于全局的默认图标路径
@ -176,32 +83,28 @@ def setIcon( bitmap: str = './musicreater.ico', default: str = '') -> bool:
return True return True
except Exception as e: except Exception as e:
log(str(e), 'ERROR') log(str(e), 'ERROR')
if debug: if self.debug:
raise e raise e
return False return False
def setMenu() -> None: def setMenu(__root) -> None:
'''设置根菜单''' '''设置根菜单'''
if not self.menuWidgets:
global _RootMenu
global _mainMenuBar
if not menuWidgets:
# 如果传入空参数则返回当前菜单 # 如果传入空参数则返回当前菜单
try: try:
return _RootMenu return self._RootMenu
except Exception as E: except Exception as E:
if debug: if self.debug:
raise E raise E
log('无法读取菜单信息', 'WARRING') log('无法读取菜单信息', 'WARRING')
# 如果不是空参数则新建菜单 # 如果不是空参数则新建菜单
log('新建一个菜单') log('新建一个菜单')
_RootMenu = {} self._RootMenu = {}
_mainMenuBar = tk.Menu(__root) self._mainMenuBar = tk.Menu(__root)
for menuName, menuCmd in menuWidgets.items(): for menuName, menuCmd in self.menuWidgets.items():
# 取得一个菜单名和一堆菜单函数及其显示名称 # 取得一个菜单名和一堆菜单函数及其显示名称
menu = tk.Menu(_mainMenuBar, tearoff=0) menu = tk.Menu(self._mainMenuBar, tearoff=0)
for cmdName, cmdFunc in menuCmd.items(): for cmdName, cmdFunc in menuCmd.items():
if cmdName: if cmdName:
menu.add_command(label=cmdName, command=cmdFunc) menu.add_command(label=cmdName, command=cmdFunc)
@ -209,10 +112,10 @@ def setMenu() -> None:
else: else:
menu.add_separator() menu.add_separator()
log('分隔符 -- 分隔符') log('分隔符 -- 分隔符')
_mainMenuBar.add_cascade(label=menuName, menu=menu) self._mainMenuBar.add_cascade(label=menuName, menu=menu)
_RootMenu[menuName] = menu self._RootMenu[menuName] = menu
log('计入一个菜单 -- ' + menuName) log('计入一个菜单 -- ' + menuName)
__root.config(menu=_mainMenuBar) __root.config(menu=self._mainMenuBar)
log('菜单设置完毕') log('菜单设置完毕')
def addMenu(menuRoot: str = '', menuLabel: str = '', menuCommand=None): def addMenu(menuRoot: str = '', menuLabel: str = '', menuCommand=None):
@ -223,33 +126,27 @@ def addMenu( menuRoot: str = '', menuLabel: str = '', menuCommand=None):
所需要增加的项目显示的文字 所需要增加的项目显示的文字
:param menuCommand : <function> :param menuCommand : <function>
''' '''
if menuRoot in self._RootMenu.keys:
global _RootMenu
global _mainMenuBar
if menuRoot in _RootMenu.keys:
# 如果已经有父菜单 # 如果已经有父菜单
if menuLabel: if menuLabel:
# 增加菜单指令 # 增加菜单指令
_RootMenu[menuRoot].add_command( self._RootMenu[menuRoot].add_command(
label=menuLabel, command=menuCommand label=menuLabel, command=menuCommand
) )
else: else:
# 增加分隔栏 # 增加分隔栏
_RootMenu[menuRoot].add_separator() self._RootMenu[menuRoot].add_separator()
else: else:
# 没有父菜单则新增一个父菜单 # 没有父菜单则新增一个父菜单
menu = tk.Menu(_mainMenuBar, tearoff=False) menu = tk.Menu(self._mainMenuBar, tearoff=False)
if menuLabel: if menuLabel:
menu.add_command(label=menuLabel, command=menuCommand) menu.add_command(label=menuLabel, command=menuCommand)
else: else:
menu.add_separator() menu.add_separator()
_mainMenuBar.add_cascade(label=menuRoot, menu=menu) self._mainMenuBar.add_cascade(label=menuRoot, menu=menu)
_RootMenu[menuRoot] = menu self._RootMenu[menuRoot] = menu
def initWidget( def initWidget(__root) -> None:
) -> None:
'''设置窗口小部件,分为: '''设置窗口小部件,分为:
:· WordView :· WordView
:快捷按钮面板 ButtonBar :快捷按钮面板 ButtonBar
@ -258,46 +155,41 @@ def initWidget(
:各个音轨的显示框 TrackFrame :各个音轨的显示框 TrackFrame
:信息显示版 InfoBar :信息显示版 InfoBar
''' '''
self._wordviewBar = tk.Label(
global _wordviewBar
global _infoBar
global _buttonBar
_wordviewBar = tk.Label(
__root, __root,
bg='black', bg='black',
fg='white', fg='white',
text=wordView, text=self.wordView,
font=(fontPattern[0], 30), font=(fontPattern[0], 30),
) )
# 定义 言·论 版面 # 定义 言·论 版面
log('言·论版面设置完成') log('言·论版面设置完成')
_infoBar = tk.Label( self._infoBar = tk.Label(
__root, __root,
bg='white', bg='white',
fg='black', fg='black',
text=infoBar, text=self.infoBar,
font=(fontPattern[0], 10), font=(fontPattern[0], 10),
) )
# 定义 信息显示版 # 定义 信息显示版
log('信息显示版设置完成') log('信息显示版设置完成')
_buttonBar = tk.Frame( self._buttonBar = tk.Frame(
__root, __root,
bd=2, bd=2,
) )
# 定义 快捷按钮面板. 注意这里是以一个Frame为容器而不是一个Button列表后面的版面也以Frame容器居多 # 定义 快捷按钮面板. 注意这里是以一个Frame为容器而不是一个Button列表后面的版面也以Frame容器居多
setButtonBar(buttons) self.setButtonBar(self.buttons)
_wordviewBar.pack(side='top', fill='x') self._wordviewBar.pack(side='top', fill='x')
_buttonBar.pack(side='top', fill='x') self._buttonBar.pack(side='top', fill='x')
_infoBar.pack(side='bottom', fill='x') self._infoBar.pack(side='bottom', fill='x')
def setButtonBar( def setButtonBar(
self,
buttonList: list = [], buttonList: list = [],
defaultMissingTexturePath: str = './resources/uimage/missing_texture.png', defaultMissingTexturePath: str = './resources/uimage/missing_texture.png',
separatorButtonTexturePath: str = './resources/uimage/separator_line.png', separatorButtonTexturePath: str = './resources/uimage/separator_line.png',
@ -310,9 +202,7 @@ def setButtonBar(
# 图标应该如下 # 图标应该如下
# 新建 打开 保存 | # 新建 打开 保存 |
global _buttonBarList self._buttonBarList = []
_buttonBarList = []
'''按钮对象列表,注意软件调用的时候千万别动!''' '''按钮对象列表,注意软件调用的时候千万别动!'''
separatorimg = tk.PhotoImage(file=separatorButtonTexturePath) separatorimg = tk.PhotoImage(file=separatorButtonTexturePath)
@ -325,11 +215,11 @@ def setButtonBar(
img = tk.PhotoImage(file=args[0]) img = tk.PhotoImage(file=args[0])
except: except:
log('载入图片失败,使用默认图片','WARNING') log('载入图片失败,使用默认图片','WARNING')
if debug: if self.debug:
raise FileNotFoundError(f'图片{args[0]}不存在') raise FileNotFoundError(f'图片{args[0]}不存在')
img = tk.PhotoImage(file=defaultMissingTexturePath) img = tk.PhotoImage(file=defaultMissingTexturePath)
button = tk.Button( button = tk.Button(
_buttonBar, self._buttonBar,
text=name, text=name,
command=args[1], command=args[1],
image=img, image=img,
@ -338,19 +228,19 @@ def setButtonBar(
font=(fontPattern[0], 10), font=(fontPattern[0], 10),
) )
button.pack(side='left', padx=5, pady=5) button.pack(side='left', padx=5, pady=5)
_buttonBarList.append(button) self._buttonBarList.append(button)
# 添加按钮 # 添加按钮
tk.Label(_buttonBar, image=separatorimg).pack( tk.Label(self._buttonBar, image=separatorimg).pack(
side='left', padx=5, pady=5 side='left', padx=5, pady=5
) )
def setWordView( text: str) -> None: def setWordView(self, text: str) -> None:
'''重新设置言·论版的文字''' '''重新设置言·论版的文字'''
_wordviewBar['text'] = text self._wordviewBar['text'] = text
def setInfoBar( text: str) -> None: def setInfoBar(self, text: str) -> None:
'''重新设置信息显示版的文字''' '''重新设置信息显示版的文字'''
_infoBar['text'] = text self._infoBar['text'] = text
# ========================================================= # =========================================================
# 预置函数部分 # 预置函数部分
@ -426,7 +316,7 @@ def authorWindowStarter(
class ProgressBar: class ProgressBar:
def __init__( def __init__(
self,
root: tk.Tk = tk.Tk(), root: tk.Tk = tk.Tk(),
style: tuple = (DEFAULTBLUE, BLACK, WHITE), style: tuple = (DEFAULTBLUE, BLACK, WHITE),
type: bool = False, type: bool = False,
@ -444,7 +334,7 @@ class ProgressBar:
显示的附加信息 显示的附加信息
:param debug : bool :param debug : bool
是否输出日志到控制台''' 是否输出日志到控制台'''
root = root self.root = root
# TODO # TODO
@ -452,7 +342,84 @@ class ProgressBar:
if __name__ == '__mian__': if __name__ == '__mian__':
import os
os.chdir('../') # __root,
authorWindowStarter() # 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 = '就绪',
'''使用参数建立基本的 音·创 窗口
:param root 根窗口
:param debug 是否将日志输出到控制台
:param title 窗口标题
wordview: str #言论部分显示的字样
button: list = [ # 操作按钮部分
dict = {
按钮名称 : tuple(按钮图标,执行函数)
},
],
settingbox: list = [ # 设置部分显示的字样及其对应的设置函数
(
设置名称:str,
值类型:tuple,
显示内容:str,
设置操作函数:<function>,
)
],
map: list = [ # 一首曲目的音符数据
音符数据
]
:param infobar str 显示信息用
'''
if debug:
log('载入参数')
# 载入参量 注意!图标将不被载入参数
self.title = title
'''窗口标题'''
self.menuWidgets = menuWidget
'''菜单设定项'''
self.wordView = wordView
'''言·论 所显示的文字'''
self.buttons = buttons
'''快捷功能按钮'''
self.settingBox = settingBox
'''设置框'''
self.notemap = notemap
'''音符列表'''
self.infoBar = infobar
'''信息显示版所显示的文字'''
self.debug = debug
'''是否打开调试模式'''
self.setTitle(__root,)
self.setGeometry(__root, geometry)
self.setIcon(__root, *iconbitmap)
self.setMenu(__root)
self.initWidget(__root)
self.start(__root)
def start(self, __root) -> None:
# 启动主消息循环
__root.mainloop()

View File

@ -1,9 +1,11 @@
<h1 align="center">音·创 Musicreater</h1> <h1 align="center">音·创 Musicreater</h1>
<p align="center"> <p align="center">
<img width="128" height="128" src="https://s1.ax1x.com/2022/04/01/qhfOPA.png" > <img width="128" height="128" src="https://s1.ax1x.com/2022/05/06/Ouhghj.md.png" >
</p> </p>
<h3 align="center">一个免费开源的《我的世界:基岩版》音乐编辑制作软件</h3>
<p align="center"> <p align="center">
<img src="https://forthebadge.com/images/badges/built-with-love.svg"> <img src="https://forthebadge.com/images/badges/built-with-love.svg">
<p> <p>
@ -17,6 +19,31 @@
简体中文🇨🇳 | [English🇬🇧](README_EN.md) 简体中文🇨🇳 | [English🇬🇧](README_EN.md)
> 是谁把科技的领域布满政治的火药
>
> 是谁把纯净的蓝天染上暗淡的沉灰
>
> 中国人民无不热爱自己伟大的祖国
>
> 我们不会忘记屈辱历史留下的惨痛
>
> 我们希望世界和平
>
> 我们希望获得世界的尊重
>
> 愿世上再也没有战争
>
> 无论是热还是冷
>
> 无论是经济还是政治
>
> 让美妙的和平的优雅的音乐响彻世界
>
> ——金羿
> 2022 5 7
## 软件介绍🚀 ## 软件介绍🚀
音·创 Musicreater 是一款免费开源的 **《我的世界:基岩版》** 音乐制作软件 音·创 Musicreater 是一款免费开源的 **《我的世界:基岩版》** 音乐制作软件

View File

@ -1,9 +1,11 @@
<h1 align="center">音·创 Musicreater</h1> <h1 align="center">音·创 Musicreater</h1>
<p align="center"> <p align="center">
<img width="128" height="128" src="https://s1.ax1x.com/2022/04/01/qhfOPA.png" > <img width="128" height="128" src="https://s1.ax1x.com/2022/05/06/Ouhghj.md.png" >
</p> </p>
<h3 align="center">An open source and free software of making music in Minecraft</h3>
<p align="center"> <p align="center">
<img src="https://forthebadge.com/images/badges/built-with-love.svg"> <img src="https://forthebadge.com/images/badges/built-with-love.svg">
<p> <p>
@ -17,6 +19,31 @@
[简体中文🇨🇳](README.md) | English🇬🇧 [简体中文🇨🇳](README.md) | English🇬🇧
> Who has dropped political gunpowder into the technology
>
> Who has dyed clear blue sky into the dark grey
>
> All Chinese people love our great homeland
>
> We *WILL* remember the remain pain of the humiliating history
>
> We love the whole world but in peace
>
> We love everyone but under respect
>
> It is to be hoped that the war ends forever
>
> Whatever it is cold or hot
>
> Whatever it is economical or political
>
> Just let the wonderful music of peace surround the world
>
> ---- Eilles Wan
> 7/5 2022
**Notice that the language support of *README* may be a little SLOW.** **Notice that the language support of *README* may be a little SLOW.**
## Introduction🚀 ## Introduction🚀

View File

@ -88,10 +88,11 @@ def __loadLanguage(languageFilename: str):
return _text return _text
if not DEFAULTLANGUAGE == 'zh-CN':
if DEFAULTLANGUAGE in LANGUAGELIST.keys(): if DEFAULTLANGUAGE in LANGUAGELIST.keys():
_TEXT = __loadLanguage('./languages/' + DEFAULTLANGUAGE + '.lang') _TEXT = __loadLanguage('./languages/' + DEFAULTLANGUAGE + '.lang')
else: else:
log(f"无法打开当前本地化文本{DEFAULTLANGUAGE}", level='ERROR')
raise KeyError(f'无法打开默认语言{DEFAULTLANGUAGE}') raise KeyError(f'无法打开默认语言{DEFAULTLANGUAGE}')
@ -113,7 +114,7 @@ def _(text: str, debug: bool = False):
if debug: if debug:
raise KeyError(f'无法找到翻译文本{text}') raise KeyError(f'无法找到翻译文本{text}')
else: else:
log(f'无法找到本地化文本{text}','ERROR') log(f'无法找到本地化文本{text}','WARRING')
return '' return ''

View File

@ -5,7 +5,7 @@
# 也切勿在正文结尾放! # 也切勿在正文结尾放!
LANGKEY zh-CN LANGKEY zh-CN
LANGCHINESENAME 简体中文 中国大陆 LANGCHINESENAME 简体中文 中国大陆
LANGENGLIFHNAME Simplified Chinese, Chinese Mainland LANGENGLISHNAME Simplified Chinese, Chinese Mainland
LANGLOCALNAME 简体中文 中国大陆 LANGLOCALNAME 简体中文 中国大陆
MSCT 音·创 MSCT 音·创
F音创 音·创 Musicreater F音创 音·创 Musicreater

View File

@ -1,6 +1,8 @@
开发说明\|指南 开发说明\|指南
============== ==============
***不要看了,这玩意没啥意义了。***
此文件旨在使后期欲参与开发之人员减轻其开发负担,同时也为了我们正在开发的人员详细说明功能与用法 此文件旨在使后期欲参与开发之人员减轻其开发负担,同时也为了我们正在开发的人员详细说明功能与用法
掌握开发指南之后,在调用函数等的过程中将会更加方便 掌握开发指南之后,在调用函数等的过程中将会更加方便

BIN
resources/msctIcon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 123 KiB

After

Width:  |  Height:  |  Size: 7.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 551 B

After

Width:  |  Height:  |  Size: 2.4 KiB