pygui: added option to launch core-pygui into a specific session using an id

This commit is contained in:
Blake Harnden 2020-07-22 17:18:35 -07:00
parent 165e404184
commit e34002b851
5 changed files with 34 additions and 26 deletions

View file

@ -26,7 +26,7 @@ HEIGHT: int = 800
class Application(ttk.Frame):
def __init__(self, proxy: bool) -> None:
def __init__(self, proxy: bool, session_id: int = None) -> None:
super().__init__()
# load node icons
NodeUtils.setup()
@ -56,7 +56,7 @@ class Application(ttk.Frame):
self.core: CoreClient = CoreClient(self, proxy)
self.setup_app()
self.draw()
self.core.setup()
self.core.setup(session_id)
def setup_scaling(self) -> None:
self.fonts_size = {name: font.nametofont(name)["size"] for name in font.names()}

View file

@ -473,7 +473,7 @@ class CoreClient:
except grpc.RpcError as 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
"""
@ -494,14 +494,26 @@ class CoreClient:
)
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()
sessions = response.sessions
if len(sessions) == 0:
self.create_new_session()
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:
dialog = SessionsDialog(self.app, True)
dialog.show()
if not sessions:
self.create_new_session()
else:
dialog = SessionsDialog(self.app, True)
dialog.show()
except grpc.RpcError as e:
logging.exception("core setup error")
dialog = ErrorDialog(self.app, "Setup Error", e.details())

View file

@ -1,9 +1,10 @@
import tkinter as tk
from tkinter import ttk
from typing import TYPE_CHECKING, Optional
from core.gui.dialogs.dialog import Dialog
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
if TYPE_CHECKING:
@ -21,21 +22,15 @@ class ErrorDialog(Dialog):
def draw(self) -> None:
self.top.columnconfigure(0, weight=1)
self.top.rowconfigure(1, weight=1)
frame = ttk.Frame(self.top, padding=FRAME_PAD)
frame.grid(pady=PADY, sticky="ew")
frame.columnconfigure(1, weight=1)
image = Images.get(ImageEnum.ERROR, 36)
label = ttk.Label(frame, image=image)
image = Images.get(ImageEnum.ERROR, 24)
label = ttk.Label(
self.top, text=self.title, image=image, compound=tk.LEFT, anchor=tk.CENTER
)
label.image = image
label.grid(row=0, column=0, padx=PADX)
label = ttk.Label(frame, text=self.title)
label.grid(row=0, column=1, sticky="ew")
label.grid(sticky=tk.EW, pady=PADY)
self.error_message = CodeText(self.top)
self.error_message.text.insert("1.0", self.details)
self.error_message.text.config(state="disabled")
self.error_message.grid(sticky="nsew", pady=PADY)
self.error_message.text.config(state=tk.DISABLED)
self.error_message.grid(sticky=tk.NSEW, pady=PADY)
button = ttk.Button(self.top, text="Close", command=lambda: self.destroy())
button.grid(sticky="ew")
button.grid(sticky=tk.EW)

View file

@ -40,14 +40,14 @@ def main():
# create node one
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)
logging.info("created node: %s", response)
node1_id = response.node_id
# create node two
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)
logging.info("created node: %s", response)
node2_id = response.node_id

View file

@ -13,6 +13,7 @@ if __name__ == "__main__":
parser.add_argument("-l", "--level", choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], default="INFO",
help="logging level")
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()
# check home directory exists and create if necessary
@ -28,5 +29,5 @@ if __name__ == "__main__":
# start app
Images.load_all()
app = Application(args.proxy)
app = Application(args.proxy, args.session)
app.mainloop()