Initial wiring of Commands widget logic
This commit is contained in:
parent
d073282c66
commit
82fc45373d
|
@ -37,14 +37,26 @@ class List_Box(Gtk.ScrolledWindow):
|
|||
super(List_Box, self).__init__()
|
||||
|
||||
self.setup_styling()
|
||||
tree, store = self.create_treeview()
|
||||
self.add_custom_signals()
|
||||
self.add_widgets()
|
||||
self._starting()
|
||||
|
||||
self.add(tree)
|
||||
self.set_size_request(360, 240)
|
||||
|
||||
def setup_styling(self):
|
||||
self.set_vexpand(True)
|
||||
|
||||
def add_custom_signals(self):
|
||||
event_system.subscribe("shutting-down", self._shutting_down)
|
||||
event_system.subscribe("run_command", self.run_command)
|
||||
event_system.subscribe("add_command", self.add_command)
|
||||
event_system.subscribe("del_command", self.del_command)
|
||||
|
||||
def add_widgets(self):
|
||||
tree, self.store = self.create_treeview()
|
||||
|
||||
self.add(tree)
|
||||
self.set_size_request(360, 240)
|
||||
|
||||
def create_treeview(self):
|
||||
tree = Gtk.TreeView()
|
||||
store = Gtk.ListStore(str)
|
||||
|
@ -53,7 +65,7 @@ class List_Box(Gtk.ScrolledWindow):
|
|||
selec = tree.get_selection()
|
||||
|
||||
tree.set_model(store)
|
||||
selec.set_mode(2)
|
||||
selec.set_mode(Gtk.SelectionMode.MULTIPLE)
|
||||
|
||||
column.pack_start(name, True)
|
||||
column.add_attribute(name, "text", 0)
|
||||
|
@ -64,9 +76,112 @@ class List_Box(Gtk.ScrolledWindow):
|
|||
tree.set_headers_visible(True)
|
||||
tree.set_enable_tree_lines(False)
|
||||
|
||||
tree.set_can_focus(False)
|
||||
tree.columns_autosize()
|
||||
|
||||
tree.connect("row-activated", self._row_activated)
|
||||
|
||||
return tree, store
|
||||
|
||||
def _starting(self):
|
||||
file = f"{CONFIG_PATH}/commands_file.text"
|
||||
|
||||
import os
|
||||
if not os.path.exists(file): return
|
||||
|
||||
commands = []
|
||||
with open(file, "r") as f:
|
||||
commands = f.readlines()
|
||||
|
||||
for command in commands:
|
||||
self.store.append([command.strip()])
|
||||
|
||||
def _shutting_down(self):
|
||||
commands = ""
|
||||
itr = self.store.get_iter_first()
|
||||
|
||||
while itr:
|
||||
commands += f"{self.store.get_value(itr, 0)}\n"
|
||||
itr = self.store.iter_next(itr)
|
||||
|
||||
with open(f"{CONFIG_PATH}/commands_file.text", "w+") as f:
|
||||
f.write( commands.strip() )
|
||||
|
||||
def _row_activated(self, tree_view, path, column):
|
||||
itr = self.store.get_iter(path)
|
||||
command = self.store.get_value(itr, 0)
|
||||
typwriter.type(command)
|
||||
|
||||
def run_command(self):
|
||||
...
|
||||
|
||||
def add_command(self, command):
|
||||
self.store.append([command])
|
||||
|
||||
def del_command(self):
|
||||
...
|
||||
|
||||
|
||||
class CommandEntry(Gtk.Box):
|
||||
"""docstring for CommandEntry."""
|
||||
|
||||
def __init__(self):
|
||||
super(CommandEntry, self).__init__()
|
||||
|
||||
self.setup_styling()
|
||||
self.add_widgets()
|
||||
|
||||
|
||||
def setup_styling(self):
|
||||
self.set_orientation(Gtk.Orientation.HORIZONTAL)
|
||||
self.set_hexpand(True)
|
||||
self.set_margin_top(5)
|
||||
self.set_margin_bottom(10)
|
||||
|
||||
def add_widgets(self):
|
||||
entry = Gtk.Entry()
|
||||
add_btn = Gtk.Button(label = "+")
|
||||
del_btn = Gtk.Button(label = "-")
|
||||
run_btn = Gtk.Button(label = "RUN >")
|
||||
|
||||
add_btn.set_always_show_image(True)
|
||||
del_btn.set_always_show_image(True)
|
||||
|
||||
entry.set_hexpand(True)
|
||||
entry.set_placeholder_text("Command...")
|
||||
entry.set_tooltip_text("Command...")
|
||||
|
||||
entry.connect("enter-notify-event", self.focus_entry)
|
||||
entry.connect("leave-notify-event", self.unfocus_entry)
|
||||
|
||||
add_btn.connect("clicked", self.add_command)
|
||||
del_btn.connect("clicked", self.del_command)
|
||||
run_btn.connect("clicked", self.run_command)
|
||||
|
||||
for widget in [run_btn, entry, add_btn, del_btn]:
|
||||
self.add(widget)
|
||||
|
||||
def focus_entry(self, widget, eve = None):
|
||||
event_system.emit("set_focusable")
|
||||
widget = self.get_children()[1]
|
||||
widget.grab_focus()
|
||||
|
||||
def unfocus_entry(self, widget, eve = None):
|
||||
widget = self.get_children()[1]
|
||||
widget.grab_remove()
|
||||
event_system.emit("unset_focusable")
|
||||
|
||||
def run_command(self, button):
|
||||
event_system.emit("run_command")
|
||||
|
||||
def add_command(self, button):
|
||||
command = self.get_children()[1].get_text().strip()
|
||||
if command:
|
||||
event_system.emit("add_command", command)
|
||||
|
||||
def del_command(self, button):
|
||||
event_system.emit("del_command")
|
||||
|
||||
|
||||
class Grid_Box(Gtk.Grid):
|
||||
"""docstring for Grid_Box."""
|
||||
|
@ -89,6 +204,7 @@ class Grid_Box(Gtk.Grid):
|
|||
self.attach(Left_Key(), 0, 1, 1, 1)
|
||||
self.attach(Right_Key(), 2, 1, 1, 1)
|
||||
|
||||
|
||||
def setup_styling(self):
|
||||
self.set_margin_top(5)
|
||||
self.set_margin_bottom(5)
|
||||
|
@ -103,13 +219,14 @@ class Controls_Column(Gtk.Box):
|
|||
|
||||
self.setup_styling()
|
||||
|
||||
for key in [Button_Box(), List_Box(), Grid_Box()]:
|
||||
for key in [Button_Box(), List_Box(), CommandEntry(), Grid_Box()]:
|
||||
self.add(key)
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def setup_styling(self):
|
||||
self.set_orientation(1) # HORIZONTAL = 0, VERTICAL = 1
|
||||
self.set_orientation(Gtk.Orientation.VERTICAL)
|
||||
self.set_vexpand(True)
|
||||
self.set_margin_start(10)
|
||||
self.set_margin_end(10)
|
||||
|
|
|
@ -47,8 +47,20 @@ class Auto_Type(Gtk.Box):
|
|||
self.set_margin_bottom(5)
|
||||
|
||||
def setup_signals(self):
|
||||
self._auto_typer.connect("enter-notify-event", self.focus_entry)
|
||||
self._auto_typer.connect("leave-notify-event", self.unfocus_entry)
|
||||
self._type_btn.connect("released", self.type_out)
|
||||
|
||||
def focus_entry(self, widget, eve = None):
|
||||
event_system.emit("set_focusable")
|
||||
widget = self.get_children()[1]
|
||||
widget.grab_focus()
|
||||
|
||||
def unfocus_entry(self, widget, eve = None):
|
||||
widget = self.get_children()[1]
|
||||
widget.grab_remove()
|
||||
event_system.emit("unset_focusable")
|
||||
|
||||
def type_out(self, widget = None, eve = None):
|
||||
text = self._auto_typer.get_text()
|
||||
typwriter.type_string(text)
|
||||
|
|
|
@ -27,22 +27,22 @@ class Window(SignalsMixin, Gtk.ApplicationWindow):
|
|||
self.setup_styling()
|
||||
self.setup_signals()
|
||||
self.setup_custom_event_signals()
|
||||
self.add_custom_signals()
|
||||
self.add(Container())
|
||||
|
||||
self.show_all()
|
||||
|
||||
def setup_signals(self):
|
||||
self.connect("delete-event", Gtk.main_quit)
|
||||
self.connect("delete-event", self._tear_down)
|
||||
|
||||
def setup_win_settings(self):
|
||||
self.set_icon_from_file(ICON_FILE)
|
||||
self.set_title(app_name)
|
||||
self.set_default_size(800, 200)
|
||||
self.set_keep_above(True)
|
||||
self.set_accept_focus(False)
|
||||
self.set_skip_taskbar_hint(True)
|
||||
self.set_skip_pager_hint(True)
|
||||
self.set_type_hint(3) # 3 = TOOLBAR
|
||||
self.unset_focusable()
|
||||
self.set_gravity(8) # 5 = CENTER, 8 = SOUTH
|
||||
self.set_position(1) # 1 = CENTER, 4 = CENTER_ALWAYS
|
||||
self.stick()
|
||||
|
@ -68,5 +68,21 @@ class Window(SignalsMixin, Gtk.ApplicationWindow):
|
|||
cr.paint()
|
||||
cr.set_operator(cairo.OPERATOR_OVER)
|
||||
|
||||
def add_custom_signals(self):
|
||||
event_system.subscribe("unset_focusable", self.unset_focusable)
|
||||
event_system.subscribe("set_focusable", self.set_focusable)
|
||||
|
||||
def unset_focusable(self):
|
||||
self.set_accept_focus(False)
|
||||
|
||||
def set_focusable(self):
|
||||
self.set_accept_focus(True)
|
||||
self.set_focus(None)
|
||||
|
||||
def main(self):
|
||||
Gtk.main()
|
||||
|
||||
def _tear_down(self, widget = None, eve = None):
|
||||
event_system.emit("shutting-down")
|
||||
Gtk.main_quit()
|
||||
|
||||
|
|
Loading…
Reference in New Issue