Files
bbbbbs/main.py
2022-12-01 13:13:14 +01:00

162 lines
6.3 KiB
Python
Executable File

#!/usr/bin/python3
import gi
import config
from datetime import datetime
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class MainWindow(Gtk.Window):
def __init__(self):
super().__init__(title="bardzo biedny BBS %s"%config.version)
############################## Boxes #####################################
pad=15
self.main_box = Gtk.Box()
self.main_box.set_orientation(Gtk.Orientation.HORIZONTAL)
# left side
self.left_box = Gtk.Box()
self.left_box.set_orientation(Gtk.Orientation.VERTICAL)
self.left_box.set_spacing(0)
self.left_button_box = Gtk.Box()
self.left_button_box.set_orientation(Gtk.Orientation.HORIZONTAL)
self.left_button_box.set_spacing(pad)
# right side
self.right_box = Gtk.Box()
self.right_box.set_orientation(Gtk.Orientation.VERTICAL)
self.right_box.set_spacing(0)
self.title_author_box = Gtk.Box()
self.title_author_box.set_orientation(Gtk.Orientation.HORIZONTAL)
self.title_author_box.set_spacing(pad)
self.message_box = Gtk.Box()
self.message_box.set_orientation(Gtk.Orientation.VERTICAL)
self.message_box.set_spacing(2)
self.date_time_box = Gtk.Box()
self.date_time_box.set_orientation(Gtk.Orientation.HORIZONTAL)
self.date_time_box.set_spacing(pad)
self.synthesize_listen_box = Gtk.Box()
self.synthesize_listen_box.set_orientation(Gtk.Orientation.HORIZONTAL)
self.synthesize_listen_box.set_spacing(pad)
self.clear_save_box = Gtk.Box()
self.clear_save_box.set_orientation(Gtk.Orientation.HORIZONTAL)
self.clear_save_box.set_spacing(pad)
################################ Widgets ######################################
# left side
self.transmission_list = Gtk.ListBox()
self.transmission_list.connect("row-activated", self.on_picked_transmission)
for count in range(5):
label = Gtk.Label()
label.set_text("row %i" % (count))
self.transmission_list.add(label)
self.add_transmission_button = Gtk.Button(label="Add transmission")
self.add_transmission_button.connect("clicked", self.on_add_transmission)
self.delete_transmission_button = Gtk.Button(label="Delete transmission")
self.delete_transmission_button.connect("clicked", self.on_delete_transmission)
# right side
self.title = Gtk.Entry()
self.title.set_placeholder_text("Title")
self.author = Gtk.Entry()
self.author.set_placeholder_text("Author")
self.message_label = Gtk.Label(label="Message")
self.message = Gtk.TextView()
self.calendar = Gtk.Calendar()
self.calendar.connect("day-selected", self.on_date_picked)
self.timeslots = Gtk.ListBox()
for slot in ["09:00", "15:00", "21:00"]:
row = Gtk.ListBoxRow()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
row.add(hbox)
time_label = Gtk.Label(label=slot, xalign=0)
hbox.pack_start(time_label, True, True, 0)
hbox.pack_start(Gtk.CheckButton(), False, True, 0)
self.timeslots.add(row)
self.synthesize_button = Gtk.Button(label="synthesize")
self.listen_button = Gtk.Button(label="listen")
self.clear_button = Gtk.Button(label="clear")
self.save_button = Gtk.Button(label="save")
self.save_button.connect("clicked", self.on_transmission_saved)
# we need to put the buttons in a sizegroup to make the synthesize button the same length as the rest
self.right_sizegroup = Gtk.SizeGroup(mode=Gtk.SizeGroupMode.HORIZONTAL)
self.right_sizegroup.add_widget(self.synthesize_button)
self.right_sizegroup.add_widget(self.listen_button)
self.right_sizegroup.add_widget(self.clear_button)
self.right_sizegroup.add_widget(self.save_button)
######################### organise objects ###################################
self.add(self.main_box)
self.main_box.pack_start(self.left_box, True, True, pad)
self.main_box.pack_start(self.right_box, True, True, pad)
self.left_box.pack_start(self.transmission_list, True, True, pad)
self.left_box.pack_start(self.left_button_box, False, True, pad)
self.left_button_box.pack_start(self.add_transmission_button, True, True, 0)
self.left_button_box.pack_start(self.delete_transmission_button, True, True, 0)
self.right_box.pack_start(self.title_author_box, False, True, pad)
self.title_author_box.pack_start(self.title, True, True, 0)
self.title_author_box.pack_start(self.author, True, True, 0)
self.right_box.pack_start(self.message_box, True, True, pad)
self.message_box.pack_start(self.message_label, False, True, 0)
self.message_box.pack_start(self.message, True, True, 0)
self.right_box.pack_start(self.date_time_box, True, True, pad)
self.date_time_box.pack_start(self.calendar, True, True, 0)
self.date_time_box.pack_start(self.timeslots, True, True, 0)
self.right_box.pack_start(self.synthesize_listen_box, False, True, 0)
self.synthesize_listen_box.pack_start(self.synthesize_button, True, True, 0)
self.synthesize_listen_box.pack_start(self.listen_button, True, True, 0)
self.right_box.pack_start(self.clear_save_box, False, True, pad)
self.clear_save_box.pack_start(self.clear_button, True, True, 0)
self.clear_save_box.pack_start(self.save_button, True, True, 0)
def on_picked_transmission(self, row, user_data):
print("row %i activated" % user_data.get_index())
def on_add_transmission(self, user_data):
print("new transmission %s"%(datetime.now().isoformat()))
def on_delete_transmission(self, user_data):
print("transmission %s deleted" % self.transmission_list.get_selected_row().get_index())
def on_date_picked(self, user_data):
year, month, day = self.calendar.get_date()
month +=1
print("Date selected: %i/%i/%i" %(year,month,day))
def on_transmission_saved(self, user_data):
print("title: %s" % self.title.get_buffer().get_text())
win = MainWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()