Skip to content

Commit

Permalink
support custom actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkobrombin committed Nov 11, 2021
1 parent 382fd3a commit e4e1722
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion easyterm
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,21 @@ class Terminal(Vte.Terminal):


class HeaderBar(Handy.HeaderBar):
actions_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)

def __init__(self, *args, **kwds):
super(HeaderBar, self).__init__(*args, **kwds)
self.set_show_close_button(True)
self.set_title(CONF_NAME)
self.pack_start(self.actions_box)

def build_actions(self, actions:dict):
for action in actions:
button = Gtk.Button()
button.set_tooltip_text(action["tooltip"])
button.set_image(Gtk.Image.new_from_icon_name(action["icon"], Gtk.IconSize.BUTTON))
button.connect("clicked", action["callback"])
self.actions_box.pack_start(button, False, False, 0)


class MainWindow(Handy.ApplicationWindow):
Expand All @@ -38,7 +49,7 @@ class MainWindow(Handy.ApplicationWindow):
headerbar = HeaderBar()
terminal = Terminal()

def __init__(self, cwd:str="", command:list=[], env:list=[], *args, **kwds):
def __init__(self, cwd:str="", command:list=[], env:list=[], actions:list=[], *args, **kwds):
super().__init__()
self.set_title(CONF_NAME)
self.set_default_size(800, 450)
Expand All @@ -48,6 +59,9 @@ class MainWindow(Handy.ApplicationWindow):
self.box.pack_start(self.headerbar, False, False, 0)
self.box.pack_start(self.terminal, True, True, 0)

if actions:
self.headerbar.build_actions(actions)

if cwd == "":
cwd = CONF_DEF_CWD
if command == []:
Expand Down

0 comments on commit e4e1722

Please sign in to comment.