From 052142ac08208d6aba56eea2b72feb46ff1ef332 Mon Sep 17 00:00:00 2001 From: EillesWan Date: Wed, 9 Mar 2022 22:10:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AD=A3=E5=9C=A8=E4=BF=AE=E6=94=B9=EF=BC=8C?= =?UTF-8?q?=E6=B2=A1=E6=94=B9=E5=AE=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- msctLib/display.py | 74 ++++++++++++++--- msctLib/log.py | 78 ++++++++++++++++++ msctLib/settings.py | 9 +- msctLib/开发说明兼指南.md | 2 +- .../__pycache__/bugReporter.cpython-38.pyc | Bin 4595 -> 4593 bytes resources/myWords.txt | 3 +- 6 files changed, 151 insertions(+), 15 deletions(-) create mode 100644 msctLib/log.py diff --git a/msctLib/display.py b/msctLib/display.py index 266ff66..34406d0 100644 --- a/msctLib/display.py +++ b/msctLib/display.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -'''音·创的GUI界面显示库 +'''音·创的GUI窗口界面显示库 :若要使用其他界面显示,请详见: :开发说明|指南''' @@ -7,14 +7,27 @@ import tkinter as tk import tkinter.simpledialog as sdialog import tkinter.filedialog as fdialog +from msctLib.log import log + + +DEFAULTBLUE = (0, 137, 242) +WEAKBLUE = (0, 161, 231) +LIGHTBLUE = (38, 226, 255) +RED = (255, 52, 50) +PURPLE = (171, 112, 255) +GREEN = (0, 255, 33) +WHITE = (242, 244, 246) +BLACK = (18, 17, 16) + -from tkinter import * -root = tk.Tk() class disp: - def __init__(self,root:tk.Tk = root,debug:bool = False,**kwgs) -> None: + # 正在修改,没改完 + def __init__(self,root:tk.Tk = tk.Tk(),debug:bool = False,title:str = '', + geometry : str = '0x0', iconbitmap : tuple = ('',''), menuWidget:dict = {}, + wordView : str = '音·创 Musicreater', ) -> None: '''传入root参数为窗口根,kwgs详见开发说明|指南''' self.root = root @@ -39,29 +52,54 @@ class disp: elif debug: raise KeyError(f'无法定位函数{func}') - def setTitle(self,title:str = '') -> None: + def setTitle(self,title:str = '',debug : bool = False) -> None: '''设置窗口标题''' self.root.title = title + if debug: + 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) + '''设置根菜单''' + if not kwgs: + return self.RootMenu + self.RootMenu = {} + self.mainMenuBar = tk.Menu(self.root) for menuName,menuCmd in kwgs.items(): - menu = tk.Menu(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) else: menu.add_separator() - mainMenuBar.add_cascade(label=menuName,menu=menu) - menus.append(menu) + self.mainMenuBar.add_cascade(label=menuName,menu=menu) + self.RootMenu[menuName] = menu + self.root.config(menu=self.mainMenuBar) + + def addMenu(self,menuRoot:str = '',menuLabel:str = '',menuCommand:str = None): + '''增加一个菜单项''' + if menuRoot in self.RootMenu.keys: + if menuLabel: + self.RootMenu[menuRoot].add_command(label = menuLabel, command = menuCommand) + else: + self.RootMenu[menuRoot].add_separator() + else: + 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 + + def setWidget(self,**kwgs) -> None: self._wordviewBar = tk.Label(self.root) @@ -76,5 +114,17 @@ class disp: class ProgressBar: - def __init__(self,root) -> None: - pass \ No newline at end of file + def __init__(self,root:tk.Tk = tk.Tk(),style:tuple = (DEFAULTBLUE,BLACK,WHITE), + type : bool = False, info : str = '', debug:bool = False) -> None: + '''建立一个进度条或者加载等待界面 + :param root : tk.Tk + 建立进度条的根窗口 + :param style : tuple + 设置主题颜色,第一个参数为进度条或者等待转圈圈的颜色,第二个参数为前景色,第三个是背景色 + :param type : bool + 类型,为 False 时为进度条,为 True 时为等待板 + :param info : str + 显示的附加信息 + :param debug : bool + 是否输出日志到控制台''' + self.root = root \ No newline at end of file diff --git a/msctLib/log.py b/msctLib/log.py new file mode 100644 index 0000000..7562ef3 --- /dev/null +++ b/msctLib/log.py @@ -0,0 +1,78 @@ +"""音·创的日志消息处理""" +# 诸葛亮与八卦阵帮忙修改语法 日期:---2022年1月19日 +# 统计:致命(三级)错误:0个;警告(二级)错误:0个;语法(一级)错误:9个 + +# 对开发者说的话: +# +# 请不要修改这里的日志,日志是给开发者和专业人士看的 +# 而不是给普通用户看的,因此,没必要使用开发者自己也 +# 不习惯的日志系统,比如说,之前诸葛亮与八卦阵 (bgArray) +# 用了 logging 库来改写我原来的日志支持,但是我反 +# 而找不到我想要的信息了,所以,日志系统给我们开发者 +# 自己看得好就可以了昂,真的别改了。而且,诸葛八卦改 +# 了之后并没有多好,喵喵喵,所以我就换回来了。我知道 +# logging 库比较常用,而且功能也好,但是我们毕竟没 +# 这个必要,就别用那个库了昂,球球了~ +# ——金羿 Eilles +# 2022 03 09 + +# To ALL the developers who will change this part: +# +# Please do NOT change anything in this file! +# The log file is only for developers or +# someone who knows a lot about our program +# to see, but not the common users. So it +# is NOT NECESSARY to use a logging system +# that we do not familiar or we do not like. +# Take bgAray “诸葛亮与八卦阵” as a example, +# he once change this `log.py` into +# logging-library-based log support system. +# But after the change had done, I could NOT +# find useful infomation according to the +# log file... So use this file but not to +# make changes PLEASE!!! I know some libraries +# like logging is usually better than the +# simple system in this file and it is normal +# to use but, I think it is not necessery, +# so PLEASE DO NOT USE OTHER LIBs TO +# OVERWRITE MY LIBRARY, THANKS. +# ——Eilles 金羿 +# 03/09/2022 + + + +import datetime,os + +#载入日志功能 +StrStartTime = str(datetime.datetime.now()).replace(':', '_')[:-7] +'''字符串型的程序开始时间''' + + +def log(info:str = '',level : str = 'INFO', isPrinted:bool = False): + '''将信息连同当前时间载入日志 + :param info : str + 日志信息 + :param level : str['INFO','WARRING','ERROR','CRASH'] + 信息等级 + :param isPrinted : bool + 是否在控制台打印 + + :return bool + 表示是否完成任务''' + + try: + + if not os.path.exists('./log/'): + os.makedirs('./log/') + + outputinfo = f'{str(datetime.datetime.now())[11:19]}-[{level}] {info}' + + with open('./log/'+StrStartTime+'.msct.log', 'a',encoding='UTF-8') as f: + f.write(outputinfo+'\n') + + if isPrinted: + print(outputinfo) + + return True + except: + return False diff --git a/msctLib/settings.py b/msctLib/settings.py index 59f6adf..ac9b306 100644 --- a/msctLib/settings.py +++ b/msctLib/settings.py @@ -1,7 +1,14 @@ # -*- coding:utf-8 -*- - +DEFAULTBLUE = (0, 137, 242) +WEAKBLUE = (0, 161, 231) +LIGHTBLUE = (38, 226, 255) +RED = (255, 52, 50) +PURPLE = (171, 112, 255) +GREEN = (0, 255, 33) +WHITE = (242, 244, 246) +BLACK = (18, 17, 16) settings = { 'language' : 'zh-CN', diff --git a/msctLib/开发说明兼指南.md b/msctLib/开发说明兼指南.md index 7ff22a3..1864c76 100644 --- a/msctLib/开发说明兼指南.md +++ b/msctLib/开发说明兼指南.md @@ -66,7 +66,7 @@ functions.py中会调取./addon/目录下的全部功能文件,这些功能文 `菜单名` : `str` 显示在菜单上的字符串 `选项名` : `str` 显示在菜单选项上的字符串 `选项函数` : `function` 菜单调取的函数(无返回值,无入参) - 当 `选项名` 的布尔值判定为 `False` 的时候,无论 `选项函数` 为何,皆插入一段分割线 + 当 `选项名` 的布尔值判定为 `False` 的时候,无论 `选项函数` 为何,皆插入一段分割线,但 `选项函数` 不得为空 2. `setWidget`对窗口部件的放置 ```python diff --git a/msctspt/__pycache__/bugReporter.cpython-38.pyc b/msctspt/__pycache__/bugReporter.cpython-38.pyc index 618156fb8393b17f1095399c74ced0f5e15e4d62..22addb3683926fe10f3f951f19bab5a4aed1b5e5 100644 GIT binary patch delta 34 ocmeyY{85=Vl$V!_0SMZxRFY~p@?PX&V>Qq-(lglnjE9#M0G`JPzW@LL delta 36 qcmeyU{8^bdl$V!_0SJsZe