minor cleanup, mess with bind tags
This commit is contained in:
parent
effc940235
commit
be55cc5432
6
data.py
6
data.py
|
|
@ -39,6 +39,7 @@ def initialize_db_tables(filename):
|
|||
|
||||
|
||||
def close_db():
|
||||
global conn
|
||||
if conn:
|
||||
conn.close()
|
||||
conn = None
|
||||
|
|
@ -54,11 +55,6 @@ def open_db(filename=FILENAME):
|
|||
return conn
|
||||
|
||||
|
||||
def generate_stars(width, height, minimum_distance_between_stars):
|
||||
for x, y in poisson(width, height, minimum_distance_between_stars):
|
||||
yield x, y, round(1 + expovariate(1))
|
||||
|
||||
|
||||
def main(filename):
|
||||
print('Initializing db file', filename)
|
||||
conn = initialize_db_tables(filename)
|
||||
|
|
|
|||
4
stars.py
4
stars.py
|
|
@ -18,10 +18,11 @@
|
|||
# along with game. If not see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from random import randint, expovariate, seed
|
||||
import sqlite3
|
||||
from poisson import poisson
|
||||
|
||||
|
||||
seed(23)
|
||||
|
||||
MINIMUM_DISTANCE_BETWEEN_STARS = 160
|
||||
WIDTH, HEIGHT = 10240, 7680
|
||||
|
||||
|
|
@ -38,7 +39,6 @@ def generate_stars(width, height, minimum_distance_between_stars):
|
|||
|
||||
def init_db(conn):
|
||||
print('Generating star data.')
|
||||
seed(23)
|
||||
c = conn.cursor()
|
||||
for values in generate_stars(WIDTH, HEIGHT, MINIMUM_DISTANCE_BETWEEN_STARS):
|
||||
c.execute('insert into stars values (?, ?, ?)', values)
|
||||
|
|
|
|||
10
ui.py
10
ui.py
|
|
@ -32,6 +32,7 @@ class App:
|
|||
frame = self.frame = Frame(root, bg='green')
|
||||
frame.rowconfigure(0, weight=1)
|
||||
frame.columnconfigure(0, weight=1)
|
||||
frame.pack(expand=True, fill=BOTH)
|
||||
|
||||
C = self.canvas = Canvas(frame, *canvas_args, **canvas_kw)
|
||||
|
||||
|
|
@ -63,13 +64,18 @@ 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(
|
||||
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, sid=star_id, x=x, y=y: root.title(f'{x}, {y}')))
|
||||
|
||||
app.frame.mainloop()
|
||||
data.close_db()
|
||||
|
|
|
|||
Loading…
Reference in New Issue