-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameUiComponents.py
157 lines (127 loc) · 6.27 KB
/
gameUiComponents.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
from .observable import Observable
from . import *
from .independentComponents import *
def crim(name):
i = createImage("gresource/" + name + ".png", 30, 30)
return i
class ButtonDroppDown(MovableFrame):
def __init__(self,master:Window,disableX=False, width=380, height=320, highlightbackground="black", titel="", x=0, y=0,imagepath="",
disableDrag=False,
closeCommand=None):
global thread
MovableFrame.__init__(self, master=master, width=width, height=height, highlightbackground=highlightbackground,highlightcolor=Collor.selector_none,
highlightthickness=3, bd=0,
bg=Collor.bg)
self.disableX=disableX
self.disableDrag=disableDrag
self.width=width
self.height=height
self.master=master
self.closeCommand=closeCommand
self.mFrame=mFrame=self
mFrame.place(x=x, y=y, width=width, height=height)
f = Frame(mFrame, bg=Collor.bg_darker)
font_size_medium = tkfont.Font(family="Bahnschrift", size=12, weight="bold")
f.pack(side="top", anchor="n", fill="x")
self.Label = LabelButton(master=f,img=imagepath).pack(side="left", anchor="nw")
titel = L = Label(f, bg=Collor.bg_darker, fg=Collor.fg, font=font_size_medium, text=titel, anchor="w")
self.MoveEvents=[]
titel.pack(side="left", anchor="nw")
if not self.disableDrag:
self.make_draggable(titel, mFrame)
self.make_draggable(f, mFrame)
if not disableX:
def close( frame):
frame.place_forget()
if self.closeCommand:
self.closeCommand()
B = Button(f, text="❌", relief="flat", bg=Collor.bg_darker, fg=Collor.fg,
command=lambda: close( mFrame), border=0)
B.pack(side="right", anchor="ne")
def place_in_screen_window_rescue(self,widget):
print("trigger",int(self.mFrame.place_info()["y"]))
if int(self.mFrame.place_info()["y"])<0:
print("fix")
self.mFrame.place_configure(y=0)
elif int(self.mFrame.place_info()["x"])<-self.width+80:
print("fix")
self.mFrame.place_configure(x=-self.width+80)
elif int(self.mFrame.place_info()["x"])>self.master.winfo_width()-50:
print("fix")
self.mFrame.place_configure(x=self.master.winfo_width()-50)
elif int(self.mFrame.place_info()["y"])>self.master.winfo_height()-40:
print("fix")
self.mFrame.place_configure(y=self.master.winfo_height()-40)
def make_draggable(self,widget, toMoveWiget):
widget.bind("<ButtonRelease-1>", lambda e: self.place_in_screen_window_rescue(widget))
widget.bind("<Button-1>", lambda e: self.on_drag_start(e, widget, toMoveWiget))
widget.bind("<B1-Motion>", lambda e: self.on_drag_motion(e, widget, toMoveWiget))
def on_drag_start(self,event, widget, tomove):
widget._drag_start_x = event.x
widget._drag_start_y = event.y
tomove._drag_start_x = tomove.winfo_x()
tomove._drag_start_y = tomove.winfo_y()
tomove.last_xy=None
def on_drag_motion(self,event, widget, tomove):
x = tomove.winfo_x() - widget._drag_start_x + event.x
y = tomove.winfo_y() - widget._drag_start_y + event.y
if tomove.last_xy==None:
tomove.last_xy=(x,y)
if (not(tomove.last_xy[0]-20<x<tomove.last_xy[0]+20))|(not(tomove.last_xy[1]-20<y<tomove.last_xy[1]+20)):
tomove.place(x=x, y=y)
self.master.update_idletasks()
class ItemButton(Frame):
def __init__(self,displayName,args=(),function=None,**kwargs):
super().__init__(highlightthickness=1,bg=Collor.bg,highlightbackground=Collor.selector_none,**kwargs)
nameMaxLen=16
s=20
L=LabelButton(master=self, img=createImage("../gresource/unknown_64.png", s, s)).pack(side="left")
if len(displayName)>nameMaxLen:
displayName=displayName[0:nameMaxLen+2]+"..."
f=tkfont.Font(family="Bahnschrift",size=12)
L=Label(master=self,text=displayName,width=20,font=f,bg=Collor.bg,fg=Collor.fg)
L.pack(side="left",fill="x")
self.bindLabel=L
self.b=LabelButton(master=self, img=createImage("../gresource/cancel_64.png", s, s), command=self.pusch)
self.b.pack(side="left")
self.isAplied=False
self.function=function
self.args=args
def pusch(self):
self.isAplied=not self.isAplied
self.setApplied(self.isAplied)
if self.function:
self.function(*self.args)
def setApplied(self,tr):
s = 20
if tr:
self.b.configure(image=createImage("../gresource/done_64.png", s, s))
else:
self.b.configure(image=createImage("../gresource/cancel_64.png", s, s))
class Table(Frame):
def __init__(self,data=[],font=None,orientTop="col", **kwargs): #data contains in form [row->[>col in strings]] NAMES SCHOULD BE COL 0
Frame.__init__(self,highlightthickness=2, bg=Collor.bg, highlightbackground=Collor.selector_none, **kwargs)
self.columnconfigure(0,weight=len(data))
self.rowconfigure(0,weight=200)
def updateLable(lable:Label,value):
lable.configure(text=str(value))
for n,row in enumerate(data):
#f=Frame()
#f.pack(side="top",anchor="nw")
for n2,col in enumerate(row):
L=Label(master=self,font=font,bg=Collor.bg,fg=Collor.fg)
if type(col)==Observable:
col.subscribe(lambda value:updateLable(L,value))
L.configure(text=str(col.gv()))
else:
L.configure(text=col)
if orientTop=="row":
if n==0:
L.configure( highlightbackground = Collor.fg, highlightthickness = 1)
else:
if n2 == 0:
L.configure(anchor="w")
L.configure(highlightbackground=Collor.selector_none, highlightthickness=1)
print(n2)
L.grid(row=n,sticky="we",column=n2)
print("i")