def __init__(self, parent, tile_size, grid_vm=None): Frame.__init__(self, parent, relief=RAISED, borderwidth=1) self.parent = parent self.tile_size = tile_size self.grid_vm = grid_vm self.columnconfigure(0, weight=1) self.columnconfigure(1, pad=3) self.rowconfigure(0, weight=1) self.rowconfigure(1, pad=3) hbar = Scrollbar(self, orient=HORIZONTAL) vbar = Scrollbar(self, orient=VERTICAL) canvas = Canvas(self, xscrollcommand=hbar.set, yscrollcommand=vbar.set) self.canvas = canvas self.lines = [] canvas.bind_all("<MouseWheel>", self._on_mousewheel_vertical) canvas.bind_all("<Shift-MouseWheel>", self._on_mousewheel_horizontal) # Set up scroll bars hbar.pack(side=BOTTOM, fill=X) hbar.config(command=canvas.xview) vbar.pack(side=RIGHT, fill=Y) vbar.config(command=canvas.yview) canvas.grid(column=0, row=0, sticky=N + W + E + S) hbar.grid(column=0, row=1, sticky=W + E) vbar.grid(column=1, row=0, sticky=N + S) if grid_vm: self.set_vm(grid_vm)
class PhyUI(): def callback_switcher(self): """ Callback function for switching status between 'freezed' and 'on going'. """ play_ref = self.button_play if not self.locked : play_ref.config(text = "Play") self.locked = True else: play_ref.config(text = "Freeze") self.locked = False def keyevent_up_press(self, event): """ Callback for pressing up key. """ self.mouse_lock = True self.selected_user_accel_factor[0] = 1 def keyevent_up_release(self, event): """ Callback for releasing up key. """ self.mouse_lock = False self.selected_user_accel_factor[0] = 0 def keyevent_down_press(self, event): """ Callback for pressing down key. """ self.mouse_lock = True self.selected_user_accel_factor[1] = 1 def keyevent_down_release(self, event): """ Callback for releasing down key. """ self.mouse_lock = False self.selected_user_accel_factor[1] = 0 def keyevent_left_press(self, event): """ Callback for pressing left key. """ self.mouse_lock = True self.selected_user_accel_factor[2] = 1 def keyevent_left_release(self, event): """ Callback for releasing left key. """ self.mouse_lock = False self.selected_user_accel_factor[2] = 0 def keyevent_right_press(self, event): """ Callback for pressing right key """ self.mouse_lock = True self.selected_user_accel_factor[3] = 1 def keyevent_right_release(self, event): """ Callback for releasing right key """ self.mouse_lock = False self.selected_user_accel_factor[3] = 0 def __init__(self, root_handle, canvas_width, canvas_height): """ Setup the whole application.""" self.locked = True # True for freeze. self.mouse_lock = False # True for locking the mouse behavior. self.selected = None # What ball is selected now? self.selected_user_accel_factor = [0, 0, 0, 0] # Acceleration from user's keypress event self.selected_user_accel_val = [Vect2D(0, 15), Vect2D(0, -5), Vect2D(-5, 0), Vect2D(5, 0)] self.circles = [] # Reference to all the balls. # Initialize the main variables for the application self.frm_main = Frame(root_handle) self.frm_side_top = LabelFrame(root_handle, text = "Realtime Parameters:") self.frm_side_bot = Frame(root_handle) # Setup the frames self.canv_width = canvas_width self.canv_height = canvas_height self.canvas_base = Vect2D(0, self.canv_height) self.canvas = Canvas( self.frm_main, width = self.canv_width, height = self.canv_height, bg = "#cccccc") # Setup the canvas self.canvas.bind_all("<KeyPress-w>", self.keyevent_up_press) self.canvas.bind_all("<KeyRelease-w>", self.keyevent_up_release) self.canvas.bind_all("<KeyPress-a>", self.keyevent_left_press) self.canvas.bind_all("<KeyRelease-a>", self.keyevent_left_release) self.canvas.bind_all("<KeyPress-d>", self.keyevent_right_press) self.canvas.bind_all("<KeyRelease-d>", self.keyevent_right_release) self.canvas.bind_all("<KeyPress-s>", self.keyevent_down_press) self.canvas.bind_all("<KeyRelease-s>", self.keyevent_down_release) # Setup all keys self.button_play = Button(self.frm_side_bot, text = "Play", command = self.callback_switcher) self.button_add = Button(self.frm_side_bot, text = "Exit", command = root_handle.quit) # Setup all the buttons side_names = ["Mass", "Positioin", "Velocity", "Acceleration"] self.side_label = [] self.side_entry = [] for name in side_names: self.side_label.append(Label(self.frm_side_top, text = name + ":")) self.side_entry.append(Label(self.frm_side_top, width = 20)) # Setup information area located on the sidebar self.frm_main.grid(row = 0, column = 0, rowspan = 2) self.frm_side_top.grid(row = 0, column = 1, sticky = "S") self.frm_side_bot.grid(row = 1, column = 1, sticky = "S") self.canvas.grid(row = 0, column = 0, columnspan = 2) self.button_play.grid(row = 1, column = 0, sticky = "E") self.button_add.grid(row = 1, column = 1, sticky = "W") for i in xrange(len(self.side_label)): self.side_label[i].grid(row = i, column = 0) self.side_entry[i].grid(row = i, column = 1) # Build up the layout def set_viewport(self, math_bl, math_tr): """ Set the translation rate. You should call this before calling trans or rev_trans. """ self.scale_factor = Vect2D( self.canv_width / float(math_tr.x - math_bl.x), -self.canv_height / float(math_tr.y - math_bl.y)) self.math_base = math_bl def trans(self, pos): """ Translation (from math coord to canvas coord).""" return (pos - self.math_base).scale(self.scale_factor) + \ self.canvas_base def rev_trans(self, pos): """ Reverse translation (from canvas coord to math coord).""" return (pos - self.canvas_base).rev_scale(self.scale_factor) + \ self.math_base def canvas_refresh(self, id, vertexes): """ Refresh the canvas """ self.canvas.coords(id, vertexes) def update_side_bot(self): """ Update the information posted on the side bar.""" if self.selected: self.side_entry[0].config(text = str(self.selected.mass)) self.side_entry[1].config(text = self.selected.shift.get_str()) self.side_entry[2].config(text = self.selected.velo.get_str()) self.side_entry[3].config(text = self.selected.accel.get_str()) else: for i in xrange(4): self.side_entry[i].config(text = "") def create_circle(self, vertexes): """ Create a circle graphically and return the id of the object. """ return self.canvas.create_oval( vertexes, fill="white" ) def create_line(self, vertexes): """ Create a line graphically and return the id of the object.""" return self.canvas.create_line(vertexes) def register_trigger(self, obj, real_interval, math_interval): """ Call this for hooking any simulated objects.""" self.canvas.after( real_interval, obj.refresh, real_interval, math_interval)
class text_canvas(Frame): def __init__(self, parent, font_size, input_handler, filename): Frame.__init__(self, parent) self.parent = parent self.text_font = tkFont.Font(family='Monaco', size=font_size, weight='bold') self.filename = filename self.cheight, self.cwidth, self.line_num_spacing = font_size, self.text_font.measure('c'), 50 self.line_height = ((self.winfo_screenheight() - self.cheight)/(self.cheight + 2) - 4) self.init_UI(input_handler) def init_UI(self, input_handler): self.parent.title('') self.pack(fill=BOTH, expand=1) self.init_canvas(input_handler) def get_dimensions(self): return { 'cheight': self.cheight, 'cwidth': self.cwidth, 'line_num_spacing':self.line_num_spacing, 'line_height': self.line_height, 'screen_width': self.winfo_screenwidth(), 'screen_height': self.winfo_screenheight() } def init_canvas(self, input_handler): self.canvas = Canvas(self, highlightthickness=0, width=self.winfo_screenwidth(), height=self.winfo_screenheight(), bg=options['background_color']) self.canvas.pack() self.canvas.focus_set() self.bind_events(input_handler) def clear_all(self): self.canvas.delete('all') def get_line_height(self): return self.line_height def get_grid_y(self, y): return self.cheight * y + (y * 2) def write_line_grid(self, y, line): for token in line: self.write_text_grid(token[0], y, token[1], token[2]) # write line of text at given grid co-ordinates def write_text_grid(self, x, y, text, color=options['text_color']): x_val = self.cwidth * x + self.line_num_spacing # 2 pixel spacing between each line y_val = self.cheight * y + (y * 2) self.canvas.create_text(x_val, y_val, anchor='nw', text=text, font=self.text_font, fill=color) def write_status_line(self, text, textcolor=options['status_text_color'], backgroundcolor=options['status_background_color']): y = self.line_height + 1 self.canvas.create_rectangle(0, self.cheight * y + (y * 2), self.winfo_screenwidth(), self.cheight * y + (y * 2) + self.cheight + 4, fill=backgroundcolor, outline=backgroundcolor) self.write_text_grid(0, self.line_height + 1, text, textcolor) def draw_highlight_grid(self, y, x1, x2, highlightcolor=options['text_highlight_color']): y_val = self.cheight * y + (y * 2) x1_val = self.cwidth * x1 + self.line_num_spacing x2_val = self.cwidth * x2 + self.line_num_spacing self.canvas.create_rectangle(x1_val, y_val, x2_val, y_val + self.cheight + 4, fill=highlightcolor, outline=highlightcolor) def draw_line_numbers(self, start, highlightcolor=options['line_num_highlight_color'], textcolor=options['line_num_text_color']): self.canvas.create_rectangle(0, 0, self.line_num_spacing / 2, self.winfo_screenheight(), fill=highlightcolor, outline=highlightcolor) for i in range(self.line_height + 1): self.canvas.create_text(0, self.cheight * i + (i * 2), anchor='nw', text=str(start + i), font=self.text_font, fill=textcolor) def draw_cursor(self, x, y, highlightcolor=options['cursor_highlight_color'], cursorcolor=options['cursor_color']): x_val = self.cwidth * x + self.line_num_spacing y_val = self.cheight * y + (y * 2) self.canvas.create_rectangle(0, y_val, self.winfo_screenwidth(), y_val + self.cheight + 4, fill=highlightcolor, outline=highlightcolor) self.canvas.create_rectangle(x_val, 0, x_val + self.cwidth, self.winfo_screenheight(), fill=highlightcolor, outline=highlightcolor) self.canvas.create_rectangle(x_val, y_val, x_val + self.cwidth, y_val + self.cheight + 4, fill=cursorcolor, outline=cursorcolor) def draw_rectangle_absolute(self, x1, y1, x2, y2, color): self.canvas.create_rectangle(x1, y1, x2, y2, fill=color, outline=color) def bind_events(self, input_handler): # TODO: this should be cleaned up ideally into a separate handler list input_handler.set_GUI_reference(self) self.canvas.bind('<Key>', input_handler.key) self.canvas.bind_all('<Escape>', input_handler.escape) self.canvas.bind_all('<Control-a>', input_handler.control_a) self.canvas.bind_all('<Control-b>', input_handler.control_b) self.canvas.bind_all('<Control-c>', input_handler.control_c) self.canvas.bind_all('<Control-d>', input_handler.control_d) self.canvas.bind_all('<Control-e>', input_handler.control_e) self.canvas.bind_all('<Control-f>', input_handler.control_f) self.canvas.bind_all('<Control-g>', input_handler.control_g) self.canvas.bind_all('<Control-h>', input_handler.control_h) self.canvas.bind_all('<Control-i>', input_handler.control_i) self.canvas.bind_all('<Control-j>', input_handler.control_j) self.canvas.bind_all('<Control-k>', input_handler.control_k) self.canvas.bind_all('<Control-l>', input_handler.control_l) self.canvas.bind_all('<Control-m>', input_handler.control_m) self.canvas.bind_all('<Control-n>', input_handler.control_n) self.canvas.bind_all('<Control-o>', input_handler.control_o) self.canvas.bind_all('<Control-p>', input_handler.control_p) self.canvas.bind_all('<Control-q>', input_handler.control_q) self.canvas.bind_all('<Control-r>', input_handler.control_r) self.canvas.bind_all('<Control-s>', input_handler.control_s) self.canvas.bind_all('<Control-t>', input_handler.control_t) self.canvas.bind_all('<Control-u>', input_handler.control_u) self.canvas.bind_all('<Control-v>', input_handler.control_v) self.canvas.bind_all('<Control-w>', input_handler.control_w) self.canvas.bind_all('<Control-x>', input_handler.control_x) self.canvas.bind_all('<Control-y>', input_handler.control_y) self.canvas.bind_all('<Control-z>', input_handler.control_z) self.canvas.bind_all("<MouseWheel>", input_handler.mouse_scroll) self.canvas.bind_all('<Control-braceright>', input_handler.control_braceright) self.canvas.bind_all('<Control-braceleft>', input_handler.control_braceleft)
def on_show_frame(self): self.canvas_wrappers = [] self.canvases = [] self.page_num = 0 if len(self.controller.sr_results) == 0: self.controller.show_frame(SrNoFramesFoundScreen) else: pages = int(ceil(len(self.controller.sr_results) / 10.0)) for page in range(0, pages): canvas_wrapper = Frame(self.content_wrapper, borderwidth="1", relief="solid") canvas = Canvas(canvas_wrapper, width=int(WINDOW_WIDTH * 7 / 8), height=(WINDOW_HEIGHT * 2 / 3)) scroll_bar = Scrollbar(canvas_wrapper, orient=VERTICAL, command=canvas.yview) results_list_frame = Frame(canvas) canvas.configure(yscrollcommand=scroll_bar.set) canvas.create_window(0, 0, window=results_list_frame) canvas.bind_all("<Up>", self.on_up_key) canvas.bind_all("<Down>", self.on_down_key) canvas.bind_all("<Left>", self.on_left_key) canvas.bind_all("<Right>", self.on_right_key) canvas.grid(row=0, column=0, sticky="nsew") scroll_bar.grid(row=0, column=1, sticky="ns") canvas_wrapper.grid(row=2, column=0, columnspan=3, sticky="nsew") select_buttons_on_page = [] for row in range(0, RESULTS_PER_PAGE): result_num = page * RESULTS_PER_PAGE + row if result_num < len(self.controller.sr_results): frame_num = self.controller.sr_results[result_num][ FRAME_NUM_LABEL] result_entry = Frame(results_list_frame, borderwidth="1", relief="solid") description = PLabel( result_entry, text="Frame #" + str(int(frame_num)) + ", Time: " + str(datetime.timedelta(seconds=frame_num / 30))) preview_wrapper = Frame(result_entry) left_video_preview = Label( preview_wrapper, image=self.controller.sr_results[result_num][LEFT]) right_video_preview = Label( preview_wrapper, image=self.controller.sr_results[result_num] [RIGHT]) select_button = SrSelectButton( preview_wrapper, self.controller, self.controller.sr_results[result_num] [SR_MAP_LABEL], text="Select") select_buttons_on_page.append(select_button) description.pack() left_video_preview.grid(row=row, column=0) right_video_preview.grid(row=row, column=1) select_button.grid(row=row, column=2) preview_wrapper.pack() result_entry.pack() for i in range(0, len(select_buttons_on_page)): select_buttons_on_page[i].configure( command=select_buttons_on_page[i].use_sr_map) self.master.update_idletasks() canvas.config(scrollregion=canvas.bbox("all")) canvas.yview_moveto(0) self.canvas_wrappers.append(canvas_wrapper) self.canvases.append(canvas) self.prev_result_page = Button( self.content_wrapper, text="<", command=lambda: self.prev_page_command()) self.page_info_label = PLabel( self.content_wrapper, text=get_page_info_label_message(self.page_num, len(self.canvases), RESULTS_PER_PAGE)) self.next_result_page = Button( self.content_wrapper, text=">", command=lambda: self.next_page_command()) self.prev_result_page.grid(row=3, column=0) self.page_info_label.grid(row=3, column=1) self.next_result_page.grid(row=3, column=2) self.canvas_wrappers[self.page_num].tkraise()
class ImageSelectWindow(object): def __init__(self): self.image_Wid = 300 self.image_Hei = 300 self.image_interval = 10 self.canvas_Wid = 930 self.canvas_Hei = 600 self.window_wid = self.canvas_Wid + 160 self.window_Hei = self.canvas_Hei # init state control variable self.has_select_root_path = False # sign has select root path(where the sub-directories save) or not self.root_path = '' self.group_list = [] # create main window self.mainWin = Tkinter.Tk() self.mainWin.geometry( str(self.window_wid) + 'x' + str(self.window_Hei)) # init the size of window self.mainWin.title("image select tool") self.mainWin.tk.eval('package require Tix') # bind the key press event(space to pass, q to quit) self.mainWin.bind('<KeyPress>', self._keyPressEvent) # create init image(a black background) self.img_path_list = [] self.photo_img_list = [] # create Canvas control self.max_shown_num = 90 self.cv = Canvas(self.mainWin, bg='white', width=self.canvas_Wid, height=self.canvas_Hei, scrollregion=(0, 0, self.canvas_Wid, (self.image_Hei + self.image_interval) * math.ceil(self.max_shown_num / 3))) self.vbar = Scrollbar(self.cv, orient=Tkinter.VERTICAL) self.vbar.pack(side=Tkinter.RIGHT, fill=Tkinter.Y) self.vbar.config(command=self.cv.yview) self.cv.config(yscrollcommand=self.vbar.set) self.cv.pack(side=Tkinter.LEFT, expand=True, fill=Tkinter.BOTH) # bind the mouse click event self.cv.bind('<Button-1>', self._mouseClickEvent) # bind the mouse wheel event self.cv.bind_all('<MouseWheel>', self._mouseWheelEvent) # create total Frame to lay out all components self.frame = Frame(self.mainWin, width=250, height=self.window_Hei) self.frame.pack(side=Tkinter.LEFT) # create text control self.save_path = './image_select_result' self.entry = Entry(self.frame, state='normal') self.entry.pack(side=Tkinter.TOP) self.entry.insert(0, self.save_path) # create 'START' button self.btn_start = Button(self.frame, text='START', command=self._selectPath, activeforeground='blue', activebackground='white', bg='blue', fg='white') self.btn_start.pack(side=Tkinter.TOP, pady=30) # create data annotation label button self.btn_pass = Button(self.frame, text='PASS', command=lambda: self._passCurrentGroup(), activeforeground='black', activebackground='blue', bg='white', fg='black') self.btn_pass.pack(side=Tkinter.TOP, pady=30) #NumericUpDown控件 self.num_count = Control(self.frame, integer=True, max=-1, min=-1, value=-1, step=1, label='current Image:', command=self._showImages) self.num_count.label.config(font='Helvetica -14 bold') self.num_count.pack(side=Tkinter.TOP, pady=30) # create 'QUIT' button self.btn_quit = Button(self.frame, text='QUIT', command=self.mainWin.quit, activeforeground='blue', activebackground='white', bg='red', fg='white') self.btn_quit.pack(side=Tkinter.BOTTOM, pady=100) def _keyPressEvent(self, event): if event.keycode == 32: self._passCurrentGroup() elif event.keycode == 81: self.mainWin.destroy() def _mouseClickEvent(self, event): # get coordinate of x x_coordinate = event.x # compute coordinate of y # get the location of the scrollBar in the scroll range scale = self.vbar.get()[0] start_y = scale * ((self.image_Hei + self.image_interval) * math.ceil(self.max_shown_num / 3)) y_coordinate = start_y + event.y self._selectOneImage(x_coordinate, y_coordinate) def _mouseWheelEvent(self, event): self.cv.yview_scroll(-1 * (event.delta / 20), "units") def _showImages(self, ev=None): if self.has_select_root_path: if int(self.num_count['value']) == -1: # clear the images draw before first for idx in range(len(self.img_path_list)): self.cv.delete(self.img_path_list[idx]) self.img_path_list = [] self.photo_img_list = [] return else: # clear the images draw before first for idx in range(len(self.img_path_list)): self.cv.delete(self.img_path_list[idx]) # get the current group path and images list img_group_path = self.group_list[int(self.num_count['value'])] self.img_path_list = self._getImagePathList(img_group_path) self.img_path_list = self.img_path_list[:min( len(self.img_path_list), self.max_shown_num)] self.photo_img_list = [] for idx in range(len(self.img_path_list)): # load the current image cur_img_path = self.img_path_list[idx] cur_img = Image.open(cur_img_path).resize( (self.image_Wid, self.image_Hei)) self.photo_img_list.append(ImageTk.PhotoImage(cur_img)) # draw cur image to the appropriate location by index x_coordinate = (idx % 3) * (self.image_Wid + self.image_interval) y_coordinate = math.floor( idx / 3) * (self.image_Hei + self.image_interval) self.cv.create_image((x_coordinate, y_coordinate), anchor=Tkinter.NW, image=self.photo_img_list[idx], tags=self.img_path_list[idx]) # give a tag is convenient for delete later def _passCurrentGroup(self): cur_idx = int(self.num_count['value']) if cur_idx != -1: # check has next group or not if cur_idx + 1 < len(self.group_list): self.num_count['value'] = str(cur_idx + 1) else: tkMessageBox.showinfo( title='thanks', message='all the image select mission has finished~') def _selectOneImage(self, x_coordinate, y_coordinate): cur_idx = int(self.num_count['value']) if cur_idx == -1: return col = math.floor(x_coordinate / (self.image_Wid + self.image_interval)) row = math.floor(y_coordinate / (self.image_Hei + self.image_interval)) idx = int(row * 3 + col) if idx < len(self.img_path_list): img_click_path = self.img_path_list[idx] cur_img = Image.open(img_click_path) img_name = img_click_path.split('\\')[-1] cur_save_path = os.path.join(self.save_path, img_name) cur_img.save(cur_save_path) def _selectPath(self): self.root_path = tkFileDialog.askdirectory() self.group_list = self._getGroupPathList() if len(self.group_list) > 0: self.has_select_root_path = True self.num_count.config(max=len(self.group_list) - 1) self.num_count['value'] = str(0) else: self.has_select_root_path = False self.num_count['value'] = str(-1) self.num_count.config(max=-1) tkMessageBox.showwarning( 'warning', 'No available sub-directories detected! please re-select root path and start' ) def _getGroupPathList(self): group_list = [] for root, dirs, files in os.walk(self.root_path): for dir_name in dirs: cur_group_path = os.path.join(root, dir_name) group_list.append(cur_group_path) return group_list def _getImagePathList(self, img_group_path): img_path_list = [] for root, dirs, files in os.walk(img_group_path): for file_name in files: cur_img_path = os.path.join(img_group_path, file_name) img_path_list.append(cur_img_path) return img_path_list
class Viewer(Frame): def __init__(self, master,x=600,y=200, onLeft=None, onRight=None, **kwargs): self.root=master self.xsize=x self.ysize=y self.onLeft=onLeft self.onRight=onRight self.ratio=100. Frame.__init__(self, master,width=x,height=y, **kwargs) self.canvas = Canvas(self, width=x, height=y, background="white") self.xsb = Scrollbar(self, orient="horizontal", command=self.canvas.xview) self.ysb = Scrollbar(self, orient="vertical", command=self.canvas.yview) self.canvas.configure(yscrollcommand=self.ysb.set, xscrollcommand=self.xsb.set) self.canvas.configure(scrollregion=(0,0,x,y)) self.xsb.grid(row=1, column=0, sticky="ew") self.ysb.grid(row=0, column=1, sticky="ns") self.canvas.grid(row=0, column=0, sticky="nsew") self.grid_rowconfigure(0, weight=1) self.grid_columnconfigure(0, weight=1) self.canvas.bind("<Button-1>", self.clickL) self.canvas.bind("<Button-3>", self.clickR) # This is what enables using the mouse: self.canvas.bind("<ButtonPress-1>", self.move_start) self.canvas.bind("<B1-Motion>", self.move_move) #linux scroll self.canvas.bind("<Button-4>", self.zoomerP) self.canvas.bind("<Button-5>", self.zoomerM) self.canvas.bind_all("<Prior>", self.zoomerP) self.canvas.bind_all("<Next>", self.zoomerM) self.canvas.bind_all("E", self.zoomExtens) #windows scroll self.canvas.bind_all("<MouseWheel>",self.zoomer) def reset(self): pass def set_title(self, title): self.root.title( title) #move def move_start(self, event): self.canvas.scan_mark(event.x, event.y) return True def move_move(self, event): self.canvas.scan_dragto(event.x, event.y, gain=1) return True #windows zoom def zoomer(self,event): if (event.delta > 0): self.ratio *= 1.1 elif (event.delta < 0): self.ratio *= 0.9 self.redraw() def redraw(self): self.canvas.delete("all") self.canvas.configure(scrollregion = self.canvas.bbox("all")) def zoomExtens(self, *args): x0,y0,x1,y1 = self.canvas.bbox("all") xlen=x1-x0 ylen=y1-y0 height=self.canvas.winfo_height() width=self.canvas.winfo_width() unfit=min(width/float(xlen), height/float(ylen)) self.ratio*=unfit self.redraw() # """" if xlen and ylen: self ratio*= self.canvas.scale("all", xlen/2., ylen/2., float(self.xsize)/xlen, float(self.ysize)/ylen) self.canvas.configure(scrollregion = self.canvas.bbox("all")) """ #linux zoom def zoomerP(self,event): self.canvas.scale("all", event.x, event.y, 1.1, 1.1) self.canvas.configure(scrollregion = self.canvas.bbox("all")) def zoomerM(self,event): self.canvas.scale("all", event.x, event.y, 0.9, 0.9) self.canvas.configure(scrollregion = self.canvas.bbox("all")) def pose2p(self, pose): x,y=pose[:2] return int(x*self.ratio), -int(y*self.ratio) def line2p(self, line): if type(line[0]) in (float, int): line=zip(line[::2],line[1::2]) return map(self.pose2p, line) def p2m(self, x, y): return x/self.ratio, -y/self.ratio def create_line(self, coords, **kwargs): return self.canvas.create_line(self.line2p(coords), **kwargs) def create_polygon(self, coords, **kwargs): return self.canvas.create_polygon(self.line2p(coords), **kwargs) def delete(self, object): self.canvas.delete(object) def clickL(self, event): if self.onLeft: x,y=self.p2m(int(self.canvas.canvasx(event.x)), int(self.canvas.canvasy(event.y))) self.onLeft(x,y) return True def clickR(self, event): if self.onRight: x,y=self.p2m(int(self.canvas.canvasx(event.x)), int(self.canvas.canvasy(event.y))) self.onRight(x,y) return True