Callbacks for temp buttons
parent
b4b0db1be6
commit
93b7588978
|
@ -94,3 +94,8 @@ ENV/
|
|||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
bin/
|
||||
include/
|
||||
lib64
|
||||
pyvenv.cfg
|
||||
*.glade~
|
||||
|
|
|
@ -129,12 +129,13 @@
|
|||
<property name="orientation">vertical</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<object class="GtkButton" id="temp_up_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="always_show_image">True</property>
|
||||
<signal name="clicked" handler="on_temp_adjust" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
|
@ -165,12 +166,13 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<object class="GtkButton" id="temp_down_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="always_show_image">True</property>
|
||||
<signal name="clicked" handler="on_temp_adjust" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
|
@ -296,6 +298,8 @@
|
|||
<property name="name">sched_enable</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="active">True</property>
|
||||
<signal name="state-set" handler="on_manual_switch" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
|
|
|
@ -1,37 +1,67 @@
|
|||
import threading
|
||||
import gi
|
||||
import random
|
||||
from time import sleep
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk, Gdk, Gio
|
||||
from gi.repository import Gtk, Gdk, Gio, GLib
|
||||
|
||||
from thermoberry import graphs
|
||||
from thermoberry import graphs #, sensor
|
||||
|
||||
class Handler:
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
builder = self.app.builder
|
||||
self.toggle_manual_switch = builder.get_object('sched_enable_switch')
|
||||
|
||||
self.temp_up_button = builder.get_object('temp_up_button')
|
||||
self.temp_up_button.op = 'up'
|
||||
|
||||
self.temp_dn_button = builder.get_object('temp_down_button')
|
||||
self.temp_dn_button.op = 'dn'
|
||||
|
||||
def onDestroy(self, *args):
|
||||
Gtk.main_quit()
|
||||
|
||||
#def onButtonPressed(self, button):
|
||||
#print("Hello World!")
|
||||
|
||||
def on_temp_adjust(self, button):
|
||||
print(f'Adjust temp {button.op}')
|
||||
if button.op == 'up':
|
||||
self.app.manual_temp_increase()
|
||||
elif button.op == 'dn':
|
||||
self.app.manual_temp_decrease()
|
||||
|
||||
|
||||
def on_manual_switch(self, switch, on):
|
||||
buttons_enabled = False
|
||||
if on:
|
||||
buttons_enabled = True
|
||||
|
||||
self.temp_up_button.set_sensitive(buttons_enabled)
|
||||
self.temp_dn_button.set_sensitive(buttons_enabled)
|
||||
|
||||
class ListBoxRowWithData(Gtk.ListBoxRow):
|
||||
def __init__(self, data):
|
||||
super(Gtk.ListBoxRow, self).__init__()
|
||||
self.data = data
|
||||
self.add(Gtk.Label(data))
|
||||
|
||||
class AppWindow(Gtk.ApplicationWindow):
|
||||
def __init__(self):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
class Interface(Gtk.Application):
|
||||
def __init__(self):
|
||||
Gtk.Application.__init__(self,
|
||||
application_id="org.bhartshorn.thermoberry",
|
||||
flags=Gio.ApplicationFlags.FLAGS_NONE)
|
||||
self.window = None
|
||||
self.manual_temp = 0
|
||||
self.max_temp = 100
|
||||
self.min_temp = 30
|
||||
|
||||
def do_startup(self):
|
||||
Gtk.Application.do_startup(self)
|
||||
self.builder = Gtk.Builder()
|
||||
self.builder.add_from_file("static/main.glade")
|
||||
self.builder.connect_signals(Handler())
|
||||
self.builder.connect_signals(Handler(self))
|
||||
|
||||
self.window = self.builder.get_object("main_window")
|
||||
|
||||
|
@ -43,6 +73,14 @@ class Interface(Gtk.Application):
|
|||
self.context = self.window.get_style_context()
|
||||
self.context.add_provider_for_screen(self.screen, self.bg_style_css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
||||
|
||||
|
||||
self.rh_label = self.builder.get_object('humidity_label')
|
||||
self.temp_label = self.builder.get_object('temp_label')
|
||||
|
||||
thread = threading.Thread(target=self.query_sensor)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
||||
plot = graphs.HistoryPlot()
|
||||
canvas = plot.get_canvas()
|
||||
|
||||
|
@ -60,9 +98,31 @@ class Interface(Gtk.Application):
|
|||
self.add_window(self.window)
|
||||
self.window.show_all()
|
||||
|
||||
def update_numbers(self, temp, rh):
|
||||
self.rh_label.set_text(str(rh) + '%')
|
||||
self.temp_label.set_text(str(temp) + '°')
|
||||
|
||||
def manual_temp_increase(self):
|
||||
if self.manual_temp < self.max_temp:
|
||||
self.manual_temp += 1
|
||||
print(f'New temp: {self.manual_temp}')
|
||||
|
||||
def manual_temp_decrease(self):
|
||||
if self.manual_temp > self.min_temp:
|
||||
self.manual_temp -= 1
|
||||
print(f'New temp: {self.manual_temp}')
|
||||
|
||||
def query_sensor(self):
|
||||
while True:
|
||||
sleep(2)
|
||||
GLib.idle_add(self.update_numbers, random.randint(50,200), random.randint(20,40))
|
||||
|
||||
def on_css_error(self, provider, section, error):
|
||||
print(error)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#def run(self):
|
||||
#Gtk.main()
|
||||
|
|
Loading…
Reference in New Issue