Show/hide/toggle reticule.

This commit is contained in:
Simon Forman 2024-04-16 14:04:47 -07:00
parent 8e88347e37
commit 59b0241616
1 changed files with 19 additions and 5 deletions

View File

@ -20,6 +20,9 @@
# #
RETICULE = 'reticule_tag'
class Reticule: class Reticule:
def __init__(self, canvas, width, height, radius_x=35, radius_y=20, color='green'): def __init__(self, canvas, width, height, radius_x=35, radius_y=20, color='green'):
@ -58,11 +61,11 @@ class Reticule:
w, h = self.width, self.height w, h = self.width, self.height
coords = self.get_reticule_coords(w >> 1, h >> 1) # Center. coords = self.get_reticule_coords(w >> 1, h >> 1) # Center.
append(canvas.create_line(*next(coords), fill=self.color)) append(canvas.create_line(*next(coords), tags=RETICULE, fill=self.color))
append(canvas.create_line(*next(coords), fill=self.color)) append(canvas.create_line(*next(coords), tags=RETICULE, fill=self.color))
append(canvas.create_line(*next(coords), fill=self.color)) append(canvas.create_line(*next(coords), tags=RETICULE, fill=self.color))
append(canvas.create_line(*next(coords), fill=self.color)) append(canvas.create_line(*next(coords), tags=RETICULE, fill=self.color))
append(canvas.create_oval(*next(coords), outline=self.color)) append(canvas.create_oval(*next(coords), tags=RETICULE, outline=self.color))
def set_reticule(self, x, y): def set_reticule(self, x, y):
self.xy_cache = x, y self.xy_cache = x, y
@ -73,6 +76,17 @@ class Reticule:
def handle_set_event(self, event): def handle_set_event(self, event):
self.set_reticule(event.x, event.y) self.set_reticule(event.x, event.y)
def hide(self):
self.canvas.itemconfig(RETICULE, state=HIDDEN)
def show(self):
self.canvas.itemconfig(RETICULE, state=NORMAL)
def toggle(self):
current_state = self.canvas.itemconfig(RETICULE, 'state')[4]
new_state = NORMAL if current_state == HIDDEN else HIDDEN
self.canvas.itemconfig(RETICULE, state=new_state)
if __name__ == '__main__': if __name__ == '__main__':
from tkinter import * from tkinter import *