New source selection buttons

This commit is contained in:
2023-12-16 05:00:11 +01:00
parent edc1e62ff3
commit d88a21c6f0
3 changed files with 435 additions and 143 deletions

View File

@@ -18,7 +18,7 @@
<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="default-height">600</property>
<property name="gravity">center</property>
<signal name="destroy" handler="onDestroy" swapped="no"/>
<child>
@@ -145,17 +145,22 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="spacing">8</property>
<property name="layout-style">start</property>
<property name="homogeneous">True</property>
<property name="layout-style">expand</property>
<child>
<object class="GtkToggleButton">
<object class="GtkToggleButton" id="tb_image">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="toggled" handler="onToggleButtonImageClicked" swapped="no"/>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">8</property>
<property name="margin-end">8</property>
<property name="margin-top">8</property>
<property name="margin-bottom">8</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage">
@@ -192,14 +197,19 @@
</packing>
</child>
<child>
<object class="GtkToggleButton">
<object class="GtkToggleButton" id="tb_heic">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="toggled" handler="onToggleButtonHeicClicked" swapped="no"/>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">8</property>
<property name="margin-end">8</property>
<property name="margin-top">8</property>
<property name="margin-bottom">8</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage">
@@ -236,14 +246,19 @@
</packing>
</child>
<child>
<object class="GtkToggleButton">
<object class="GtkToggleButton" id="tb_folder">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="toggled" handler="onToggleButtonFolderClicked" swapped="no"/>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">8</property>
<property name="margin-end">8</property>
<property name="margin-top">8</property>
<property name="margin-bottom">8</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage">
@@ -284,7 +299,8 @@
</object>
</child>
<child>
<object class="GtkListBoxRow" id="lbr_set">
<object class="GtkListBoxRow" id="lbr_image">
<property name="height-request">64</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<child>
@@ -327,6 +343,7 @@
</child>
<child>
<object class="GtkListBoxRow" id="lbr_heic">
<property name="height-request">64</property>
<property name="can-focus">True</property>
<child>
<object class="GtkBox">
@@ -370,6 +387,7 @@
</child>
<child>
<object class="GtkListBoxRow" id="lbr_folder">
<property name="height-request">64</property>
<property name="can-focus">True</property>
<child>
<object class="GtkBox">
@@ -450,76 +468,11 @@
<property name="can-focus">False</property>
<property name="row-spacing">8</property>
<property name="column-spacing">8</property>
<child>
<object class="GtkImage">
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">image-x-generic</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkImage">
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">image-x-generic</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkImage">
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">image-x-generic</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkImage">
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">image-x-generic</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="left-attach">3</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkImage">
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">image-x-generic</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="left-attach">4</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">label</property>
<property name="label" translatable="yes">00:00 - 07:35</property>
</object>
<packing>
<property name="left-attach">0</property>
@@ -530,7 +483,7 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">label</property>
<property name="label" translatable="yes">08:15 - 08:43</property>
</object>
<packing>
<property name="left-attach">1</property>
@@ -541,7 +494,7 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">label</property>
<property name="label" translatable="yes">11:13 - 13:12</property>
</object>
<packing>
<property name="left-attach">2</property>
@@ -552,7 +505,7 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">label</property>
<property name="label" translatable="yes">14:42 - 15:41</property>
</object>
<packing>
<property name="left-attach">3</property>
@@ -563,7 +516,7 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">label</property>
<property name="label" translatable="yes">16:13 - 16:52</property>
</object>
<packing>
<property name="left-attach">4</property>
@@ -571,19 +524,119 @@
</packing>
</child>
<child>
<placeholder/>
<object class="GtkImage">
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixbuf">../../../../../Desktop/cdw-concept/image-set/9.jpg</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<placeholder/>
<object class="GtkImage">
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixbuf">../../../../../Desktop/cdw-concept/image-set/2.jpg</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<placeholder/>
<object class="GtkImage">
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixbuf">../../../../../Desktop/cdw-concept/image-set/4.jpg</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<placeholder/>
<object class="GtkImage">
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixbuf">../../../../../Desktop/cdw-concept/image-set/6.jpg</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="left-attach">3</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<placeholder/>
<object class="GtkImage">
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixbuf">../../../../../Desktop/cdw-concept/image-set/8.jpg</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="left-attach">4</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkComboBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkComboBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkComboBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkComboBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">3</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkComboBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">4</property>
<property name="top-attach">1</property>
</packing>
</child>
</object>
<packing>
@@ -605,23 +658,23 @@
</packing>
</child>
<child>
<object class="GtkBox">
<!-- n-columns=5 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="spacing">8</property>
<property name="row-spacing">8</property>
<property name="column-spacing">8</property>
<child>
<object class="GtkImage">
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">image-x-generic</property>
<property name="pixbuf">../../../../../Desktop/cdw-concept/image-set/1.jpg</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
@@ -629,13 +682,12 @@
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">image-x-generic</property>
<property name="pixbuf">../../../../../Desktop/cdw-concept/image-set/9.jpg</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="left-attach">4</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
@@ -643,13 +695,12 @@
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">image-x-generic</property>
<property name="pixbuf">../../../../../Desktop/cdw-concept/image-set/7.jpg</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="left-attach">3</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
@@ -657,13 +708,130 @@
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">image-x-generic</property>
<property name="pixbuf">../../../../../Desktop/cdw-concept/image-set/5.jpg</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
<property name="left-attach">2</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkImage">
<property name="width-request">200</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixbuf">../../../../../Desktop/cdw-concept/image-set/3.jpg</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">07:35 - 08:14</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">08:44 - 11:12</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">13:13 - 14:41</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">15:41 - 16:12</property>
</object>
<packing>
<property name="left-attach">3</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">16:53 - 23:59</property>
</object>
<packing>
<property name="left-attach">4</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkComboBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkComboBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkComboBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">3</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkComboBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkComboBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">4</property>
<property name="top-attach">2</property>
</packing>
</child>
</object>
@@ -673,9 +841,6 @@
<property name="position">2</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>

