Merge pull request 'join window' (#654) from hsjobeki-main into main
This commit is contained in:
@@ -49,7 +49,6 @@ class Application(Gtk.Application):
|
|||||||
def show_list(self) -> None:
|
def show_list(self) -> None:
|
||||||
prev = self.window
|
prev = self.window
|
||||||
self.window = self.windows.__dict__["overview"](cbs=self.cbs)
|
self.window = self.windows.__dict__["overview"](cbs=self.cbs)
|
||||||
self.do_activate()
|
|
||||||
prev.hide()
|
prev.hide()
|
||||||
|
|
||||||
def show_join(self) -> None:
|
def show_join(self) -> None:
|
||||||
@@ -57,7 +56,6 @@ class Application(Gtk.Application):
|
|||||||
self.window = self.windows.__dict__["join"](
|
self.window = self.windows.__dict__["join"](
|
||||||
cbs=self.cbs, initial_values=InitialJoinValues(url="")
|
cbs=self.cbs, initial_values=InitialJoinValues(url="")
|
||||||
)
|
)
|
||||||
self.do_activate()
|
|
||||||
prev.hide()
|
prev.hide()
|
||||||
|
|
||||||
def do_startup(self) -> None:
|
def do_startup(self) -> None:
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ from collections.abc import Callable
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
|
from clan_cli.clan_uri import ClanURI
|
||||||
|
from clan_cli.history.add import add_history, list_history
|
||||||
|
|
||||||
from clan_vm_manager import assets
|
from clan_vm_manager import assets
|
||||||
|
|
||||||
@@ -13,9 +15,63 @@ from gi.repository import GdkPixbuf, Gio, Gtk
|
|||||||
|
|
||||||
|
|
||||||
class Trust(Gtk.Box):
|
class Trust(Gtk.Box):
|
||||||
def __init__(self, url: str, show_next: Callable[[], None]) -> None:
|
def __init__(
|
||||||
|
self, url: str, show_next: Callable[[], None], stack: Gtk.Stack
|
||||||
|
) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.show_next = show_next
|
self.show_next = show_next
|
||||||
|
self.stack = stack
|
||||||
|
self.url = url
|
||||||
|
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.Label(label=str(url))
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
def on_trust(self, widget: Gtk.Widget) -> None:
|
||||||
|
print(f"trusted: {self.url}")
|
||||||
|
uri = ClanURI(self.url)
|
||||||
|
add_history(uri)
|
||||||
|
history = list_history()
|
||||||
|
found = filter(lambda item: item.flake.flake_url == uri.get_internal(), history)
|
||||||
|
if found:
|
||||||
|
[item] = found
|
||||||
|
self.stack.add_titled(
|
||||||
|
Details(url=uri.get_internal(), description=item.flake.description),
|
||||||
|
"details",
|
||||||
|
"Details",
|
||||||
|
)
|
||||||
|
self.show_next()
|
||||||
|
self.stack.set_visible_child_name("details")
|
||||||
|
|
||||||
|
|
||||||
|
class Details(Gtk.Box):
|
||||||
|
def __init__(self, url: str, description: str | None) -> None:
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
icon = Gtk.Image.new_from_pixbuf(
|
icon = Gtk.Image.new_from_pixbuf(
|
||||||
GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||||
@@ -33,73 +89,50 @@ class Trust(Gtk.Box):
|
|||||||
upper.add(Gtk.Label(label="Clan URL"))
|
upper.add(Gtk.Label(label="Clan URL"))
|
||||||
upper.add(icon)
|
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.show_next()
|
|
||||||
|
|
||||||
|
|
||||||
class Details(Gtk.Box):
|
|
||||||
def __init__(self, url: str, show_next: Callable[[], None]) -> None:
|
|
||||||
super().__init__()
|
|
||||||
self.show_next = show_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))
|
label = Gtk.Label(label=str(url))
|
||||||
|
|
||||||
upper.add(label)
|
upper.add(label)
|
||||||
|
|
||||||
description = Gtk.TextBuffer()
|
description_label = Gtk.Label(label=description)
|
||||||
description.set_text("Lorem ipsum")
|
upper.add(description_label)
|
||||||
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 = Gtk.Box(orientation="horizontal", expand=True)
|
||||||
lower.set_spacing(20)
|
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 = Gtk.Button(label="Join")
|
||||||
join_button.connect("clicked", self.on_join)
|
join_button.connect("clicked", self.on_join)
|
||||||
layout.add(join_button)
|
join_action_area = Gtk.Box(orientation="horizontal", expand=False)
|
||||||
|
join_button_area = Gtk.Box(orientation="vertical", expand=False)
|
||||||
|
join_action_area.pack_end(join_button_area, expand=False, fill=False, padding=0)
|
||||||
|
join_button_area.pack_end(join_button, expand=False, fill=False, padding=0)
|
||||||
|
join_details = Gtk.Label(label="Info")
|
||||||
|
|
||||||
|
join_details_area = Gtk.Box(orientation="horizontal", expand=False)
|
||||||
|
join_label_area = Gtk.Box(orientation="vertical", expand=False)
|
||||||
|
join_label_area.pack_end(join_details, expand=False, fill=False, padding=0)
|
||||||
|
for info in [
|
||||||
|
"Memory: 2 GiB",
|
||||||
|
"CPU: 2 Cores",
|
||||||
|
"Storage: 64 GiB",
|
||||||
|
]:
|
||||||
|
details_label = Gtk.Label(label=info)
|
||||||
|
details_label.set_justify(Gtk.Justification.LEFT)
|
||||||
|
join_label_area.pack_end(details_label, expand=False, fill=False, padding=0)
|
||||||
|
|
||||||
|
join_details_area.pack_start(
|
||||||
|
join_label_area, expand=False, fill=False, padding=0
|
||||||
|
)
|
||||||
|
|
||||||
|
lower.pack_start(join_details_area, expand=True, fill=True, padding=0)
|
||||||
|
lower.pack_end(join_action_area, expand=True, fill=True, padding=0)
|
||||||
|
layout.pack_start(upper, expand=False, fill=False, padding=0)
|
||||||
|
layout.add(lower)
|
||||||
|
|
||||||
self.add(layout)
|
self.add(layout)
|
||||||
|
|
||||||
def on_join(self, widget: Gtk.Widget) -> None:
|
def on_join(self, widget: Gtk.Widget) -> None:
|
||||||
print("join")
|
# TODO: @Qubasa
|
||||||
self.show_next()
|
raise Exception("Not ready yet.")
|
||||||
|
|
||||||
|
|
||||||
class JoinWindow(Gtk.ApplicationWindow):
|
class JoinWindow(Gtk.ApplicationWindow):
|
||||||
@@ -125,15 +158,17 @@ class JoinWindow(Gtk.ApplicationWindow):
|
|||||||
self.stack = Gtk.Stack()
|
self.stack = Gtk.Stack()
|
||||||
|
|
||||||
self.stack.add_titled(
|
self.stack.add_titled(
|
||||||
Details(str(initial_values.url), show_next=self.show_details),
|
Trust(
|
||||||
"details",
|
str(initial_values.url), show_next=self.show_details, stack=self.stack
|
||||||
"Details",
|
),
|
||||||
)
|
|
||||||
self.stack.add_titled(
|
|
||||||
Trust(str(initial_values.url), show_next=self.show_details),
|
|
||||||
"trust",
|
"trust",
|
||||||
"Trust",
|
"Trust",
|
||||||
)
|
)
|
||||||
|
# self.stack.add_titled(
|
||||||
|
# self.details,
|
||||||
|
# "details",
|
||||||
|
# "Details",
|
||||||
|
# )
|
||||||
|
|
||||||
vbox.add(self.stack)
|
vbox.add(self.stack)
|
||||||
|
|
||||||
@@ -143,7 +178,7 @@ class JoinWindow(Gtk.ApplicationWindow):
|
|||||||
self.show_all()
|
self.show_all()
|
||||||
|
|
||||||
def show_details(self) -> None:
|
def show_details(self) -> None:
|
||||||
self.stack.set_visible_child_name("details")
|
self.show_all()
|
||||||
|
|
||||||
def switch(self, widget: Gtk.Widget) -> None:
|
def switch(self, widget: Gtk.Widget) -> None:
|
||||||
self.cbs.show_list()
|
self.cbs.show_list()
|
||||||
|
|||||||
@@ -16,19 +16,13 @@ from ..ui.clan_select_list import ClanEdit, ClanList
|
|||||||
class OverviewWindow(Gtk.ApplicationWindow):
|
class OverviewWindow(Gtk.ApplicationWindow):
|
||||||
def __init__(self, cbs: Callbacks) -> None:
|
def __init__(self, cbs: Callbacks) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
# Initialize the main window
|
|
||||||
self.set_title("cLAN Manager")
|
self.set_title("cLAN Manager")
|
||||||
self.connect("delete-event", self.on_quit)
|
self.connect("delete-event", self.on_quit)
|
||||||
self.set_default_size(800, 600)
|
self.set_default_size(800, 600)
|
||||||
|
|
||||||
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6, expand=True)
|
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6, expand=True)
|
||||||
self.add(vbox)
|
self.add(vbox)
|
||||||
|
|
||||||
# Add a notebook layout
|
|
||||||
# https://python-gtk-3-tutorial.readthedocs.io/en/latest/layout.html#notebook
|
|
||||||
self.notebook = Gtk.Notebook()
|
|
||||||
self.stack = Gtk.Stack()
|
self.stack = Gtk.Stack()
|
||||||
# self.stack_switcher = Gtk.StackSwitcher()
|
|
||||||
|
|
||||||
self.list_hooks = {
|
self.list_hooks = {
|
||||||
"remount_list": self.remount_list_view,
|
"remount_list": self.remount_list_view,
|
||||||
|
|||||||
Reference in New Issue
Block a user