def dragging_motion ( self, event ): """ Handles a mouse motion event in dragging mode. """ x0, y0 = self._xy dxy = [ event.x - x0, event.y - y0 ] isv = self.is_vertical dxy[ 1 - isv ] = 0 ci = self.highlighted control = ci.control idxy = control.size idxy2 = idxy[ isv ] / 2 cdxy = self.control.size position = self._position ixy = [ position[0] + dxy[0], position[1] + dxy[1] ] ixy[ isv ] = max( min( ixy[ isv ], cdxy[ isv ] - idxy2 ), -idxy2 ) ci.position = tuple( ixy ) self._check_swap() amount = 0 if ixy[ isv ] < -(idxy2 / 2): amount = ClickScrollAmount elif ixy[ isv ] > (cdxy[ isv ] - (1.5 * idxy2)): amount = -ClickScrollAmount if (amount != 0) and (self._amount == 0): do_after( AutoScrollDelay, self._scroll_toolbar ) self._amount = amount
def normal_left_down ( self, event ): """ Handles the left mouse button being pressed in normal mode. """ if self.normal_motion( event ): self._y = event.y n = len( self.value ) factory = self.factory operations = factory.operations delete = 'delete' in operations add = 'add' in operations move = 'move' in operations self.state = ('pending' if move else 'clicking') mode = None if (not event.alt_down) and add: max_len = factory.max_len mode = 'add' if (max_len < 0) or (n < max_len) else 'hover' if delete: do_after( 600, self._check_delete ) self.mode = (mode if mode is not None else ('delete' if delete and (n > factory.min_len) else ('move' if move and (not (add or delete)) else 'hover'))) else: self.state = 'ignoring'
def normal_left_down ( self, event ): """ Handles a left mouse button down event in normal mode. """ x, y = self._xy = ( event.x, event.y ) self.state = 'pending' self._scroll_amount_for( event ) if not event.control_down: do_after( AutoScrollDelay, self._scroll_toolbar )
def _scroll_toolbar ( self ): """ Performs an auto-scroll of the toolbar contents. """ # Make sure we are still in 'scroll' mode: if self.state in ( 'pending', 'scrolling' ): self.helper.scroll_active( self._amount ) self.state = 'scrolling' do_after( AutoScrollInterval, self._scroll_toolbar )
def _left_down ( self, event ): """ Handles the left mouse being pressed. """ if self.adapter.enabled: self._x, self._y = event.x, event.y self._pending = True self.adapter.mouse_capture = True do_after( 150, self._delayed_click )
def _source_set ( self, source ): """ Handles the 'source' facet being changed. """ if self.can_save: if not self._dont_update: self.needs_save = True do_after( 750, self._syntax_check ) else: self._syntax_check()
def watch ( self, handler, file_name, remove = False ): """ Adds/Removes a file watch *handler* for the file specified by *file_name*, which may contain wildcard characters (e.g. '/tmp/*.py'). """ for name in iglob( file_name ): self._watch( handler, name, remove ) if not remove: do_after( 500, self._check_watch )
def _check_watch ( self ): """ Watches a list of WatchedFile objects for changes. """ now = time() for wf in self.watched_files: wf.process() if len( self.watched_files ) > 0: delta = max( 500, int( (time() - now) * 100000 ) ) do_after( delta, self._check_watch )
def _left_down ( self, event ): """ Handles the left mouse being pressed. """ if self.adapter.enabled: self._wheel = self._mx = self._my = None self._x, self._y = event.x, event.y self._low, self._high = self.value self._pending = True self.adapter.mouse_capture = True self._drag = self._action_for( event ) do_after( 150, self._delayed_click )
def _refresh ( self ): """ Refreshes the contents of the editor. """ # Make sure the editor has not already been closed before proceeding: if self.object is not None: for item in self.items: item.update = True refresh = self.factory.refresh if refresh > 0: do_after( refresh, self._refresh )
def _mouse_enter ( self, item, event ): """ Handles the mouse entering an item. """ self.item = item self.opacity = 0.0 delay = self.delay if delay == 0: self.pending_xy = None else: self.pending_xy = ( event.x, event.y ) if delay < 1000: do_after( delay, self._start_expander )
def _scroll_toolbar ( self ): """ Scroll the toolbar while in edit mode. """ if self._amount != 0: highlighted = self.highlighted if highlighted is not None: position = highlighted.position self.scroll_active( self._amount ) self._sync_images() highlighted.position = position self._check_swap() do_after( DragScrollInterval, self._scroll_toolbar )
def normal_left_down ( self, x, y, event ): """ Handles the user pressing the left mouse button while in the normal color selection mode. """ self.cell1 = self.cell2 = self._cell_at( x, y ) if event.alt_down: self.state = 'dragging' self.refresh() elif event.control_down: self._start_copy( event.shift_down ) else: self.state = 'pending' do_after( LongClick, self._start_drag )
def _update_virtual_size ( self ): """ Attempt to perform a virtual size update that has been deferred. If the pending size is None, then the update has already been performed and can be ignored. If mouse capture is still in effect, then reschedule the update for later. Otherwise, perform the requested update. """ if self.pending_virtual_size is not None: if self.capture is None: self.stacker.virtual_size = self.pending_virtual_size self.pending_virtual_size = None else: do_after( 250, self._update_virtual_size )
def _left_down ( self, event ): """ Handles the left mouse being pressed. """ self._x, self._y = event.x, event.y self._pending = True self._init_value() self.adapter.mouse_capture = True if self.factory.active_color != self.factory.hover_color: self.adapter.refresh() do_after( 200, self._delayed_click )
def show ( self, parent = None, title = '' ): """ Display the wait message for a limited duration. """ view = View( HGroup( spring, Item( 'message', show_label = False, style = 'readonly' ), spring ), title = title ) do_after( int( 1000.0 * self.time ), self.edit_facets( parent = parent, view = view ).dispose )
def normal_motion ( self, event ): """ Handles the mouse moving in normal mode. """ x, y = event.x, event.y item = self._item_at( x, y ) if self.factory.hover is not None: if item is not self.hover_item: do_after( 333, self._call_hover, item ) self.hover_item = item if self.factory.ordering == 'user': cursor = 'arrow' if (item is not None) and item.in_drag( x, y ): cursor = 'sizens' self.control.cursor = cursor
def _key ( self, event ): """ Handles keyboard events by routing them to the correct stack item. """ item = self.focus if item is None: item = self.mouse_item if item is not None: # Save the current size of the item (in case the event handler # modifies it): size = item.bounds[2:] # Send the event to the item: item.keyboard = event # Now, check to see if the size of the item changed: self._check_size( item, size ) if self.focus is None: do_after( 100, self._mouse_at )
def _convert_images ( self ): """ Convert all of the currently selected images using the image knife settings. """ now = time() path = self.output_path if not isdir( path ): try: makedirs( path ) except: self.status = 'Could not create directory: %s' % path return for file_name in self.selected_files: if not self._convert_image( file_name ): break self.status = '%d files converted in %.2f seconds' % ( len( self.selected_files ), time() - now ) do_after( 3000, self.set, converted = True )
def update_editor_item ( self, event ): """ Handles items in the editor's list content being added or removed. """ self.item_changed_pending = set() add_to_bottom = ((event.index == len( self.all_items )) and (len( event.removed ) == 0) and (len( event.added ) > 0)) af = self._adapter_for self.all_items[ event.index: event.index + len( event.removed ) ] = \ [ af( item ) for item in event.added ] self._dispatch_pending() # If new content was added to the bottom of the stack, automatically # scroll the control so that the new content is visible: # Note: Doing this automatically may not always be desirable. If not, # then we can add an option to the editor factory to enable/disable it. if add_to_bottom: if self.is_vertical: do_after( 100, self.adapter.scroll_to, 0, None ) else: do_after( 100, self.adapter.scroll_to, None, 0 )
def init_ui ( self, parent ): """ Finishes initializing the editor by creating the underlying toolkit widget. """ factory = self.factory self.facet_set( show_files = factory.show_files, select_directories = factory.select_directories ) # Set up the threshold and context number of lines to display: self.glob = factory.facet_value( 'glob' ) self.root = factory.facet_value( 'root' ) # Set up the name of the file the user double-clicked on: self.double_clicked = factory.facet_value( 'double_clicked' ) # Schedule an automatic refresh (if requested): if factory.refresh > 0: do_after( factory.refresh, self._refresh ) # Create and return the editor view: return self.edit_facets( parent = parent, kind = 'editor' )
def feature_activate ( self, event, drag_object = Undefined ): """ Returns whether or not a specified window position is over the feature 'trigger' icon, and if so, triggers display of the feature icons. """ global text_dy if (self.feature_mode in NO_FEATURE_ICON) or (not self._is_tab): return False # In 'drag' mode, we may get the same coordinate over and over again. # We don't want to restart the timer, so exit now: exy = ( event.x, event.y ) if self._feature_popup_xy == exy: return True x, y, dx, dy = self.drag_bounds images = self.theme.images idx = images.tab_feature_normal.width idy = images.tab_feature_normal.height theme = self.tab_theme slice = theme.image_slice tc = theme.content ox, oy = theme.label.left, theme.label.top y += (oy + ((dy + slice.xtop + tc.top - slice.xbottom - tc.bottom - text_dy) / 2)) x += ox + slice.xleft + tc.left # If this is part of a drag operation, prepare for drag mode: if drag_object is not Undefined: self.pre_drag( drag_object, FEATURE_EXTERNAL_DRAG ) # If the pointer is over the feature 'trigger' icon and the control # is feature enabled, then display the feature pop-up: if (self.is_in( event, x, y, idx, idy ) and (self.feature_mode not in NO_FEATURE_ICON)): self._feature_popup_xy = exy do_after( 100, self._feature_popup ) return True
def update_editor ( self ): """ Updates the editor when the object facet changes externally to the editor. """ control = self.control if self.playing: control.Stop() control.LoadFile( self.value ) self._file_loaded = True # Note: It seems to be necessary to Play/Stop the control to avoid a # hard wx crash when 'PlayNextFrame' is called the first time (must # be some kind of internal initialization issue): control.Play() control.Stop() if self.playing or self._not_first: self._playing_set() else: do_after( 300, self._frame_changed ) self._not_first = True
def _update ( self ): """ Updates the current set of active instance counts. """ # Force a garbage collection: collect() selected = self.selected selected_class = None if selected is None else selected[0] last_counts = self.last_counts monitor = self.monitor self.total_count = monitor.total_count self.count = monitor.count items = [] for id_class, counts in monitor.counts.iteritems(): count = counts[3] history = last_counts.get( id_class ) if history is None: last_counts[ id_class ] = history = [ -1 ] * HistoryItems change = count - history[-1] if change != 0: history.append( count ) if len( history ) > HistoryItems: del history[0] items.append( ( id_class, counts[0], counts[1], counts[2], count, change, history ) ) if id_class == selected_class: selected = items[-1] self.counts = items self.selected = selected if self.ui_info is not None: do_after( 1000, self._update )
def _restart_needed ( self ): if self.animate: do_after( 500, self._restart_animation )
def _rebuild ( self ): """ Refresh the display and its content positions. """ self._reorder() do_after( 250, self._retab )
def _count_set ( self ): do_after( 500, self.set, selected = '', update = True )
def _images_modified ( self ): """ Handles any facet affecting the list of variation images being changed. """ do_after( 150, self._create_variations )
def _max_images_set ( self ): """ Handles the 'max_images' facet being changed. """ do_after( 1000, self._check_count )
def _defer_check_highlighted ( self, event ): """ Sets the highlighted control and hide/show zone after a brief pause to allow any animations to complete. """ do_after( 300, self._check_highlighted, event.x, event.y )