From 768a35a2c5ef8bb802e273ba92cdc69400fa21f6 Mon Sep 17 00:00:00 2001 From: cxykevin Date: Sat, 20 Apr 2024 18:06:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0basicwindow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- magictk/__init__.py | 1 + magictk/_window_ctl.py | 10 +---- magictk/basicwindow.py | 92 ++++++++++++++++++++++++++++++++++++++++++ magictk/entry.py | 11 +++-- magictk/progressbar.py | 11 +---- magictk/window.py | 26 +++--------- 6 files changed, 110 insertions(+), 41 deletions(-) create mode 100644 magictk/basicwindow.py diff --git a/magictk/__init__.py b/magictk/__init__.py index 29f0f5f..41f998f 100644 --- a/magictk/__init__.py +++ b/magictk/__init__.py @@ -1,4 +1,5 @@ from magictk.window import Window +from magictk.basicwindow import Tk from magictk.button import Button, ButtonFill from magictk.progressbar import ProgressBar from magictk.checkbox import Checkbox, RadioGroup diff --git a/magictk/_window_ctl.py b/magictk/_window_ctl.py index 5335935..6789282 100644 --- a/magictk/_window_ctl.py +++ b/magictk/_window_ctl.py @@ -1,13 +1,7 @@ import tkinter from tkinter import ttk -try: - import color_tmpl -except: - from magictk import color_tmpl -try: - import photoload -except: - from magictk import photoload +from magictk import color_tmpl +from magictk import photoload def exit_btn_set(self, root): diff --git a/magictk/basicwindow.py b/magictk/basicwindow.py new file mode 100644 index 0000000..93f3f64 --- /dev/null +++ b/magictk/basicwindow.py @@ -0,0 +1,92 @@ +import time +import tkinter +import os +from tkinter import ttk +from magictk import color_tmpl +from magictk import _window_ctl +from magictk import _window_size +from magictk import workspace +from magictk import photoload +import sys + +WIN_INF = -10000 + + +class Tk(ttk.Frame): + x = 200 + y = 200 + w = 500 + h = 350 + color = color_tmpl.default_color + anim = [] + FRAME_INFO = "Normal" + __break_win = True + + def __load_color(self) -> None: + self.main_tk.configure(bg=self.color["background"]) + self.style.configure( + 'Test1.TFrame', background="#FF0000") + self.style.configure( + 'Test2.TFrame', background="#00FF00") + self.style.configure( + 'Test3.TFrame', background="#0000FF") + self.style.configure( + 'Main.TFrame', background=self.color["background"]) + self.style.configure( + 'Root.TFrame', background=self.color["background"]) + self.style.configure( + 'Splitline.TFrame', background=self.color["border_light"]) + self.style.configure( + 'BarExitButton.TFrame', background=self.color["background"]) + self.style.configure( + 'LabBarZoomButton.TLabel', background=self.color["background"]) + self.style.configure( + 'LabBarIcon.TLabel', background=self.color["background"]) + self.style.configure( + 'LabTitle.TLabel', background=self.color["background"], fg=self.color["primary_text"]) + self.style.configure( + 'BarIconicButton.TFrame', background=self.color["background"]) + self.style.configure( + 'Size.TFrame', background=self.color["background"]) + self.style.configure( + 'LabelTitle.TFrame', background=self.color["background"]) + + def __init__(self, w=500, h=350, title="MagicTk", color_list: dict = None) -> None: + self.root = self + self.title = title + self.w = w + self.h = h + if (color_list is not None): + self.color = color_list + self.main_tk = tkinter.Tk() + self.style = ttk.Style() + self.__load_color() + ttk.Widget.__init__(self, self.main_tk, "ttk::frame", { + "style": "Main.TFrame"}) + self.main_tk.title(title) + self.place(x=0, y=0, relwidth=1, relheight=1) + self.main_tk.geometry( + f"{self.w}x{self.h}+{self.x}+{self.y}") + + def mainloop(self) -> None: + t_start = time.time() + while (self.__break_win): + delta_t = time.time()-t_start + if (delta_t > 0.02): # flash animation + t_start = time.time() + n = 0 + for i in self.anim: + if (i is not None): + retn = i() + if (retn == -1): + self.anim[n] = None + n += 1 + self.anim = [i for i in self.anim if i is not None] + else: + pass + self.main_tk.update() + self.main_tk.destroy() + self.__break_win = None + + def quit(self) -> None: + self.__break_win = False diff --git a/magictk/entry.py b/magictk/entry.py index c0ff967..0b5b438 100644 --- a/magictk/entry.py +++ b/magictk/entry.py @@ -248,17 +248,19 @@ class Entry: def __bind_event(self): def closecallback(obj): if (self.__is_hover == 1): - if sys.platform.startswith("linux"): + if sys.platform.startswith("linux") and self.root.FRAME_INFO == "Custom": self.top.destroy() self.__is_hover = 0 self.canvas.focus_force() def pressrelease_v(event: tkinter.Event): if (self.__is_hover == 1): - closecallback(event) + pass + # closecallback(event) else: self.__is_hover = 1 - if sys.platform.startswith("linux"): # what's fuck? + # what's fuck? + if sys.platform.startswith("linux") and self.root.FRAME_INFO == "Custom": self.top = tkinter.Toplevel() self.top.geometry( f"{1}x{1}+{10000}+{10000}") @@ -285,6 +287,7 @@ class Entry: self.inputobj.bind("", pressrelease_v) self.show_label.bind("", pressrelease_v) self.__input_textvar.trace_add("write", update_text) - # self.frames.bind_all("", closecallback) if (sys.platform.startswith("linux")): self.frames.bind("", closecallback) + else: + self.inputobj.bind_all("", closecallback) diff --git a/magictk/progressbar.py b/magictk/progressbar.py index c4732fb..4267521 100644 --- a/magictk/progressbar.py +++ b/magictk/progressbar.py @@ -1,15 +1,8 @@ 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 +from magictk import color_tmpl +from magictk import photoload class ProgressBar: diff --git a/magictk/window.py b/magictk/window.py index fb73df6..b365b98 100644 --- a/magictk/window.py +++ b/magictk/window.py @@ -2,26 +2,11 @@ import time import tkinter import os from tkinter import ttk -try: - import color_tmpl -except ImportError: - from magictk import color_tmpl -try: - import _window_ctl -except ImportError: - from magictk import _window_ctl -try: - import _window_size -except ImportError: - from magictk import _window_size -try: - import workspace -except ImportError: - from magictk import workspace -try: - import photoload -except ImportError: - from magictk import photoload +from magictk import color_tmpl +from magictk import _window_ctl +from magictk import _window_size +from magictk import workspace +from magictk import photoload import sys WIN_INF = -10000 @@ -43,6 +28,7 @@ class Window(ttk.Frame): disable_move = False min_w = 200 min_h = 100 + FRAME_INFO = "Custom" def update_size(self) -> None: self.tk_w_without_bar.set(self.w-48*3)