feat: dzgui 7 alpha

This commit is contained in:
aclist committed 2025-12-08 17:32:25 +09:00
1 parent 1acdbd58c5
commit 2e5b771137
150 files changed
+10359

No files matched your search

+75
View File
@@ -0,0 +1,75 @@
import logging
from dzgui.views.trees.tree_base import TreeView
from dzgui.const.enum import Popup, ContextMenu
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib, Gdk, GObject, Pango # noqa E402
logger = logging.getLogger(__name__)
class ContextMixin(TreeView):
def present_menu(self,
widget: Gtk.Widget,
event: Gdk.EventButton | Gdk.EventKey,
) -> None:
#if self.is_selection_empty():
# return
if event.type is Gdk.EventType.BUTTON_PRESS:
try:
pathinfo = self.get_path_at_pos(int(event.x), int(event.y))
if pathinfo is None:
return
(path, col, cellx, celly) = pathinfo
if path is None:
return
self.set_cursor(path, col, False)
except AttributeError:
pass
if event.type is Gdk.EventType.KEY_PRESS:
if event.state is not Gdk.ModifierType.CONTROL_MASK:
return
if event.keyval is not Gdk.KEY_l:
return
group = self.menu
self.context_menu = Gtk.Menu()
for row in group.value:
item = Gtk.MenuItem(label=row.dict["label"])
item.connect("activate", self._on_menu_click, row)
self.context_menu.append(item)
self.context_menu.show_all()
match event.type:
case Gdk.EventType.KEY_PRESS:
self.context_menu.popup_at_widget(
widget, Gdk.Gravity.CENTER, Gdk.Gravity.WEST
)
case Gdk.EventType.BUTTON_PRESS | Gdk.EventType.BUTTON_RELEASE:
self.context_menu.popup_at_pointer(event)
self.context_menu.select_first(False)
def _on_menu_click(self, widget: Gtk.MenuItem, enum: ContextMenu) -> None:
"""
Local mods page allows multi selection, so ensure that only focused row
is selected. Used by ContextMenu.OPEN_WORKSHOP and ContextMenu.DELETE_MOD.
Mod tree right panel supports multi-delete, but context menu enforces
single deletion on the focused row.
Debug log page allows multi selection and copy of rows, so special handling
is used.
"""
if enum == ContextMenu.COPY_LOG_CLIPBOARD:
model, records = self.get_selection().get_selected_rows()
clipboard = self.controller.copy_log(records)
self.controller.copy_clipboard(clipboard)
else:
path = self.get_focused_row_path()
self.controller.menu_action(enum, path)
+58
View File
@@ -0,0 +1,58 @@
from dzgui.const.enum import CursorPosition
from dzgui.const.constants import SEPARATOR
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib, Gdk, GObject, Pango # noqa E402
class CursorMixin:
def _vim_nav(self, event: Gdk.EventKey):
match event.keyval:
case Gdk.KEY_g:
self._move_cursor(CursorPosition.TOP)
case Gdk.KEY_G:
self._move_cursor(CursorPosition.BOTTOM)
case Gdk.KEY_j:
self._move_cursor(CursorPosition.DOWN)
case Gdk.KEY_k:
self._move_cursor(CursorPosition.UP)
case Gdk.KEY_l | Gdk.KEY_Right:
if event.state is Gdk.ModifierType.CONTROL_MASK:
return
self.controller.mediator.right_panel.focus_button_box()
case _:
return False
def _move_cursor(self, position: CursorPosition) -> bool:
cur_row = self.get_focused_row_index()
model = self.get_model()
if model:
end = len(model) - 1
else:
return True
if position == CursorPosition.DOWN:
if cur_row == end:
return True
dest = cur_row + 1
if model[dest][0] == SEPARATOR:
dest += 1
if position == CursorPosition.UP:
if cur_row == 0:
return True
dest = cur_row - 1
if model[dest][0] == "SEPARATOR":
dest -= 1
if position == CursorPosition.TOP:
if cur_row == 0:
return True
dest = 0
if position == CursorPosition.BOTTOM:
if cur_row == end:
return True
dest = end
path = Gtk.TreePath.new_from_indices([dest])
self.set_cursor(path)
return True
+16
View File
@@ -0,0 +1,16 @@
from dzgui.views.trees.tree_base import TreeView
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib, Gdk, GObject, Pango # noqa E402
class ModsMixin:
def _on_mod_row_activated(self,
tree: TreeView,
path: Gtk.TreePath,
column: Gtk.TreeViewColumn
) -> None:
path = self.get_focused_row_path()
self.controller.open_mod_page(path)
+21
View File
@@ -0,0 +1,21 @@
from dzgui.const.enum import VAdjustment
from dzgui.const.constants import SCROLL_INCREMENT
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gdk # noqa
class ScrollableMixin:
def _set_adjustment(self, adjustment = VAdjustment) -> None:
vadj = self.scrollable.get_vadjustment()
match adjustment:
case VAdjustment.TOP:
adj = vadj.get_lower()
case VAdjustment.BOTTOM:
adj = vadj.get_upper()
case VAdjustment.UP:
adj = vadj.get_value() - SCROLL_INCREMENT
case VAdjustment.DOWN:
adj = vadj.get_value() + SCROLL_INCREMENT
vadj.set_value(adj)