Changeset 85:eec51a7eb05c
- Timestamp:
- 12/13/10 01:28:02 (5 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Interface.py
r79 r85 13 13 class Handlers(object): 14 14 15 def __init__(self, cell_size=8, line_width=1 ,delay=10, offset_x=0, offset_y=0):# cell_size is size of cell, including line width, if there is it 15 def __init__(self, cell_size=8, line_width=1 ,delay=10, dx=0, dy=0):# cell_size is size of cell, including line width, if there is it 16 16 self.cell_size = cell_size 17 17 self.line_width = line_width 18 18 self.delay = delay 19 self. offset_x = offset_x20 self. offset_y = offset_y 19 self.dx = dx 20 self.dy = dy 21 21 self.after_id = 0 22 self.mouse_offset_x = 023 self.mouse_offset_y = 024 22 self.mouse_zoom = 0 25 23 self.zoom_divisor = 1 ? ? 144 142 self.cells = [] 145 143 shift = self.cell_size + self.line_width 146 left = -self.offset_x +self.line_width147 top = -self.offset_y +self.line_width 144 left = self.line_width 145 top = self.line_width 148 146 for row in range(automata.height): 149 147 self.cells.append([]) ? ? 197 195 198 196 def press1(self, event):# drawer 199 self.col1 = event.x / (self.cell_size + self.line_width) - self.offset_x 200 self.row1 = event.y / (self.cell_size + self.line_width) - self.offset_y 197 scr_reg = canvas.cget("scrollregion").split() 198 self.dx = int(scroll_x.get()[0] * int(scr_reg[2])) 199 self.dy = int(scroll_y.get()[0] * int(scr_reg[3])) 200 self.col1 = (event.x + self.dx) / (self.cell_size + self.line_width) 201 self.row1 = (event.y + self.dy) / (self.cell_size + self.line_width) 201 202 if self.col1 >= 0 and self.row1 >= 0: 202 203 self.new_state([(self.row1, self.col1)]) 203 204 204 205 def motion1(self, event):# drawer 205 col = (event.x - self.offset_x * (self.cell_size + self.line_width)) / (self.cell_size + self.line_width)206 row = (event.y - self.offset_y * (self.cell_size + self.line_width)) / (self.cell_size + self.line_width) 206 col = (event.x + self.dx) / (self.cell_size + self.line_width) 207 row = (event.y + self.dy) / (self.cell_size + self.line_width) 207 208 if not (self.col1 == col and self.row1 == row): 208 209 if abs(self.col1 - col) <= 1 and abs(self.row1 - row) <= 1: ? ? 214 215 215 216 def press3(self, event):# drawer 216 self.col3 = event.x / (self.cell_size + self.line_width) - self.offset_x 217 self.row3 = event.y / (self.cell_size + self.line_width) - self.offset_y 217 scr_reg = canvas.cget("scrollregion").split() 218 self.dx = int(scroll_x.get()[0] * int(scr_reg[2])) 219 self.dy = int(scroll_y.get()[0] * int(scr_reg[3])) 220 self.col3 = (event.x + self.dx) / (self.cell_size + self.line_width) 221 self.row3 = (event.y + self.dy) / (self.cell_size + self.line_width) 218 222 if self.col1 >= 0 and self.row1 >= 0: 219 223 self.new_state([(self.row3, self.col3)], -1) 220 224 221 225 def motion3(self, event):# drawer 222 col = (event.x - self.offset_x * (self.cell_size + self.line_width)) / (self.cell_size + self.line_width)223 row = (event.y - self.offset_y * (self.cell_size + self.line_width)) / (self.cell_size + self.line_width) 226 col = (event.x + self.dx) / (self.cell_size + self.line_width) 227 row = (event.y + self.dy) / (self.cell_size + self.line_width) 224 228 if not (self.col3 == col and self.row3 == row): 225 229 if abs(self.col3 - col) <= 1 and abs(self.row3 - row) <= 1: ? ? 235 239 def release_key(self, event):# drawer 236 240 self.char = None 237 238 def press1_ctrl(self, event):# change_offset (B1+ctrl)239 canvas.focus_set()240 self.mouse_offset_x = event.x241 self.mouse_offset_y = event.y242 243 def motion1_ctrl(self, event):# change_offset (B1+ctrl)244 self.offset_x = (event.x - self.mouse_offset_x) / (self.cell_size + self.line_width)245 self.offset_y = (event.y - self.mouse_offset_y) / (self.cell_size + self.line_width)246 self.mouse_offset_x = event.x247 self.mouse_offset_y = event.y248 self.draw()249 250 def press13(self, event):# zoom251 canvas.focus_set()252 self.mouse_zoom = event.y253 254 def motion13(self, event):# zoom255 delta = (event.y - self.mouse_zoom) / self.zoom_divisor256 self.cell_size = self.cell_size + delta257 if self.cell_size > 50:258 self.cell_size = 50259 if self.cell_size < 1:260 self.cell_size = 1261 self.mouse_zoom = event.y262 self.draw()263 241 264 242 def to_top(self):# replace choosen state to top ? ? 519 497 canvas.bind_all("<KeyPress>", handlers.press_key) 520 498 canvas.bind_all("<KeyRelease>", handlers.release_key) 521 #canvas.bind("<Control-ButtonPress-1>", handlers.press1_ctrl)522 #canvas.bind("<Control-B1-Motion>", handlers.motion1_ctrl)523 #canvas.bind("<Shift-ButtonPress-1>", handlers.press13)524 #canvas.bind("<Shift-ButtonPress-1>", handlers.motion13)525 499 526 500 scroll_x=Scrollbar(root, orient="horizontal")
Note: See TracChangeset
for help on using the changeset viewer.