-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_frame_walls.py
More file actions
executable file
·205 lines (159 loc) · 6.46 KB
/
edit_frame_walls.py
File metadata and controls
executable file
·205 lines (159 loc) · 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import tkinter
from extra_widgets import MyButton
# from extra_tools import get_line_points
from edit_frame_grid import GridFrame, GridLeftToolsFrame, GridRightToolsFrame
from pacworms_global import CONST, VAR
class WallsFrame(tkinter.Frame):
def __init__(self, parent):
"""
:param parent:
"""
tkinter.Frame.__init__(self, parent)
# self.parent = parent
self.configure(background=CONST.WidgetsColor.frame_grid_buttons)
#
# centrer la grille -> GRID(0, 0)
#
self.columnconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
#
# init. variables
#
# self.mouse_left_right_pressed = False
# self.walls_state_value = 0
#
# frames bars left and right -> GRID(0, 0)
#
frames_bar_left = tkinter.Frame(self, background=CONST.WidgetsColor.frame_grid_buttons)
frames_bar_left.grid(column=0, row=0, padx=0, pady=2, sticky="nsw")
#
# lefts buttons
#
self.button_point = MyButton(frames_bar_left, "ICON_POINT")
self.button_line = MyButton(frames_bar_left, "ICON_LINE")
self.button_rectangle = MyButton(frames_bar_left, "ICON_RECTANGLE")
self.button_filled_rectangle = MyButton(frames_bar_left, "ICON_FILLED_RECTANGLE")
self.button_circle = MyButton(frames_bar_left, "ICON_CIRCLE")
self.button_filled_circle = MyButton(frames_bar_left, "ICON_FILLED_CIRCLE")
self.button_point.config(command=lambda: self.action_button_point())
self.button_line.config(command=lambda: self.action_button_line())
self.button_rectangle.config(command=lambda: self.action_button_rectangle())
self.button_filled_rectangle.config(command=lambda: self.action_button_filled_rectangle())
self.button_circle.config(command=lambda: self.action_button_circle())
self.button_filled_circle.config(command=lambda: self.action_button_filled_circle())
self.button_point.grid(column=0, row=0, padx=2, pady=1)
self.button_line.grid(column=1, row=0, padx=2, pady=1)
self.button_rectangle.grid(column=2, row=0, padx=2, pady=1)
self.button_filled_rectangle.grid(column=3, row=0, padx=2, pady=1)
self.button_circle.grid(column=4, row=0, padx=2, pady=1)
self.button_filled_circle.grid(column=5, row=0, padx=2, pady=1)
#
# right buttons
#
# ...
#
# frames grid -> GRID(0, 1)
#
# create GridFrame with Walls
self.obj_grid_frame = GridFrame(self, VAR.levels.walls)
self.obj_grid_frame.grid(column=0, row=1)
#
# frames bar left and right -> GRID(0, 2)
#
obj_grid_left_tools_frame = GridLeftToolsFrame(self)
obj_grid_right_tools_frame = GridRightToolsFrame(self, self.obj_grid_frame)
obj_grid_left_tools_frame.grid(column=0, row=2, sticky="nsw")
obj_grid_right_tools_frame.grid(column=0, row=2, sticky="nse")
#
# canvas mouses actions
#
self.canvas = self.obj_grid_frame.get_canvas()
self.canvas.bind('<Button-1>', self.mouse_left_click)
self.canvas.bind("<B1-Motion>", self.mouse_left_motion)
self.canvas.bind('<ButtonRelease-1>', self.mouse_left_release)
# self.canvas.bind('<Button-3>', lambda event, arg1=0: self.mouse_left_right_click(event, arg1))
# self.canvas.bind('<ButtonRelease-3>', self.mouse_left_right_release)
#
# par defaut point button
#
self.action_button_point()
def buttons_init(self):
"""
:return:
"""
self.button_point.set_state(0)
self.button_line.set_state(0)
self.button_rectangle.set_state(0)
self.button_filled_rectangle.set_state(0)
self.button_circle.set_state(0)
self.button_filled_circle.set_state(0)
def action_button_point(self):
"""
:return:
"""
self.buttons_init()
self.button_point.set_state(1)
def action_button_line(self):
"""
:return:
"""
self.buttons_init()
self.button_line.set_state(1)
def action_button_rectangle(self):
"""
:return:
"""
self.buttons_init()
self.button_rectangle.set_state(1)
def action_button_filled_rectangle(self):
"""
:return:
"""
self.buttons_init()
self.button_filled_rectangle.set_state(1)
def action_button_circle(self):
"""
:return:
"""
self.buttons_init()
self.button_circle.set_state(1)
def action_button_filled_circle(self):
"""
:return:
"""
self.buttons_init()
self.button_filled_circle.set_state(1)
def mouse_left_click(self, event):
"""
- récuperer les coordonnées du clic gauche de la souris, colonne et ligne
- 2 règles : les coordonnées colonne et ligne sont dans la grille et la case est vide
- si ok : on affiche un point et on marque la case
:param event:
:return:
"""
column, line = self.obj_grid_frame.get_grid_position(event.x, event.y)
if self.obj_grid_frame.test_mouse_coords(column, line):
if VAR.levels.walls.get_foreground(column, line) == 0:
self.obj_grid_frame.draw_box_full(column, line, CONST.EditGridElements.walls_color_fg)
VAR.levels.walls.set_foreground(CONST.EditGridElements.walls_value, column, line)
def mouse_left_motion(self, event):
"""
- afficher les coordonnées de la souris
- récuperer les coordonnées du clic gauche de la souris, colonne et ligne
- 2 règles : les coordonnées colonne et ligne sont dans la grille et la case est vide
- si ok : on affiche un point et on marque la case
:param event:
:return:
"""
self.obj_grid_frame.show_mouse_coords(event)
column, line = self.obj_grid_frame.get_grid_position(event.x, event.y)
if self.obj_grid_frame.test_mouse_coords(column, line):
if VAR.levels.walls.get_foreground(column, line) == 0:
self.obj_grid_frame.draw_box_full(column, line, CONST.EditGridElements.walls_color_fg)
VAR.levels.walls.set_foreground(CONST.EditGridElements.walls_value, column, line)
def mouse_left_release(self, event):
"""
:param event:
:return:
"""
pass