-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeViews.py
More file actions
191 lines (144 loc) · 6.15 KB
/
timeViews.py
File metadata and controls
191 lines (144 loc) · 6.15 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
from tkinter import Canvas, Tk,font
import calendar as cale
class Calendar(Canvas):
def __init__(self, tfont=None,fontfg="#ffffff", **kwargs):
Canvas.__init__(self,**kwargs)
if tfont==None:
tfont=font.Font(family="Calibre", size=20)
self.colums=7
self.fontfg=fontfg
self.font=tfont
self.month,self.year=0,0
self.badgeZ=40
self.textMargin=8
self.spacing=5
self.colidebles={}
self.bind("<Button-1>",self._colisions)
def _colisions(self,e):
x,y=e.x,e.y
for func in self.colidebles:
for value in self.colidebles[func]:
x1,y1,x2,y2=self.bbox(value)
if (x1<x<x2)&(y1<y<y2):
print("Value",value)
if func:
func(value)
return
pass
def _create_round_rectangle(self, x1, y1, x2, y2, radius=25, **kwargs):
points = [x1 + radius, y1, x1 + radius, y1, x2 - radius, y1, x2 - radius, y1,
x2, y1, x2, y1 + radius, x2, y1 + radius, x2, y2 - radius,
x2, y2 - radius, x2, y2, x2 - radius, y2, x2 - radius, y2, x1 + radius, y2,
x1 + radius, y2, x1, y2, x1, y2 - radius, x1, y2 - radius, x1, y1 + radius,
x1, y1 + radius, x1, y1]
return self.create_polygon(points, **kwargs, smooth=True)
def _topBar(self,width,title,font,height=30,textmarginx=10,bg="#83C9F4"):
bgr=self._create_round_rectangle(0,0,width,30,fill=bg)
ca=self.create_text(textmarginx,0, anchor="nw", text=title, font=font,
fill=self.fontfg)
a4 = self.bbox(ca)
cax = a4[2] - a4[0]
cay = a4[3] - a4[1]
print("gds", cax, cay)
margin_y = (height - cay) // 2
self.moveto(ca, x=textmarginx, y=margin_y)
def trigerBack(i):
self.event_generate("<<Last>>")
def trigerForth(i):
self.event_generate("<<Next>>")
c=self.create_text(width-(textmarginx+40), margin_y, anchor="nw", text="ᐸ", font=font,
fill=self.fontfg)
self.addclickables(trigerBack,c)
c1=self.create_text(width-(textmarginx+20), margin_y, anchor="nw", text="ᐳ", font=font,
fill=self.fontfg)
self.addclickables(trigerForth, c1)
return [ca,bgr,c,c1]
def _bindTBClicks(self):
pass
def addclickables(self,func,obj):
if func in self.colidebles.keys():
self.colidebles[func]+=[obj]
return
self.colidebles[func]= [obj]
def addBadge(self,xr,yr,day,color,click=None):
xb,yb=20,40
setx=xb+(xr*self.badgeZ)+(self.spacing*xr)
sety=yb+(yr*self.badgeZ)+(self.spacing*yr)
print(setx,sety)
c=self._create_round_rectangle(setx,sety,setx+self.badgeZ,sety+self.badgeZ,fill=color,radius=10)
self.addclickables(click,c)
ca=self.create_text(setx+self.textMargin,sety+self.textMargin,anchor="nw",text=day,font=self.font,fill=self.fontfg)
a4=self.bbox(ca)
cax=a4[2]-a4[0]
cay = a4[3]-a4[1]
print("gds",cax,cay)
margin_x=(self.badgeZ-cax)//2
margin_y = (self.badgeZ - cay) // 2
self.moveto(ca,x=setx+margin_x,y=sety+margin_y)
return [c,ca]
def delItems(self,ids):
print(ids)
for id in ids:
self.delete(id)
for func in self.colidebles:
if id in self.colidebles[func]:
self.colidebles[func].remove(id)
def genCal(self,weeks,marks={},defuldCollor="#83C9F4",onclicl=None):
l=[]
def oncl(id):
print("l34",l)
if onclicl:
onclicl(l.index(id)//2+1)
for n,week in enumerate(weeks):
print(week)
for n2,day in enumerate(week):
if day==0:
continue
day=day
if day in marks.keys():
l+=self.addBadge(n2,n,day=str(day),color=marks[day],click=oncl)
else:
l+=self.addBadge(n2,n, day=str(day), color=defuldCollor,click=oncl)
print("l",l)
return l
def StandartCalder(self,date:[int,int],getMarkersFunction:{}=None,onDayClicked=None,badgeColor="#83C9F4",tbbg="#83C9F4"):
self.year=date[0]
self.month=date[1]
def ondKlick(d):
if onDayClicked:
onDayClicked((d,self.month,self.year))
self.update()
def getmarks()->dict:
if getMarkersFunction:
print("Marking")
return getMarkersFunction(self.year, self.month)
return {}
tb=self._topBar(self.winfo_width(), "March", font=font.Font(size=10, font="Calibre", weight="bold"),bg=tbbg)
monthNames=["","January","February","March","April","May","June","July","August","September","Oktober","November","December"]
rc = cale.monthcalendar(self.year,self.month)
comps=self.genCal(rc,marks=getmarks(),onclicl=ondKlick,defuldCollor=badgeColor)
self.itemconfig(tb[0],text=monthNames[self.month]+f" {self.year}")
def next(u):
nonlocal rc,comps
if 0<self.month<12:
self.month+=1
elif self.month==12:
self.month=1
self.year+=1
rc = cale.monthcalendar(self.year, self.month)
self.delItems(comps)
self.itemconfig(tb[0],text=monthNames[self.month]+f" {self.year}")
comps = self.genCal(rc,marks=getmarks(),onclicl=ondKlick,defuldCollor=badgeColor)
def last(u):
nonlocal rc, comps
if self.month == 1:
self.month = 12
self.year -= 1
else:
self.month -= 1
rc = cale.monthcalendar(self.year, self.month)
self.delItems(comps)
self.itemconfig(tb[0], text=monthNames[self.month] + f" {self.year}")
comps = self.genCal(rc,marks=getmarks(),onclicl=ondKlick,defuldCollor=badgeColor)
self.bind("<<Next>>",next)
self.bind("<<Last>>", last)