Migrate time circle to time bar
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,4 +4,5 @@ extracted/
|
||||
custom_images/
|
||||
*.txt
|
||||
selected/
|
||||
__pycache__
|
||||
__pycache__
|
||||
*.svg
|
||||
1141
cinnamon-dynamic-wallpaper@TobiZog/5.4/preferences/preferences.glade
Normal file
1141
cinnamon-dynamic-wallpaper@TobiZog/5.4/preferences/preferences.glade
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
# Imports
|
||||
import gi, os
|
||||
from time_bar import create_bar
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, GdkPixbuf
|
||||
|
||||
|
||||
# Global definitions
|
||||
GLADE_URI = os.path.dirname(os.path.abspath(__file__)) + "/preferences.glade"
|
||||
|
||||
|
||||
class Preferences:
|
||||
""" Preference window class
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
self.builder = Gtk.Builder()
|
||||
self.builder.add_from_file(GLADE_URI)
|
||||
self.builder.connect_signals(self)
|
||||
|
||||
# Time bar
|
||||
# todo: Sample times
|
||||
create_bar(1036, 200, [0, 455, 494, 523, 673, 792, 882, 941, 973, 1013, 1440])
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file("time_bar.svg")
|
||||
self.builder.get_object("img_bar").set_from_pixbuf(pixbuf)
|
||||
|
||||
|
||||
def show(self):
|
||||
""" Display the window to the screen
|
||||
"""
|
||||
window = self.builder.get_object("window_main")
|
||||
window.show_all()
|
||||
|
||||
self.builder.get_object("lbr_heic").set_visible(False)
|
||||
self.builder.get_object("lbr_folder").set_visible(False)
|
||||
|
||||
Gtk.main()
|
||||
|
||||
|
||||
def onDestroy(self, *args):
|
||||
""" Lifecycle handler when window will be destroyed
|
||||
"""
|
||||
Gtk.main_quit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Preferences().show()
|
||||
@@ -0,0 +1,45 @@
|
||||
import math
|
||||
|
||||
def create_bar(image_width, image_height, times):
|
||||
image_code = ['<svg xmlns="http://www.w3.org/2000/svg" width="' + str(image_width) + '" height="210">']
|
||||
colors = ["00193dff", "05597fff", "54babfff", "bfe3c2ff", "ffbf6bff", "fdb55cff", "f37f73ff", "7f3d85ff", "4a217aff", "00193dff"]
|
||||
|
||||
for i in range(0, 10):
|
||||
start_point = (((100 / 1440) * times[i] / 100) * image_width)
|
||||
width = math.ceil((((100 / 1440) * (times[i + 1] - times[i]) / 100) * image_width))
|
||||
image_code.append('<rect fill="#%s" x="%s" y="60" width="%s" height="100"/>' % (colors[i], start_point, width))
|
||||
|
||||
bar_part_mid = start_point + width / 2
|
||||
|
||||
if (i < 5):
|
||||
polyline_x = i * 10 + 10
|
||||
polyline_y = 0
|
||||
image_x = 100 + i * (200 + 8)
|
||||
elif (i < 9):
|
||||
polyline_x = (i - 4) * 10 + 160
|
||||
polyline_y = 210
|
||||
image_x = 200 + (i - 5) * (200 + 8)
|
||||
|
||||
if i < 9:
|
||||
image_code.append(
|
||||
'<polyline points="%s,%s %s,%s %s,%s %s,100" stroke="#%s" fill="none" stroke-width="5" />' %
|
||||
(image_x, polyline_y, image_x, polyline_x, bar_part_mid, polyline_x, bar_part_mid, colors[i])
|
||||
)
|
||||
|
||||
for i in range(0, 8):
|
||||
image_code.append(
|
||||
'<line x1="%s" y1="60" x2="%s" y2="160" stroke="gray" stroke-width="2" />' %
|
||||
(i * (image_width // 8), i * (image_width // 8))
|
||||
)
|
||||
|
||||
image_code.append(
|
||||
'<text x="%s" y="155" fill="gray" font-size="20" font-family="Liberation Sans">%s</text>' %
|
||||
(i * (image_width // 8) + 5, i * 3)
|
||||
)
|
||||
|
||||
# Write to file
|
||||
file = open("time_bar.svg", "w")
|
||||
for i in image_code:
|
||||
file.write(i + '\n')
|
||||
|
||||
file.write('</svg>')
|
||||
@@ -1,131 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import gi, os, math, cairo
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, GdkPixbuf
|
||||
|
||||
GLADE_URI = os.path.dirname(os.path.abspath(__file__)) + "/prefs.glade"
|
||||
|
||||
class Preferences:
|
||||
def __init__(self) -> None:
|
||||
self.builder = Gtk.Builder()
|
||||
self.builder.add_from_file(GLADE_URI)
|
||||
self.builder.connect_signals(self)
|
||||
|
||||
# 0:00 = 0%
|
||||
# 7:05 = 29.58
|
||||
# 7:39 = 32.08
|
||||
# 8:20 = 34.58
|
||||
# 11:46 = 49.17
|
||||
# 14:32 = 60.42
|
||||
# 16:36 = 69.17
|
||||
# 17:57 = 74.58
|
||||
# 18:41 = 77.92
|
||||
# 19:15 = 80
|
||||
|
||||
# Numbers for test purposes
|
||||
self.create_doughnut([29.57, 2.51, 2.5, 14.6, 11.26, 8.76, 5.42, 3.35, 2.09])
|
||||
|
||||
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file("example.svg")
|
||||
self.builder.get_object("image").set_from_pixbuf(pixbuf)
|
||||
|
||||
|
||||
def create_doughnut(self, list_of_percentages: list):
|
||||
color_list = [
|
||||
[0.00, 0.10, 0.24],
|
||||
[0.02, 0.35, 0.50],
|
||||
[0.33, 0.73, 0.75],
|
||||
[0.75, 0.89, 0.76],
|
||||
[1.00, 0.75, 0.42],
|
||||
[0.99, 0.71, 0.36],
|
||||
[0.95, 0.50, 0.45],
|
||||
[0.50, 0.24, 0.52],
|
||||
[0.29, 0.13, 0.48],
|
||||
[0.00, 0.10, 0.24],
|
||||
]
|
||||
|
||||
image_height = 350
|
||||
image_width = 350
|
||||
|
||||
|
||||
with cairo.SVGSurface("example.svg", image_height, image_width) as surface:
|
||||
# Create the draw object
|
||||
context = cairo.Context(surface)
|
||||
|
||||
# Calculate sizes
|
||||
xc, yc = image_height / 2, image_width / 2
|
||||
radius = image_height * 0.35
|
||||
doughnut_width = image_height * 0.2
|
||||
|
||||
# -25 turns the graph 45° anti-clockwise
|
||||
total_percentage = -25
|
||||
|
||||
# Completes the doughnut to 100%
|
||||
list_of_percentages.append(100 - sum(list_of_percentages))
|
||||
|
||||
|
||||
context.set_line_width(doughnut_width)
|
||||
|
||||
# Draw the arc parts
|
||||
for i, percentage in enumerate(list_of_percentages):
|
||||
print(i)
|
||||
context.set_source_rgb(color_list[i][0], color_list[i][1], color_list[i][2])
|
||||
|
||||
if total_percentage != 0:
|
||||
angle1 = 360 / (100 / total_percentage) * (math.pi/180)
|
||||
else:
|
||||
angle1 = 0
|
||||
|
||||
angle2 = 360 / (100 / (total_percentage + percentage)) * (math.pi/180)
|
||||
|
||||
context.arc(xc, yc, radius, angle1, angle2)
|
||||
total_percentage += percentage
|
||||
context.stroke()
|
||||
|
||||
# Draw the times labels
|
||||
context.set_source_rgb(0.5, 0.5, 0.5)
|
||||
# context.set_font_size(18)
|
||||
|
||||
# context.move_to(xc - 20, 20)
|
||||
# context.show_text("00")
|
||||
|
||||
# context.move_to(360, yc)
|
||||
# context.show_text("06")
|
||||
|
||||
# context.move_to(xc - 20, image_height)
|
||||
# context.show_text("12")
|
||||
|
||||
# context.move_to(10, yc)
|
||||
# context.show_text("18")
|
||||
# context.stroke()
|
||||
|
||||
# Draw the hour strokes
|
||||
context.set_line_width(2)
|
||||
lines_list = [
|
||||
[[xc, yc - radius + doughnut_width / 2 - 5], [xc, yc - radius + doughnut_width / 2 + 5]],
|
||||
[[xc + radius - doughnut_width / 2 - 5, yc], [xc + radius - doughnut_width / 2 + 5, yc]],
|
||||
[[xc, yc + radius - doughnut_width / 2 - 5], [xc, yc + radius - doughnut_width / 2 + 5]],
|
||||
[[xc - radius + doughnut_width / 2 - 5, yc], [xc - radius + doughnut_width / 2 + 5, yc]],
|
||||
]
|
||||
|
||||
for line in lines_list:
|
||||
context.move_to(line[0][0], line[0][1])
|
||||
context.line_to(line[1][0], line[1][1])
|
||||
context.stroke()
|
||||
|
||||
|
||||
|
||||
def show(self):
|
||||
window = self.builder.get_object("window_main")
|
||||
window.show_all()
|
||||
|
||||
Gtk.main()
|
||||
|
||||
|
||||
def onDestroy(self, *args):
|
||||
Gtk.main_quit()
|
||||
|
||||
if __name__ == "__main__":
|
||||
Preferences().show()
|
||||
@@ -1,373 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.40.0 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.24"/>
|
||||
<object class="GtkWindow" id="window_main">
|
||||
<property name="can-focus">False</property>
|
||||
<property name="window-position">center</property>
|
||||
<property name="default-width">1024</property>
|
||||
<property name="default-height">768</property>
|
||||
<property name="gravity">center</property>
|
||||
<signal name="destroy" handler="onDestroy" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkStack" id="stack_main">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="transition-type">crossfade</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="gtkbox_imageset">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="margin-start">48</property>
|
||||
<property name="margin-end">48</property>
|
||||
<property name="margin-top">8</property>
|
||||
<property name="margin-bottom">8</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">8</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">Behaviour</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkListBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<property name="activate-on-single-click">False</property>
|
||||
<child>
|
||||
<object class="GtkListBoxRow">
|
||||
<property name="height-request">36</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="margin-start">12</property>
|
||||
<property name="margin-end">12</property>
|
||||
<property name="margin-top">12</property>
|
||||
<property name="margin-bottom">12</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Expand image over all displays</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSwitch">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">3</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">Image Source</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkListBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<property name="activate-on-single-click">False</property>
|
||||
<child>
|
||||
<object class="GtkListBoxRow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">Image Selection</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkListBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<property name="activate-on-single-click">False</property>
|
||||
<child>
|
||||
<object class="GtkListBoxRow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<child>
|
||||
<!-- n-columns=4 n-rows=4 -->
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image">
|
||||
<property name="width-request">350</property>
|
||||
<property name="height-request">350</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="stock">gtk-missing-image</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">1</property>
|
||||
<property name="width">2</property>
|
||||
<property name="height">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="pixbuf">../../../Desktop/lakeside/8.jpg</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="pixbuf">../../../Desktop/lakeside/9.jpg</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">0</property>
|
||||
<property name="width">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="pixbuf">../../../Desktop/lakeside/1.jpg</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">3</property>
|
||||
<property name="top-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="pixbuf">../../../Desktop/lakeside/2.jpg</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">3</property>
|
||||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="pixbuf">../../../Desktop/lakeside/3.jpg</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">3</property>
|
||||
<property name="top-attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="pixbuf">../../../Desktop/lakeside/7.jpg</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="pixbuf">../../../Desktop/lakeside/6.jpg</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="pixbuf">../../../Desktop/lakeside/5.jpg</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">3</property>
|
||||
<property name="width">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="pixbuf">../../../Desktop/lakeside/4.jpg</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">2</property>
|
||||
<property name="top-attach">3</property>
|
||||
<property name="width">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">image_config</property>
|
||||
<property name="title" translatable="yes">Image Configuration</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="gtkbox_location_time">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">location_times</property>
|
||||
<property name="title" translatable="yes">Location & Times</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="gtkbox_about">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">about</property>
|
||||
<property name="title" translatable="yes">About</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="spacing">0</property>
|
||||
<property name="show-close-button">True</property>
|
||||
<child type="title">
|
||||
<object class="GtkStackSwitcher">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="stack">stack_main</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label">gtk-apply</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<property name="use-stock">True</property>
|
||||
<property name="always-show-image">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
Reference in New Issue
Block a user