添加basicwindow
Build and Publish / Run (push) Successful in 48s Details

This commit is contained in:
cxykevin 2024-04-20 18:06:05 +08:00
parent b93fa15176
commit 768a35a2c5
6 changed files with 110 additions and 41 deletions

View File

@ -1,4 +1,5 @@
from magictk.window import Window from magictk.window import Window
from magictk.basicwindow import Tk
from magictk.button import Button, ButtonFill from magictk.button import Button, ButtonFill
from magictk.progressbar import ProgressBar from magictk.progressbar import ProgressBar
from magictk.checkbox import Checkbox, RadioGroup from magictk.checkbox import Checkbox, RadioGroup

View File

@ -1,12 +1,6 @@
import tkinter import tkinter
from tkinter import ttk from tkinter import ttk
try:
import color_tmpl
except:
from magictk import color_tmpl from magictk import color_tmpl
try:
import photoload
except:
from magictk import photoload from magictk import photoload

92
magictk/basicwindow.py Normal file
View File

@ -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

View File

@ -248,17 +248,19 @@ class Entry:
def __bind_event(self): def __bind_event(self):
def closecallback(obj): def closecallback(obj):
if (self.__is_hover == 1): 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.top.destroy()
self.__is_hover = 0 self.__is_hover = 0
self.canvas.focus_force() self.canvas.focus_force()
def pressrelease_v(event: tkinter.Event): def pressrelease_v(event: tkinter.Event):
if (self.__is_hover == 1): if (self.__is_hover == 1):
closecallback(event) pass
# closecallback(event)
else: else:
self.__is_hover = 1 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 = tkinter.Toplevel()
self.top.geometry( self.top.geometry(
f"{1}x{1}+{10000}+{10000}") f"{1}x{1}+{10000}+{10000}")
@ -285,6 +287,7 @@ class Entry:
self.inputobj.bind("<ButtonRelease-1>", pressrelease_v) self.inputobj.bind("<ButtonRelease-1>", pressrelease_v)
self.show_label.bind("<ButtonRelease-1>", pressrelease_v) self.show_label.bind("<ButtonRelease-1>", pressrelease_v)
self.__input_textvar.trace_add("write", update_text) self.__input_textvar.trace_add("write", update_text)
# self.frames.bind_all("<FocusOut>", closecallback)
if (sys.platform.startswith("linux")): if (sys.platform.startswith("linux")):
self.frames.bind("<Leave>", closecallback) self.frames.bind("<Leave>", closecallback)
else:
self.inputobj.bind_all("<FocusOut>", closecallback)

View File

@ -1,14 +1,7 @@
import json import json
import tkinter import tkinter
from tkinter import ttk from tkinter import ttk
from tkinter import font as tkfont
try:
import color_tmpl
except ImportError:
from magictk import color_tmpl from magictk import color_tmpl
try:
import photoload
except ImportError:
from magictk import photoload from magictk import photoload

View File

@ -2,25 +2,10 @@ import time
import tkinter import tkinter
import os import os
from tkinter import ttk from tkinter import ttk
try:
import color_tmpl
except ImportError:
from magictk import color_tmpl from magictk import color_tmpl
try:
import _window_ctl
except ImportError:
from magictk import _window_ctl from magictk import _window_ctl
try:
import _window_size
except ImportError:
from magictk import _window_size from magictk import _window_size
try:
import workspace
except ImportError:
from magictk import workspace from magictk import workspace
try:
import photoload
except ImportError:
from magictk import photoload from magictk import photoload
import sys import sys
@ -43,6 +28,7 @@ class Window(ttk.Frame):
disable_move = False disable_move = False
min_w = 200 min_w = 200
min_h = 100 min_h = 100
FRAME_INFO = "Custom"
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)