Start preferences redesign
This commit is contained in:
131
cinnamon-dynamic-wallpaper@TobiZog/preferences.py
Normal file
131
cinnamon-dynamic-wallpaper@TobiZog/preferences.py
Normal file
@@ -0,0 +1,131 @@
|
||||
#!/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()
|
||||
373
cinnamon-dynamic-wallpaper@TobiZog/prefs.glade
Normal file
373
cinnamon-dynamic-wallpaper@TobiZog/prefs.glade
Normal file
@@ -0,0 +1,373 @@
|
||||
<?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