-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeline.py
141 lines (104 loc) · 4.76 KB
/
timeline.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
import datetime
import imageModifier
import WindowComponents
from copy import deepcopy
from ConfigManager import ConfigManager
from DatabaseHandler import DatabaseHandler
from SystemInfo import SystemInfo
images = []
imageRenderer = None
lastResizeTimeMS = SystemInfo.getTimeMS()
datetimeText = None
oldSliderVal = 0
def getDate(ms, format):
seconds = ms / 1000
date = datetime.datetime.fromtimestamp(seconds)
return date.strftime(format)
def getElementSize(widget):
return widget.winfo_width(), widget.winfo_height()
def resizeWindow(width, height):
WindowComponents.Base.timeline.geometry(f"{width}x{height}")
WindowComponents.Base.timelineWidth = width
WindowComponents.Base.timelineHeight = height
def handleResize(event):
global lastResizeTimeMS
width = event.width
height = event.height
def render():
newWidth = WindowComponents.Base.timeline.winfo_width()
newHeight = WindowComponents.Base.timeline.winfo_height()
if newWidth == width and newHeight == height and imageRenderer:
imageRenderer.renderImageFromBin(images[WindowComponents.Base.timelineCurrentImage]["bin"])
if width != WindowComponents.Base.timelineWidth or height != WindowComponents.Base.timelineHeight:
WindowComponents.Base.timelineWidth = width
WindowComponents.Base.timelineHeight = height
WindowComponents.Base.timeline.after(75, render)
def createToplevel():
WindowComponents.Base.timelineWidth = WindowComponents.Base.screenSize[0] // 2
WindowComponents.Base.timelineHeight = WindowComponents.Base.screenSize[1] // 2
WindowComponents.Base.timeline = WindowComponents.Base.ctk.CTkToplevel()
WindowComponents.Base.timeline.title("Librecall - Timeline")
WindowComponents.Base.timeline.geometry(f"{WindowComponents.Base.timelineWidth}x{WindowComponents.Base.timelineHeight}")
WindowComponents.Base.timeline.focus()
WindowComponents.Base.timeline.bind("<Configure>", handleResize)
def onImageRender():
image = images[WindowComponents.Base.timelineCurrentImage]
datetimeFormat = ConfigManager().get("DATE_FORMAT")
time = int(image["date"])
if datetimeText:
datetimeText.setText(getDate(time, datetimeFormat))
def handleSlider(val):
oldimg = WindowComponents.Base.timelineCurrentImage
WindowComponents.Base.timelineCurrentImage = val
if oldimg != val:
imageRenderer.renderImageFromBin(images[WindowComponents.Base.timelineCurrentImage]["bin"])
def createTimelineWindow():
global images, imageRenderer, datetimeText
if WindowComponents.Base.timeline and WindowComponents.Base.timeline.winfo_exists():
return
configManager = ConfigManager()
dbHandler = DatabaseHandler()
sysInfo = SystemInfo()
dbHandler.makeConnection()
images = dbHandler.getImages()
dbHandler.endConnection()
imageCount = len(images)
if not imageCount:
WindowComponents.Notification("No images", "You don't have any screenshots stored that can be viewed here.")
return
createToplevel()
screenAR = imageModifier.getAspectRatio(WindowComponents.Base.screenSize)
toplevel = WindowComponents.Base.timeline
ctk = WindowComponents.Base.ctk
blankSpace = WindowComponents.TextLabel("", _app=toplevel)
blankSpace.label.configure(font=(None, 2))
toplevel.grid_rowconfigure(0, pad=1)
titleText = WindowComponents.TextLabel("Timeline", _app=toplevel, align="center")
titleText.label.configure(font=(None, 18))
datetimeText = WindowComponents.TextLabel("datetime", _app=toplevel, align="center")
datetimeText.label.configure(font=(None, 14))
slider = WindowComponents.Slider("Image", 0, 0, imageCount - 1, _app=toplevel, _callback=handleSlider)
imageRenderer = WindowComponents.ImagePreview(app=toplevel, onImageRender=onImageRender)
def deleteImage():
global imageCount, images
dbHandler.makeConnection()
sliderVal = slider.getValue()
imageID = images[sliderVal]["id"]
dbHandler.deleteImage(imageID)
images = dbHandler.getImages()
imageCount = len(images)
if not imageCount:
toplevel.destroy()
elif imageCount == 1:
slider.slider.configure(state="disabled")
slider.valueText.configure(text="0 (only value)")
else:
slider.slider.configure(from_=0, to=imageCount - 1)
if sliderVal >= imageCount and imageCount:
slider.slider.set(imageCount - 1)
slider._callback(imageCount - 1)
else:
if imageCount:
imageRenderer.renderImageFromBin(images[sliderVal]["bin"])
dbHandler.endConnection()
deleteImageButton = WindowComponents.FullWidthButton("Delete this image", deleteImage, _app=toplevel)