Skip to content

Commit

Permalink
refactor: ui actions; fix type hinting for gtk
Browse files Browse the repository at this point in the history
  • Loading branch information
dynobo committed Apr 15, 2024
1 parent 060c9b8 commit c679627
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 188 deletions.
1 change: 1 addition & 0 deletions keyhint/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Package entry for keyhint."""

from keyhint import app

if __name__ == "__main__":
Expand Down
12 changes: 6 additions & 6 deletions keyhint/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@

import logging
import sys
from collections.abc import Mapping
from typing import Any

import gi

gi.require_version("Gtk", "4.0")
gi.require_version("Adw", "1")

from gi.repository import Adw, Gio, GLib, Gtk # noqa: E402
from gi.repository import Adw, Gio, GLib # noqa: E402

from keyhint.window import KeyhintWindow # noqa: E402

Expand All @@ -36,10 +34,12 @@ class Application(Adw.Application):

def __init__(self, *args, **kwargs) -> None: # noqa: ANN002, ANN003
"""Initialize application with command line options."""
super().__init__(
*args,
kwargs.update(
application_id="eu.dynobo.keyhint",
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
)
super().__init__(
*args,
**kwargs,
)
self.options: dict = {}
Expand Down Expand Up @@ -67,7 +67,7 @@ def do_activate(self, *_, **__) -> None: # noqa: ANN002, ANN003
window.set_application(self)
window.present()

def do_command_line(self, cli: Gtk, **__: Mapping[Any, Any]) -> int:
def do_command_line(self, cli: Gio.ApplicationCommandLine) -> int:
"""Store command line options in class attribute for later usage."""
self.options = cli.get_options_dict().end().unpack()

Expand Down
1 change: 1 addition & 0 deletions keyhint/config/cli.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ eza = "ls clone with coloring"
duf = "Basic disk usage"
ncdu = "Recursive disk usage analyzer"
s-tui = "Stress test and monitor"
btm = "System resources dashboard"

[section.Navigating]
pwd = "Print working dir"
Expand Down
66 changes: 31 additions & 35 deletions keyhint/resources/headerbar.ui
Original file line number Diff line number Diff line change
Expand Up @@ -215,41 +215,37 @@
</property>
</object>

<template class="headerbar_box" parent="GtkBox">
<child>
<object class="AdwHeaderBar" id="headerbar">
<property name="hexpand">true</property>
<child type="start">
<object class="GtkDropDown" id="sheet_dropdown">
<property name="can-focus">True</property>
<property name="tooltip-text" translatable="yes">Switch cheatsheet</property>
<property name="model">
<object class="GtkStringList">
<items />
</object>
</property>
</object>
</child>
<child type="title">
<object class="GtkSearchEntry" id="search_entry">
<property name="placeholder-text" translatable="true">Ctrl+F to filter...</property>
<property name="width-request">400</property>
</object>
</child>
<child type="end">
<object class="GtkMenuButton">
<property name="icon-name">open-menu-symbolic</property>
<property name="tooltip-text" translatable="true">Main Menu</property>
<property name="popover">popover_menu</property>
</object>
</child>
<child type="end">
<object class="GtkToggleButton" id="fullscreen_button">
<property name="icon-name">view-fullscreen-symbolic</property>
<property name="tooltip-text">Toggle fullscreen (F11)</property>
<property name="action-name">win.fullscreen</property>
</object>
</child>
<template class="headerbar" parent="GtkHeaderBar">
<property name="hexpand">true</property>
<child type="start">
<object class="GtkDropDown" id="sheet_dropdown">
<property name="can-focus">True</property>
<property name="tooltip-text" translatable="yes">Switch cheatsheet</property>
<property name="model">
<object class="GtkStringList">
<items />
</object>
</property>
</object>
</child>
<child type="title">
<object class="GtkSearchEntry" id="search_entry">
<property name="placeholder-text" translatable="true">Ctrl+F to filter...</property>
<property name="width-request">400</property>
</object>
</child>
<child type="end">
<object class="GtkMenuButton">
<property name="icon-name">open-menu-symbolic</property>
<property name="tooltip-text" translatable="true">Main Menu</property>
<property name="popover">popover_menu</property>
</object>
</child>
<child type="end">
<object class="GtkToggleButton" id="fullscreen_button">
<property name="icon-name">view-fullscreen-symbolic</property>
<property name="tooltip-text">Toggle fullscreen (F11)</property>
<property name="action-name">win.fullscreen</property>
</object>
</child>
</template>
Expand Down
Loading

0 comments on commit c679627

Please sign in to comment.