View File

@@ -2,7 +2,7 @@
# Imports
import gi, os
from time_bar import create_bar
from time_bar import create_bar_chart
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GdkPixbuf
@@ -15,16 +15,30 @@ GLADE_URI = os.path.dirname(os.path.abspath(__file__)) + "/preferences.glade"
class Preferences:
""" Preference window class
"""
#################### Lifecycle ####################
def __init__(self) -> None:
self.builder = Gtk.Builder()
self.builder.add_from_file(GLADE_URI)
self.builder.connect_signals(self)
# UI objects
self.buttonImageSet = self.builder.get_object("tb_image")
self.buttonHeicFile = self.builder.get_object("tb_heic")
self.buttonSourceFolder = self.builder.get_object("tb_folder")
self.listBoxRowImageSet = self.builder.get_object("lbr_image")
self.listBoxRowHeicFile = self.builder.get_object("lbr_heic")
self.listBoxRowSourceFolder = self.builder.get_object("lbr_folder")
self.imgBar = self.builder.get_object("img_bar")
# Time bar
# todo: Sample times
create_bar(1036, 200, [0, 455, 494, 523, 673, 792, 882, 941, 973, 1013, 1440])
create_bar_chart(1036, 150, [0, 455, 494, 523, 673, 792, 882, 941, 973, 1013])
pixbuf = GdkPixbuf.Pixbuf.new_from_file("time_bar.svg")
self.builder.get_object("img_bar").set_from_pixbuf(pixbuf)
self.imgBar.set_from_pixbuf(pixbuf)
def show(self):
@@ -33,8 +47,7 @@ class Preferences:
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)
self.buttonImageSet.set_active(True)
Gtk.main()
@@ -45,5 +58,36 @@ class Preferences:
Gtk.main_quit()
#################### Callbacks ####################
def onToggleButtonImageClicked(self, button):
if button.get_active():
self.buttonHeicFile.set_active(False)
self.buttonSourceFolder.set_active(False)
self.listBoxRowImageSet.set_visible(True)
self.listBoxRowHeicFile.set_visible(False)
self.listBoxRowSourceFolder.set_visible(False)
def onToggleButtonHeicClicked(self, button):
if button.get_active():
self.buttonImageSet.set_active(False)
self.buttonSourceFolder.set_active(False)
self.listBoxRowImageSet.set_visible(False)
self.listBoxRowHeicFile.set_visible(True)
self.listBoxRowSourceFolder.set_visible(False)
def onToggleButtonFolderClicked(self, button):
if button.get_active():
self.buttonImageSet.set_active(False)
self.buttonHeicFile.set_active(False)
self.listBoxRowImageSet.set_visible(False)
self.listBoxRowHeicFile.set_visible(False)
self.listBoxRowSourceFolder.set_visible(True)
if __name__ == "__main__":
Preferences().show()

