mirror of
https://github.com/aclist/dztui.git
synced 2026-08-29 11:17:12 +02:00
Compare commits
7 Commits
ad85bb7343
...
a8b7ea5008
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8b7ea5008 | ||
|
|
6a6b4c8027 | ||
|
|
c2ef7449e5 | ||
|
|
96fb484b38 | ||
|
|
1e6ff9c4f7 | ||
|
|
4313075b61 | ||
|
|
88270382f1 |
@ -53,13 +53,13 @@ def is_mission(path: Path) -> bool:
|
||||
file = path / "init.c"
|
||||
return file.exists()
|
||||
|
||||
def tokenize(mod: Path) -> dict[Any] | None:
|
||||
def tokenize(mod: Path) -> dict[str, Any] | None:
|
||||
file = mod.joinpath("meta.cpp")
|
||||
delimiter=r"\s*=\s*"
|
||||
modmeta = {}
|
||||
try:
|
||||
with open(file, "r", encoding="utf-8") as file:
|
||||
for line in file:
|
||||
with open(file, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
line = line.strip().rstrip(";")
|
||||
if not line:
|
||||
continue
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository.Gtk import ListStore # noqa E402
|
||||
from gi.repository import Gdk, GObject # noqa E402
|
||||
@ -155,7 +156,7 @@ class Emitter(GObject.GObject):
|
||||
def lan_page_initialized(self) -> None:
|
||||
pass
|
||||
|
||||
@GObject.Signal(flags=GObject.SignalFlags.RUN_LAST, arg_types=(object, str, bool))
|
||||
@GObject.Signal(flags=GObject.SignalFlags.RUN_LAST, arg_types=(object, str))
|
||||
def custom_mods_loaded(self, store: "FastInsertListStore", folder: str) -> None:
|
||||
pass
|
||||
|
||||
|
||||
@ -30,9 +30,8 @@ class OfflineManager:
|
||||
self.local_mods: list[str] | None
|
||||
self.custom_mods: list[str] | None
|
||||
|
||||
|
||||
def get_mission(self) -> None:
|
||||
folder = self.open_folderpicker()
|
||||
folder = self.open_folderpicker(dialogs.mission_dialog)
|
||||
if folder is None:
|
||||
return
|
||||
is_valid = is_mission(folder)
|
||||
@ -43,7 +42,7 @@ class OfflineManager:
|
||||
self.emitter.emit("custom_mission_loaded", str(folder), is_valid)
|
||||
|
||||
def get_custom_mods(self, local_mods: list[str]) -> None:
|
||||
folder = self.open_folderpicker()
|
||||
folder = self.open_folderpicker(dialogs.custom_mod_dialog)
|
||||
if folder is None:
|
||||
return
|
||||
self.parse_custom_mods(local_mods, folder)
|
||||
@ -54,7 +53,9 @@ class OfflineManager:
|
||||
store = ModelFactory().make_mod_store()
|
||||
store.extend(mods)
|
||||
|
||||
func = StoredFunc(lambda: self.emitter.emit("custom_mods_loaded", store, folder))
|
||||
func = StoredFunc(
|
||||
lambda: self.emitter.emit("custom_mods_loaded", store, folder)
|
||||
)
|
||||
self.thread_man.set_cleanup_func(func)
|
||||
|
||||
def setup(
|
||||
@ -91,8 +92,8 @@ class OfflineManager:
|
||||
|
||||
launch_offline(client, self.appid, name, combined_mods, self.mission_folder)
|
||||
|
||||
def open_folderpicker(self) -> Union["Path", None]:
|
||||
picker = FolderPicker(self.controller.get_window())
|
||||
def open_folderpicker(self, title: str) -> Union["Path", None]:
|
||||
picker = FolderPicker(self.controller.get_window(), title)
|
||||
folder = picker.pick_folder()
|
||||
picker.destroy()
|
||||
return folder
|
||||
|
||||
@ -16,3 +16,6 @@ checking_api = "Checking API key"
|
||||
running = "Running"
|
||||
failed = "FAILED"
|
||||
ok = "OK"
|
||||
|
||||
mission_dialog = "Set a mission folder location"
|
||||
custom_mod_dialog = "Set location to a custom mods folder"
|
||||
|
||||
@ -31,40 +31,61 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
class Icon(Gtk.Image):
|
||||
def __init__(self, name: str, l_margin: int = 0) -> None:
|
||||
def __init__(self, name: str, margin_start: int = 0, margin_end: int = 0) -> None:
|
||||
super().__init__(
|
||||
icon_name=name,
|
||||
icon_size=Gtk.IconSize.BUTTON,
|
||||
margin_start=l_margin,
|
||||
margin_start=margin_start,
|
||||
margin_end=margin_end,
|
||||
ypad=2,
|
||||
)
|
||||
|
||||
|
||||
class LargeIcon(Gtk.Image):
|
||||
def __init__(self, name: str, l_margin: int = 5) -> None:
|
||||
def __init__(self, name: str, margin_start: int = 5, margin_end: int = 0) -> None:
|
||||
super().__init__(
|
||||
icon_name=name, icon_size=Gtk.IconSize.LARGE_TOOLBAR, margin_start=l_margin
|
||||
icon_name=name,
|
||||
icon_size=Gtk.IconSize.LARGE_TOOLBAR,
|
||||
margin_start=margin_start,
|
||||
margin_end=margin_end,
|
||||
)
|
||||
|
||||
|
||||
class IconButton(Gtk.Button):
|
||||
def __init__(self, icon: str, margin: int = 0) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
icon: str,
|
||||
position: Gtk.PositionType = Gtk.PositionType.RIGHT,
|
||||
margin_start: int = 0,
|
||||
margin_end: int = 0,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.icon = Icon(icon, l_margin=margin)
|
||||
self.icon = Icon(icon, margin_start=margin_start, margin_end=margin_end)
|
||||
self.set_image(self.icon)
|
||||
self.set_image_position(Gtk.PositionType.RIGHT)
|
||||
self.set_image_position(position)
|
||||
# self.set_image_position(Gtk.PositionType.RIGHT)
|
||||
self.set_focus_on_click(False)
|
||||
|
||||
|
||||
class IconTextButton(IconButton):
|
||||
def __init__(self, icon: str, label: str) -> None:
|
||||
super().__init__(icon, margin=5)
|
||||
def __init__(
|
||||
self, icon: str, label: str, position: Gtk.PositionType = Gtk.PositionType.RIGHT
|
||||
) -> None:
|
||||
match position:
|
||||
case Gtk.PositionType.RIGHT:
|
||||
super().__init__(icon, position, margin_start=5)
|
||||
case Gtk.PositionType.LEFT:
|
||||
super().__init__(icon, position, margin_end=5)
|
||||
case _:
|
||||
raise ValueError("Unsupported position type")
|
||||
self.set_label(label)
|
||||
|
||||
|
||||
class LargeIconTextButton(IconButton):
|
||||
def __init__(self, icon: str, label: str) -> None:
|
||||
super().__init__(icon)
|
||||
def __init__(
|
||||
self, icon: str, label: str, position: Gtk.PositionType = Gtk.PositionType.RIGHT
|
||||
) -> None:
|
||||
super().__init__(icon, position)
|
||||
self.set_label(label)
|
||||
self.set_image(LargeIcon(icon))
|
||||
|
||||
|
||||
@ -36,9 +36,9 @@ class FilePicker(Gtk.FileChooserDialog):
|
||||
|
||||
|
||||
class FolderPicker(Gtk.FileChooserDialog):
|
||||
def __init__(self, parent: Gtk.Window) -> None:
|
||||
def __init__(self, parent: Gtk.Window, title: str) -> None:
|
||||
super().__init__(
|
||||
title=picker.title,
|
||||
title=title,
|
||||
action=Gtk.FileChooserAction.SELECT_FOLDER,
|
||||
parent=parent,
|
||||
resizable=True,
|
||||
|
||||
@ -66,11 +66,13 @@ class FolderHBox(HBox):
|
||||
self.set_margin_bottom(5)
|
||||
|
||||
# TODO: alternate class for left-aligned icons
|
||||
self.button = IconTextButton(FOLDER, btn_label)
|
||||
self.button = IconTextButton(FOLDER, btn_label, Gtk.PositionType.LEFT)
|
||||
self.button.set_halign(Gtk.Align.START)
|
||||
self.button.set_image_position(Gtk.PositionType.LEFT)
|
||||
|
||||
self.scrolled_label = Gtk.ScrolledWindow(propagate_natural_width=True, halign=Gtk.Align.START)
|
||||
self.scrolled_label = Gtk.ScrolledWindow(
|
||||
propagate_natural_width=True, halign=Gtk.Align.START
|
||||
)
|
||||
self.label = Gtk.Label()
|
||||
self.scrolled_label.add(self.label)
|
||||
self.extend([self.button, self.scrolled_label])
|
||||
@ -88,7 +90,9 @@ class FolderHBox(HBox):
|
||||
|
||||
|
||||
class ModFrame(HeadingFrame):
|
||||
def __init__(self, parent: OfflineLoader, controller: "Controller", label: str) -> None:
|
||||
def __init__(
|
||||
self, parent: OfflineLoader, controller: "Controller", label: str
|
||||
) -> None:
|
||||
super().__init__(heading=label)
|
||||
|
||||
self.parent = parent
|
||||
@ -118,7 +122,12 @@ class ModFrame(HeadingFrame):
|
||||
|
||||
# TODO: inherit icons from warnings area in preconnect dialog
|
||||
# TODO: strings
|
||||
self.error_label = Gtk.Label(label="No mods found", halign=Gtk.Align.START, margin_start=10, margin_bottom=5)
|
||||
self.error_label = Gtk.Label(
|
||||
label="No mods found",
|
||||
halign=Gtk.Align.START,
|
||||
margin_start=10,
|
||||
margin_bottom=5,
|
||||
)
|
||||
self.vbox.pack_end(self.error_label, expand=True, fill=True, padding=3)
|
||||
|
||||
def set_error(self, msg: str) -> None:
|
||||
@ -199,7 +208,7 @@ class CustomModFrame(ModFrame):
|
||||
self.custom_hbox.hide_label()
|
||||
self.tree_vbox.hide()
|
||||
|
||||
def present_tree(self, folder: str, store: "FastInsertListStore") -> None:
|
||||
def present_tree(self, store: "FastInsertListStore", folder: str) -> None:
|
||||
self.custom_hbox.set_label(folder)
|
||||
self.tree.set_model(store)
|
||||
self.tree_vbox.show()
|
||||
@ -214,12 +223,13 @@ class CustomModFrame(ModFrame):
|
||||
if len(store) == 0:
|
||||
self.hide_tree()
|
||||
else:
|
||||
self.present_tree()
|
||||
self.present_tree(store, folder)
|
||||
|
||||
def _on_custom_button_clicked(self, button: Gtk.Button) -> None:
|
||||
local_mods = self.get_mods()
|
||||
self.parent.offline_man.get_custom_mods(local_mods)
|
||||
|
||||
|
||||
class MissionFrame(HeadingFrame):
|
||||
def __init__(self, parent: OfflineLoader, controller: "Controller") -> None:
|
||||
super().__init__(heading=offline.mission_frame)
|
||||
@ -232,14 +242,18 @@ class MissionFrame(HeadingFrame):
|
||||
self.mission_button = self.mission_hbox.get_button()
|
||||
self.mission_button.connect("clicked", self._on_mission_button_clicked)
|
||||
|
||||
self.warning = Gtk.Label(halign=Gtk.Align.START, margin_start=10, margin_bottom=5)
|
||||
self.warning = Gtk.Label(
|
||||
halign=Gtk.Align.START, margin_start=10, margin_bottom=5
|
||||
)
|
||||
self.vbox = VBox()
|
||||
self.vbox.extend([self.mission_hbox, self.warning])
|
||||
self.frame.add(self.vbox)
|
||||
|
||||
self.emitter.connect("custom_mission_loaded", self._on_mission_loaded)
|
||||
|
||||
def _on_mission_loaded(self, emitter: "Emitter", folder: str, is_valid: bool) -> None:
|
||||
def _on_mission_loaded(
|
||||
self, emitter: "Emitter", folder: str, is_valid: bool
|
||||
) -> None:
|
||||
self.mission_hbox.set_label(folder)
|
||||
if not is_valid:
|
||||
self.warning.show()
|
||||
|
||||
@ -60,6 +60,27 @@ class ModTreeView(ModsMixin, ContextMixin, TreeView): # type: ignore
|
||||
self.connect("button-press-event", self.present_menu)
|
||||
self.connect("key-press-event", self.present_menu)
|
||||
|
||||
self.connect("button-press-event", self.on_row_click)
|
||||
|
||||
def on_row_click(self, widget: Gtk.TreeView, event: Gdk.EventButton) -> bool:
|
||||
if event.state is Gdk.ModifierType.CONTROL_MASK and event.button == 1:
|
||||
path_info = widget.get_path_at_pos(int(event.x), int(event.y))
|
||||
if path_info is None:
|
||||
return False
|
||||
path, column, cellx, celly = path_info
|
||||
model = self.get_model()
|
||||
if model is None:
|
||||
return False
|
||||
if path is None:
|
||||
return False
|
||||
_iter = model.get_iter(path)
|
||||
if self.get_selection().iter_is_selected(_iter):
|
||||
self.get_selection().unselect_iter(_iter)
|
||||
else:
|
||||
self.get_selection().select_iter(_iter)
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_mod_man(self) -> ModManager:
|
||||
return self.mod_man
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user