添加progbar
This commit is contained in:
parent
e4a2f35d6a
commit
1ea843e53d
|
@ -1,104 +1,104 @@
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
|
|
||||||
# C extensions
|
# C extensions
|
||||||
*.so
|
*.so
|
||||||
|
|
||||||
# Distribution / packaging
|
# Distribution / packaging
|
||||||
.Python
|
.Python
|
||||||
build/
|
build/
|
||||||
develop-eggs/
|
develop-eggs/
|
||||||
dist/
|
dist/
|
||||||
downloads/
|
downloads/
|
||||||
eggs/
|
eggs/
|
||||||
.eggs/
|
.eggs/
|
||||||
lib/
|
lib/
|
||||||
lib64/
|
lib64/
|
||||||
parts/
|
parts/
|
||||||
sdist/
|
sdist/
|
||||||
var/
|
var/
|
||||||
wheels/
|
wheels/
|
||||||
*.egg-info/
|
*.egg-info/
|
||||||
.installed.cfg
|
.installed.cfg
|
||||||
*.egg
|
*.egg
|
||||||
MANIFEST
|
MANIFEST
|
||||||
|
|
||||||
# PyInstaller
|
# PyInstaller
|
||||||
# Usually these files are written by a python script from a template
|
# Usually these files are written by a python script from a template
|
||||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
*.manifest
|
*.manifest
|
||||||
*.spec
|
*.spec
|
||||||
|
|
||||||
# Installer logs
|
# Installer logs
|
||||||
pip-log.txt
|
pip-log.txt
|
||||||
pip-delete-this-directory.txt
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
# Unit test / coverage reports
|
# Unit test / coverage reports
|
||||||
htmlcov/
|
htmlcov/
|
||||||
.tox/
|
.tox/
|
||||||
.coverage
|
.coverage
|
||||||
.coverage.*
|
.coverage.*
|
||||||
.cache
|
.cache
|
||||||
nosetests.xml
|
nosetests.xml
|
||||||
coverage.xml
|
coverage.xml
|
||||||
*.cover
|
*.cover
|
||||||
.hypothesis/
|
.hypothesis/
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
|
|
||||||
# Translations
|
# Translations
|
||||||
*.mo
|
*.mo
|
||||||
*.pot
|
*.pot
|
||||||
|
|
||||||
# Django stuff:
|
# Django stuff:
|
||||||
*.log
|
*.log
|
||||||
local_settings.py
|
local_settings.py
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
|
|
||||||
# Flask stuff:
|
# Flask stuff:
|
||||||
instance/
|
instance/
|
||||||
.webassets-cache
|
.webassets-cache
|
||||||
|
|
||||||
# Scrapy stuff:
|
# Scrapy stuff:
|
||||||
.scrapy
|
.scrapy
|
||||||
|
|
||||||
# Sphinx documentation
|
# Sphinx documentation
|
||||||
docs/_build/
|
docs/_build/
|
||||||
|
|
||||||
# PyBuilder
|
# PyBuilder
|
||||||
target/
|
target/
|
||||||
|
|
||||||
# Jupyter Notebook
|
# Jupyter Notebook
|
||||||
.ipynb_checkpoints
|
.ipynb_checkpoints
|
||||||
|
|
||||||
# pyenv
|
# pyenv
|
||||||
.python-version
|
.python-version
|
||||||
.idea/
|
.idea/
|
||||||
# celery beat schedule file
|
# celery beat schedule file
|
||||||
celerybeat-schedule
|
celerybeat-schedule
|
||||||
workspace.xml
|
workspace.xml
|
||||||
# SageMath parsed files
|
# SageMath parsed files
|
||||||
*.sage.py
|
*.sage.py
|
||||||
.idea/workspace.xml
|
.idea/workspace.xml
|
||||||
# Environments
|
# Environments
|
||||||
.env
|
.env
|
||||||
.venv
|
.venv
|
||||||
env/
|
env/
|
||||||
venv/
|
venv/
|
||||||
ENV/
|
ENV/
|
||||||
env.bak/
|
env.bak/
|
||||||
venv.bak/
|
venv.bak/
|
||||||
|
|
||||||
# Spyder project settings
|
# Spyder project settings
|
||||||
.spyderproject
|
.spyderproject
|
||||||
.spyproject
|
.spyproject
|
||||||
|
|
||||||
# Rope project settings
|
# Rope project settings
|
||||||
.ropeproject
|
.ropeproject
|
||||||
|
|
||||||
# mkdocs documentation
|
# mkdocs documentation
|
||||||
/site
|
/site
|
||||||
|
|
||||||
# mypy
|
# mypy
|
||||||
.mypy_cache/
|
.mypy_cache/
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
{
|
{
|
||||||
// 使用 IntelliSense 了解相关属性。
|
// 使用 IntelliSense 了解相关属性。
|
||||||
// 悬停以查看现有属性的描述。
|
// 悬停以查看现有属性的描述。
|
||||||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Python 调试",
|
"name": "Python 调试",
|
||||||
"type": "debugpy",
|
"type": "debugpy",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "debug.py",
|
"program": "debug.py",
|
||||||
"console": "integratedTerminal"
|
"console": "integratedTerminal"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "重新生成资源包",
|
"name": "重新生成资源包",
|
||||||
"type": "debugpy",
|
"type": "debugpy",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "photo2/run.py",
|
"program": "photo2/run.py",
|
||||||
"console": "integratedTerminal"
|
"console": "integratedTerminal"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
27
debug.py
27
debug.py
|
@ -1,5 +1,22 @@
|
||||||
import magictk
|
import magictk
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
win = magictk.window.Window()
|
win = magictk.Window()
|
||||||
win.mainloop()
|
pb = magictk.ProgressBar(win)
|
||||||
|
pb.pack()
|
||||||
|
magictk.Button(win, text="Default(+)",
|
||||||
|
func=lambda s: pb.add_progress(0.1)).pack()
|
||||||
|
magictk.ButtonFill(win, text="Primary(-)",
|
||||||
|
func=lambda s: pb.add_progress(-0.1)).pack()
|
||||||
|
magictk.ButtonFill(win, color_type="success", text="Success(+)",
|
||||||
|
func=lambda s: pb.add_progress(0.02)).pack()
|
||||||
|
magictk.ButtonFill(win, color_type="info", text="Info(-)",
|
||||||
|
func=lambda s: pb.add_progress(-0.02)).pack()
|
||||||
|
magictk.ButtonFill(win, color_type="warning", text="Warning(+)",
|
||||||
|
func=lambda s: pb.add_progress(0.3)).pack()
|
||||||
|
magictk.ButtonFill(win, color_type="danger", text="Danger(-)",
|
||||||
|
func=lambda s: pb.add_progress(-0.3)).pack()
|
||||||
|
win.mainloop()
|
||||||
|
|
||||||
|
# from magictk import workspace
|
||||||
|
# print(workspace.get_gtk_workspace_size())
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
from magictk.window import Window
|
from magictk.window import Window
|
||||||
from magictk.button import Button, ButtonFill
|
from magictk.button import Button, ButtonFill
|
||||||
|
from magictk.progressbar import ProgressBar
|
||||||
|
|
|
@ -1,232 +1,232 @@
|
||||||
import tkinter
|
import tkinter
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
try:
|
try:
|
||||||
import color_tmpl
|
import color_tmpl
|
||||||
except:
|
except:
|
||||||
from magictk import color_tmpl
|
from magictk import color_tmpl
|
||||||
try:
|
try:
|
||||||
import photoload
|
import photoload
|
||||||
except:
|
except:
|
||||||
from magictk import photoload
|
from magictk import photoload
|
||||||
|
|
||||||
|
|
||||||
def exit_btn_set(self, root):
|
def exit_btn_set(self, root):
|
||||||
img_exit = photoload.loadimg("close")
|
img_exit = photoload.loadimg("close")
|
||||||
img_act_exit = photoload.loadimg("close_active")
|
img_act_exit = photoload.loadimg("close_active")
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarExitButton.TFrame', background=self.color["background"])
|
'BarExitButton.TFrame', background=self.color["background"])
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarExitButton.TLabel', background=self.color["background"])
|
'BarExitButton.TLabel', background=self.color["background"])
|
||||||
exit_btn = ttk.Frame(root, style='BarExitButton.TFrame',
|
exit_btn = ttk.Frame(root, style='BarExitButton.TFrame',
|
||||||
height=self.top_h, width=48)
|
height=self.top_h, width=48)
|
||||||
exit_btn.pack(anchor="n", side='right')
|
exit_btn.pack(anchor="n", side='right')
|
||||||
exit_btn_flash = 0 # total 6f
|
exit_btn_flash = 0 # total 6f
|
||||||
exit_btn_flash_mode = 0
|
exit_btn_flash_mode = 0
|
||||||
label = ttk.Label(
|
label = ttk.Label(
|
||||||
exit_btn, style='BarExitButton.TLabel', image=img_exit, anchor=tkinter.CENTER)
|
exit_btn, style='BarExitButton.TLabel', image=img_exit, anchor=tkinter.CENTER)
|
||||||
label.place(width=48, height=self.top_h, x=0, y=0)
|
label.place(width=48, height=self.top_h, x=0, y=0)
|
||||||
|
|
||||||
def animation():
|
def animation():
|
||||||
nonlocal exit_btn_flash, exit_btn_flash_mode
|
nonlocal exit_btn_flash, exit_btn_flash_mode
|
||||||
if (exit_btn_flash_mode == 0 and exit_btn_flash > 0):
|
if (exit_btn_flash_mode == 0 and exit_btn_flash > 0):
|
||||||
exit_btn_flash -= 1
|
exit_btn_flash -= 1
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarExitButton.TFrame', background=color_tmpl.mix_color(self.color["background"], "#C42B1C", exit_btn_flash/6))
|
'BarExitButton.TFrame', background=color_tmpl.mix_color(self.color["background"], "#C42B1C", exit_btn_flash/6))
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarExitButton.TLabel', background=color_tmpl.mix_color(self.color["background"], "#C42B1C", exit_btn_flash/6))
|
'BarExitButton.TLabel', background=color_tmpl.mix_color(self.color["background"], "#C42B1C", exit_btn_flash/6))
|
||||||
if (exit_btn_flash >= 3):
|
if (exit_btn_flash >= 3):
|
||||||
label.configure(image=img_act_exit)
|
label.configure(image=img_act_exit)
|
||||||
else:
|
else:
|
||||||
label.configure(image=img_exit)
|
label.configure(image=img_exit)
|
||||||
if (exit_btn_flash_mode == 1 and exit_btn_flash < 6):
|
if (exit_btn_flash_mode == 1 and exit_btn_flash < 6):
|
||||||
exit_btn_flash += 1
|
exit_btn_flash += 1
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarExitButton.TFrame', background=color_tmpl.mix_color(self.color["background"], "#C42B1C", exit_btn_flash/6))
|
'BarExitButton.TFrame', background=color_tmpl.mix_color(self.color["background"], "#C42B1C", exit_btn_flash/6))
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarExitButton.TLabel', background=color_tmpl.mix_color(self.color["background"], "#C42B1C", exit_btn_flash/6))
|
'BarExitButton.TLabel', background=color_tmpl.mix_color(self.color["background"], "#C42B1C", exit_btn_flash/6))
|
||||||
if (exit_btn_flash >= 3):
|
if (exit_btn_flash >= 3):
|
||||||
label.configure(image=img_act_exit)
|
label.configure(image=img_act_exit)
|
||||||
else:
|
else:
|
||||||
label.configure(image=img_exit)
|
label.configure(image=img_exit)
|
||||||
if (exit_btn_flash_mode == 2):
|
if (exit_btn_flash_mode == 2):
|
||||||
exit_btn_flash = 6
|
exit_btn_flash = 6
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarExitButton.TFrame', background="#94141E")
|
'BarExitButton.TFrame', background="#94141E")
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarExitButton.TLabel', background="#94141E")
|
'BarExitButton.TLabel', background="#94141E")
|
||||||
if (exit_btn_flash >= 3):
|
if (exit_btn_flash >= 3):
|
||||||
label.configure(image=img_act_exit)
|
label.configure(image=img_act_exit)
|
||||||
else:
|
else:
|
||||||
label.configure(image=img_exit)
|
label.configure(image=img_exit)
|
||||||
self.anim.append(animation)
|
self.anim.append(animation)
|
||||||
|
|
||||||
def enters_exit(event):
|
def enters_exit(event):
|
||||||
nonlocal exit_btn_flash_mode
|
nonlocal exit_btn_flash_mode
|
||||||
exit_btn_flash_mode = 1
|
exit_btn_flash_mode = 1
|
||||||
|
|
||||||
def leaves_exit(event):
|
def leaves_exit(event):
|
||||||
nonlocal exit_btn_flash_mode
|
nonlocal exit_btn_flash_mode
|
||||||
exit_btn_flash_mode = 0
|
exit_btn_flash_mode = 0
|
||||||
|
|
||||||
def presshold_exit(event):
|
def presshold_exit(event):
|
||||||
nonlocal exit_btn_flash_mode
|
nonlocal exit_btn_flash_mode
|
||||||
exit_btn_flash_mode = 2
|
exit_btn_flash_mode = 2
|
||||||
|
|
||||||
def press_exit(event):
|
def press_exit(event):
|
||||||
nonlocal exit_btn_flash_mode
|
nonlocal exit_btn_flash_mode
|
||||||
if (exit_btn_flash_mode == 2):
|
if (exit_btn_flash_mode == 2):
|
||||||
exit_btn_flash_mode = 0
|
exit_btn_flash_mode = 0
|
||||||
self.quit()
|
self.quit()
|
||||||
else:
|
else:
|
||||||
exit_btn_flash_mode = 0
|
exit_btn_flash_mode = 0
|
||||||
exit_btn.bind("<Enter>", enters_exit)
|
exit_btn.bind("<Enter>", enters_exit)
|
||||||
exit_btn.bind("<Leave>", leaves_exit)
|
exit_btn.bind("<Leave>", leaves_exit)
|
||||||
exit_btn.bind("<Button-1>", presshold_exit)
|
exit_btn.bind("<Button-1>", presshold_exit)
|
||||||
exit_btn.bind("<ButtonRelease-1>", press_exit)
|
exit_btn.bind("<ButtonRelease-1>", press_exit)
|
||||||
label.bind("<Enter>", enters_exit)
|
label.bind("<Enter>", enters_exit)
|
||||||
label.bind("<Leave>", leaves_exit)
|
label.bind("<Leave>", leaves_exit)
|
||||||
label.bind("<Button-1>", presshold_exit)
|
label.bind("<Button-1>", presshold_exit)
|
||||||
label.bind("<ButtonRelease-1>", press_exit)
|
label.bind("<ButtonRelease-1>", press_exit)
|
||||||
|
|
||||||
|
|
||||||
def zoom_btn_set(self, root):
|
def zoom_btn_set(self, root):
|
||||||
img_default = photoload.loadimg("zoom")
|
img_default = photoload.loadimg("zoom")
|
||||||
img_inzoom = photoload.loadimg("zoom2normal")
|
img_inzoom = photoload.loadimg("zoom2normal")
|
||||||
|
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarZoomButton.TFrame', background=self.color["background"])
|
'BarZoomButton.TFrame', background=self.color["background"])
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarZoomButton.TLabel', background=self.color["background"])
|
'BarZoomButton.TLabel', background=self.color["background"])
|
||||||
zoom_btn = ttk.Frame(root, style='BarZoomButton.TFrame',
|
zoom_btn = ttk.Frame(root, style='BarZoomButton.TFrame',
|
||||||
height=self.top_h, width=48)
|
height=self.top_h, width=48)
|
||||||
zoom_btn.pack(anchor="n", side='right')
|
zoom_btn.pack(anchor="n", side='right')
|
||||||
zoom_btn_flash = 0 # total 4f
|
zoom_btn_flash = 0 # total 4f
|
||||||
zoom_btn_flash_mode = 0
|
zoom_btn_flash_mode = 0
|
||||||
label = ttk.Label(
|
label = ttk.Label(
|
||||||
zoom_btn, style='BarZoomButton.TLabel', image=img_default, anchor=tkinter.CENTER)
|
zoom_btn, style='BarZoomButton.TLabel', image=img_default, anchor=tkinter.CENTER)
|
||||||
label.place(width=48, height=self.top_h, x=0, y=0)
|
label.place(width=48, height=self.top_h, x=0, y=0)
|
||||||
|
|
||||||
def animation():
|
def animation():
|
||||||
nonlocal zoom_btn_flash, zoom_btn_flash_mode
|
nonlocal zoom_btn_flash, zoom_btn_flash_mode
|
||||||
if (zoom_btn_flash_mode == 0 and zoom_btn_flash > 0):
|
if (zoom_btn_flash_mode == 0 and zoom_btn_flash > 0):
|
||||||
zoom_btn_flash -= 1
|
zoom_btn_flash -= 1
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarZoomButton.TFrame', background=color_tmpl.mix_color(self.color["background"], self.color["border_base"], zoom_btn_flash/4))
|
'BarZoomButton.TFrame', background=color_tmpl.mix_color(self.color["background"], self.color["border_base"], zoom_btn_flash/4))
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarZoomButton.TLabel', background=color_tmpl.mix_color(self.color["background"], self.color["border_base"], zoom_btn_flash/4))
|
'BarZoomButton.TLabel', background=color_tmpl.mix_color(self.color["background"], self.color["border_base"], zoom_btn_flash/4))
|
||||||
if (zoom_btn_flash_mode == 1 and zoom_btn_flash < 4):
|
if (zoom_btn_flash_mode == 1 and zoom_btn_flash < 4):
|
||||||
zoom_btn_flash += 1
|
zoom_btn_flash += 1
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarZoomButton.TFrame', background=color_tmpl.mix_color(self.color["background"], self.color["border_base"], zoom_btn_flash/4))
|
'BarZoomButton.TFrame', background=color_tmpl.mix_color(self.color["background"], self.color["border_base"], zoom_btn_flash/4))
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarZoomButton.TLabel', background=color_tmpl.mix_color(self.color["background"], self.color["border_base"], zoom_btn_flash/4))
|
'BarZoomButton.TLabel', background=color_tmpl.mix_color(self.color["background"], self.color["border_base"], zoom_btn_flash/4))
|
||||||
if (zoom_btn_flash_mode == 2):
|
if (zoom_btn_flash_mode == 2):
|
||||||
zoom_btn_flash = 4
|
zoom_btn_flash = 4
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarZoomButton.TFrame', background=color_tmpl.setlight(self.color["border_base"], 0.76))
|
'BarZoomButton.TFrame', background=color_tmpl.setlight(self.color["border_base"], 0.76))
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarZoomButton.TLabel', background=color_tmpl.setlight(self.color["border_base"], 0.76))
|
'BarZoomButton.TLabel', background=color_tmpl.setlight(self.color["border_base"], 0.76))
|
||||||
self.anim.append(animation)
|
self.anim.append(animation)
|
||||||
|
|
||||||
def enters_zoom(event):
|
def enters_zoom(event):
|
||||||
nonlocal zoom_btn_flash_mode
|
nonlocal zoom_btn_flash_mode
|
||||||
zoom_btn_flash_mode = 1
|
zoom_btn_flash_mode = 1
|
||||||
|
|
||||||
def leaves_zoom(event):
|
def leaves_zoom(event):
|
||||||
nonlocal zoom_btn_flash_mode
|
nonlocal zoom_btn_flash_mode
|
||||||
zoom_btn_flash_mode = 0
|
zoom_btn_flash_mode = 0
|
||||||
|
|
||||||
def presshold_zoom(event):
|
def presshold_zoom(event):
|
||||||
nonlocal zoom_btn_flash_mode
|
nonlocal zoom_btn_flash_mode
|
||||||
zoom_btn_flash_mode = 2
|
zoom_btn_flash_mode = 2
|
||||||
|
|
||||||
def press_zoom(event):
|
def press_zoom(event):
|
||||||
nonlocal zoom_btn_flash_mode
|
nonlocal zoom_btn_flash_mode
|
||||||
if (zoom_btn_flash_mode == 2):
|
if (zoom_btn_flash_mode == 2):
|
||||||
zoom_btn_flash_mode = 0
|
zoom_btn_flash_mode = 0
|
||||||
self.zoom()
|
self.zoom()
|
||||||
else:
|
else:
|
||||||
zoom_btn_flash_mode = 0
|
zoom_btn_flash_mode = 0
|
||||||
|
|
||||||
def update_icon(*args):
|
def update_icon(*args):
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
label.configure(image=img_inzoom)
|
label.configure(image=img_inzoom)
|
||||||
else:
|
else:
|
||||||
label.configure(image=img_default)
|
label.configure(image=img_default)
|
||||||
self.update_icon = update_icon
|
self.update_icon = update_icon
|
||||||
zoom_btn.bind("<Enter>", enters_zoom)
|
zoom_btn.bind("<Enter>", enters_zoom)
|
||||||
zoom_btn.bind("<Leave>", leaves_zoom)
|
zoom_btn.bind("<Leave>", leaves_zoom)
|
||||||
zoom_btn.bind("<Button-1>", presshold_zoom)
|
zoom_btn.bind("<Button-1>", presshold_zoom)
|
||||||
zoom_btn.bind("<ButtonRelease-1>", press_zoom)
|
zoom_btn.bind("<ButtonRelease-1>", press_zoom)
|
||||||
label.bind("<Enter>", enters_zoom)
|
label.bind("<Enter>", enters_zoom)
|
||||||
label.bind("<Leave>", leaves_zoom)
|
label.bind("<Leave>", leaves_zoom)
|
||||||
label.bind("<Button-1>", presshold_zoom)
|
label.bind("<Button-1>", presshold_zoom)
|
||||||
label.bind("<ButtonRelease-1>", press_zoom)
|
label.bind("<ButtonRelease-1>", press_zoom)
|
||||||
|
|
||||||
|
|
||||||
def iconic_btn_set(self, root):
|
def iconic_btn_set(self, root):
|
||||||
img_iconic = photoload.loadimg("iconic")
|
img_iconic = photoload.loadimg("iconic")
|
||||||
|
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarIconicButton.TFrame', background=self.color["background"])
|
'BarIconicButton.TFrame', background=self.color["background"])
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarIconicButton.TLabel', background=self.color["background"])
|
'BarIconicButton.TLabel', background=self.color["background"])
|
||||||
|
|
||||||
iconic_btn = ttk.Frame(root, style='BarIconicButton.TFrame',
|
iconic_btn = ttk.Frame(root, style='BarIconicButton.TFrame',
|
||||||
height=self.top_h, width=48)
|
height=self.top_h, width=48)
|
||||||
iconic_btn.pack(anchor="n", side='right')
|
iconic_btn.pack(anchor="n", side='right')
|
||||||
iconic_btn_flash = 0 # total 4f
|
iconic_btn_flash = 0 # total 4f
|
||||||
iconic_btn_flash_mode = 0
|
iconic_btn_flash_mode = 0
|
||||||
label = ttk.Label(
|
label = ttk.Label(
|
||||||
iconic_btn, style='BarIconicButton.TLabel', image=img_iconic, anchor=tkinter.CENTER)
|
iconic_btn, style='BarIconicButton.TLabel', image=img_iconic, anchor=tkinter.CENTER)
|
||||||
label.place(width=48, height=self.top_h, x=0, y=0)
|
label.place(width=48, height=self.top_h, x=0, y=0)
|
||||||
|
|
||||||
def animation():
|
def animation():
|
||||||
nonlocal iconic_btn_flash, iconic_btn_flash_mode
|
nonlocal iconic_btn_flash, iconic_btn_flash_mode
|
||||||
if (iconic_btn_flash_mode == 0 and iconic_btn_flash > 0):
|
if (iconic_btn_flash_mode == 0 and iconic_btn_flash > 0):
|
||||||
iconic_btn_flash -= 1
|
iconic_btn_flash -= 1
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarIconicButton.TFrame', background=color_tmpl.mix_color(self.color["background"], self.color["border_light"], iconic_btn_flash/4))
|
'BarIconicButton.TFrame', background=color_tmpl.mix_color(self.color["background"], self.color["border_light"], iconic_btn_flash/4))
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarIconicButton.TLabel', background=color_tmpl.mix_color(self.color["background"], self.color["border_light"], iconic_btn_flash/4))
|
'BarIconicButton.TLabel', background=color_tmpl.mix_color(self.color["background"], self.color["border_light"], iconic_btn_flash/4))
|
||||||
if (iconic_btn_flash_mode == 1 and iconic_btn_flash < 4):
|
if (iconic_btn_flash_mode == 1 and iconic_btn_flash < 4):
|
||||||
iconic_btn_flash += 1
|
iconic_btn_flash += 1
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarIconicButton.TFrame', background=color_tmpl.mix_color(self.color["background"], self.color["border_light"], iconic_btn_flash/4))
|
'BarIconicButton.TFrame', background=color_tmpl.mix_color(self.color["background"], self.color["border_light"], iconic_btn_flash/4))
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarIconicButton.TLabel', background=color_tmpl.mix_color(self.color["background"], self.color["border_light"], iconic_btn_flash/4))
|
'BarIconicButton.TLabel', background=color_tmpl.mix_color(self.color["background"], self.color["border_light"], iconic_btn_flash/4))
|
||||||
if (iconic_btn_flash_mode == 2):
|
if (iconic_btn_flash_mode == 2):
|
||||||
iconic_btn_flash = 4
|
iconic_btn_flash = 4
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarIconicButton.TFrame', background=color_tmpl.setlight(self.color["border_base"], 0.76))
|
'BarIconicButton.TFrame', background=color_tmpl.setlight(self.color["border_base"], 0.76))
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarIconicButton.TLabel', background=color_tmpl.setlight(self.color["border_base"], 0.76))
|
'BarIconicButton.TLabel', background=color_tmpl.setlight(self.color["border_base"], 0.76))
|
||||||
self.anim.append(animation)
|
self.anim.append(animation)
|
||||||
|
|
||||||
def enters_iconic(event):
|
def enters_iconic(event):
|
||||||
nonlocal iconic_btn_flash_mode
|
nonlocal iconic_btn_flash_mode
|
||||||
iconic_btn_flash_mode = 1
|
iconic_btn_flash_mode = 1
|
||||||
|
|
||||||
def leaves_iconic(event):
|
def leaves_iconic(event):
|
||||||
nonlocal iconic_btn_flash_mode
|
nonlocal iconic_btn_flash_mode
|
||||||
iconic_btn_flash_mode = 0
|
iconic_btn_flash_mode = 0
|
||||||
|
|
||||||
def presshold_iconic(event):
|
def presshold_iconic(event):
|
||||||
nonlocal iconic_btn_flash_mode
|
nonlocal iconic_btn_flash_mode
|
||||||
iconic_btn_flash_mode = 2
|
iconic_btn_flash_mode = 2
|
||||||
|
|
||||||
def press_iconic(event):
|
def press_iconic(event):
|
||||||
nonlocal iconic_btn_flash_mode
|
nonlocal iconic_btn_flash_mode
|
||||||
if (iconic_btn_flash_mode == 2):
|
if (iconic_btn_flash_mode == 2):
|
||||||
iconic_btn_flash_mode = 0
|
iconic_btn_flash_mode = 0
|
||||||
self.iconify()
|
self.iconify()
|
||||||
else:
|
else:
|
||||||
iconic_btn_flash_mode = 0
|
iconic_btn_flash_mode = 0
|
||||||
iconic_btn.bind("<Enter>", enters_iconic)
|
iconic_btn.bind("<Enter>", enters_iconic)
|
||||||
iconic_btn.bind("<Leave>", leaves_iconic)
|
iconic_btn.bind("<Leave>", leaves_iconic)
|
||||||
iconic_btn.bind("<Button-1>", presshold_iconic)
|
iconic_btn.bind("<Button-1>", presshold_iconic)
|
||||||
iconic_btn.bind("<ButtonRelease-1>", press_iconic)
|
iconic_btn.bind("<ButtonRelease-1>", press_iconic)
|
||||||
label.bind("<Enter>", enters_iconic)
|
label.bind("<Enter>", enters_iconic)
|
||||||
label.bind("<Leave>", leaves_iconic)
|
label.bind("<Leave>", leaves_iconic)
|
||||||
label.bind("<Button-1>", presshold_iconic)
|
label.bind("<Button-1>", presshold_iconic)
|
||||||
label.bind("<ButtonRelease-1>", press_iconic)
|
label.bind("<ButtonRelease-1>", press_iconic)
|
||||||
|
|
|
@ -1,414 +1,414 @@
|
||||||
import tkinter
|
import tkinter
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
|
|
||||||
def place_move_up(self, root):
|
def place_move_up(self, root):
|
||||||
global change_bar_move_up, up_move_start, up_move
|
global change_bar_move_up, up_move_start, up_move
|
||||||
move_up = ttk.Frame(
|
move_up = ttk.Frame(
|
||||||
root, style="Size.TFrame", height=6, width=self.tk_w_without_bar.get(), cursor="top_side")
|
root, style="Size.TFrame", height=6, width=self.tk_w_without_bar.get(), cursor="top_side")
|
||||||
|
|
||||||
def change_bar_move_up(*args, **kwargs):
|
def change_bar_move_up(*args, **kwargs):
|
||||||
move_up.configure(width=self.tk_w_without_bar.get())
|
move_up.configure(width=self.tk_w_without_bar.get())
|
||||||
self.tk_w_without_bar.trace_add('write', change_bar_move_up)
|
self.tk_w_without_bar.trace_add('write', change_bar_move_up)
|
||||||
move_up.place(x=0, y=0)
|
move_up.place(x=0, y=0)
|
||||||
upstart_h = self.h
|
upstart_h = self.h
|
||||||
upstart_y = self.y
|
upstart_y = self.y
|
||||||
|
|
||||||
def up_move_start(event: tkinter.Event):
|
def up_move_start(event: tkinter.Event):
|
||||||
# self.disable_move = True
|
# self.disable_move = True
|
||||||
# print(1)
|
# print(1)
|
||||||
nonlocal upstart_h, upstart_y
|
nonlocal upstart_h, upstart_y
|
||||||
upstart_h = self.h-self.top_h
|
upstart_h = self.h-self.top_h
|
||||||
upstart_y = event.y_root
|
upstart_y = event.y_root
|
||||||
|
|
||||||
def up_move(event: tkinter.Event):
|
def up_move(event: tkinter.Event):
|
||||||
nonlocal upstart_h, upstart_y
|
nonlocal upstart_h, upstart_y
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
return
|
return
|
||||||
now_y = event.y_root
|
now_y = event.y_root
|
||||||
delta_y = upstart_y-now_y
|
delta_y = upstart_y-now_y
|
||||||
now_h = upstart_h+delta_y
|
now_h = upstart_h+delta_y
|
||||||
if (now_h < self.min_h):
|
if (now_h < self.min_h):
|
||||||
return
|
return
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.y = upstart_y-delta_y
|
self.y = upstart_y-delta_y
|
||||||
self.h = now_h+self.top_h
|
self.h = now_h+self.top_h
|
||||||
self.update_size()
|
self.update_size()
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
move_up.bind("<Button-1>", up_move_start)
|
move_up.bind("<Button-1>", up_move_start)
|
||||||
move_up.bind("<B1-Motion>", up_move)
|
move_up.bind("<B1-Motion>", up_move)
|
||||||
|
|
||||||
|
|
||||||
def place_move_up_bar(self, root):
|
def place_move_up_bar(self, root):
|
||||||
move_up_bar = ttk.Frame(
|
move_up_bar = ttk.Frame(
|
||||||
root, style="Size.TFrame", height=1, width=48*3, cursor="top_side")
|
root, style="Size.TFrame", height=1, width=48*3, cursor="top_side")
|
||||||
|
|
||||||
def change_bar_move_up(*args, **kwargs):
|
def change_bar_move_up(*args, **kwargs):
|
||||||
move_up_bar.place(x=self.tk_w_without_bar.get(), y=0)
|
move_up_bar.place(x=self.tk_w_without_bar.get(), y=0)
|
||||||
self.tk_w_without_bar.trace_add('write', change_bar_move_up)
|
self.tk_w_without_bar.trace_add('write', change_bar_move_up)
|
||||||
|
|
||||||
self.tk_w_without_bar.trace_add('write', change_bar_move_up)
|
self.tk_w_without_bar.trace_add('write', change_bar_move_up)
|
||||||
move_up_bar.place(y=0, x=self.tk_w_without_bar.get())
|
move_up_bar.place(y=0, x=self.tk_w_without_bar.get())
|
||||||
move_up_bar.bind("<Button-1>", up_move_start)
|
move_up_bar.bind("<Button-1>", up_move_start)
|
||||||
move_up_bar.bind("<B1-Motion>", up_move)
|
move_up_bar.bind("<B1-Motion>", up_move)
|
||||||
|
|
||||||
|
|
||||||
def place_move_down(self, root):
|
def place_move_down(self, root):
|
||||||
global down_move_start, down_move
|
global down_move_start, down_move
|
||||||
move_down = ttk.Frame(
|
move_down = ttk.Frame(
|
||||||
root, style="Size.TFrame", height=4, width=self.tk_w_without_bar.get(), cursor="bottom_side")
|
root, style="Size.TFrame", height=4, width=self.tk_w_without_bar.get(), cursor="bottom_side")
|
||||||
|
|
||||||
def change_bar_move_up(*args, **kwargs):
|
def change_bar_move_up(*args, **kwargs):
|
||||||
move_down.place(x=0, y=self.top_h+self.h-4, relwidth=1)
|
move_down.place(x=0, y=self.top_h+self.h-4, relwidth=1)
|
||||||
self.tk_w_without_bar.trace_add('write', change_bar_move_up)
|
self.tk_w_without_bar.trace_add('write', change_bar_move_up)
|
||||||
move_down.place(x=0, y=self.top_h+self.h-4, relwidth=1)
|
move_down.place(x=0, y=self.top_h+self.h-4, relwidth=1)
|
||||||
downstart_h = self.h
|
downstart_h = self.h
|
||||||
downstart_y = self.y
|
downstart_y = self.y
|
||||||
|
|
||||||
def down_move_start(event: tkinter.Event):
|
def down_move_start(event: tkinter.Event):
|
||||||
nonlocal downstart_h, downstart_y
|
nonlocal downstart_h, downstart_y
|
||||||
downstart_h = self.h-self.top_h
|
downstart_h = self.h-self.top_h
|
||||||
downstart_y = event.y_root
|
downstart_y = event.y_root
|
||||||
|
|
||||||
def down_move(event: tkinter.Event):
|
def down_move(event: tkinter.Event):
|
||||||
nonlocal downstart_h, downstart_y
|
nonlocal downstart_h, downstart_y
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
return
|
return
|
||||||
now_y = event.y_root
|
now_y = event.y_root
|
||||||
delta_y = downstart_y-now_y
|
delta_y = downstart_y-now_y
|
||||||
now_h = downstart_h-delta_y
|
now_h = downstart_h-delta_y
|
||||||
if (now_h < self.min_h):
|
if (now_h < self.min_h):
|
||||||
return
|
return
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.h = now_h+self.top_h
|
self.h = now_h+self.top_h
|
||||||
self.update_size()
|
self.update_size()
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
move_down.bind("<Button-1>", down_move_start)
|
move_down.bind("<Button-1>", down_move_start)
|
||||||
move_down.bind("<B1-Motion>", down_move)
|
move_down.bind("<B1-Motion>", down_move)
|
||||||
|
|
||||||
|
|
||||||
def place_move_left(self, root):
|
def place_move_left(self, root):
|
||||||
global left_move_start, left_move
|
global left_move_start, left_move
|
||||||
move_left = ttk.Frame(
|
move_left = ttk.Frame(
|
||||||
root, style="Size.TFrame", width=6, height=self.top_h, cursor="left_side")
|
root, style="Size.TFrame", width=6, height=self.top_h, cursor="left_side")
|
||||||
|
|
||||||
move_left.place(x=0, y=0)
|
move_left.place(x=0, y=0)
|
||||||
leftstart_w = self.w
|
leftstart_w = self.w
|
||||||
leftstart_x = self.x
|
leftstart_x = self.x
|
||||||
|
|
||||||
def left_move_start(event: tkinter.Event):
|
def left_move_start(event: tkinter.Event):
|
||||||
# self.disable_move = True
|
# self.disable_move = True
|
||||||
# print(1)
|
# print(1)
|
||||||
nonlocal leftstart_w, leftstart_x
|
nonlocal leftstart_w, leftstart_x
|
||||||
leftstart_w = self.w
|
leftstart_w = self.w
|
||||||
leftstart_x = event.x_root
|
leftstart_x = event.x_root
|
||||||
|
|
||||||
def left_move(event: tkinter.Event):
|
def left_move(event: tkinter.Event):
|
||||||
nonlocal leftstart_w, leftstart_x
|
nonlocal leftstart_w, leftstart_x
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
return
|
return
|
||||||
now_x = event.x_root
|
now_x = event.x_root
|
||||||
delta_x = leftstart_x-now_x
|
delta_x = leftstart_x-now_x
|
||||||
now_w = leftstart_w+delta_x
|
now_w = leftstart_w+delta_x
|
||||||
if (now_w < self.min_w):
|
if (now_w < self.min_w):
|
||||||
return
|
return
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.x = leftstart_x-delta_x
|
self.x = leftstart_x-delta_x
|
||||||
self.w = now_w
|
self.w = now_w
|
||||||
self.update_size()
|
self.update_size()
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
move_left.bind("<Button-1>", left_move_start)
|
move_left.bind("<Button-1>", left_move_start)
|
||||||
move_left.bind("<B1-Motion>", left_move)
|
move_left.bind("<B1-Motion>", left_move)
|
||||||
|
|
||||||
|
|
||||||
def place_move_left_bar(self, root):
|
def place_move_left_bar(self, root):
|
||||||
move_left = ttk.Frame(
|
move_left = ttk.Frame(
|
||||||
root, style="Size.TFrame", width=4, height=self.h, cursor="left_side")
|
root, style="Size.TFrame", width=4, height=self.h, cursor="left_side")
|
||||||
|
|
||||||
def change_bar_move_up(*args, **kwargs):
|
def change_bar_move_up(*args, **kwargs):
|
||||||
move_left.configure(height=self.h)
|
move_left.configure(height=self.h)
|
||||||
self.tk_w_without_bar.trace_add('write', change_bar_move_up)
|
self.tk_w_without_bar.trace_add('write', change_bar_move_up)
|
||||||
move_left.place(x=0, y=self.top_h)
|
move_left.place(x=0, y=self.top_h)
|
||||||
|
|
||||||
move_left.bind("<Button-1>", left_move_start)
|
move_left.bind("<Button-1>", left_move_start)
|
||||||
move_left.bind("<B1-Motion>", left_move)
|
move_left.bind("<B1-Motion>", left_move)
|
||||||
|
|
||||||
|
|
||||||
def place_move_right(self, root):
|
def place_move_right(self, root):
|
||||||
global right_move, right_move_start
|
global right_move, right_move_start
|
||||||
move_right = ttk.Frame(
|
move_right = ttk.Frame(
|
||||||
root, style="Size.TFrame", width=1, height=self.top_h, cursor="right_side")
|
root, style="Size.TFrame", width=1, height=self.top_h, cursor="right_side")
|
||||||
|
|
||||||
def change_bar_move(*args, **kwargs):
|
def change_bar_move(*args, **kwargs):
|
||||||
move_right.place(x=self.w-1, y=0)
|
move_right.place(x=self.w-1, y=0)
|
||||||
self.tk_w_without_bar.trace_add('write', change_bar_move)
|
self.tk_w_without_bar.trace_add('write', change_bar_move)
|
||||||
move_right.place(x=self.w-1, y=0)
|
move_right.place(x=self.w-1, y=0)
|
||||||
rightstart_w = self.w
|
rightstart_w = self.w
|
||||||
rightstart_x = self.x
|
rightstart_x = self.x
|
||||||
|
|
||||||
def right_move_start(event: tkinter.Event):
|
def right_move_start(event: tkinter.Event):
|
||||||
# self.disable_move = True
|
# self.disable_move = True
|
||||||
# print(1)
|
# print(1)
|
||||||
nonlocal rightstart_w, rightstart_x
|
nonlocal rightstart_w, rightstart_x
|
||||||
rightstart_w = self.w
|
rightstart_w = self.w
|
||||||
rightstart_x = event.x_root
|
rightstart_x = event.x_root
|
||||||
|
|
||||||
def right_move(event: tkinter.Event):
|
def right_move(event: tkinter.Event):
|
||||||
nonlocal rightstart_w, rightstart_x
|
nonlocal rightstart_w, rightstart_x
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
return
|
return
|
||||||
now_x = event.x_root
|
now_x = event.x_root
|
||||||
delta_x = rightstart_x-now_x
|
delta_x = rightstart_x-now_x
|
||||||
now_w = rightstart_w-delta_x
|
now_w = rightstart_w-delta_x
|
||||||
if (now_w < self.min_w):
|
if (now_w < self.min_w):
|
||||||
return
|
return
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.w = now_w
|
self.w = now_w
|
||||||
self.update_size()
|
self.update_size()
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
move_right.bind("<Button-1>", right_move_start)
|
move_right.bind("<Button-1>", right_move_start)
|
||||||
move_right.bind("<B1-Motion>", right_move)
|
move_right.bind("<B1-Motion>", right_move)
|
||||||
|
|
||||||
|
|
||||||
def place_move_right_bar(self, root):
|
def place_move_right_bar(self, root):
|
||||||
move_right = ttk.Frame(
|
move_right = ttk.Frame(
|
||||||
root, style="Size.TFrame", width=4, height=self.h, cursor="right_side")
|
root, style="Size.TFrame", width=4, height=self.h, cursor="right_side")
|
||||||
|
|
||||||
def change_bar_move_right(*args, **kwargs):
|
def change_bar_move_right(*args, **kwargs):
|
||||||
move_right.place(x=self.w-4, y=self.top_h)
|
move_right.place(x=self.w-4, y=self.top_h)
|
||||||
move_right.configure(height=self.h)
|
move_right.configure(height=self.h)
|
||||||
self.tk_w_without_bar.trace_add('write', change_bar_move_right)
|
self.tk_w_without_bar.trace_add('write', change_bar_move_right)
|
||||||
move_right.place(x=self.w-4, y=self.top_h)
|
move_right.place(x=self.w-4, y=self.top_h)
|
||||||
move_right.bind("<Button-1>", right_move_start)
|
move_right.bind("<Button-1>", right_move_start)
|
||||||
move_right.bind("<B1-Motion>", right_move)
|
move_right.bind("<B1-Motion>", right_move)
|
||||||
|
|
||||||
|
|
||||||
def place_move_LT_bar(self, root):
|
def place_move_LT_bar(self, root):
|
||||||
move_LT = ttk.Frame(
|
move_LT = ttk.Frame(
|
||||||
root, style="Size.TFrame", width=8, height=8, cursor="top_left_corner")
|
root, style="Size.TFrame", width=8, height=8, cursor="top_left_corner")
|
||||||
|
|
||||||
move_LT.place(x=0, y=0)
|
move_LT.place(x=0, y=0)
|
||||||
|
|
||||||
leftstart_w = self.w
|
leftstart_w = self.w
|
||||||
leftstart_x = self.x
|
leftstart_x = self.x
|
||||||
upstart_h = self.h
|
upstart_h = self.h
|
||||||
upstart_y = self.y
|
upstart_y = self.y
|
||||||
|
|
||||||
def LT_move_start(event=None):
|
def LT_move_start(event=None):
|
||||||
nonlocal leftstart_w, leftstart_x
|
nonlocal leftstart_w, leftstart_x
|
||||||
leftstart_w = self.w
|
leftstart_w = self.w
|
||||||
leftstart_x = event.x_root
|
leftstart_x = event.x_root
|
||||||
nonlocal upstart_h, upstart_y
|
nonlocal upstart_h, upstart_y
|
||||||
upstart_h = self.h-self.top_h
|
upstart_h = self.h-self.top_h
|
||||||
upstart_y = event.y_root
|
upstart_y = event.y_root
|
||||||
|
|
||||||
def LT_move(event=None):
|
def LT_move(event=None):
|
||||||
while 1:
|
while 1:
|
||||||
nonlocal leftstart_w, leftstart_x
|
nonlocal leftstart_w, leftstart_x
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
break
|
break
|
||||||
now_x = event.x_root
|
now_x = event.x_root
|
||||||
delta_x = leftstart_x-now_x
|
delta_x = leftstart_x-now_x
|
||||||
now_w = leftstart_w+delta_x
|
now_w = leftstart_w+delta_x
|
||||||
if (now_w < self.min_w):
|
if (now_w < self.min_w):
|
||||||
break
|
break
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.x = leftstart_x-delta_x
|
self.x = leftstart_x-delta_x
|
||||||
self.w = now_w
|
self.w = now_w
|
||||||
break
|
break
|
||||||
while 1:
|
while 1:
|
||||||
nonlocal upstart_h, upstart_y
|
nonlocal upstart_h, upstart_y
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
break
|
break
|
||||||
now_y = event.y_root
|
now_y = event.y_root
|
||||||
delta_y = upstart_y-now_y
|
delta_y = upstart_y-now_y
|
||||||
now_h = upstart_h+delta_y
|
now_h = upstart_h+delta_y
|
||||||
if (now_h < self.min_h):
|
if (now_h < self.min_h):
|
||||||
break
|
break
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.y = upstart_y-delta_y
|
self.y = upstart_y-delta_y
|
||||||
self.h = now_h+self.top_h
|
self.h = now_h+self.top_h
|
||||||
break
|
break
|
||||||
self.update_size()
|
self.update_size()
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
|
|
||||||
move_LT.bind("<Button-1>", LT_move_start)
|
move_LT.bind("<Button-1>", LT_move_start)
|
||||||
move_LT.bind("<B1-Motion>", LT_move)
|
move_LT.bind("<B1-Motion>", LT_move)
|
||||||
|
|
||||||
|
|
||||||
def place_move_RT_bar(self, root):
|
def place_move_RT_bar(self, root):
|
||||||
move_RT = ttk.Frame(
|
move_RT = ttk.Frame(
|
||||||
root, style="Size.TFrame", width=2, height=2, cursor="top_right_corner")
|
root, style="Size.TFrame", width=2, height=2, cursor="top_right_corner")
|
||||||
|
|
||||||
def change_bar_move(*args, **kwargs):
|
def change_bar_move(*args, **kwargs):
|
||||||
move_RT.place(x=self.w-2, y=0)
|
move_RT.place(x=self.w-2, y=0)
|
||||||
self.tk_w_without_bar.trace_add('write', change_bar_move)
|
self.tk_w_without_bar.trace_add('write', change_bar_move)
|
||||||
move_RT.place(x=self.w-2, y=0)
|
move_RT.place(x=self.w-2, y=0)
|
||||||
|
|
||||||
upstart_h = self.h
|
upstart_h = self.h
|
||||||
upstart_y = self.y
|
upstart_y = self.y
|
||||||
rightstart_w = self.w
|
rightstart_w = self.w
|
||||||
rightstart_x = self.x
|
rightstart_x = self.x
|
||||||
|
|
||||||
def RT_move_start(event=None):
|
def RT_move_start(event=None):
|
||||||
nonlocal upstart_h, upstart_y
|
nonlocal upstart_h, upstart_y
|
||||||
upstart_h = self.h-self.top_h
|
upstart_h = self.h-self.top_h
|
||||||
upstart_y = event.y_root
|
upstart_y = event.y_root
|
||||||
nonlocal rightstart_w, rightstart_x
|
nonlocal rightstart_w, rightstart_x
|
||||||
rightstart_w = self.w
|
rightstart_w = self.w
|
||||||
rightstart_x = event.x_root
|
rightstart_x = event.x_root
|
||||||
|
|
||||||
def RT_move(event=None):
|
def RT_move(event=None):
|
||||||
while 1:
|
while 1:
|
||||||
nonlocal upstart_h, upstart_y
|
nonlocal upstart_h, upstart_y
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
break
|
break
|
||||||
now_y = event.y_root
|
now_y = event.y_root
|
||||||
delta_y = upstart_y-now_y
|
delta_y = upstart_y-now_y
|
||||||
now_h = upstart_h+delta_y
|
now_h = upstart_h+delta_y
|
||||||
if (now_h < self.min_h):
|
if (now_h < self.min_h):
|
||||||
break
|
break
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.y = upstart_y-delta_y
|
self.y = upstart_y-delta_y
|
||||||
self.h = now_h+self.top_h
|
self.h = now_h+self.top_h
|
||||||
break
|
break
|
||||||
while 1:
|
while 1:
|
||||||
nonlocal rightstart_w, rightstart_x
|
nonlocal rightstart_w, rightstart_x
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
break
|
break
|
||||||
now_x = event.x_root
|
now_x = event.x_root
|
||||||
delta_x = rightstart_x-now_x
|
delta_x = rightstart_x-now_x
|
||||||
now_w = rightstart_w-delta_x
|
now_w = rightstart_w-delta_x
|
||||||
if (now_w < self.min_w):
|
if (now_w < self.min_w):
|
||||||
break
|
break
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.w = now_w
|
self.w = now_w
|
||||||
break
|
break
|
||||||
self.update_size()
|
self.update_size()
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
|
|
||||||
move_RT.bind("<Button-1>", RT_move_start)
|
move_RT.bind("<Button-1>", RT_move_start)
|
||||||
move_RT.bind("<B1-Motion>", RT_move)
|
move_RT.bind("<B1-Motion>", RT_move)
|
||||||
|
|
||||||
|
|
||||||
def place_move_RB_bar(self, root):
|
def place_move_RB_bar(self, root):
|
||||||
move_RB = ttk.Frame(
|
move_RB = ttk.Frame(
|
||||||
root, style="Size.TFrame", width=6, height=6, cursor="bottom_right_corner")
|
root, style="Size.TFrame", width=6, height=6, cursor="bottom_right_corner")
|
||||||
|
|
||||||
def change_bar_move(*args, **kwargs):
|
def change_bar_move(*args, **kwargs):
|
||||||
move_RB.place(x=self.w-6, y=self.h-6+self.top_h)
|
move_RB.place(x=self.w-6, y=self.h-6+self.top_h)
|
||||||
self.tk_w_without_bar.trace_add('write', change_bar_move)
|
self.tk_w_without_bar.trace_add('write', change_bar_move)
|
||||||
move_RB.place(x=self.w-6, y=self.h-6+self.top_h)
|
move_RB.place(x=self.w-6, y=self.h-6+self.top_h)
|
||||||
|
|
||||||
rightstart_x = self.x
|
rightstart_x = self.x
|
||||||
rightstart_w = self.w
|
rightstart_w = self.w
|
||||||
downstart_h = self.h
|
downstart_h = self.h
|
||||||
downstart_y = self.y
|
downstart_y = self.y
|
||||||
|
|
||||||
def RB_move_start(event=None):
|
def RB_move_start(event=None):
|
||||||
nonlocal rightstart_w, rightstart_x
|
nonlocal rightstart_w, rightstart_x
|
||||||
rightstart_w = self.w
|
rightstart_w = self.w
|
||||||
rightstart_x = event.x_root
|
rightstart_x = event.x_root
|
||||||
nonlocal downstart_h, downstart_y
|
nonlocal downstart_h, downstart_y
|
||||||
downstart_h = self.h-self.top_h
|
downstart_h = self.h-self.top_h
|
||||||
downstart_y = event.y_root
|
downstart_y = event.y_root
|
||||||
|
|
||||||
def RB_move(event=None):
|
def RB_move(event=None):
|
||||||
while 1:
|
while 1:
|
||||||
nonlocal rightstart_w, rightstart_x
|
nonlocal rightstart_w, rightstart_x
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
break
|
break
|
||||||
now_x = event.x_root
|
now_x = event.x_root
|
||||||
delta_x = rightstart_x-now_x
|
delta_x = rightstart_x-now_x
|
||||||
now_w = rightstart_w-delta_x
|
now_w = rightstart_w-delta_x
|
||||||
if (now_w < self.min_w):
|
if (now_w < self.min_w):
|
||||||
break
|
break
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.w = now_w
|
self.w = now_w
|
||||||
break
|
break
|
||||||
while 1:
|
while 1:
|
||||||
nonlocal downstart_h, downstart_y
|
nonlocal downstart_h, downstart_y
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
break
|
break
|
||||||
now_y = event.y_root
|
now_y = event.y_root
|
||||||
delta_y = downstart_y-now_y
|
delta_y = downstart_y-now_y
|
||||||
now_h = downstart_h-delta_y
|
now_h = downstart_h-delta_y
|
||||||
if (now_h < self.min_h):
|
if (now_h < self.min_h):
|
||||||
break
|
break
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.h = now_h+self.top_h
|
self.h = now_h+self.top_h
|
||||||
break
|
break
|
||||||
self.update_size()
|
self.update_size()
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
|
|
||||||
move_RB.bind("<Button-1>", RB_move_start)
|
move_RB.bind("<Button-1>", RB_move_start)
|
||||||
move_RB.bind("<B1-Motion>", RB_move)
|
move_RB.bind("<B1-Motion>", RB_move)
|
||||||
|
|
||||||
|
|
||||||
def place_move_LB_bar(self, root):
|
def place_move_LB_bar(self, root):
|
||||||
move_LB = ttk.Frame(
|
move_LB = ttk.Frame(
|
||||||
root, style="Size.TFrame", width=4, height=4, cursor="bottom_left_corner")
|
root, style="Size.TFrame", width=4, height=4, cursor="bottom_left_corner")
|
||||||
|
|
||||||
def change_bar_move(*args, **kwargs):
|
def change_bar_move(*args, **kwargs):
|
||||||
move_LB.place(x=0, y=self.h-4+self.top_h)
|
move_LB.place(x=0, y=self.h-4+self.top_h)
|
||||||
self.tk_w_without_bar.trace_add('write', change_bar_move)
|
self.tk_w_without_bar.trace_add('write', change_bar_move)
|
||||||
move_LB.place(x=0, y=self.h-4+self.top_h)
|
move_LB.place(x=0, y=self.h-4+self.top_h)
|
||||||
|
|
||||||
leftstart_w = self.w
|
leftstart_w = self.w
|
||||||
leftstart_x = self.x
|
leftstart_x = self.x
|
||||||
downstart_h = self.h
|
downstart_h = self.h
|
||||||
downstart_y = self.y
|
downstart_y = self.y
|
||||||
|
|
||||||
def LB_move_start(event=None):
|
def LB_move_start(event=None):
|
||||||
nonlocal leftstart_w, leftstart_x
|
nonlocal leftstart_w, leftstart_x
|
||||||
leftstart_w = self.w
|
leftstart_w = self.w
|
||||||
leftstart_x = event.x_root
|
leftstart_x = event.x_root
|
||||||
nonlocal downstart_h, downstart_y
|
nonlocal downstart_h, downstart_y
|
||||||
downstart_h = self.h-self.top_h
|
downstart_h = self.h-self.top_h
|
||||||
downstart_y = event.y_root
|
downstart_y = event.y_root
|
||||||
|
|
||||||
def LB_move(event=None):
|
def LB_move(event=None):
|
||||||
while 1:
|
while 1:
|
||||||
nonlocal leftstart_w, leftstart_x
|
nonlocal leftstart_w, leftstart_x
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
break
|
break
|
||||||
now_x = event.x_root
|
now_x = event.x_root
|
||||||
delta_x = leftstart_x-now_x
|
delta_x = leftstart_x-now_x
|
||||||
now_w = leftstart_w+delta_x
|
now_w = leftstart_w+delta_x
|
||||||
if (now_w < self.min_w):
|
if (now_w < self.min_w):
|
||||||
break
|
break
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.x = leftstart_x-delta_x
|
self.x = leftstart_x-delta_x
|
||||||
self.w = now_w
|
self.w = now_w
|
||||||
break
|
break
|
||||||
while 1:
|
while 1:
|
||||||
nonlocal downstart_h, downstart_y
|
nonlocal downstart_h, downstart_y
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
break
|
break
|
||||||
now_y = event.y_root
|
now_y = event.y_root
|
||||||
delta_y = downstart_y-now_y
|
delta_y = downstart_y-now_y
|
||||||
now_h = downstart_h-delta_y
|
now_h = downstart_h-delta_y
|
||||||
if (now_h < self.min_h):
|
if (now_h < self.min_h):
|
||||||
break
|
break
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.h = now_h+self.top_h
|
self.h = now_h+self.top_h
|
||||||
break
|
break
|
||||||
self.update_size()
|
self.update_size()
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
|
|
||||||
move_LB.bind("<Button-1>", LB_move_start)
|
move_LB.bind("<Button-1>", LB_move_start)
|
||||||
move_LB.bind("<B1-Motion>", LB_move)
|
move_LB.bind("<B1-Motion>", LB_move)
|
||||||
|
|
||||||
|
|
||||||
def placeall(self, root):
|
def placeall(self, root):
|
||||||
place_move_up(self, root)
|
place_move_up(self, root)
|
||||||
place_move_up_bar(self, root)
|
place_move_up_bar(self, root)
|
||||||
place_move_down(self, root)
|
place_move_down(self, root)
|
||||||
place_move_left(self, root)
|
place_move_left(self, root)
|
||||||
place_move_left_bar(self, root)
|
place_move_left_bar(self, root)
|
||||||
place_move_right(self, root)
|
place_move_right(self, root)
|
||||||
place_move_right_bar(self, root)
|
place_move_right_bar(self, root)
|
||||||
place_move_LT_bar(self, root)
|
place_move_LT_bar(self, root)
|
||||||
place_move_RT_bar(self, root)
|
place_move_RT_bar(self, root)
|
||||||
place_move_LB_bar(self, root)
|
place_move_LB_bar(self, root)
|
||||||
place_move_RB_bar(self, root)
|
place_move_RB_bar(self, root)
|
||||||
|
|
|
@ -1,483 +1,487 @@
|
||||||
import json
|
import json
|
||||||
import tkinter
|
import tkinter
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
from tkinter import font as tkfont
|
from tkinter import font as tkfont
|
||||||
try:
|
try:
|
||||||
import color_tmpl
|
import color_tmpl
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from magictk import color_tmpl
|
from magictk import color_tmpl
|
||||||
try:
|
try:
|
||||||
import photoload
|
import photoload
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from magictk import photoload
|
from magictk import photoload
|
||||||
|
|
||||||
|
|
||||||
def set_font():
|
def set_font():
|
||||||
global use_font
|
global use_font
|
||||||
font_family = ["Helvetica Neue", "Helvetica", "PingFang SC", "Hiragino Sans GB",
|
font_family = ["Helvetica Neue", "Helvetica", "PingFang SC", "Hiragino Sans GB",
|
||||||
"Microsoft YaHei",
|
"Microsoft YaHei",
|
||||||
"微软雅黑",
|
"微软雅黑",
|
||||||
"Arial", "sans-serif"]
|
"Arial", "sans-serif"]
|
||||||
t_family = tkfont.families(root=None, displayof=None)
|
t_family = tkfont.families(root=None, displayof=None)
|
||||||
for i in font_family:
|
for i in font_family:
|
||||||
if i in t_family:
|
if i in t_family:
|
||||||
use_font = i
|
use_font = i
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print("Unknown font")
|
print("Unknown font")
|
||||||
|
|
||||||
|
|
||||||
class Button:
|
class Button:
|
||||||
color = color_tmpl.default_color
|
color = color_tmpl.default_color
|
||||||
__fill_obj = []
|
__fill_obj = []
|
||||||
__fill_func = []
|
__fill_func = []
|
||||||
__fill_gc = []
|
__fill_gc = []
|
||||||
__fill_fc = []
|
__fill_fc = []
|
||||||
__fill_hc = []
|
__fill_hc = []
|
||||||
hover_mode = 0.0
|
hover_mode = 0.0
|
||||||
__is_hover = 0
|
__is_hover = 0
|
||||||
__flash_t = 0
|
__flash_t = 0
|
||||||
max_flash = 4
|
max_flash = 4
|
||||||
__anim_obj_id = -1
|
__anim_obj_id = -1
|
||||||
__color_bd = "border_base"
|
__color_bd = "border_base"
|
||||||
__color_bg = "background"
|
__color_bg = "background"
|
||||||
__color_fg = "primary"
|
__color_fg = "primary"
|
||||||
__color_fg1 = "primary_light"
|
__color_fg1 = "primary_light"
|
||||||
__color_fg2 = "primary_light2"
|
__color_fg2 = "primary_light2"
|
||||||
text = "Button"
|
text = "Button"
|
||||||
|
|
||||||
def __draw_corner(self, r_x, r_y, x, y, **kwargs):
|
def __draw_corner(self, r_x, r_y, x, y, **kwargs):
|
||||||
border_info = json.loads(photoload.loadres("buttonborder"))
|
border_info = json.loads(photoload.loadres("buttonborder"))
|
||||||
y_n = 0
|
y_n = 0
|
||||||
for i in border_info:
|
for i in border_info:
|
||||||
x_n = 0
|
x_n = 0
|
||||||
for j in i:
|
for j in i:
|
||||||
if (r_x == 0):
|
if (r_x == 0):
|
||||||
px = x+x_n+1
|
px = x+x_n+1
|
||||||
else:
|
else:
|
||||||
px = x+4-x_n-1
|
px = x+4-x_n-1
|
||||||
if (r_y == 0):
|
if (r_y == 0):
|
||||||
py = y+y_n+1
|
py = y+y_n+1
|
||||||
else:
|
else:
|
||||||
py = y+4-y_n-1
|
py = y+4-y_n-1
|
||||||
if (j < 0):
|
if (j < 0):
|
||||||
lcolor = -j
|
lcolor = -j
|
||||||
else:
|
else:
|
||||||
lcolor = j
|
lcolor = j
|
||||||
g_color = color_tmpl.mix_color(
|
g_color = color_tmpl.mix_color(
|
||||||
self.color["background"], self.color[self.__color_bd], int((1-lcolor/255)*1000)/1000)
|
self.color["background"], self.color[self.__color_bd], int((1-lcolor/255)*1000)/1000)
|
||||||
if (j < 0):
|
if (j < 0):
|
||||||
f_color = color_tmpl.mix_color(
|
f_color = color_tmpl.mix_color(
|
||||||
self.color[self.__color_fg2], self.color[self.__color_fg1], int((1-lcolor/255)*1000)/1000)
|
self.color[self.__color_fg2], self.color[self.__color_fg1], int((1-lcolor/255)*1000)/1000)
|
||||||
else:
|
else:
|
||||||
f_color = color_tmpl.mix_color(
|
f_color = color_tmpl.mix_color(
|
||||||
self.color["background"], self.color[self.__color_fg1], int((1-lcolor/255)*1000)/1000)
|
self.color["background"], self.color[self.__color_fg1], int((1-lcolor/255)*1000)/1000)
|
||||||
if (j < 0):
|
if (j < 0):
|
||||||
h_color = color_tmpl.mix_color(
|
h_color = color_tmpl.mix_color(
|
||||||
self.color[self.__color_fg2], self.color[self.__color_fg], int((1-lcolor/255)*1000)/1000)
|
self.color[self.__color_fg2], self.color[self.__color_fg], int((1-lcolor/255)*1000)/1000)
|
||||||
else:
|
else:
|
||||||
h_color = color_tmpl.mix_color(
|
h_color = color_tmpl.mix_color(
|
||||||
self.color["background"], self.color[self.__color_fg], int((1-lcolor/255)*1000)/1000)
|
self.color["background"], self.color[self.__color_fg], int((1-lcolor/255)*1000)/1000)
|
||||||
|
|
||||||
obj = self.canvas.create_rectangle(
|
obj = self.canvas.create_rectangle(
|
||||||
px, py, px, py, width=0, fill=g_color)
|
px, py, px, py, width=0, fill=g_color)
|
||||||
|
|
||||||
def update_color(obj, g_color, f_color, h_color):
|
def update_color(obj, g_color, f_color, h_color):
|
||||||
if (self.__is_hover == 2):
|
if (self.__is_hover == 2):
|
||||||
self.canvas.itemconfig(
|
self.canvas.itemconfig(
|
||||||
obj, fill=h_color)
|
obj, fill=h_color)
|
||||||
else:
|
else:
|
||||||
self.canvas.itemconfig(
|
self.canvas.itemconfig(
|
||||||
obj, fill=color_tmpl.mix_color(g_color, f_color, self.hover_mode))
|
obj, fill=color_tmpl.mix_color(g_color, f_color, self.hover_mode))
|
||||||
|
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_func.append(update_color)
|
||||||
self.__fill_gc.append(g_color)
|
self.__fill_gc.append(g_color)
|
||||||
self.__fill_fc.append(f_color)
|
self.__fill_fc.append(f_color)
|
||||||
self.__fill_hc.append(h_color)
|
self.__fill_hc.append(h_color)
|
||||||
self.__fill_obj.append(obj)
|
self.__fill_obj.append(obj)
|
||||||
x_n += 1
|
x_n += 1
|
||||||
y_n += 1
|
y_n += 1
|
||||||
|
|
||||||
def __update_color(self):
|
def __update_color(self):
|
||||||
n = 0
|
n = 0
|
||||||
for i in self.__fill_func:
|
for i in self.__fill_func:
|
||||||
i(self.__fill_obj[n], self.__fill_gc[n],
|
i(self.__fill_obj[n], self.__fill_gc[n],
|
||||||
self.__fill_fc[n], self.__fill_hc[n])
|
self.__fill_fc[n], self.__fill_hc[n])
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
def __init__(self, master=None, root_anim=None, w=80, h=30, text="Button", color_list: None | dict = None):
|
def __init__(self, master=None, root_anim=None, w=80, h=30, text="Button", func=lambda s: print("Press"), color_list: None | dict = None):
|
||||||
set_font()
|
set_font()
|
||||||
self.w = max(80, w)
|
self.__func = func
|
||||||
self.h = max(30, h)
|
self.w = max(80, w)
|
||||||
self.text = text
|
self.h = max(30, h)
|
||||||
self.__master = master
|
self.text = text
|
||||||
if (color_list is not None):
|
self.__master = master
|
||||||
self.color = color_list
|
if (color_list is not None):
|
||||||
if (root_anim == None):
|
self.color = color_list
|
||||||
self.__root = master
|
if (root_anim == None):
|
||||||
else:
|
self.__root = master
|
||||||
self.__root = root_anim
|
else:
|
||||||
|
self.__root = root_anim
|
||||||
self.canvas = tkinter.Canvas(
|
|
||||||
master, bg=self.color["background"], width=self.w, height=self.h, borderwidth=0, bd=0, highlightcolor=self.color["background"], highlightthickness=0)
|
self.canvas = tkinter.Canvas(
|
||||||
|
master, bg=self.color["background"], width=self.w, height=self.h, borderwidth=0, bd=0, highlightcolor=self.color["background"], highlightthickness=0)
|
||||||
self.__draw()
|
|
||||||
self.__update_color()
|
self.__draw()
|
||||||
self.__bind_event()
|
self.__update_color()
|
||||||
self.bind_anim()
|
self.__bind_event()
|
||||||
|
self.bind_anim()
|
||||||
def pack(self, *args, **kwargs):
|
|
||||||
self.canvas.pack(*args, **kwargs)
|
def pack(self, *args, **kwargs):
|
||||||
|
self.canvas.pack(*args, **kwargs)
|
||||||
def guid(self, *args, **kwargs):
|
|
||||||
self.canvas.guid(*args, **kwargs)
|
def guid(self, *args, **kwargs):
|
||||||
|
self.canvas.guid(*args, **kwargs)
|
||||||
def place(self, *args, **kwargs):
|
|
||||||
self.canvas.place(*args, **kwargs)
|
def place(self, *args, **kwargs):
|
||||||
|
self.canvas.place(*args, **kwargs)
|
||||||
def __draw(self):
|
|
||||||
self.__draw_corner(0, 0, 0, 0)
|
def __draw(self):
|
||||||
self.__draw_corner(1, 0, self.w-4, 0)
|
self.__draw_corner(0, 0, 0, 0)
|
||||||
self.__draw_corner(0, 1, 0, self.h-5)
|
self.__draw_corner(1, 0, self.w-4, 0)
|
||||||
self.__draw_corner(1, 1, self.w-4, self.h-5)
|
self.__draw_corner(0, 1, 0, self.h-5)
|
||||||
|
self.__draw_corner(1, 1, self.w-4, self.h-5)
|
||||||
def update_color(obj, g_color, f_color, h_color):
|
|
||||||
if (self.__is_hover == 2):
|
def update_color(obj, g_color, f_color, h_color):
|
||||||
self.canvas.itemconfig(
|
if (self.__is_hover == 2):
|
||||||
obj, fill=h_color)
|
self.canvas.itemconfig(
|
||||||
else:
|
obj, fill=h_color)
|
||||||
self.canvas.itemconfig(
|
else:
|
||||||
obj, fill=color_tmpl.mix_color(g_color, f_color, self.hover_mode))
|
self.canvas.itemconfig(
|
||||||
self.__fill_fc.append(self.color[self.__color_fg1])
|
obj, fill=color_tmpl.mix_color(g_color, f_color, self.hover_mode))
|
||||||
self.__fill_gc.append(self.color[self.__color_bd])
|
self.__fill_fc.append(self.color[self.__color_fg1])
|
||||||
self.__fill_hc.append(self.color[self.__color_fg])
|
self.__fill_gc.append(self.color[self.__color_bd])
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_hc.append(self.color[self.__color_fg])
|
||||||
self.__fill_obj.append(self.canvas.create_line(
|
self.__fill_func.append(update_color)
|
||||||
1, 5, 1, self.h-5, width=1, fill=self.color[self.__color_bd]))
|
self.__fill_obj.append(self.canvas.create_line(
|
||||||
self.__fill_fc.append(self.color[self.__color_fg1])
|
1, 5, 1, self.h-5, width=1, fill=self.color[self.__color_bd]))
|
||||||
self.__fill_gc.append(self.color[self.__color_bd])
|
self.__fill_fc.append(self.color[self.__color_fg1])
|
||||||
self.__fill_hc.append(self.color[self.__color_fg])
|
self.__fill_gc.append(self.color[self.__color_bd])
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_hc.append(self.color[self.__color_fg])
|
||||||
self.__fill_obj.append(self.canvas.create_line(
|
self.__fill_func.append(update_color)
|
||||||
5, 1, self.w-4, 1, width=1, fill=self.color[self.__color_fg1]))
|
self.__fill_obj.append(self.canvas.create_line(
|
||||||
self.__fill_fc.append(self.color[self.__color_fg1])
|
5, 1, self.w-4, 1, width=1, fill=self.color[self.__color_fg1]))
|
||||||
self.__fill_gc.append(self.color[self.__color_bd])
|
self.__fill_fc.append(self.color[self.__color_fg1])
|
||||||
self.__fill_hc.append(self.color[self.__color_fg])
|
self.__fill_gc.append(self.color[self.__color_bd])
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_hc.append(self.color[self.__color_fg])
|
||||||
self.__fill_obj.append(self.canvas.create_line(
|
self.__fill_func.append(update_color)
|
||||||
self.w-1, 5, self.w-1, self.h-5, width=1, fill=self.color[self.__color_fg1]))
|
self.__fill_obj.append(self.canvas.create_line(
|
||||||
self.__fill_fc.append(self.color[self.__color_fg1])
|
self.w-1, 5, self.w-1, self.h-5, width=1, fill=self.color[self.__color_fg1]))
|
||||||
self.__fill_gc.append(self.color[self.__color_bd])
|
self.__fill_fc.append(self.color[self.__color_fg1])
|
||||||
self.__fill_hc.append(self.color[self.__color_fg])
|
self.__fill_gc.append(self.color[self.__color_bd])
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_hc.append(self.color[self.__color_fg])
|
||||||
self.__fill_obj.append(self.canvas.create_line(
|
self.__fill_func.append(update_color)
|
||||||
5, self.h-2, self.w-4, self.h-2, width=1, fill=self.color[self.__color_fg1]))
|
self.__fill_obj.append(self.canvas.create_line(
|
||||||
|
5, self.h-2, self.w-4, self.h-2, width=1, fill=self.color[self.__color_fg1]))
|
||||||
self.__fill_fc.append(self.color[self.__color_fg2])
|
|
||||||
self.__fill_gc.append(self.color["background"])
|
self.__fill_fc.append(self.color[self.__color_fg2])
|
||||||
self.__fill_hc.append(self.color[self.__color_fg2])
|
self.__fill_gc.append(self.color["background"])
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_hc.append(self.color[self.__color_fg2])
|
||||||
self.__fill_obj.append(self.canvas.create_rectangle(
|
self.__fill_func.append(update_color)
|
||||||
2, 5, self.w-1, self.h-5, width=0, fill=self.color[self.__color_fg2]))
|
self.__fill_obj.append(self.canvas.create_rectangle(
|
||||||
|
2, 5, self.w-1, self.h-5, width=0, fill=self.color[self.__color_fg2]))
|
||||||
self.__fill_fc.append(self.color[self.__color_fg2])
|
|
||||||
self.__fill_gc.append(self.color["background"])
|
self.__fill_fc.append(self.color[self.__color_fg2])
|
||||||
self.__fill_hc.append(self.color[self.__color_fg2])
|
self.__fill_gc.append(self.color["background"])
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_hc.append(self.color[self.__color_fg2])
|
||||||
self.__fill_obj.append(self.canvas.create_rectangle(
|
self.__fill_func.append(update_color)
|
||||||
5, 2, self.w-4, self.h-2, width=0, fill=self.color[self.__color_fg2]))
|
self.__fill_obj.append(self.canvas.create_rectangle(
|
||||||
|
5, 2, self.w-4, self.h-2, width=0, fill=self.color[self.__color_fg2]))
|
||||||
self.__fill_fc.append(self.color[self.__color_fg])
|
|
||||||
self.__fill_gc.append(self.color["regular_text"])
|
self.__fill_fc.append(self.color[self.__color_fg])
|
||||||
self.__fill_hc.append(self.color[self.__color_fg])
|
self.__fill_gc.append(self.color["regular_text"])
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_hc.append(self.color[self.__color_fg])
|
||||||
self.__fill_obj.append(
|
self.__fill_func.append(update_color)
|
||||||
self.canvas.create_text(int(self.w/2), int(self.h/2), text=self.text, font=(use_font, 10)))
|
self.__fill_obj.append(
|
||||||
|
self.canvas.create_text(int(self.w/2), int(self.h/2), text=self.text, font=(use_font, 10)))
|
||||||
def bind_anim(self):
|
|
||||||
def anim_magictk():
|
def bind_anim(self):
|
||||||
if (self.__is_hover == 1 and self.__flash_t < self.max_flash):
|
def anim_magictk():
|
||||||
self.__flash_t += (1 if (len(self.__root.anim) > 6) else 1)
|
if (self.__is_hover == 1 and self.__flash_t < self.max_flash):
|
||||||
self.__flash_t = min(self.__flash_t, self.max_flash)
|
self.__flash_t += (1 if (len(self.__root.anim) > 6) else 1)
|
||||||
self.hover_mode = self.__flash_t/self.max_flash
|
self.__flash_t = min(self.__flash_t, self.max_flash)
|
||||||
self.__update_color()
|
self.hover_mode = self.__flash_t/self.max_flash
|
||||||
elif (self.__is_hover == 0 and self.__flash_t > 0):
|
self.__update_color()
|
||||||
self.__flash_t -= (1 if (len(self.__root.anim) > 6) else 1)
|
elif (self.__is_hover == 0 and self.__flash_t > 0):
|
||||||
self.__flash_t = max(self.__flash_t, 0)
|
self.__flash_t -= (1 if (len(self.__root.anim) > 6) else 1)
|
||||||
self.hover_mode = self.__flash_t/self.max_flash
|
self.__flash_t = max(self.__flash_t, 0)
|
||||||
self.__update_color()
|
self.hover_mode = self.__flash_t/self.max_flash
|
||||||
# elif (self.__is_hover == 0 and self.__flash_t <= 0):
|
self.__update_color()
|
||||||
# if self.__anim_obj_id != -1:
|
# elif (self.__is_hover == 0 and self.__flash_t <= 0):
|
||||||
# self.__anim_obj_id = None
|
# if self.__anim_obj_id != -1:
|
||||||
|
# self.__anim_obj_id = None
|
||||||
def anim_normal(*args):
|
|
||||||
if (self.__is_hover == 1 and self.__flash_t < self.max_flash):
|
def anim_normal(*args):
|
||||||
self.__flash_t += 1
|
if (self.__is_hover == 1 and self.__flash_t < self.max_flash):
|
||||||
self.hover_mode = self.__flash_t/self.max_flash
|
self.__flash_t += 1
|
||||||
self.__update_color()
|
self.hover_mode = self.__flash_t/self.max_flash
|
||||||
elif (self.__is_hover == 0 and self.__flash_t > 0):
|
self.__update_color()
|
||||||
self.__flash_t -= 1
|
elif (self.__is_hover == 0 and self.__flash_t > 0):
|
||||||
self.hover_mode = self.__flash_t/self.max_flash
|
self.__flash_t -= 1
|
||||||
self.__update_color()
|
self.hover_mode = self.__flash_t/self.max_flash
|
||||||
self.__root.after(anim_normal, 16)
|
self.__update_color()
|
||||||
|
self.__root.after(anim_normal, 16)
|
||||||
try:
|
|
||||||
self.__root.anim == 0
|
try:
|
||||||
except:
|
self.__root.anim == 0
|
||||||
self.__root.after(anim_normal, 16)
|
except:
|
||||||
else:
|
self.__root.after(anim_normal, 16)
|
||||||
if (anim_magictk not in self.__root.anim):
|
else:
|
||||||
self.__root.anim.append(anim_magictk)
|
if (anim_magictk not in self.__root.anim):
|
||||||
self.__anim_obj_id = self.__root.anim[-1]
|
self.__root.anim.append(anim_magictk)
|
||||||
|
self.__anim_obj_id = self.__root.anim[-1]
|
||||||
def __bind_event(self):
|
|
||||||
def enter_v(*args):
|
def __bind_event(self):
|
||||||
# self.bind_anim()
|
def enter_v(*args):
|
||||||
if (self.__is_hover == 0):
|
# self.bind_anim()
|
||||||
self.__is_hover = 1
|
if (self.__is_hover == 0):
|
||||||
self.canvas.bind("<Enter>", enter_v)
|
self.__is_hover = 1
|
||||||
|
self.canvas.bind("<Enter>", enter_v)
|
||||||
def leave_v(*args):
|
|
||||||
# self.bind_anim()
|
def leave_v(*args):
|
||||||
if (self.__is_hover == 1):
|
# self.bind_anim()
|
||||||
self.__is_hover = 0
|
if (self.__is_hover == 1):
|
||||||
self.canvas.bind("<Leave>", leave_v)
|
self.__is_hover = 0
|
||||||
|
self.canvas.bind("<Leave>", leave_v)
|
||||||
def press_v(*args):
|
|
||||||
self.__is_hover = 2
|
def press_v(*args):
|
||||||
self.__update_color()
|
self.__is_hover = 2
|
||||||
self.canvas.bind("<Button-1>", press_v)
|
self.__update_color()
|
||||||
|
self.canvas.bind("<Button-1>", press_v)
|
||||||
def pressrelease_v(*args):
|
|
||||||
# self.bind_anim()
|
def pressrelease_v(*args):
|
||||||
self.__is_hover = 1
|
# self.bind_anim()
|
||||||
self.__update_color()
|
self.__is_hover = 1
|
||||||
self.canvas.bind("<ButtonRelease-1>", pressrelease_v)
|
self.__func(self)
|
||||||
|
self.__update_color()
|
||||||
|
self.canvas.bind("<ButtonRelease-1>", pressrelease_v)
|
||||||
class ButtonFill(Button):
|
|
||||||
__color_bd = "primary"
|
|
||||||
__color_bg = "primary"
|
class ButtonFill(Button):
|
||||||
__color_fg = "primary"
|
__color_bd = "primary"
|
||||||
__color_fg1 = "primary_light3"
|
__color_bg = "primary"
|
||||||
__color_fg2 = "primary_dark"
|
__color_fg = "primary"
|
||||||
color = color_tmpl.default_color
|
__color_fg1 = "primary_light3"
|
||||||
__fill_obj = []
|
__color_fg2 = "primary_dark"
|
||||||
__fill_func = []
|
color = color_tmpl.default_color
|
||||||
__fill_gc = []
|
__fill_obj = []
|
||||||
__fill_fc = []
|
__fill_func = []
|
||||||
__fill_hc = []
|
__fill_gc = []
|
||||||
hover_mode = 0.0
|
__fill_fc = []
|
||||||
__is_hover = 0
|
__fill_hc = []
|
||||||
__flash_t = 0
|
hover_mode = 0.0
|
||||||
max_flash = 4
|
__is_hover = 0
|
||||||
__anim_obj_id = -1
|
__flash_t = 0
|
||||||
text = "ButtonFill"
|
max_flash = 4
|
||||||
|
__anim_obj_id = -1
|
||||||
def __draw_corner(self, r_x, r_y, x, y, **kwargs):
|
text = "ButtonFill"
|
||||||
border_info = json.loads(photoload.loadres("buttonborder"))
|
|
||||||
y_n = 0
|
def __draw_corner(self, r_x, r_y, x, y, **kwargs):
|
||||||
for i in border_info:
|
border_info = json.loads(photoload.loadres("buttonborder"))
|
||||||
x_n = 0
|
y_n = 0
|
||||||
for j in i:
|
for i in border_info:
|
||||||
if (r_x == 0):
|
x_n = 0
|
||||||
px = x+x_n+1
|
for j in i:
|
||||||
else:
|
if (r_x == 0):
|
||||||
px = x+4-x_n-1
|
px = x+x_n+1
|
||||||
if (r_y == 0):
|
else:
|
||||||
py = y+y_n+1
|
px = x+4-x_n-1
|
||||||
else:
|
if (r_y == 0):
|
||||||
py = y+4-y_n-1
|
py = y+y_n+1
|
||||||
if (j < 0):
|
else:
|
||||||
lcolor = -j
|
py = y+4-y_n-1
|
||||||
else:
|
if (j < 0):
|
||||||
lcolor = j
|
lcolor = -j
|
||||||
if (j < 0):
|
else:
|
||||||
g_color = color_tmpl.mix_color(
|
lcolor = j
|
||||||
self.color[self.__color_bg], self.color[self.__color_bd], int((1-lcolor/255)*1000)/1000)
|
if (j < 0):
|
||||||
else:
|
g_color = color_tmpl.mix_color(
|
||||||
g_color = color_tmpl.mix_color(
|
self.color[self.__color_bg], self.color[self.__color_bd], int((1-lcolor/255)*1000)/1000)
|
||||||
self.color["background"], self.color[self.__color_bd], int((1-lcolor/255)*1000)/1000)
|
else:
|
||||||
if (j < 0):
|
g_color = color_tmpl.mix_color(
|
||||||
f_color = color_tmpl.mix_color(
|
self.color["background"], self.color[self.__color_bd], int((1-lcolor/255)*1000)/1000)
|
||||||
self.color[self.__color_fg1], self.color[self.__color_fg1], int((1-lcolor/255)*1000)/1000)
|
if (j < 0):
|
||||||
else:
|
f_color = color_tmpl.mix_color(
|
||||||
f_color = color_tmpl.mix_color(
|
self.color[self.__color_fg1], self.color[self.__color_fg1], int((1-lcolor/255)*1000)/1000)
|
||||||
self.color["background"], self.color[self.__color_fg1], int((1-lcolor/255)*1000)/1000)
|
else:
|
||||||
if (j < 0):
|
f_color = color_tmpl.mix_color(
|
||||||
h_color = color_tmpl.mix_color(
|
self.color["background"], self.color[self.__color_fg1], int((1-lcolor/255)*1000)/1000)
|
||||||
self.color[self.__color_fg2], self.color[self.__color_fg2], int((1-lcolor/255)*1000)/1000)
|
if (j < 0):
|
||||||
else:
|
h_color = color_tmpl.mix_color(
|
||||||
h_color = color_tmpl.mix_color(
|
self.color[self.__color_fg2], self.color[self.__color_fg2], int((1-lcolor/255)*1000)/1000)
|
||||||
self.color["background"], self.color[self.__color_fg2], int((1-lcolor/255)*1000)/1000)
|
else:
|
||||||
|
h_color = color_tmpl.mix_color(
|
||||||
obj = self.canvas.create_rectangle(
|
self.color["background"], self.color[self.__color_fg2], int((1-lcolor/255)*1000)/1000)
|
||||||
px, py, px, py, width=0, fill=g_color)
|
|
||||||
|
obj = self.canvas.create_rectangle(
|
||||||
def update_color(obj, g_color, f_color, h_color):
|
px, py, px, py, width=0, fill=g_color)
|
||||||
if (self.__is_hover == 2):
|
|
||||||
self.canvas.itemconfig(
|
def update_color(obj, g_color, f_color, h_color):
|
||||||
obj, fill=h_color)
|
if (self.__is_hover == 2):
|
||||||
else:
|
self.canvas.itemconfig(
|
||||||
self.canvas.itemconfig(
|
obj, fill=h_color)
|
||||||
obj, fill=color_tmpl.mix_color(g_color, f_color, self.hover_mode))
|
else:
|
||||||
|
self.canvas.itemconfig(
|
||||||
self.__fill_func.append(update_color)
|
obj, fill=color_tmpl.mix_color(g_color, f_color, self.hover_mode))
|
||||||
self.__fill_gc.append(g_color)
|
|
||||||
self.__fill_fc.append(f_color)
|
self.__fill_func.append(update_color)
|
||||||
self.__fill_hc.append(h_color)
|
self.__fill_gc.append(g_color)
|
||||||
self.__fill_obj.append(obj)
|
self.__fill_fc.append(f_color)
|
||||||
x_n += 1
|
self.__fill_hc.append(h_color)
|
||||||
y_n += 1
|
self.__fill_obj.append(obj)
|
||||||
|
x_n += 1
|
||||||
def __update_color(self):
|
y_n += 1
|
||||||
n = 0
|
|
||||||
for i in self.__fill_func:
|
def __update_color(self):
|
||||||
i(self.__fill_obj[n], self.__fill_gc[n],
|
n = 0
|
||||||
self.__fill_fc[n], self.__fill_hc[n])
|
for i in self.__fill_func:
|
||||||
n += 1
|
i(self.__fill_obj[n], self.__fill_gc[n],
|
||||||
|
self.__fill_fc[n], self.__fill_hc[n])
|
||||||
def __init__(self, master=None, root_anim=None, color_type="primary", w=80, h=30, text="Button", color_list: None | dict = None):
|
n += 1
|
||||||
set_font()
|
|
||||||
self.__color_bd = color_type
|
def __init__(self, master=None, root_anim=None, color_type="primary", w=80, h=30, text="Button", func=lambda s: print("Press"), color_list: None | dict = None):
|
||||||
self.__color_bg = color_type
|
self.__func = func
|
||||||
self.__color_fg = color_type
|
set_font()
|
||||||
self.__color_fg1 = color_type+"_light3"
|
self.__color_bd = color_type
|
||||||
self.__color_fg2 = color_type+"_dark"
|
self.__color_bg = color_type
|
||||||
self.w = max(80, w)
|
self.__color_fg = color_type
|
||||||
self.h = max(30, h)
|
self.__color_fg1 = color_type+"_light3"
|
||||||
self.text = text
|
self.__color_fg2 = color_type+"_dark"
|
||||||
self.__master = master
|
self.w = max(80, w)
|
||||||
if (color_list is not None):
|
self.h = max(30, h)
|
||||||
self.color = color_list
|
self.text = text
|
||||||
if (root_anim == None):
|
self.__master = master
|
||||||
self.__root = master
|
if (color_list is not None):
|
||||||
else:
|
self.color = color_list
|
||||||
self.__root = root_anim
|
if (root_anim == None):
|
||||||
|
self.__root = master
|
||||||
self.canvas = tkinter.Canvas(
|
else:
|
||||||
master, bg=self.color["background"], width=self.w, height=self.h, borderwidth=0, bd=0, highlightcolor=self.color["background"], highlightthickness=0)
|
self.__root = root_anim
|
||||||
|
|
||||||
self.__draw()
|
self.canvas = tkinter.Canvas(
|
||||||
self.__update_color()
|
master, bg=self.color["background"], width=self.w, height=self.h, borderwidth=0, bd=0, highlightcolor=self.color["background"], highlightthickness=0)
|
||||||
self.__bind_event()
|
|
||||||
self.bind_anim()
|
self.__draw()
|
||||||
|
self.__update_color()
|
||||||
def __draw(self):
|
self.__bind_event()
|
||||||
self.__draw_corner(0, 0, 0, 0)
|
self.bind_anim()
|
||||||
self.__draw_corner(1, 0, self.w-4, 0)
|
|
||||||
self.__draw_corner(0, 1, 0, self.h-5)
|
def __draw(self):
|
||||||
self.__draw_corner(1, 1, self.w-4, self.h-5)
|
self.__draw_corner(0, 0, 0, 0)
|
||||||
|
self.__draw_corner(1, 0, self.w-4, 0)
|
||||||
def update_color(obj, g_color, f_color, h_color):
|
self.__draw_corner(0, 1, 0, self.h-5)
|
||||||
if (self.__is_hover == 2):
|
self.__draw_corner(1, 1, self.w-4, self.h-5)
|
||||||
self.canvas.itemconfig(
|
|
||||||
obj, fill=h_color)
|
def update_color(obj, g_color, f_color, h_color):
|
||||||
else:
|
if (self.__is_hover == 2):
|
||||||
self.canvas.itemconfig(
|
self.canvas.itemconfig(
|
||||||
obj, fill=color_tmpl.mix_color(g_color, f_color, self.hover_mode))
|
obj, fill=h_color)
|
||||||
self.__fill_fc.append(self.color[self.__color_fg1])
|
else:
|
||||||
self.__fill_gc.append(self.color[self.__color_bd])
|
self.canvas.itemconfig(
|
||||||
self.__fill_hc.append(self.color[self.__color_fg2])
|
obj, fill=color_tmpl.mix_color(g_color, f_color, self.hover_mode))
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_fc.append(self.color[self.__color_fg1])
|
||||||
self.__fill_obj.append(self.canvas.create_line(
|
self.__fill_gc.append(self.color[self.__color_bd])
|
||||||
1, 5, 1, self.h-5, width=1, fill=self.color[self.__color_bd]))
|
self.__fill_hc.append(self.color[self.__color_fg2])
|
||||||
self.__fill_fc.append(self.color[self.__color_fg1])
|
self.__fill_func.append(update_color)
|
||||||
self.__fill_gc.append(self.color[self.__color_bd])
|
self.__fill_obj.append(self.canvas.create_line(
|
||||||
self.__fill_hc.append(self.color[self.__color_fg2])
|
1, 5, 1, self.h-5, width=1, fill=self.color[self.__color_bd]))
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_fc.append(self.color[self.__color_fg1])
|
||||||
self.__fill_obj.append(self.canvas.create_line(
|
self.__fill_gc.append(self.color[self.__color_bd])
|
||||||
5, 1, self.w-4, 1, width=1, fill=self.color[self.__color_fg1]))
|
self.__fill_hc.append(self.color[self.__color_fg2])
|
||||||
self.__fill_fc.append(self.color[self.__color_fg1])
|
self.__fill_func.append(update_color)
|
||||||
self.__fill_gc.append(self.color[self.__color_bd])
|
self.__fill_obj.append(self.canvas.create_line(
|
||||||
self.__fill_hc.append(self.color[self.__color_fg2])
|
5, 1, self.w-4, 1, width=1, fill=self.color[self.__color_fg1]))
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_fc.append(self.color[self.__color_fg1])
|
||||||
self.__fill_obj.append(self.canvas.create_line(
|
self.__fill_gc.append(self.color[self.__color_bd])
|
||||||
self.w-1, 5, self.w-1, self.h-5, width=1, fill=self.color[self.__color_fg1]))
|
self.__fill_hc.append(self.color[self.__color_fg2])
|
||||||
self.__fill_fc.append(self.color[self.__color_fg1])
|
self.__fill_func.append(update_color)
|
||||||
self.__fill_gc.append(self.color[self.__color_bd])
|
self.__fill_obj.append(self.canvas.create_line(
|
||||||
self.__fill_hc.append(self.color[self.__color_fg2])
|
self.w-1, 5, self.w-1, self.h-5, width=1, fill=self.color[self.__color_fg1]))
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_fc.append(self.color[self.__color_fg1])
|
||||||
self.__fill_obj.append(self.canvas.create_line(
|
self.__fill_gc.append(self.color[self.__color_bd])
|
||||||
5, self.h-2, self.w-4, self.h-2, width=1, fill=self.color[self.__color_fg1]))
|
self.__fill_hc.append(self.color[self.__color_fg2])
|
||||||
|
self.__fill_func.append(update_color)
|
||||||
self.__fill_fc.append(self.color[self.__color_fg1])
|
self.__fill_obj.append(self.canvas.create_line(
|
||||||
self.__fill_gc.append(self.color[self.__color_bd])
|
5, self.h-2, self.w-4, self.h-2, width=1, fill=self.color[self.__color_fg1]))
|
||||||
self.__fill_hc.append(self.color[self.__color_fg2])
|
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_fc.append(self.color[self.__color_fg1])
|
||||||
self.__fill_obj.append(self.canvas.create_rectangle(
|
self.__fill_gc.append(self.color[self.__color_bd])
|
||||||
2, 5, self.w-1, self.h-5, width=0, fill=self.color[self.__color_fg2]))
|
self.__fill_hc.append(self.color[self.__color_fg2])
|
||||||
|
self.__fill_func.append(update_color)
|
||||||
self.__fill_fc.append(self.color[self.__color_fg1])
|
self.__fill_obj.append(self.canvas.create_rectangle(
|
||||||
self.__fill_gc.append(self.color[self.__color_bd])
|
2, 5, self.w-1, self.h-5, width=0, fill=self.color[self.__color_fg2]))
|
||||||
self.__fill_hc.append(self.color[self.__color_fg2])
|
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_fc.append(self.color[self.__color_fg1])
|
||||||
self.__fill_obj.append(self.canvas.create_rectangle(
|
self.__fill_gc.append(self.color[self.__color_bd])
|
||||||
5, 2, self.w-4, self.h-2, width=0, fill=self.color[self.__color_fg2]))
|
self.__fill_hc.append(self.color[self.__color_fg2])
|
||||||
|
self.__fill_func.append(update_color)
|
||||||
self.__fill_fc.append("#FFFFFF")
|
self.__fill_obj.append(self.canvas.create_rectangle(
|
||||||
self.__fill_gc.append("#FFFFFF")
|
5, 2, self.w-4, self.h-2, width=0, fill=self.color[self.__color_fg2]))
|
||||||
self.__fill_hc.append("#FFFFFF")
|
|
||||||
self.__fill_func.append(update_color)
|
self.__fill_fc.append("#FFFFFF")
|
||||||
self.__fill_obj.append(
|
self.__fill_gc.append("#FFFFFF")
|
||||||
self.canvas.create_text(int(self.w/2), int(self.h/2), text=self.text, font=(use_font, 10)))
|
self.__fill_hc.append("#FFFFFF")
|
||||||
|
self.__fill_func.append(update_color)
|
||||||
def bind_anim(self):
|
self.__fill_obj.append(
|
||||||
def anim_magictk():
|
self.canvas.create_text(int(self.w/2), int(self.h/2), text=self.text, font=(use_font, 10)))
|
||||||
if (self.__is_hover == 1 and self.__flash_t < self.max_flash):
|
|
||||||
self.__flash_t += (1 if (len(self.__root.anim) > 6) else 1)
|
def bind_anim(self):
|
||||||
self.__flash_t = min(self.__flash_t, self.max_flash)
|
def anim_magictk():
|
||||||
self.hover_mode = self.__flash_t/self.max_flash
|
if (self.__is_hover == 1 and self.__flash_t < self.max_flash):
|
||||||
self.__update_color()
|
self.__flash_t += (1 if (len(self.__root.anim) > 6) else 1)
|
||||||
elif (self.__is_hover == 0 and self.__flash_t > 0):
|
self.__flash_t = min(self.__flash_t, self.max_flash)
|
||||||
self.__flash_t -= (1 if (len(self.__root.anim) > 6) else 1)
|
self.hover_mode = self.__flash_t/self.max_flash
|
||||||
self.__flash_t = max(self.__flash_t, 0)
|
self.__update_color()
|
||||||
self.hover_mode = self.__flash_t/self.max_flash
|
elif (self.__is_hover == 0 and self.__flash_t > 0):
|
||||||
self.__update_color()
|
self.__flash_t -= (1 if (len(self.__root.anim) > 6) else 1)
|
||||||
# elif (self.__is_hover == 0 and self.__flash_t <= 0):
|
self.__flash_t = max(self.__flash_t, 0)
|
||||||
# if self.__anim_obj_id != -1:
|
self.hover_mode = self.__flash_t/self.max_flash
|
||||||
# self.__anim_obj_id = None
|
self.__update_color()
|
||||||
|
# elif (self.__is_hover == 0 and self.__flash_t <= 0):
|
||||||
def anim_normal(*args):
|
# if self.__anim_obj_id != -1:
|
||||||
if (self.__is_hover == 1 and self.__flash_t < self.max_flash):
|
# self.__anim_obj_id = None
|
||||||
self.__flash_t += 1
|
|
||||||
self.hover_mode = self.__flash_t/self.max_flash
|
def anim_normal(*args):
|
||||||
self.__update_color()
|
if (self.__is_hover == 1 and self.__flash_t < self.max_flash):
|
||||||
elif (self.__is_hover == 0 and self.__flash_t > 0):
|
self.__flash_t += 1
|
||||||
self.__flash_t -= 1
|
self.hover_mode = self.__flash_t/self.max_flash
|
||||||
self.hover_mode = self.__flash_t/self.max_flash
|
self.__update_color()
|
||||||
self.__update_color()
|
elif (self.__is_hover == 0 and self.__flash_t > 0):
|
||||||
self.__root.after(anim_normal, 16)
|
self.__flash_t -= 1
|
||||||
|
self.hover_mode = self.__flash_t/self.max_flash
|
||||||
try:
|
self.__update_color()
|
||||||
self.__root.anim == 0
|
self.__root.after(anim_normal, 16)
|
||||||
except:
|
|
||||||
self.__root.after(anim_normal, 16)
|
try:
|
||||||
else:
|
self.__root.anim == 0
|
||||||
if (anim_magictk not in self.__root.anim):
|
except:
|
||||||
self.__root.anim.append(anim_magictk)
|
self.__root.after(anim_normal, 16)
|
||||||
self.__anim_obj_id = self.__root.anim[-1]
|
else:
|
||||||
|
if (anim_magictk not in self.__root.anim):
|
||||||
def __bind_event(self):
|
self.__root.anim.append(anim_magictk)
|
||||||
def enter_v(*args):
|
self.__anim_obj_id = self.__root.anim[-1]
|
||||||
# self.bind_anim()
|
|
||||||
if (self.__is_hover == 0):
|
def __bind_event(self):
|
||||||
self.__is_hover = 1
|
def enter_v(*args):
|
||||||
self.canvas.bind("<Enter>", enter_v)
|
# self.bind_anim()
|
||||||
|
if (self.__is_hover == 0):
|
||||||
def leave_v(*args):
|
self.__is_hover = 1
|
||||||
# self.bind_anim()
|
self.canvas.bind("<Enter>", enter_v)
|
||||||
if (self.__is_hover == 1):
|
|
||||||
self.__is_hover = 0
|
def leave_v(*args):
|
||||||
self.canvas.bind("<Leave>", leave_v)
|
# self.bind_anim()
|
||||||
|
if (self.__is_hover == 1):
|
||||||
def press_v(*args):
|
self.__is_hover = 0
|
||||||
self.__is_hover = 2
|
self.canvas.bind("<Leave>", leave_v)
|
||||||
self.__update_color()
|
|
||||||
self.canvas.bind("<Button-1>", press_v)
|
def press_v(*args):
|
||||||
|
self.__is_hover = 2
|
||||||
def pressrelease_v(*args):
|
self.__update_color()
|
||||||
# self.bind_anim()
|
self.canvas.bind("<Button-1>", press_v)
|
||||||
self.__is_hover = 1
|
|
||||||
self.__update_color()
|
def pressrelease_v(*args):
|
||||||
self.canvas.bind("<ButtonRelease-1>", pressrelease_v)
|
# self.bind_anim()
|
||||||
|
self.__is_hover = 1
|
||||||
|
self.__func(self)
|
||||||
|
self.__update_color()
|
||||||
|
self.canvas.bind("<ButtonRelease-1>", pressrelease_v)
|
||||||
|
|
|
@ -1,68 +1,68 @@
|
||||||
import colorsys
|
import colorsys
|
||||||
|
|
||||||
default_color = {
|
default_color = {
|
||||||
"primary": "#409EFF",
|
"primary": "#409EFF",
|
||||||
"primary_light": "#C6E2FF",
|
"primary_light": "#C6E2FF",
|
||||||
"primary_light2": "#ECF5FF",
|
"primary_light2": "#ECF5FF",
|
||||||
"primary_light3": "#79BBFF",
|
"primary_light3": "#79BBFF",
|
||||||
"primary_dark": "#337ECC",
|
"primary_dark": "#337ECC",
|
||||||
"success": "#67C23A",
|
"success": "#67C23A",
|
||||||
"success_light": "#E1F3D8",
|
"success_light": "#E1F3D8",
|
||||||
"success_light2": "#F0F9EB",
|
"success_light2": "#F0F9EB",
|
||||||
"success_light3": "#95D475",
|
"success_light3": "#95D475",
|
||||||
"success_dark": "#529B2E",
|
"success_dark": "#529B2E",
|
||||||
"warning": "#E6A23C",
|
"warning": "#E6A23C",
|
||||||
"warning_light": "#FAECD8",
|
"warning_light": "#FAECD8",
|
||||||
"warning_light2": "#E6A23C",
|
"warning_light2": "#E6A23C",
|
||||||
"warning_light3": "#EEBE77",
|
"warning_light3": "#EEBE77",
|
||||||
"warning_dark": "#B88230",
|
"warning_dark": "#B88230",
|
||||||
"danger": "#F56C6C",
|
"danger": "#F56C6C",
|
||||||
"danger_light": "#FDE2E2",
|
"danger_light": "#FDE2E2",
|
||||||
"danger_light2": "#FEF0F0",
|
"danger_light2": "#FEF0F0",
|
||||||
"danger_light3": "#F89898",
|
"danger_light3": "#F89898",
|
||||||
"danger_dark": "#C45656",
|
"danger_dark": "#C45656",
|
||||||
"info": "#909399",
|
"info": "#909399",
|
||||||
"info_light": "#E9E9EB",
|
"info_light": "#E9E9EB",
|
||||||
"info_light2": "#F4F4F5",
|
"info_light2": "#F4F4F5",
|
||||||
"info_light3": "#B1B3B8",
|
"info_light3": "#B1B3B8",
|
||||||
"info_dark": "#73767A",
|
"info_dark": "#73767A",
|
||||||
"primary_text": "#303133",
|
"primary_text": "#303133",
|
||||||
"regular_text": "#606266",
|
"regular_text": "#606266",
|
||||||
"secondary_text": "#909399",
|
"secondary_text": "#909399",
|
||||||
"placeholder": "#C0C4CC",
|
"placeholder": "#C0C4CC",
|
||||||
"border_base": "#DCDFE6",
|
"border_base": "#DCDFE6",
|
||||||
"border_light": "#E4E7ED",
|
"border_light": "#E4E7ED",
|
||||||
"background": "#FFFFFF"
|
"background": "#FFFFFF"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def hex2rgb(color: str):
|
def hex2rgb(color: str):
|
||||||
return (int(color[1:3], 16), int(color[3:5], 16), int(color[5:7], 16))
|
return (int(color[1:3], 16), int(color[3:5], 16), int(color[5:7], 16))
|
||||||
|
|
||||||
|
|
||||||
def rgb2hex(r, g, b):
|
def rgb2hex(r, g, b):
|
||||||
return f"#{str(hex(int(r)))[2:].upper():0>2}{str(hex(int(g)))[2:].upper():0>2}{str(hex(int(b)))[2:].upper():0>2}"
|
return f"#{str(hex(int(r)))[2:].upper():0>2}{str(hex(int(g)))[2:].upper():0>2}{str(hex(int(b)))[2:].upper():0>2}"
|
||||||
|
|
||||||
|
|
||||||
def hex2hls(color: str):
|
def hex2hls(color: str):
|
||||||
r, g, b = hex2rgb(color)
|
r, g, b = hex2rgb(color)
|
||||||
return colorsys.rgb_to_hls(r/255, g/255, b/255)
|
return colorsys.rgb_to_hls(r/255, g/255, b/255)
|
||||||
|
|
||||||
|
|
||||||
def hls2hex(h, l, s):
|
def hls2hex(h, l, s):
|
||||||
r, g, b = colorsys.hls_to_rgb(h, l, s)
|
r, g, b = colorsys.hls_to_rgb(h, l, s)
|
||||||
return rgb2hex(r*255, g*255, b*255)
|
return rgb2hex(r*255, g*255, b*255)
|
||||||
|
|
||||||
|
|
||||||
def setlight(color: str, light: float):
|
def setlight(color: str, light: float):
|
||||||
h, l, s = hex2hls(color)
|
h, l, s = hex2hls(color)
|
||||||
return hls2hex(h, light, s)
|
return hls2hex(h, light, s)
|
||||||
|
|
||||||
|
|
||||||
def mix_color(c1: str, c2: str, alpha: float):
|
def mix_color(c1: str, c2: str, alpha: float):
|
||||||
r2, g2, b2 = hex2rgb(c1)
|
r2, g2, b2 = hex2rgb(c1)
|
||||||
r1, g1, b1 = hex2rgb(c2)
|
r1, g1, b1 = hex2rgb(c2)
|
||||||
r3 = int(r1*alpha+r2*(1-alpha))
|
r3 = int(r1*alpha+r2*(1-alpha))
|
||||||
g3 = int(g1*alpha+g2*(1-alpha))
|
g3 = int(g1*alpha+g2*(1-alpha))
|
||||||
b3 = int(b1*alpha+b2*(1-alpha))
|
b3 = int(b1*alpha+b2*(1-alpha))
|
||||||
return rgb2hex(r3, g3, b3)
|
return rgb2hex(r3, g3, b3)
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
import pickle
|
import pickle
|
||||||
import os
|
import os
|
||||||
import tkinter
|
import tkinter
|
||||||
import base64
|
import base64
|
||||||
image_all = None
|
image_all = None
|
||||||
load_cache = {}
|
load_cache = {}
|
||||||
|
|
||||||
|
|
||||||
def fresh_image():
|
def fresh_image():
|
||||||
global image_all
|
global image_all
|
||||||
if (image_all == None):
|
if (image_all == None):
|
||||||
with open(os.path.dirname(__file__).replace("\\", "/")+"/res.pickle", "rb") as file:
|
with open(os.path.dirname(__file__).replace("\\", "/")+"/res.pickle", "rb") as file:
|
||||||
image_all = pickle.load(file)
|
image_all = pickle.load(file)
|
||||||
|
|
||||||
|
|
||||||
fresh_image()
|
fresh_image()
|
||||||
|
|
||||||
|
|
||||||
def loadimg(imgid: str):
|
def loadimg(imgid: str):
|
||||||
global image_all
|
global image_all
|
||||||
if imgid not in load_cache:
|
if imgid not in load_cache:
|
||||||
load_cache[imgid] = tkinter.PhotoImage(
|
load_cache[imgid] = tkinter.PhotoImage(
|
||||||
data=base64.b64decode(image_all[imgid]))
|
data=base64.b64decode(image_all[imgid]))
|
||||||
return load_cache[imgid]
|
return load_cache[imgid]
|
||||||
|
|
||||||
|
|
||||||
def loadres(imgid: str):
|
def loadres(imgid: str):
|
||||||
global image_all
|
global image_all
|
||||||
if imgid not in load_cache:
|
if imgid not in load_cache:
|
||||||
load_cache[imgid] = base64.b64decode(image_all[imgid])
|
load_cache[imgid] = base64.b64decode(image_all[imgid])
|
||||||
return load_cache[imgid]
|
return load_cache[imgid]
|
||||||
|
|
|
@ -0,0 +1,157 @@
|
||||||
|
import json
|
||||||
|
import tkinter
|
||||||
|
from tkinter import ttk
|
||||||
|
from tkinter import font as tkfont
|
||||||
|
try:
|
||||||
|
import color_tmpl
|
||||||
|
except ImportError:
|
||||||
|
from magictk import color_tmpl
|
||||||
|
try:
|
||||||
|
import photoload
|
||||||
|
except ImportError:
|
||||||
|
from magictk import photoload
|
||||||
|
|
||||||
|
|
||||||
|
class ProgressBar:
|
||||||
|
color = color_tmpl.default_color
|
||||||
|
__fill_obj = {}
|
||||||
|
progress = 0.0
|
||||||
|
__progress_pixel = 0
|
||||||
|
__move_progress_pixel = 0
|
||||||
|
__flash_t = 0
|
||||||
|
max_flash = 4
|
||||||
|
__anim_obj_id = -1
|
||||||
|
|
||||||
|
def __draw_corner(self, r_x, r_y, x, y, colors="#000000", rid="",bgcolor=None, **kwargs):
|
||||||
|
if bgcolor is None or self.progress==1:
|
||||||
|
bgcolor=self.color["border_light"]
|
||||||
|
self.__fill_obj[rid] = []
|
||||||
|
self.__fill_obj[rid+"_pos"] = []
|
||||||
|
border_info = json.loads(photoload.loadres("progressborder"))
|
||||||
|
y_n = 0
|
||||||
|
for i in border_info:
|
||||||
|
x_n = 0
|
||||||
|
for j in i:
|
||||||
|
if (r_x == 0):
|
||||||
|
px = x+x_n+1
|
||||||
|
else:
|
||||||
|
px = x+3-x_n-1
|
||||||
|
if (r_y == 0):
|
||||||
|
py = y+y_n+1
|
||||||
|
else:
|
||||||
|
py = y+6-y_n-1
|
||||||
|
if (j < 0):
|
||||||
|
lcolor = -j
|
||||||
|
else:
|
||||||
|
lcolor = j
|
||||||
|
# if(lcolor==255):
|
||||||
|
# continue
|
||||||
|
g_color = color_tmpl.mix_color(
|
||||||
|
bgcolor, colors, int((1-lcolor/255)*1000)/1000)
|
||||||
|
|
||||||
|
obj = self.canvas.create_rectangle(
|
||||||
|
px, py, px, py, width=0, fill=g_color)
|
||||||
|
|
||||||
|
self.__fill_obj[rid].append(obj)
|
||||||
|
self.__fill_obj[rid+"_pos"].append([x_n, y_n])
|
||||||
|
|
||||||
|
x_n += 1
|
||||||
|
y_n += 1
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self, master=None, root_anim=None, w=200, h=8, colors="primary", color_list: None | dict = None):
|
||||||
|
self.w = max(200, w)
|
||||||
|
self.h = 8
|
||||||
|
self.__master = master
|
||||||
|
self.colors = colors
|
||||||
|
if (color_list is not None):
|
||||||
|
self.color = color_list
|
||||||
|
if (root_anim == None):
|
||||||
|
self.__root = master
|
||||||
|
else:
|
||||||
|
self.__root = root_anim
|
||||||
|
|
||||||
|
self.canvas = tkinter.Canvas(
|
||||||
|
master, bg=self.color["background"], width=self.w, height=self.h, borderwidth=0, bd=0, highlightcolor=self.color["background"], highlightthickness=0)
|
||||||
|
|
||||||
|
self.__draw()
|
||||||
|
# self.__bind_event()
|
||||||
|
self.bind_anim()
|
||||||
|
|
||||||
|
def pack(self, *args, **kwargs):
|
||||||
|
self.canvas.pack(*args, **kwargs)
|
||||||
|
|
||||||
|
def guid(self, *args, **kwargs):
|
||||||
|
self.canvas.guid(*args, **kwargs)
|
||||||
|
|
||||||
|
def place(self, *args, **kwargs):
|
||||||
|
self.canvas.place(*args, **kwargs)
|
||||||
|
|
||||||
|
def __draw(self):
|
||||||
|
self.__fill_obj["bgbar"] = [
|
||||||
|
self.canvas.create_rectangle(4, 1, self.w-5, self.h-1, width=0, fill=self.color["border_light"])]
|
||||||
|
self.__draw_corner(1, 0, self.w-5, 0,
|
||||||
|
self.color["border_light"], "rightside",bgcolor=self.color["background"])
|
||||||
|
self.__fill_obj["fgbar"] = [
|
||||||
|
self.canvas.create_rectangle(4, 1, self.__progress_pixel+4, self.h-1, width=0, fill=self.color[self.colors])]
|
||||||
|
self.__draw_corner(0, 0, 1, 0, self.color[self.colors], "leftside",bgcolor=self.color["background"])
|
||||||
|
self.__draw_corner(1, 0, self.__progress_pixel+3, 0,
|
||||||
|
self.color[self.colors], "rightprog")
|
||||||
|
|
||||||
|
def __update_pixel(self):
|
||||||
|
self.__move_progress_pixel = max(4,int((self.w-6)*self.progress))
|
||||||
|
|
||||||
|
def add_progress(self, n):
|
||||||
|
self.progress = max(min(self.progress+n, 1.0), 0.0)
|
||||||
|
self.__update_pixel()
|
||||||
|
|
||||||
|
def set_progress(self, n):
|
||||||
|
self.progress = max(min(n, 1.0), 0.0)
|
||||||
|
self.__update_pixel()
|
||||||
|
|
||||||
|
def __update_prog(self):
|
||||||
|
for i in range(len(self.__fill_obj["rightprog"])):
|
||||||
|
self.canvas.coords(
|
||||||
|
self.__fill_obj["rightprog"][i], self.__progress_pixel+3-int(self.__fill_obj["rightprog_pos"][i][0]), self.__fill_obj["rightprog_pos"][i][1]+1, self.__progress_pixel+3-int(self.__fill_obj["rightprog_pos"][i][0])+1, self.__fill_obj["rightprog_pos"][i][1]+1)
|
||||||
|
self.canvas.coords(
|
||||||
|
self.__fill_obj["fgbar"][0], 4, 1, self.__progress_pixel+4, self.h-1)
|
||||||
|
|
||||||
|
def bind_anim(self):
|
||||||
|
def anim_magictk():
|
||||||
|
if (int(self.__progress_pixel) < int(self.__move_progress_pixel)):
|
||||||
|
if (self.__move_progress_pixel-self.__progress_pixel > 8):
|
||||||
|
self.__progress_pixel += 8
|
||||||
|
else:
|
||||||
|
add_n = int(
|
||||||
|
(self.__progress_pixel-self.__move_progress_pixel)/2)
|
||||||
|
if (add_n <= 2):
|
||||||
|
self.__progress_pixel = self.__move_progress_pixel
|
||||||
|
else:
|
||||||
|
self.__progress_pixel += add_n
|
||||||
|
self.__update_prog()
|
||||||
|
elif (int(self.__progress_pixel) > int(self.__move_progress_pixel)):
|
||||||
|
if (self.__progress_pixel-self.__move_progress_pixel > 8):
|
||||||
|
self.__progress_pixel -= 8
|
||||||
|
else:
|
||||||
|
add_n = int(
|
||||||
|
(self.__progress_pixel-self.__move_progress_pixel)/2)
|
||||||
|
if (add_n <= 2):
|
||||||
|
self.__progress_pixel = self.__move_progress_pixel
|
||||||
|
else:
|
||||||
|
self.__progress_pixel -= add_n
|
||||||
|
self.__update_prog()
|
||||||
|
# else:
|
||||||
|
# self.__progress_pixel = self.__move_progress_pixel
|
||||||
|
# self.__update_prog()
|
||||||
|
|
||||||
|
def anim_normal(*args):
|
||||||
|
self.__root.after(anim_normal, 16)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.__root.anim == 0
|
||||||
|
except:
|
||||||
|
self.__root.after(anim_normal, 16)
|
||||||
|
else:
|
||||||
|
if (anim_magictk not in self.__root.anim):
|
||||||
|
self.__root.anim.append(anim_magictk)
|
||||||
|
self.__anim_obj_id = self.__root.anim[-1]
|
Binary file not shown.
|
@ -1,285 +1,285 @@
|
||||||
import time
|
import time
|
||||||
import tkinter
|
import tkinter
|
||||||
import os
|
import os
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
try:
|
try:
|
||||||
import color_tmpl
|
import color_tmpl
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from magictk import color_tmpl
|
from magictk import color_tmpl
|
||||||
try:
|
try:
|
||||||
import _window_ctl
|
import _window_ctl
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from magictk import _window_ctl
|
from magictk import _window_ctl
|
||||||
try:
|
try:
|
||||||
import _window_size
|
import _window_size
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from magictk import _window_size
|
from magictk import _window_size
|
||||||
try:
|
try:
|
||||||
import workspace
|
import workspace
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from magictk import workspace
|
from magictk import workspace
|
||||||
try:
|
try:
|
||||||
import photoload
|
import photoload
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from magictk import photoload
|
from magictk import photoload
|
||||||
|
|
||||||
WIN_INF = -10000
|
WIN_INF = -10000
|
||||||
|
|
||||||
|
|
||||||
class Window(ttk.Frame):
|
class Window(ttk.Frame):
|
||||||
x = 200
|
x = 200
|
||||||
y = 200
|
y = 200
|
||||||
w = 500
|
w = 500
|
||||||
h = 350
|
h = 350
|
||||||
normal_x = -1
|
normal_x = -1
|
||||||
normal_y = 1
|
normal_y = 1
|
||||||
top_h = 28
|
top_h = 28
|
||||||
__break_win = True
|
__break_win = True
|
||||||
fullscreen = False
|
fullscreen = False
|
||||||
minmode = False
|
minmode = False
|
||||||
color = color_tmpl.default_color
|
color = color_tmpl.default_color
|
||||||
anim = []
|
anim = []
|
||||||
disable_move = False
|
disable_move = False
|
||||||
min_w = 200
|
min_w = 200
|
||||||
min_h = 100
|
min_h = 100
|
||||||
|
|
||||||
def update_size(self) -> None:
|
def update_size(self) -> None:
|
||||||
self.tk_w_without_bar.set(self.w-48*3)
|
self.tk_w_without_bar.set(self.w-48*3)
|
||||||
self.place(x=8, y=self.top_h+1+8, width=self.w-16, height=self.h-1-16)
|
self.place(x=8, y=self.top_h+1+8, width=self.w-16, height=self.h-1-16)
|
||||||
self.main_tk.geometry(
|
self.main_tk.geometry(
|
||||||
f"{self.w}x{self.h+self.top_h}+{self.x}+{self.y}")
|
f"{self.w}x{self.h+self.top_h}+{self.x}+{self.y}")
|
||||||
self.__fake_tk.geometry(
|
self.__fake_tk.geometry(
|
||||||
f"{self.w}x{self.h}+{WIN_INF}+{WIN_INF}")
|
f"{self.w}x{self.h}+{WIN_INF}+{WIN_INF}")
|
||||||
|
|
||||||
def __load_color(self) -> None:
|
def __load_color(self) -> None:
|
||||||
self.main_tk.configure(bg=self.color["background"])
|
self.main_tk.configure(bg=self.color["background"])
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'Test1.TFrame', background="#FF0000")
|
'Test1.TFrame', background="#FF0000")
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'Test2.TFrame', background="#00FF00")
|
'Test2.TFrame', background="#00FF00")
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'Test3.TFrame', background="#0000FF")
|
'Test3.TFrame', background="#0000FF")
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'Main.TFrame', background=self.color["background"])
|
'Main.TFrame', background=self.color["background"])
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'Root.TFrame', background=self.color["background"])
|
'Root.TFrame', background=self.color["background"])
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'Splitline.TFrame', background=self.color["border_light"])
|
'Splitline.TFrame', background=self.color["border_light"])
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarExitButton.TFrame', background=self.color["background"])
|
'BarExitButton.TFrame', background=self.color["background"])
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'LabBarZoomButton.TLabel', background=self.color["background"])
|
'LabBarZoomButton.TLabel', background=self.color["background"])
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'LabBarIcon.TLabel', background=self.color["background"])
|
'LabBarIcon.TLabel', background=self.color["background"])
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'LabTitle.TLabel', background=self.color["background"], fg=self.color["primary_text"])
|
'LabTitle.TLabel', background=self.color["background"], fg=self.color["primary_text"])
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'BarIconicButton.TFrame', background=self.color["background"])
|
'BarIconicButton.TFrame', background=self.color["background"])
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'Size.TFrame', background=self.color["background"])
|
'Size.TFrame', background=self.color["background"])
|
||||||
self.style.configure(
|
self.style.configure(
|
||||||
'LabelTitle.TFrame', background=self.color["background"])
|
'LabelTitle.TFrame', background=self.color["background"])
|
||||||
|
|
||||||
def __init_weights(self, root: tkinter.Frame) -> None:
|
def __init_weights(self, root: tkinter.Frame) -> None:
|
||||||
top_bar = ttk.Frame(root, style='Root.TFrame', height=self.top_h)
|
top_bar = ttk.Frame(root, style='Root.TFrame', height=self.top_h)
|
||||||
startmove_x = 0
|
startmove_x = 0
|
||||||
startmove_y = 0
|
startmove_y = 0
|
||||||
title_frame = ttk.Frame(
|
title_frame = ttk.Frame(
|
||||||
top_bar, style="LabelTitle.TFrame", height=self.top_h)
|
top_bar, style="LabelTitle.TFrame", height=self.top_h)
|
||||||
|
|
||||||
def start_move(event: tkinter.Event):
|
def start_move(event: tkinter.Event):
|
||||||
if (self.disable_move):
|
if (self.disable_move):
|
||||||
return
|
return
|
||||||
nonlocal startmove_x, startmove_y
|
nonlocal startmove_x, startmove_y
|
||||||
startmove_x = event.x_root-self.main_tk.winfo_x()
|
startmove_x = event.x_root-self.main_tk.winfo_x()
|
||||||
startmove_y = event.y_root-self.main_tk.winfo_y()
|
startmove_y = event.y_root-self.main_tk.winfo_y()
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
self.zoom()
|
self.zoom()
|
||||||
self.x = event.x_root-(event.x_root-self.main_tk.winfo_x())
|
self.x = event.x_root-(event.x_root-self.main_tk.winfo_x())
|
||||||
self.y = event.y_root-(event.y_root-self.main_tk.winfo_y())
|
self.y = event.y_root-(event.y_root-self.main_tk.winfo_y())
|
||||||
startmove_x = int(self.w/2)
|
startmove_x = int(self.w/2)
|
||||||
startmove_y = int(self.top_h/2)
|
startmove_y = int(self.top_h/2)
|
||||||
self.update_size()
|
self.update_size()
|
||||||
title_frame.configure(cursor="arrow")
|
title_frame.configure(cursor="arrow")
|
||||||
|
|
||||||
def move_win(event: tkinter.Event):
|
def move_win(event: tkinter.Event):
|
||||||
if (self.disable_move):
|
if (self.disable_move):
|
||||||
return
|
return
|
||||||
nonlocal startmove_x, startmove_y
|
nonlocal startmove_x, startmove_y
|
||||||
if (self.fullscreen):
|
if (self.fullscreen):
|
||||||
return
|
return
|
||||||
self.x = event.x_root-startmove_x
|
self.x = event.x_root-startmove_x
|
||||||
self.y = event.y_root-startmove_y
|
self.y = event.y_root-startmove_y
|
||||||
if (event.y_root < 5):
|
if (event.y_root < 5):
|
||||||
title_frame.configure(cursor="dotbox")
|
title_frame.configure(cursor="dotbox")
|
||||||
else:
|
else:
|
||||||
title_frame.configure(cursor="fleur")
|
title_frame.configure(cursor="fleur")
|
||||||
self.update_size()
|
self.update_size()
|
||||||
|
|
||||||
def special_move(event: tkinter.Event):
|
def special_move(event: tkinter.Event):
|
||||||
if (event.y_root < 5):
|
if (event.y_root < 5):
|
||||||
self.y = 50
|
self.y = 50
|
||||||
self.zoom()
|
self.zoom()
|
||||||
title_frame.configure(cursor="arrow")
|
title_frame.configure(cursor="arrow")
|
||||||
top_bar.place(x=0, y=0, relwidth=1)
|
top_bar.place(x=0, y=0, relwidth=1)
|
||||||
ttk.Frame(root, style='Splitline.TFrame',
|
ttk.Frame(root, style='Splitline.TFrame',
|
||||||
height=1).place(x=0, y=self.top_h, relwidth=1)
|
height=1).place(x=0, y=self.top_h, relwidth=1)
|
||||||
|
|
||||||
icons = ttk.Label(top_bar, image=photoload.loadimg(
|
icons = ttk.Label(top_bar, image=photoload.loadimg(
|
||||||
"icon"), width=2, compound="center", justify="center", style="LabBarIcon.TLabel")
|
"icon"), width=2, compound="center", justify="center", style="LabBarIcon.TLabel")
|
||||||
icons.bind("<ButtonRelease-2>", lambda event=None: self.quit())
|
icons.bind("<ButtonRelease-2>", lambda event=None: self.quit())
|
||||||
icons.pack(anchor="center", side='left', padx=8, pady=4)
|
icons.pack(anchor="center", side='left', padx=8, pady=4)
|
||||||
|
|
||||||
title_frame.pack(anchor="center", side='left',
|
title_frame.pack(anchor="center", side='left',
|
||||||
fill=tkinter.X, expand=True)
|
fill=tkinter.X, expand=True)
|
||||||
control_frame = ttk.Frame(
|
control_frame = ttk.Frame(
|
||||||
top_bar, style="Root.TFrame", height=self.top_h, width=48*3)
|
top_bar, style="Root.TFrame", height=self.top_h, width=48*3)
|
||||||
control_frame.pack(anchor="e", side='right')
|
control_frame.pack(anchor="e", side='right')
|
||||||
title_frame.bind("<Button-1>", start_move)
|
title_frame.bind("<Button-1>", start_move)
|
||||||
title_frame.bind("<B1-Motion>", move_win)
|
title_frame.bind("<B1-Motion>", move_win)
|
||||||
title_frame.bind("<ButtonRelease-1>", special_move)
|
title_frame.bind("<ButtonRelease-1>", special_move)
|
||||||
|
|
||||||
_window_ctl.exit_btn_set(self, root)
|
_window_ctl.exit_btn_set(self, root)
|
||||||
_window_ctl.zoom_btn_set(self, root)
|
_window_ctl.zoom_btn_set(self, root)
|
||||||
_window_ctl.iconic_btn_set(self, root)
|
_window_ctl.iconic_btn_set(self, root)
|
||||||
_window_size.placeall(self, root)
|
_window_size.placeall(self, root)
|
||||||
|
|
||||||
titles = ttk.Label(title_frame, text=self.title,
|
titles = ttk.Label(title_frame, text=self.title,
|
||||||
style="LabTitle.TLabel")
|
style="LabTitle.TLabel")
|
||||||
titles.pack()
|
titles.pack()
|
||||||
titles.bind("<Button-1>", start_move)
|
titles.bind("<Button-1>", start_move)
|
||||||
titles.bind("<B1-Motion>", move_win)
|
titles.bind("<B1-Motion>", move_win)
|
||||||
titles.bind("<ButtonRelease-1>", special_move)
|
titles.bind("<ButtonRelease-1>", special_move)
|
||||||
|
|
||||||
def __init__(self, w=500, h=350, title="MagicTk", color_list: None | dict = None) -> None:
|
def __init__(self, w=500, h=350, title="MagicTk", color_list: None | dict = None) -> None:
|
||||||
self.title = title
|
self.title = title
|
||||||
self.w = w
|
self.w = w
|
||||||
self.h = h
|
self.h = h
|
||||||
if (color_list is not None):
|
if (color_list is not None):
|
||||||
self.color = color_list
|
self.color = color_list
|
||||||
self.main_tk = tkinter.Tk()
|
self.main_tk = tkinter.Tk()
|
||||||
self.main_tk.overrideredirect(True)
|
self.main_tk.overrideredirect(True)
|
||||||
self.__fake_tk = tkinter.Tk()
|
self.__fake_tk = tkinter.Tk()
|
||||||
self.style = ttk.Style()
|
self.style = ttk.Style()
|
||||||
self.__load_color()
|
self.__load_color()
|
||||||
self.tk_w_without_bar = tkinter.IntVar()
|
self.tk_w_without_bar = tkinter.IntVar()
|
||||||
self.tk_w_without_bar.set(self.w-48*3)
|
self.tk_w_without_bar.set(self.w-48*3)
|
||||||
|
|
||||||
ttk.Widget.__init__(self, self.main_tk, "ttk::frame", {
|
ttk.Widget.__init__(self, self.main_tk, "ttk::frame", {
|
||||||
"style": "Main.TFrame"})
|
"style": "Main.TFrame"})
|
||||||
self.place(x=8, y=self.top_h+1+8, width=self.w-16, height=self.h-1-16)
|
self.place(x=8, y=self.top_h+1+8, width=self.w-16, height=self.h-1-16)
|
||||||
|
|
||||||
self.update_size()
|
self.update_size()
|
||||||
self.__fake_tk.title(self.title)
|
self.__fake_tk.title(self.title)
|
||||||
self.main_tk.title(self.title)
|
self.main_tk.title(self.title)
|
||||||
self.__fake_tk.protocol("WM_DELETE_WINDOW", self.quit)
|
self.__fake_tk.protocol("WM_DELETE_WINDOW", self.quit)
|
||||||
self.__fake_tk.bind('<FocusIn>', self.__top_window)
|
self.__fake_tk.bind('<FocusIn>', self.__top_window)
|
||||||
self.__fake_tk.resizable(0, 0)
|
self.__fake_tk.resizable(0, 0)
|
||||||
self.__init_weights(self.main_tk)
|
self.__init_weights(self.main_tk)
|
||||||
try:
|
try:
|
||||||
self.main_tk.iconbitmap(
|
self.main_tk.iconbitmap(
|
||||||
os.path.dirname(__file__)+os.sep+"icon.ico")
|
os.path.dirname(__file__)+os.sep+"icon.ico")
|
||||||
self.__fake_tk.iconbitmap(
|
self.__fake_tk.iconbitmap(
|
||||||
os.path.dirname(__file__)+os.sep+"icon.ico")
|
os.path.dirname(__file__)+os.sep+"icon.ico")
|
||||||
except:
|
except:
|
||||||
# What's fuck in Linux
|
# What's fuck in Linux
|
||||||
self.zoom()
|
self.zoom()
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
self.__fake_tk.update()
|
self.__fake_tk.update()
|
||||||
self.zoom()
|
self.zoom()
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
self.__fake_tk.update()
|
self.__fake_tk.update()
|
||||||
|
|
||||||
def mainloop(self) -> None:
|
def mainloop(self) -> None:
|
||||||
t_start = time.time()
|
t_start = time.time()
|
||||||
while (self.__break_win):
|
while (self.__break_win):
|
||||||
delta_t = time.time()-t_start
|
delta_t = time.time()-t_start
|
||||||
if (delta_t > 0.02): # flash animation
|
if (delta_t > 0.02): # flash animation
|
||||||
t_start = time.time()
|
t_start = time.time()
|
||||||
for i in self.anim:
|
for i in self.anim:
|
||||||
if (i is not None):
|
if (i is not None):
|
||||||
i()
|
i()
|
||||||
self.anim = [i for i in self.anim if i is not None]
|
self.anim = [i for i in self.anim if i is not None]
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
if (self.__fake_tk.state() == "iconic"):
|
if (self.__fake_tk.state() == "iconic"):
|
||||||
if (self.normal_x == -1):
|
if (self.normal_x == -1):
|
||||||
self.normal_x = self.x
|
self.normal_x = self.x
|
||||||
self.normal_y = self.y
|
self.normal_y = self.y
|
||||||
self.x = WIN_INF
|
self.x = WIN_INF
|
||||||
self.y = WIN_INF
|
self.y = WIN_INF
|
||||||
self.minmode = True
|
self.minmode = True
|
||||||
self.fullscreen = False
|
self.fullscreen = False
|
||||||
self.update_size()
|
self.update_size()
|
||||||
else:
|
else:
|
||||||
if (self.normal_x != -1):
|
if (self.normal_x != -1):
|
||||||
self.x = self.normal_x
|
self.x = self.normal_x
|
||||||
self.y = self.normal_y
|
self.y = self.normal_y
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.minmode = False
|
self.minmode = False
|
||||||
self.update_size()
|
self.update_size()
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
self.__fake_tk.update()
|
self.__fake_tk.update()
|
||||||
self.main_tk.destroy()
|
self.main_tk.destroy()
|
||||||
self.__fake_tk.destroy()
|
self.__fake_tk.destroy()
|
||||||
self.main_tk.mainloop()
|
self.main_tk.mainloop()
|
||||||
self.__break_win = None
|
self.__break_win = None
|
||||||
|
|
||||||
def quit(self) -> None:
|
def quit(self) -> None:
|
||||||
self.__break_win = False
|
self.__break_win = False
|
||||||
|
|
||||||
def iconify(self) -> None:
|
def iconify(self) -> None:
|
||||||
if (self.fullscreen == True):
|
if (self.fullscreen == True):
|
||||||
self.zoom()
|
self.zoom()
|
||||||
self.__fake_tk.iconify()
|
self.__fake_tk.iconify()
|
||||||
|
|
||||||
def __top_window(self, event=None) -> None:
|
def __top_window(self, event=None) -> None:
|
||||||
self.main_tk.state("normal")
|
self.main_tk.state("normal")
|
||||||
self.main_tk.focus_set()
|
self.main_tk.focus_set()
|
||||||
self.main_tk.attributes('-topmost', 'true')
|
self.main_tk.attributes('-topmost', 'true')
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
self.main_tk.attributes('-topmost', 'false')
|
self.main_tk.attributes('-topmost', 'false')
|
||||||
|
|
||||||
def zoom(self) -> None:
|
def zoom(self) -> None:
|
||||||
if (self.fullscreen == False):
|
if (self.fullscreen == False):
|
||||||
self.normal_w = self.w
|
self.normal_w = self.w
|
||||||
self.normal_h = self.h
|
self.normal_h = self.h
|
||||||
self.old_x = self.x
|
self.old_x = self.x
|
||||||
self.old_y = self.y
|
self.old_y = self.y
|
||||||
nx = 0
|
nx = 0
|
||||||
ny = 0
|
ny = 0
|
||||||
nw, nh = self.__fake_tk.maxsize()
|
nw, nh = self.__fake_tk.maxsize()
|
||||||
try:
|
try:
|
||||||
wsp = workspace.get_workspace_size()
|
wsp = workspace.get_workspace_size()
|
||||||
nx = wsp[0]
|
nx = wsp[0]
|
||||||
ny = wsp[1]
|
ny = wsp[1]
|
||||||
nw = wsp[2]
|
nw = wsp[2]
|
||||||
nh = wsp[3]-self.top_h
|
nh = wsp[3]-self.top_h
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.x = nx
|
self.x = nx
|
||||||
self.y = ny
|
self.y = ny
|
||||||
self.main_tk.geometry(
|
self.main_tk.geometry(
|
||||||
f"+{self.x}+{self.y}")
|
f"+{self.x}+{self.y}")
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
self.w = nw
|
self.w = nw
|
||||||
self.h = nh
|
self.h = nh
|
||||||
self.update_size()
|
self.update_size()
|
||||||
self.fullscreen = True
|
self.fullscreen = True
|
||||||
self.minmode = False
|
self.minmode = False
|
||||||
self.__top_window()
|
self.__top_window()
|
||||||
else:
|
else:
|
||||||
self.normal_x = -1
|
self.normal_x = -1
|
||||||
self.x = self.old_x
|
self.x = self.old_x
|
||||||
self.y = self.old_y
|
self.y = self.old_y
|
||||||
self.main_tk.geometry(
|
self.main_tk.geometry(
|
||||||
f"+{self.x}+{self.y}")
|
f"+{self.x}+{self.y}")
|
||||||
self.main_tk.update()
|
self.main_tk.update()
|
||||||
self.w = self.normal_w
|
self.w = self.normal_w
|
||||||
self.h = self.normal_h
|
self.h = self.normal_h
|
||||||
self.fullscreen = False
|
self.fullscreen = False
|
||||||
self.minmode = False
|
self.minmode = False
|
||||||
self.update_size()
|
self.update_size()
|
||||||
self.__top_window()
|
self.__top_window()
|
||||||
self.update_icon()
|
self.update_icon()
|
||||||
|
|
|
@ -1,78 +1,78 @@
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
|
|
||||||
def get_windows_workspace_size() -> Optional[Tuple[int, int, int, int]]:
|
def get_windows_workspace_size() -> Optional[Tuple[int, int, int, int]]:
|
||||||
try:
|
try:
|
||||||
import win32api
|
import win32api
|
||||||
# 获取工作区(不包括任务栏)的尺寸
|
# 获取工作区(不包括任务栏)的尺寸
|
||||||
work_area = win32api.GetMonitorInfo(
|
work_area = win32api.GetMonitorInfo(
|
||||||
win32api.MonitorFromPoint((0, 0))).get('Work')
|
win32api.MonitorFromPoint((0, 0))).get('Work')
|
||||||
x, y, width, height = work_area
|
x, y, width, height = work_area
|
||||||
width -= x
|
width -= x
|
||||||
height -= y
|
height -= y
|
||||||
return x, y, width, height
|
return x, y, width, height
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("pywin32 library is not installed.")
|
print("pywin32 library is not installed.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An error occurred: {e}")
|
print(f"An error occurred: {e}")
|
||||||
return (0, 0, 1920, 1002)
|
return (0, 0, 1920, 1002)
|
||||||
|
|
||||||
|
|
||||||
def get_gtk_workspace_size() -> Optional[Tuple[int, int, int, int]]:
|
def get_gtk_workspace_size() -> Optional[Tuple[int, int, int, int]]:
|
||||||
try:
|
try:
|
||||||
# if 1:
|
# if 1:
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
screen = gi.gdk.screen_get_default()
|
screen = gi.gdk.screen_get_default()
|
||||||
|
|
||||||
# 获取屏幕上显示器的数量
|
# 获取屏幕上显示器的数量
|
||||||
num_monitors = screen.get_n_monitors()
|
num_monitors = screen.get_n_monitors()
|
||||||
|
|
||||||
# 获取每个显示器的几何信息,并计算工作区的大小
|
# 获取每个显示器的几何信息,并计算工作区的大小
|
||||||
workarea_width = 0
|
workarea_width = 0
|
||||||
workarea_height = 0
|
workarea_height = 0
|
||||||
|
|
||||||
for i in range(num_monitors):
|
for i in range(num_monitors):
|
||||||
monitor_geometry = screen.get_monitor_geometry(i)
|
monitor_geometry = screen.get_monitor_geometry(i)
|
||||||
monitor_x = monitor_geometry.x
|
monitor_x = monitor_geometry.x
|
||||||
monitor_y = monitor_geometry.y
|
monitor_y = monitor_geometry.y
|
||||||
monitor_width = monitor_geometry.width
|
monitor_width = monitor_geometry.width
|
||||||
monitor_height = monitor_geometry.height
|
monitor_height = monitor_geometry.height
|
||||||
|
|
||||||
workarea_width += monitor_width
|
workarea_width += monitor_width
|
||||||
workarea_height += monitor_height
|
workarea_height += monitor_height
|
||||||
|
|
||||||
print("工作区大小(宽度 x 高度):{} x {}".format(workarea_width, workarea_height))
|
print("工作区大小(宽度 x 高度):{} x {}".format(workarea_width, workarea_height))
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("pygtk (PyGObject pygtk) library is not installed.")
|
print("pygtk (PyGObject pygtk) library is not installed.")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_macos_workspace_size() -> Optional[Tuple[int, int, int, int]]:
|
def get_macos_workspace_size() -> Optional[Tuple[int, int, int, int]]:
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(
|
output = subprocess.check_output(
|
||||||
['system_profiler', 'SPDisplaysDataType']).decode('utf-8')
|
['system_profiler', 'SPDisplaysDataType']).decode('utf-8')
|
||||||
lines = output.split('\n')
|
lines = output.split('\n')
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if 'Resolution:' in line:
|
if 'Resolution:' in line:
|
||||||
dimensions = line.split(':')[1].strip().split('x')
|
dimensions = line.split(':')[1].strip().split('x')
|
||||||
width = int(dimensions[0])
|
width = int(dimensions[0])
|
||||||
height = int(dimensions[1])
|
height = int(dimensions[1])
|
||||||
# system_profiler does not provide the top-left corner directly, assuming (0, 0)
|
# system_profiler does not provide the top-left corner directly, assuming (0, 0)
|
||||||
return 0, 0, width, height
|
return 0, 0, width, height
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_workspace_size() -> Optional[Tuple[int, int, int, int]]:
|
def get_workspace_size() -> Optional[Tuple[int, int, int, int]]:
|
||||||
if sys.platform.startswith('win'):
|
if sys.platform.startswith('win'):
|
||||||
return get_windows_workspace_size()
|
return get_windows_workspace_size()
|
||||||
elif sys.platform.startswith('darwin'):
|
elif sys.platform.startswith('darwin'):
|
||||||
return get_macos_workspace_size()
|
return get_macos_workspace_size()
|
||||||
return get_gtk_workspace_size()
|
return get_gtk_workspace_size()
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
255,
|
255,
|
||||||
205,
|
205,
|
||||||
64,
|
64,
|
||||||
14
|
14
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
205,
|
205,
|
||||||
34,
|
34,
|
||||||
-155,
|
-155,
|
||||||
-245
|
-245
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
64,
|
64,
|
||||||
-155,
|
-155,
|
||||||
-255,
|
-255,
|
||||||
-255
|
-255
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
14,
|
14,
|
||||||
-245,
|
-245,
|
||||||
-255,
|
-255,
|
||||||
-255
|
-255
|
||||||
]
|
]
|
||||||
]
|
]
|
|
@ -0,0 +1,32 @@
|
||||||
|
[
|
||||||
|
[
|
||||||
|
255,
|
||||||
|
157,
|
||||||
|
22
|
||||||
|
],
|
||||||
|
[
|
||||||
|
157,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
22,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
22,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
157,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
255,
|
||||||
|
157,
|
||||||
|
22
|
||||||
|
]
|
||||||
|
]
|
|
@ -1,14 +1,14 @@
|
||||||
import os
|
import os
|
||||||
import pickle
|
import pickle
|
||||||
import base64
|
import base64
|
||||||
paths = os.path.dirname(__file__).replace("\\", "/")
|
paths = os.path.dirname(__file__).replace("\\", "/")
|
||||||
pickle_jar = {}
|
pickle_jar = {}
|
||||||
print("packing...")
|
print("packing...")
|
||||||
for i in os.listdir(paths+"/res"):
|
for i in os.listdir(paths+"/res"):
|
||||||
print(f"pack {i}")
|
print(f"pack {i}")
|
||||||
with open(paths+"/res/"+i, "rb") as file:
|
with open(paths+"/res/"+i, "rb") as file:
|
||||||
pickle_jar[i.split(".")[0]] = base64.b64encode(file.read())
|
pickle_jar[i.split(".")[0]] = base64.b64encode(file.read())
|
||||||
print("write...")
|
print("write...")
|
||||||
with open(paths+"/../magictk/res.pickle", "wb") as file:
|
with open(paths+"/../magictk/res.pickle", "wb") as file:
|
||||||
pickle.dump(pickle_jar, file)
|
pickle.dump(pickle_jar, file)
|
||||||
print("done!")
|
print("done!")
|
||||||
|
|
Loading…
Reference in New Issue