96 lines
2.9 KiB
Python
Executable File
96 lines
2.9 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
#
|
|
# Copyright © 2024 Simon Forman
|
|
#
|
|
# This file is part of game
|
|
#
|
|
# game is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# game is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with game. If not see <http://www.gnu.org/licenses/>.
|
|
#
|
|
from tkinter import *
|
|
from tkinter.ttk import Notebook
|
|
|
|
import data, stars
|
|
|
|
|
|
class App:
|
|
'''
|
|
A canvas with scrolling support.
|
|
'''
|
|
|
|
def __init__(self, master=None, *canvas_args, **canvas_kw):
|
|
notebook = self.notebook = Notebook(master)
|
|
notebook.enable_traversal()
|
|
|
|
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?
|
|
|
|
frame.rowconfigure(0, weight=1)
|
|
frame.columnconfigure(0, weight=1)
|
|
|
|
# When putting a frame into a Notebook you evidently don't need
|
|
# to pack() it. Maybe because of the weights? I'm not setting
|
|
# the sticky arg to Notebook.add().
|
|
#frame.pack(expand=True, fill=BOTH)
|
|
|
|
canvas = self.canvas = Canvas(frame, *canvas_args, **canvas_kw)
|
|
|
|
scrollY = self.scrollY = Scrollbar(
|
|
frame,
|
|
orient=VERTICAL,
|
|
command=canvas.yview,
|
|
)
|
|
canvas['yscrollcommand'] = scrollY.set
|
|
|
|
scrollX = self.scrollX = Scrollbar(
|
|
frame,
|
|
orient=HORIZONTAL,
|
|
command=canvas.xview,
|
|
)
|
|
canvas['xscrollcommand'] = scrollX.set
|
|
|
|
canvas.grid(row=0, column=0, sticky=N+S+E+W)
|
|
scrollY.grid(row=0, column=1, sticky=N+S)
|
|
scrollX.grid(row=1, column=0, sticky=E+W)
|
|
|
|
canvas.bind("<Configure>", self.handle_canvas_resize)
|
|
|
|
notebook.add(frame, text='Star Map', underline=5)
|
|
notebook.pack(expand=True, fill=BOTH)
|
|
|
|
def handle_canvas_resize(self, event):
|
|
print(event)
|
|
|
|
|
|
data.open_db()
|
|
|
|
root = Tk()
|
|
app = App(root, bg='black', scrollregion=(0, 0, stars.WIDTH, stars.HEIGHT))
|
|
|
|
for x, y, radius in stars.iter_stars(data.conn):
|
|
star_id = app.canvas.create_oval(
|
|
x - radius, y - radius,
|
|
x + radius, y + radius,
|
|
fill='yellow',
|
|
outline='yellow',
|
|
activefill='#550',
|
|
activeoutline='orange',
|
|
activewidth=3,
|
|
)
|
|
app.canvas.tag_bind(star_id, '<Enter>', (lambda event, x=x, y=y: root.title(f'{x}, {y}')))
|
|
|
|
##app.frame.mainloop()
|
|
##data.close_db()
|