Äīźóģåķņ āē’ņ čē źżųą ļīčńźīāīé ģąųčķū. Ąäšåń īščćčķąėüķīćī äīźóģåķņą : http://kodomo.fbb.msu.ru/trac/cca/changeset/85%3Aeec51a7eb05c
Äąņą čēģåķåķč’: Unknown
Äąņą čķäåźńčšīāąķč’: Sun Apr 10 09:19:53 2016
Źīäčšīāźą: UTF-8
Changeset 85:eec51a7eb05c ? Cyclyc Cell Automata

Changeset 85:eec51a7eb05c


Ignore:
Timestamp:
12/13/10 01:28:02 (5 years ago)
Author:
is_rusinov
Branch:
default
Message:

correct mistake in mouse draw fix #20

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Interface.py

    r79 r85 š
    1313class Handlers(object):š
    1414        š
    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š
    1616                self.cell_size = cell_sizeš
    1717                self.line_width = line_widthš
    1818                self.delay = delayš
    19š                self.offset_x = offset_xš
    20š                self.offset_y = offset_yš
    š19                self.dx = dxš
    š20                self.dy = dyš
    2121                self.after_id = 0š
    22š                self.mouse_offset_x = 0š
    23š                self.mouse_offset_y = 0š
    2422                self.mouse_zoom = 0š
    2523                self.zoom_divisor = 1š
    ? ? š
    144142                self.cells = []š
    145143                shift = self.cell_size + self.line_widthš
    146š                left = -self.offset_x + self.line_widthš
    147š                top = -self.offset_y + self.line_widthš
    š144                left = self.line_widthš
    š145                top = self.line_widthš
    148146                for row in range(automata.height):š
    149147                        self.cells.append([])š
    ? ? š
    197195        š
    198196        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)š
    201202                if self.col1 >= 0 and self.row1 >= 0:š
    202203                        self.new_state([(self.row1, self.col1)])š
    203204        š
    204205        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)š
    207208                if not (self.col1 == col and self.row1 == row):š
    208209                        if abs(self.col1 - col) <= 1 and abs(self.row1 - row) <= 1:š
    ? ? š
    214215        š
    215216        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)š
    218222                if self.col1 >= 0 and self.row1 >= 0:š
    219223                        self.new_state([(self.row3, self.col3)], -1)š
    220224        š
    221225        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)š
    224228                if not (self.col3 == col and self.row3 == row):š
    225229                        if abs(self.col3 - col) <= 1 and abs(self.row3 - row) <= 1:š
    ? ? š
    235239        def release_key(self, event):# drawerš
    236240                self.char = Noneš
    237š        š
    238š        def press1_ctrl(self, event):# change_offset (B1+ctrl)š
    239š                canvas.focus_set()š
    240š                self.mouse_offset_x = event.xš
    241š                self.mouse_offset_y = event.yš
    242š        š
    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.xš
    247š                self.mouse_offset_y = event.yš
    248š                self.draw()š
    249š        š
    250š        def press13(self, event):# zoomš
    251š                canvas.focus_set()š
    252š                self.mouse_zoom = event.yš
    253š        š
    254š        def motion13(self, event):# zoomš
    255š                delta = (event.y - self.mouse_zoom) / self.zoom_divisorš
    256š                self.cell_size = self.cell_size + deltaš
    257š                if self.cell_size > 50:š
    258š                        self.cell_size = 50š
    259š                if self.cell_size < 1:š
    260š                        self.cell_size = 1š
    261š                self.mouse_zoom = event.yš
    262š                self.draw()š
    263241        š
    264242        def to_top(self):# replace choosen state to topš
    ? ? š
    519497canvas.bind_all("<KeyPress>", handlers.press_key)š
    520498canvas.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)š
    525499š
    526500scroll_x=Scrollbar(root, orient="horizontal")š
Note: See TracChangeset for help on using the changeset viewer.