pygui: added option to launch core-pygui into a specific session using an id
This commit is contained in:
parent
165e404184
commit
e34002b851
5 changed files with 34 additions and 26 deletions
|
@ -26,7 +26,7 @@ HEIGHT: int = 800
|
||||||
|
|
||||||
|
|
||||||
class Application(ttk.Frame):
|
class Application(ttk.Frame):
|
||||||
def __init__(self, proxy: bool) -> None:
|
def __init__(self, proxy: bool, session_id: int = None) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
# load node icons
|
# load node icons
|
||||||
NodeUtils.setup()
|
NodeUtils.setup()
|
||||||
|
@ -56,7 +56,7 @@ class Application(ttk.Frame):
|
||||||
self.core: CoreClient = CoreClient(self, proxy)
|
self.core: CoreClient = CoreClient(self, proxy)
|
||||||
self.setup_app()
|
self.setup_app()
|
||||||
self.draw()
|
self.draw()
|
||||||
self.core.setup()
|
self.core.setup(session_id)
|
||||||
|
|
||||||
def setup_scaling(self) -> None:
|
def setup_scaling(self) -> None:
|
||||||
self.fonts_size = {name: font.nametofont(name)["size"] for name in font.names()}
|
self.fonts_size = {name: font.nametofont(name)["size"] for name in font.names()}
|
||||||
|
|
|
@ -473,7 +473,7 @@ class CoreClient:
|
||||||
except grpc.RpcError as e:
|
except grpc.RpcError as e:
|
||||||
self.app.show_grpc_exception("Delete Session Error", e)
|
self.app.show_grpc_exception("Delete Session Error", e)
|
||||||
|
|
||||||
def setup(self) -> None:
|
def setup(self, session_id: int = None) -> None:
|
||||||
"""
|
"""
|
||||||
Query sessions, if there exist any, prompt whether to join one
|
Query sessions, if there exist any, prompt whether to join one
|
||||||
"""
|
"""
|
||||||
|
@ -494,10 +494,22 @@ class CoreClient:
|
||||||
)
|
)
|
||||||
group_services.add(service.name)
|
group_services.add(service.name)
|
||||||
|
|
||||||
# if there are no sessions, create a new session, else join a session
|
# join provided session, create new session, or show dialog to select an
|
||||||
|
# existing session
|
||||||
response = self.client.get_sessions()
|
response = self.client.get_sessions()
|
||||||
sessions = response.sessions
|
sessions = response.sessions
|
||||||
if len(sessions) == 0:
|
if session_id:
|
||||||
|
session_ids = set(x.id for x in sessions)
|
||||||
|
if session_id not in session_ids:
|
||||||
|
dialog = ErrorDialog(
|
||||||
|
self.app, "Join Session Error", f"{session_id} does not exist"
|
||||||
|
)
|
||||||
|
dialog.show()
|
||||||
|
self.app.close()
|
||||||
|
else:
|
||||||
|
self.join_session(session_id)
|
||||||
|
else:
|
||||||
|
if not sessions:
|
||||||
self.create_new_session()
|
self.create_new_session()
|
||||||
else:
|
else:
|
||||||
dialog = SessionsDialog(self.app, True)
|
dialog = SessionsDialog(self.app, True)
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
|
import tkinter as tk
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from core.gui.dialogs.dialog import Dialog
|
from core.gui.dialogs.dialog import Dialog
|
||||||
from core.gui.images import ImageEnum, Images
|
from core.gui.images import ImageEnum, Images
|
||||||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
from core.gui.themes import PADY
|
||||||
from core.gui.widgets import CodeText
|
from core.gui.widgets import CodeText
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -21,21 +22,15 @@ class ErrorDialog(Dialog):
|
||||||
def draw(self) -> None:
|
def draw(self) -> None:
|
||||||
self.top.columnconfigure(0, weight=1)
|
self.top.columnconfigure(0, weight=1)
|
||||||
self.top.rowconfigure(1, weight=1)
|
self.top.rowconfigure(1, weight=1)
|
||||||
|
image = Images.get(ImageEnum.ERROR, 24)
|
||||||
frame = ttk.Frame(self.top, padding=FRAME_PAD)
|
label = ttk.Label(
|
||||||
frame.grid(pady=PADY, sticky="ew")
|
self.top, text=self.title, image=image, compound=tk.LEFT, anchor=tk.CENTER
|
||||||
frame.columnconfigure(1, weight=1)
|
)
|
||||||
image = Images.get(ImageEnum.ERROR, 36)
|
|
||||||
label = ttk.Label(frame, image=image)
|
|
||||||
label.image = image
|
label.image = image
|
||||||
label.grid(row=0, column=0, padx=PADX)
|
label.grid(sticky=tk.EW, pady=PADY)
|
||||||
label = ttk.Label(frame, text=self.title)
|
|
||||||
label.grid(row=0, column=1, sticky="ew")
|
|
||||||
|
|
||||||
self.error_message = CodeText(self.top)
|
self.error_message = CodeText(self.top)
|
||||||
self.error_message.text.insert("1.0", self.details)
|
self.error_message.text.insert("1.0", self.details)
|
||||||
self.error_message.text.config(state="disabled")
|
self.error_message.text.config(state=tk.DISABLED)
|
||||||
self.error_message.grid(sticky="nsew", pady=PADY)
|
self.error_message.grid(sticky=tk.NSEW, pady=PADY)
|
||||||
|
|
||||||
button = ttk.Button(self.top, text="Close", command=lambda: self.destroy())
|
button = ttk.Button(self.top, text="Close", command=lambda: self.destroy())
|
||||||
button.grid(sticky="ew")
|
button.grid(sticky=tk.EW)
|
||||||
|
|
|
@ -40,14 +40,14 @@ def main():
|
||||||
|
|
||||||
# create node one
|
# create node one
|
||||||
position = Position(x=100, y=100)
|
position = Position(x=100, y=100)
|
||||||
node1 = Node(type=NodeType.DEFAULT, position=position)
|
node1 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||||
response = core.add_node(session_id, node1)
|
response = core.add_node(session_id, node1)
|
||||||
logging.info("created node: %s", response)
|
logging.info("created node: %s", response)
|
||||||
node1_id = response.node_id
|
node1_id = response.node_id
|
||||||
|
|
||||||
# create node two
|
# create node two
|
||||||
position = Position(x=300, y=100)
|
position = Position(x=300, y=100)
|
||||||
node2 = Node(type=NodeType.DEFAULT, position=position)
|
node2 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||||
response = core.add_node(session_id, node2)
|
response = core.add_node(session_id, node2)
|
||||||
logging.info("created node: %s", response)
|
logging.info("created node: %s", response)
|
||||||
node2_id = response.node_id
|
node2_id = response.node_id
|
||||||
|
|
|
@ -13,6 +13,7 @@ if __name__ == "__main__":
|
||||||
parser.add_argument("-l", "--level", choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], default="INFO",
|
parser.add_argument("-l", "--level", choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], default="INFO",
|
||||||
help="logging level")
|
help="logging level")
|
||||||
parser.add_argument("-p", "--proxy", action="store_true", help="enable proxy")
|
parser.add_argument("-p", "--proxy", action="store_true", help="enable proxy")
|
||||||
|
parser.add_argument("-s", "--session", type=int, help="session id to join")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# check home directory exists and create if necessary
|
# check home directory exists and create if necessary
|
||||||
|
@ -28,5 +29,5 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# start app
|
# start app
|
||||||
Images.load_all()
|
Images.load_all()
|
||||||
app = Application(args.proxy)
|
app = Application(args.proxy, args.session)
|
||||||
app.mainloop()
|
app.mainloop()
|
||||||
|
|
Loading…
Reference in a new issue