def __init__(self): # value of the built-in slider self.__slider_value = 0.0 # slider grab position self.__slider_grab_pos = 0 # whether the user is using the slider self.__is_sliding = False # whether multi select is enabled self.__multi_select = False # whether the index letter is enabled self.__letter_enabled = True # whether the letter is visible self.__letter_visible = False # timeout handler for hiding the letter view self.__letter_timeout_handler = None # handler for auto scrolling when dragging items self.__autoscroll_handler = None # timestamp of when the cursor was last positioned self.__last_cursor_time = 0 # click behavior for selecting items self.__click_behavior = self.CLICK_BEHAVIOR_SINGLE # index of the marked item self.__marked_idx = -1 GridView.__init__(self) self.connect_button_pressed(self.__on_press_button) self.connect_button_released(self.__on_release_button) self.connect_pointer_moved(self.__on_pointer_moved) self.add_overlay_renderer(self.__render_letter) self.add_overlay_renderer(self.__render_slider) self.__kscr = KineticScroller(self) self.__kscr.connect_scrolling_started(self.__on_scrolling_started) self.__kscr.connect_clicked(self.__on_clicked) self.__kscr.connect_tap_and_hold(self.__on_tap_and_hold)
def __init__(self, sizex, sizey): self.sizex = sizex self.sizey = sizey self.view = GridView(sizex,sizey,800,480) self.model = GridModel(sizex,sizey) self.keyPressed = False self.action()
def move(self, dx, dy): self.__letter_visible = True prev_offset = self.get_offset() dy, dy = GridView.move(self, dx, dy) # stop scrolling immediately if there is no more motion if (prev_offset == self.get_offset()): self.__kscr.stop_scrolling() # position slider self.__update_slider() if (self.__letter_timeout_handler): gobject.source_remove(self.__letter_timeout_handler) self.__letter_timeout_handler = gobject.timeout_add(_LETTER_TIMEOUT, self.__on_letter_timeout) return (dx, dy)
def clear_items(self): GridView.clear_items(self) self.__update_slider()
def switch_item_set(self, s): GridView.switch_item_set(self, s) self.__update_slider()
class GridControl(object): def __init__(self, sizex, sizey): self.sizex = sizex self.sizey = sizey self.view = GridView(sizex,sizey,800,480) self.model = GridModel(sizex,sizey) self.keyPressed = False self.action() def action(self): while True: self.beforeAction() for event in pygame.event.get(): self.handleEvent(event) self.afterAction() def beforeAction(self): pass def afterAction(self): pass def handleEvent(self, event): if event.type == QUIT: self.triggerEnd() if event.type == MOUSEBUTTONDOWN: self.handleMouseButtonEvents(event) if event.type == KEYUP: self.keyPressed = False if event.type == KEYDOWN and not self.keyPressed: self.keyPressed = True self.handleKeyEvents(event) def handleKeyEvents(self, event): if event.key == pygame.K_ESCAPE or event.key == pygame.K_q: self.triggerEnd() def triggerEnd(self): exit() def handleMouseButtonEvents(self, event): (x,y) = event.pos (bx,by) = self.view.point2Box(x,y) if bx in range(self.sizex) and by in range(self.sizey): if event.button == 1: self.setBox(bx,by) elif event.button == 3: self.unsetBox(bx,by) def renderModel(self): for x in range(self.sizex): for y in range(self.sizey): if self.model.getPoint(x,y) == 1: self.view.setBox(x,y) else: self.view.unsetBox(x,y) self.view.update() def setBox(self,bx,by): self.view.setBox(bx,by) self.model.setPoint(bx,by) self.view.update() def unsetBox(self,bx,by): self.view.unsetBox(bx,by) self.model.unsetPoint(bx,by) self.view.update() def invertBox(self,bx,by): pointStatus = self.model.getPoint(bx,by) if pointStatus == 0: self.setBox(bx,by) elif pointStatus ==1: self.unsetBox(bx,by)