pygui: able to start session with multiple canvases, just using 1 canvas for now
This commit is contained in:
parent
6f43d0e88f
commit
9621df6bc4
5 changed files with 34 additions and 24 deletions
|
@ -1,7 +1,7 @@
|
|||
import logging
|
||||
import tkinter as tk
|
||||
from tkinter import BooleanVar, messagebox, ttk
|
||||
from typing import TYPE_CHECKING, Dict, Optional, Set, Tuple
|
||||
from typing import TYPE_CHECKING, Dict, Optional, Set, Tuple, ValuesView
|
||||
|
||||
from core.api.grpc.wrappers import Session
|
||||
from core.gui.graph import tags
|
||||
|
@ -77,20 +77,28 @@ class CanvasManager:
|
|||
self.notebook = ttk.Notebook(self.master)
|
||||
self.notebook.grid(sticky=tk.NSEW, pady=1)
|
||||
|
||||
def next_id(self) -> int:
|
||||
def _next_id(self) -> int:
|
||||
_id = 1
|
||||
tab_ids = set(self.unique_ids.values())
|
||||
while _id in tab_ids:
|
||||
_id += 1
|
||||
return _id
|
||||
|
||||
def current(self) -> CanvasGraph:
|
||||
unique_id = self.notebook.select()
|
||||
tab_id = self.unique_ids[unique_id]
|
||||
return self.canvases[tab_id]
|
||||
|
||||
def all(self) -> ValuesView[CanvasGraph]:
|
||||
return self.canvases.values()
|
||||
|
||||
def add_canvas(self) -> CanvasGraph:
|
||||
# create tab frame
|
||||
tab = ttk.Frame(self.notebook, padding=0)
|
||||
tab.grid(sticky=tk.NSEW)
|
||||
tab.columnconfigure(0, weight=1)
|
||||
tab.rowconfigure(0, weight=1)
|
||||
tab_id = self.next_id()
|
||||
tab_id = self._next_id()
|
||||
self.notebook.add(tab, text=f"Canvas {tab_id}")
|
||||
unique_id = self.notebook.tabs()[-1]
|
||||
logging.info("tab(%s) is %s", unique_id, tab_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue