From 41860ace77fcaef171b038bb19f5a96a06601819 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Sat, 13 Apr 2024 22:25:29 -0700 Subject: [PATCH] Star System tab It's janky (I used the canvas item id for the ovals rather than the DB id column values!) but it kind of works. It's a little too dramatic to switch tabs, I think it would tend to undermine or at least not support spacial memory? It seems like a reasonable thing to bind the details of the stars when we draw them, because we have them then, eh? The other thing to do would be just bind the DB id and look up info in the DB as needed in event handlers and such? --- README.md | 13 +++++++++++++ ui.py | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 351d916..944be24 100644 --- a/README.md +++ b/README.md @@ -160,3 +160,16 @@ result between the parties) can stand in for a battle or war in this game. +Sat Apr 13 21:46:16 PDT 2024 + +For selecting a star and showing some data about it one option is a +static pane of widgets, like on the side. Another option is to have a +tooltip kind of a thing, but not transient as in you should be able to +select text on it? click controls? +A third option is to populate a notebook tab and switch to it? That +seems dramatic. + +The first and second options are easy to implement, the tooltip needs +positioning logic. Let's exercise the notebook... + + diff --git a/ui.py b/ui.py index 3f6ce98..dc913da 100755 --- a/ui.py +++ b/ui.py @@ -24,6 +24,8 @@ from tkinter.ttk import Notebook import data, stars +DARK_GRAY = '#222' + class App: ''' A canvas with scrolling support. @@ -33,6 +35,8 @@ class App: notebook = self.notebook = Notebook(master) notebook.enable_traversal() + # Star Map + frame = self.frame = Frame(None, background='green') # When putting a frame into a Notebook you use the add() method. # but what should the parent of the frame be? The Notebook? @@ -67,12 +71,34 @@ class App: canvas.bind("", self.handle_canvas_resize) + # Star System + + star_system_frame = self.star_system_frame = Frame(None, bg=DARK_GRAY) + star_system_frame.columnconfigure(0, weight=1) + + star_name_label = self.star_name_label = Label(star_system_frame, text='Star Name', bg='green', fg='white', anchor=W) + star_name_label.grid(row=0, column=0, sticky=E+W) + + star_x_label = self.star_x_label = Label(star_system_frame, text='x', bg='green', fg='white', anchor=W) + star_x_label.grid(row=1, column=0, sticky=E+W) + star_y_label = self.star_y_label = Label(star_system_frame, text='y', bg='green', fg='white', anchor=W) + star_y_label.grid(row=2, column=0, sticky=E+W) + + # Notebook Tabs + notebook.add(frame, text='Star Map', underline=5) + notebook.add(star_system_frame, text='Star System', underline=6) + self.star_system_tab_id = notebook.tabs()[-1] notebook.pack(expand=True, fill=BOTH) def handle_canvas_resize(self, event): print(event) + def update_star_system_tab(self, star_id, x, y): + self.star_name_label['text'] = str(star_id) + self.star_x_label['text'] = f'x: {x}' + self.star_y_label['text'] = f'y: {y}' + self.notebook.select(self.star_system_tab_id) data.open_db() @@ -89,7 +115,13 @@ for x, y, radius in stars.iter_stars(data.conn): activeoutline='orange', activewidth=3, ) - app.canvas.tag_bind(star_id, '', (lambda event, x=x, y=y: root.title(f'{x}, {y}'))) + app.canvas.tag_bind( + star_id, + '', + (lambda event, star_id=star_id, x=x, y=y: + app.update_star_system_tab(star_id, x, y) + ) + ) ##app.frame.mainloop() ##data.close_db()