View File

@@ -1,45 +1,128 @@
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"]
image_code = []
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))
colors = [
"00193dff",
"05597fff",
"54babfff",
"bfe3c2ff",
"ffbf6bff",
"fdb55cff",
"f37f73ff",
"7f3d85ff",
"4a217aff",
"00193dff"
]
bar_part_mid = start_point + width / 2
bar_pos_x = []
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)
)
def create_bar_chart(image_width, image_height, times):
create_bar(image_width, image_height, times)
create_polylines(image_width, image_height)
create_time_markers(image_width, image_height)
# Write to file
image_code.insert(0, '<svg xmlns="http://www.w3.org/2000/svg" width="%s" height="%s">' % (image_width, image_height))
image_code.append('</svg>')
file = open("time_bar.svg", "w")
for i in image_code:
file.write(i + '\n')
file.write('</svg>')
def create_bar(image_width: int, image_height: int, times: list):
""" Generates the code for the horizontal multi-color bar chart
Args:
image_width (int): Total width of the image
image_height (int): Total height of the image
times (list): List of start times of the periods, in minutes
"""
x = 0
y = 40
width = 0
height = image_height - 80
times.append(1440)
# Adding the bar parts
for i in range(1, len(times)):
width = math.ceil((((100 / 1440) * (times[i] - times[i - 1]) / 100) * image_width))
image_code.append(
'<rect fill="#%s" x="%s" y="%s" width="%s" height="%s"/>' % (colors[i - 1], x, y, width, height)
)
bar_pos_x.append(x)
x += width
def create_time_markers(image_width: int, image_height: int):
""" Generates the code for the vertical hour markers
Args:
image_width (int): Total width of the image
image_height (int): Total height of the image
"""
for i in range(0, 8):
image_code.append(
'<line x1="%s" y1="40" x2="%s" y2="%s" stroke="gray" stroke-width="2" />' %
(i * (image_width // 8), i * (image_width // 8), image_height - 40)
)
image_code.append(
'<text x="%s" y="%s" fill="gray" font-size="20" font-family="Liberation Sans">%s</text>' %
(i * (image_width // 8) + 5, image_height - 45, i * 3)
)
def create_polylines(image_width: int, image_height: int):
""" Generates the code for the polylines which connect the images with the bar sections
Args:
image_width (int): Total width of the image
image_height (int): Total height of the image
"""
bar_x_start = 0
bar_pos_x.append(image_width)
for i in range(0, len(bar_pos_x) - 1):
# X-Middle of a bar
bar_mid = bar_x_start + (bar_pos_x[i + 1] - bar_x_start) / 2
# Position of the image in the window
image_x = (image_width - 32) / 10 + ((i // 2) % 5) * image_width / 5
# i == 0, 2, 4, ... => Upper Polylines
if (i % 2 == 0):
polyline_y = 0
else:
polyline_y = image_height
if i == 0 or i == 8:
polyline_x = 30
elif i == 2 or i == 6:
polyline_x = 20
elif i == 1 or i == 9:
polyline_x = image_height - 30
elif i == 3 or i == 7:
polyline_x = image_height - 20
elif i == 5:
polyline_x = image_height - 10
else:
polyline_x = 10
image_code.append(
'<polyline points="%s,%s %s,%s %s,%s %s,%s" stroke="#%s" fill="none" stroke-width="5" />' %
(image_x, polyline_y, image_x, polyline_x, bar_mid, polyline_x, bar_mid, image_height / 2, colors[i])
)
# Store the end point of the bar as start point of the next
bar_x_start = bar_pos_x[i + 1]
# Hannover
#create_bar_chart(1036, 180, [0, 455, 494, 523, 673, 792, 882, 941, 973, 1013])
# Other Test bar
#create_bar_chart(1036, 180, [0, 180, 190, 523, 673, 792, 882, 941, 973, 1300])