multi window mess
This commit is contained in:
@@ -34,27 +34,29 @@ class Application(Gtk.Application):
|
||||
self.init_style()
|
||||
self.windows = windows
|
||||
initial = windows.__dict__[config.initial_window]
|
||||
|
||||
self.cbs = Callbacks(show_list=self.show_list, show_join=self.show_join)
|
||||
if issubclass(initial, JoinWindow):
|
||||
# see JoinWindow constructor
|
||||
self.window = initial(
|
||||
initial_values=InitialJoinValues(url=config.url or ""),
|
||||
cbs=Callbacks(show_list=self.show_list, show_join=self.show_join),
|
||||
cbs=self.cbs,
|
||||
)
|
||||
|
||||
if issubclass(initial, OverviewWindow):
|
||||
# see OverviewWindow constructor
|
||||
self.window = initial()
|
||||
self.window = initial(cbs=self.cbs)
|
||||
|
||||
def show_list(self) -> None:
|
||||
prev = self.window
|
||||
self.window = self.windows.__dict__["overview"]()
|
||||
self.window = self.windows.__dict__["overview"](cbs=self.cbs)
|
||||
self.do_activate()
|
||||
prev.hide()
|
||||
|
||||
def show_join(self, initial_values: InitialJoinValues) -> None:
|
||||
def show_join(self) -> None:
|
||||
prev = self.window
|
||||
self.window = self.windows.__dict__["join"]()
|
||||
self.window = self.windows.__dict__["join"](
|
||||
cbs=self.cbs, initial_values=InitialJoinValues(url="")
|
||||
)
|
||||
self.do_activate()
|
||||
prev.hide()
|
||||
|
||||
|
||||
@@ -12,4 +12,4 @@ class InitialJoinValues:
|
||||
@dataclass
|
||||
class Callbacks:
|
||||
show_list: Callable[[], None]
|
||||
show_join: Callable[[InitialJoinValues], None]
|
||||
show_join: Callable[[], None]
|
||||
|
||||
@@ -90,6 +90,7 @@ class ClanList(Gtk.Box):
|
||||
set_selected: Callable[[VMBase | None], None],
|
||||
selected_vm: VMBase | None,
|
||||
show_toolbar: bool = True,
|
||||
show_join: Callable[[], None],
|
||||
) -> None:
|
||||
super().__init__(orientation=Gtk.Orientation.VERTICAL, expand=True)
|
||||
|
||||
@@ -97,19 +98,15 @@ class ClanList(Gtk.Box):
|
||||
self.remount_list_view = remount_list
|
||||
self.set_selected = set_selected
|
||||
self.show_toolbar = show_toolbar
|
||||
self.show_join = show_join
|
||||
|
||||
# TODO: We should use somekind of useState hook here.
|
||||
# that updates the list of VMs when the user changes something
|
||||
# @hsjobeki reply: @qubasa: This is how to update data in the list store
|
||||
# self.list_store.set_value(self.list_store.get_iter(path), 3, "new value")
|
||||
# self.list_store[path][3] = "new_value"
|
||||
# This class needs to take ownership of the data because it has access to the listStore only
|
||||
self.selected_vm: VMBase | None = selected_vm
|
||||
|
||||
button_hooks = {
|
||||
"on_start_clicked": self.on_start_clicked,
|
||||
"on_stop_clicked": self.on_stop_clicked,
|
||||
"on_edit_clicked": self.on_edit_clicked,
|
||||
"on_join_clicked": self.on_join_clicked,
|
||||
}
|
||||
if show_toolbar:
|
||||
self.toolbar = ClanListToolbar(**button_hooks)
|
||||
@@ -131,6 +128,10 @@ class ClanList(Gtk.Box):
|
||||
def on_stop_clicked(self, widget: Gtk.Widget) -> None:
|
||||
print("Stop clicked")
|
||||
|
||||
def on_join_clicked(self, widget: Gtk.Widget) -> None:
|
||||
print("Join clicked")
|
||||
self.show_join()
|
||||
|
||||
def on_edit_clicked(self, widget: Gtk.Widget) -> None:
|
||||
print("Edit clicked")
|
||||
self.remount_edit_view()
|
||||
@@ -154,6 +155,7 @@ class ClanListToolbar(Gtk.Toolbar):
|
||||
on_start_clicked: Callable[[Gtk.Widget], None],
|
||||
on_stop_clicked: Callable[[Gtk.Widget], None],
|
||||
on_edit_clicked: Callable[[Gtk.Widget], None],
|
||||
on_join_clicked: Callable[[Gtk.Widget], None],
|
||||
) -> None:
|
||||
super().__init__(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
|
||||
@@ -169,6 +171,10 @@ class ClanListToolbar(Gtk.Toolbar):
|
||||
self.edit_button.connect("clicked", on_edit_clicked)
|
||||
self.add(self.edit_button)
|
||||
|
||||
self.join_button = Gtk.ToolButton(label="New")
|
||||
self.join_button.connect("clicked", on_join_clicked)
|
||||
self.add(self.join_button)
|
||||
|
||||
def set_is_selected(self, s: bool) -> None:
|
||||
if s:
|
||||
self.edit_button.set_sensitive(True)
|
||||
|
||||
@@ -1,12 +1,105 @@
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
import gi
|
||||
|
||||
from clan_vm_manager import assets
|
||||
|
||||
from ..interfaces import Callbacks, InitialJoinValues
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
|
||||
from gi.repository import Gio, Gtk
|
||||
from gi.repository import GdkPixbuf, Gio, Gtk
|
||||
|
||||
|
||||
class Trust(Gtk.Box):
|
||||
def __init__(self, url: str, next: Callable[[], None]) -> None:
|
||||
super().__init__()
|
||||
self.next = next
|
||||
|
||||
icon = Gtk.Image.new_from_pixbuf(
|
||||
GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||
filename=str(assets.loc / "placeholder.jpeg"),
|
||||
width=256,
|
||||
height=256,
|
||||
preserve_aspect_ratio=True,
|
||||
)
|
||||
)
|
||||
layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, expand=True)
|
||||
layout.set_border_width(20)
|
||||
|
||||
upper = Gtk.Box(orientation="vertical")
|
||||
upper.set_spacing(20)
|
||||
upper.add(Gtk.Label(label="Clan URL"))
|
||||
upper.add(icon)
|
||||
|
||||
self.entry = Gtk.Entry(text=str(url))
|
||||
# self.entry.set_editable(False) ?
|
||||
|
||||
upper.add(self.entry)
|
||||
|
||||
lower = Gtk.Box(orientation="vertical")
|
||||
lower.set_spacing(20)
|
||||
trust_button = Gtk.Button(label="Trust")
|
||||
trust_button.connect("clicked", self.on_trust)
|
||||
lower.add(trust_button)
|
||||
|
||||
layout.pack_start(upper, expand=True, fill=True, padding=0)
|
||||
layout.pack_end(lower, expand=True, fill=True, padding=0)
|
||||
self.set_center_widget(layout)
|
||||
# self.show_all()
|
||||
|
||||
def on_trust(self, widget: Gtk.Widget) -> None:
|
||||
print("trusted")
|
||||
print(self.entry.get_text())
|
||||
self.next()
|
||||
|
||||
|
||||
class Details(Gtk.Box):
|
||||
def __init__(self, url: str, next: Callable[[], None]) -> None:
|
||||
super().__init__()
|
||||
self.next = next
|
||||
|
||||
icon = Gtk.Image.new_from_pixbuf(
|
||||
GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||
filename=str(assets.loc / "placeholder.jpeg"),
|
||||
width=256,
|
||||
height=256,
|
||||
preserve_aspect_ratio=True,
|
||||
)
|
||||
)
|
||||
layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, expand=True)
|
||||
layout.set_border_width(20)
|
||||
|
||||
upper = Gtk.Box(orientation="vertical")
|
||||
upper.set_spacing(20)
|
||||
upper.add(icon)
|
||||
|
||||
label = Gtk.Label(label=str(url))
|
||||
|
||||
upper.add(label)
|
||||
|
||||
description = Gtk.TextBuffer()
|
||||
description.set_text("Lorem ipsum")
|
||||
text_view = Gtk.TextView.new_with_buffer(description)
|
||||
text_view.set_editable(False)
|
||||
|
||||
upper.add(text_view)
|
||||
|
||||
lower = Gtk.Box(orientation="horizontal", expand=True)
|
||||
lower.set_spacing(20)
|
||||
|
||||
layout.pack_start(upper, expand=True, fill=True, padding=0)
|
||||
layout.add(lower)
|
||||
|
||||
join_button = Gtk.Button(label="Join")
|
||||
join_button.connect("clicked", self.on_join)
|
||||
layout.add(join_button)
|
||||
self.add(layout)
|
||||
|
||||
def on_join(self, widget: Gtk.Widget) -> None:
|
||||
print("join")
|
||||
self.next()
|
||||
|
||||
|
||||
class JoinWindow(Gtk.ApplicationWindow):
|
||||
@@ -21,22 +114,35 @@ class JoinWindow(Gtk.ApplicationWindow):
|
||||
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6, expand=True)
|
||||
self.add(vbox)
|
||||
|
||||
button = Gtk.ToolButton()
|
||||
button.set_icon_name("go-previous")
|
||||
button.connect("clicked", self.switch)
|
||||
|
||||
toolbar = Gtk.Toolbar(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
toolbar.add(button)
|
||||
vbox.add(toolbar)
|
||||
|
||||
self.stack = Gtk.Stack()
|
||||
|
||||
self.stack.add_titled(Gtk.Label(str(initial_values.url)), "join", "Join")
|
||||
self.stack.add_titled(
|
||||
Details(str(initial_values.url), next=self.show_details),
|
||||
"details",
|
||||
"Details",
|
||||
)
|
||||
self.stack.add_titled(
|
||||
Trust(str(initial_values.url), next=self.show_details), "trust", "Trust"
|
||||
)
|
||||
|
||||
vbox.add(self.stack)
|
||||
vbox.add(Gtk.Entry(text=str(initial_values.url)))
|
||||
|
||||
button = Gtk.Button(
|
||||
label="To List",
|
||||
)
|
||||
button.connect("clicked", self.switch)
|
||||
vbox.add(button)
|
||||
# vbox.add(Gtk.Entry(text=str(initial_values.url)))
|
||||
|
||||
# Must be called AFTER all components were added
|
||||
self.show_all()
|
||||
|
||||
def show_details(self) -> None:
|
||||
self.stack.set_visible_child_name("details")
|
||||
|
||||
def switch(self, widget: Gtk.Widget) -> None:
|
||||
self.cbs.show_list()
|
||||
|
||||
|
||||
@@ -8,12 +8,13 @@ gi.require_version("Gtk", "3.0")
|
||||
|
||||
from gi.repository import Gio, Gtk
|
||||
|
||||
from ..interfaces import Callbacks
|
||||
from ..ui.clan_join_page import ClanJoinPage
|
||||
from ..ui.clan_select_list import ClanEdit, ClanList
|
||||
|
||||
|
||||
class OverviewWindow(Gtk.ApplicationWindow):
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, cbs: Callbacks) -> None:
|
||||
super().__init__()
|
||||
# Initialize the main window
|
||||
self.set_title("cLAN Manager")
|
||||
@@ -34,7 +35,9 @@ class OverviewWindow(Gtk.ApplicationWindow):
|
||||
"remount_edit": self.remount_edit_view,
|
||||
"set_selected": self.set_selected,
|
||||
}
|
||||
clan_list = ClanList(**self.list_hooks, selected_vm=None) # type: ignore
|
||||
clan_list = ClanList(
|
||||
**self.list_hooks, selected_vm=None, show_join=cbs.show_join
|
||||
) # type: ignore
|
||||
# Add named stacks
|
||||
self.stack.add_titled(clan_list, "list", "List")
|
||||
self.stack.add_titled(
|
||||
|
||||
Reference in New Issue
Block a user