Skip to content

Commit

Permalink
Create about window from metainfo
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Dec 17, 2023
1 parent c8a17b8 commit 4def62c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 65 deletions.
2 changes: 1 addition & 1 deletion hyperplane/gtk/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ menu primary_menu {
}
}
section {
item (_("_Reload"), "app.reload")
item (_("_Reload"), "win.reload")
}
section {
item (_("Show _Hidden Files"), "app.show-hidden")
Expand Down
1 change: 1 addition & 0 deletions hyperplane/hyperplane.gresource.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<file alias="style-dark.css">gtk/style-dark.css</file>
<file preprocess="xml-stripblanks">assets/folder-closed.svg</file>
<file preprocess="xml-stripblanks">assets/folder-open.svg</file>
<file preprocess="xml-stripblanks" alias="@APP_ID@.metainfo.xml">../data/@APP_ID@.metainfo.xml</file>
</gresource>
</gresources>
66 changes: 14 additions & 52 deletions hyperplane/items_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,6 @@ def __init__(
self.action_group = Gio.SimpleActionGroup.new()
self.insert_action_group("page", self.action_group)

self.create_action(
"zoom-in",
self.__on_zoom_in_action,
("<primary>plus", "<Primary>KP_Add", "<primary>equal"),
)
self.create_action(
"zoom-out",
self.__on_zoom_out_action,
("<primary>minus", "<Primary>KP_Subtract", "<Primary>underscore"),
)
self.create_action(
"reset-zoom", self.__reset_zoom, ("<primary>0", "<primary>KP_0")
)
self.create_action("reload", self.__reload, ("<primary>r", "F5"))

self.create_action("undo", self.__undo, ("<primary>z",))
self.create_action("open", self.__open, ("Return", "<primary>o"))
self.create_action("open-new-tab", self.__open_new_tab, ("<primary>Return",))
Expand All @@ -155,9 +140,22 @@ def __init__(
self.create_action("trash-delete", self.__trash_delete, ("Delete",))
self.create_action("trash-restore", self.__trash_restore)

def reload(self) -> None:
"""Refresh the view."""
if isinstance(self.dir_list, Gtk.DirectoryList):
self.dir_list.set_monitored(False)
self.dir_list.set_monitored(True)
return

# TODO: This works, but it would be best if instead of manually refreshing,
# tags would be monitored for changes too. I don't know how I would do that though.
if isinstance(self.dir_list, Gtk.FlattenListModel):
self.dir_list = self.__get_list(tags=self.tags)
self.filter_list.set_model(self.dir_list)

def __get_list(
self, gfile: Optional[Gio.File] = None, tags: Optional[list[str]] = None
) -> Gtk.FlattenListModel | Gtk.DirectoryList:
) -> Gtk.DirectoryList | Gtk.FlattenListModel:
attrs = ",".join(
(
Gio.FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON,
Expand Down Expand Up @@ -310,30 +308,6 @@ def create_action(
)
)

def __on_zoom_in_action(self, *_args: Any) -> None:
win = self.get_root()

if (zoom_level := shared.state_schema.get_uint("zoom-level")) > 4:
return

shared.state_schema.set_uint("zoom-level", zoom_level + 1)
win.update_zoom()

def __on_zoom_out_action(self, *_args: Any) -> None:
win = self.get_root()

if (zoom_level := shared.state_schema.get_uint("zoom-level")) < 2:
return

shared.state_schema.set_uint("zoom-level", zoom_level - 1)
win.update_zoom()

def __reset_zoom(self, *_args: Any) -> None:
win = self.get_root()

shared.state_schema.reset("zoom-level")
win.update_zoom()

def __undo(self, obj: Any, *_args: Any) -> None:
win = self.get_root()

Expand Down Expand Up @@ -417,18 +391,6 @@ def __open_with(self, *_args: Any) -> None:
# TODO: Is there any way to open multiple files?
portal.open_uri(parent, gfiles[0].get_uri(), Xdp.OpenUriFlags.ASK)

def __reload(self, *_args: Any) -> None:
if isinstance(self.dir_list, Gtk.DirectoryList):
self.dir_list.set_monitored(False)
self.dir_list.set_monitored(True)
return

# TODO: This works, but it would be best if instead of manually refreshing,
# tags would be monitored for changes too. I don't know how I would do that though.
if isinstance(self.dir_list, Gtk.FlattenListModel):
self.dir_list = self.__get_list(tags=self.tags)
self.filter_list.set_model(self.dir_list)

def __new_folder(self, *_args: Any) -> None:
path = None

Expand Down
21 changes: 13 additions & 8 deletions hyperplane/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,20 @@ def create_action(

def __on_about_action(self, *_args: Any) -> None:
"""Callback for the app.about action."""
about = Adw.AboutWindow(
transient_for=self.get_active_window(),
application_name=_("Hyperplane"),
application_icon=shared.APP_ID,
developer_name="kramo",
version="0.1.0",
developers=["kramo"],
copyright="© 2023 kramo",
about = Adw.AboutWindow.new_from_appdata(
shared.PREFIX + "/" + shared.APP_ID + ".metainfo.xml", shared.VERSION
)
about.set_transient_for(self.get_active_window())
about.set_developers(
(
"kramo https://kramo.hu",
"Benedek Dévényi https://github.com/rdbende",
)
)
about.set_designers(("kramo https://kramo.hu",))
about.set_copyright("© 2023 kramo")
# Translators: Replace this with your name for it to show up in the about window
about.set_translator_credits = (_("translator_credits"),)
about.present()

def __on_preferences_action(self, *_args: Any) -> None:
Expand Down
6 changes: 3 additions & 3 deletions hyperplane/utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def get_copy_path(path: PathLike) -> Path:


def get_gfile_display_name(gfile: Gio.File) -> str:
"""Gets the display name for a GFile."""
"""Gets the display name for a `GFile`."""
# HACK: Don't call this. Store this info somewhere instead.
return gfile.query_info(
Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, Gio.FileAttributeInfoFlags.NONE
Expand All @@ -227,9 +227,9 @@ def get_gfile_display_name(gfile: Gio.File) -> str:

def get_gfile_path(gfile: Gio.File, uri_fallback=False) -> Path | str:
"""
Gets a pathlib.Path to represent a GFile.
Gets a pathlib.Path to represent a `GFile`.
If `uri_fallback` is true and no path can be retreived but the GFile
If `uri_fallback` is true and no path can be retreived but the `GFile`
has a valid URI, returns that instead.
"""

Expand Down
38 changes: 37 additions & 1 deletion hyperplane/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ def __init__(self, **kwargs: Any) -> None:
self.create_action("forward", self.__on_forward_action)
self.lookup_action("forward").set_enabled(False)

self.create_action(
"zoom-in",
self.__on_zoom_in_action,
("<primary>plus", "<Primary>KP_Add", "<primary>equal"),
)
self.create_action(
"zoom-out",
self.__on_zoom_out_action,
("<primary>minus", "<Primary>KP_Subtract", "<Primary>underscore"),
)
self.create_action(
"reset-zoom", self.__reset_zoom, ("<primary>0", "<primary>KP_0")
)
self.create_action("reload", self.__reload, ("<primary>r", "F5"))

# TODO: This is tedious, maybe use GTK Expressions?
self.create_action("open-tag", self.__open_tag)
self.create_action("open-new-tab-tag", self.__open_new_tab_tag)
Expand Down Expand Up @@ -245,7 +260,7 @@ def set_menu_items(self, menu_items: Iterable[str]) -> None:
self.get_visible_page().action_group.lookup_action(action).set_enabled(True)

def get_gfiles_from_positions(self, positions: list[int]) -> list[Gio.File]:
"""Get a list of GFiles corresponding to positions in the ListModel."""
"""Get a list of `GFile`s corresponding to positions in the list model."""
paths = []
multi_selection = self.get_visible_page().multi_selection

Expand Down Expand Up @@ -518,6 +533,27 @@ def __on_forward_action(self, *_args: Any) -> None:

nav_bin.view.push(nav_bin.next_pages[-1])

def __on_zoom_in_action(self, *_args: Any) -> None:
if (zoom_level := shared.state_schema.get_uint("zoom-level")) > 4:
return

shared.state_schema.set_uint("zoom-level", zoom_level + 1)
self.update_zoom()

def __on_zoom_out_action(self, *_args: Any) -> None:
if (zoom_level := shared.state_schema.get_uint("zoom-level")) < 2:
return

shared.state_schema.set_uint("zoom-level", zoom_level - 1)
self.update_zoom()

def __reset_zoom(self, *_args: Any) -> None:
shared.state_schema.reset("zoom-level")
self.update_zoom()

def __reload(self, *_args: Any) -> None:
self.get_visible_page().reload()

def __create_window(self, *_args: Any) -> Adw.TabView:
win = self.get_application().do_activate()

Expand Down

0 comments on commit 4def62c

Please sign in to comment.