Cornea/src/new-src/core/widgets/delay_amount.py

62 lines
1.4 KiB
Python
Raw Normal View History

2023-04-17 03:01:16 +00:00
# Python imports
2023-04-17 04:57:12 +00:00
import time
2023-04-17 03:01:16 +00:00
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class DelayAmount(Gtk.Box):
def __init__(self):
super(DelayAmount, self).__init__()
self._setup_styling()
self._setup_signals()
2023-04-17 04:57:12 +00:00
self._subscribe_to_events()
2023-04-17 03:01:16 +00:00
self._load_widgets()
self.show_all()
def _setup_styling(self):
self.set_orientation(Gtk.Orientation.HORIZONTAL)
self.set_margin_top(5)
self.set_margin_bottom(5)
def _setup_signals(self):
...
2023-04-17 04:57:12 +00:00
def _subscribe_to_events(self):
2023-04-22 15:55:06 +00:00
event_system.subscribe("set_grab_delay", self.set_grab_delay)
2023-04-17 04:57:12 +00:00
event_system.subscribe("grab_delay", self.grab_delay)
2023-04-17 03:01:16 +00:00
def _load_widgets(self):
label = Gtk.Label("Timeout: ")
spinner = Gtk.SpinButton()
spinner.set_hexpand(True)
spinner.set_numeric(True)
spinner.set_snap_to_ticks(True)
spinner.set_digits(0)
2023-04-17 04:57:12 +00:00
spinner.set_range(0, 120)
2023-04-17 03:01:16 +00:00
spinner.set_increments(1, 5)
self.add(label)
self.add(spinner)
2023-04-17 04:57:12 +00:00
2023-04-22 15:55:06 +00:00
def set_grab_delay(self, wait = 0.0):
delay_amount = self.get_children()[1]
delay_amount.set_value(wait)
2023-04-17 04:57:12 +00:00
def grab_delay(self, wait = None):
delay_amount = self.get_children()[1]
if not wait:
wait = delay_amount.get_value_as_int()
time.sleep(wait)