76 lines
2.1 KiB
Python
Executable File
76 lines
2.1 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 *
|
|
|
|
import data, stars
|
|
|
|
|
|
class App:
|
|
'''
|
|
A canvas with scrolling support.
|
|
'''
|
|
|
|
def __init__(self, master=None, *canvas_args, **canvas_kw):
|
|
frame = self.frame = Frame(root, bg='green')
|
|
frame.rowconfigure(0, weight=1)
|
|
frame.columnconfigure(0, weight=1)
|
|
|
|
C = self.canvas = Canvas(frame, *canvas_args, **canvas_kw)
|
|
|
|
scrollY = self.scrollY = Scrollbar(
|
|
frame,
|
|
orient=VERTICAL,
|
|
command=C.yview,
|
|
)
|
|
C['yscrollcommand'] = scrollY.set
|
|
|
|
scrollX = self.scrollX = Scrollbar(
|
|
frame,
|
|
orient=HORIZONTAL,
|
|
command=C.xview,
|
|
)
|
|
C['xscrollcommand'] = scrollX.set
|
|
|
|
C.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)
|
|
|
|
C.bind("<Configure>", self.handle_canvas_resize)
|
|
|
|
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))
|
|
app.frame.pack(expand=True, fill=BOTH)
|
|
|
|
for x, y, radius in stars.iter_stars(data.conn):
|
|
app.canvas.create_oval(
|
|
x - radius, y - radius,
|
|
x + radius, y + radius,
|
|
fill='yellow',
|
|
)
|
|
|
|
app.frame.mainloop()
|