Files
eculocate/client/eculocate-gtk
2026-03-06 19:47:00 +00:00

99 lines
2.9 KiB
Python

#!/usr/bin/env python
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib
import sys
import os
import eculocate
class MyWindow(Gtk.Window):
def widgets(self):
main = Gtk.VBox()
main.add(Gtk.Label(label = "Services"))
self.hosts_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
main.add(self.hosts_box)
self.status = Gtk.Label(label = "initializing")
main.add(self.status)
start = Gtk.ToggleButton(label="Start")
main.add(start)
self.start_button = start
self.add(main)
def update_host(self, name):
if name in self.host_buttons:
print(f"already seen {name}")
else:
group = self.hosts_box.get_children()
print(f"group {group}")
if group:
n = Gtk.RadioButton.new_with_label_from_widget(group[0], name)
else:
n = Gtk.RadioButton.new_with_label(None, name)
n.set_mode(False)
n.connect("clicked", self.choose_service, name)
print(f"service {n}")
self.host_buttons[name] = n
self.hosts_box.add(n)
self.hosts_box.show_all()
def choose_service(self, e, name):
print(f"clikec {name}")
self.selected_service_name = name
def __init__(self):
super().__init__(title="Eculocate")
self.host_buttons = {}
self.widgets()
self.selected_service_name = None
self.update_host("othher.host.local")
class GtkClient(eculocate.Client):
def __init__(self, signing_key, window):
super().__init__(signing_key)
print("hre")
self.window = window
window.start_button.connect("clicked", self.on_start_button_clicked)
def on_start_button_clicked(self, widget):
print("Hello World")
if self.window.selected_service_name:
self.select_service_name(self.window.selected_service_name)
print(f"toggle record for {self.selected_service_name}")
if self.started:
self.stop_recording()
widget.set_label("start")
else:
self.start_recording()
widget.set_label("stop")
def on_services_changed(self):
for name, service in self.host_addresses.items():
print(f"updating {name}")
self.window.update_host(name)
if __name__ == '__main__':
conf_file = os.getenv("ECULOCATE_CONFIG") or "/etc/eculocate.conf"
config = eculocate.Config(conf_file)
win = MyWindow()
client = GtkClient(config, win)
win.connect("destroy", Gtk.main_quit)
win.show_all()
def update_byte_counter():
label = f"recorded {client.bytes_recorded} bytes" if client.started else "not recording"
if win.status:
win.status.set_text(label)
return True
GLib.timeout_add_seconds(1, update_byte_counter)
Gtk.main()