def _item_size_modified ( self ): """ Handles the size of the displayed items being modified. """ if self._updating_size: self._resized = True else: do_later( self._update_size )
def _file_name_set ( self, file_name ): """ Handles the 'file_name' facet being changed. """ if file_name != '': file_name = abspath( file_name ) text_files = self.text_files if self.auto_close: for i in xrange( len( text_files ) - 1, -1, -1 ): text_file = text_files[ i ] if ((not text_file.modified) and (file_name != text_file.file_name)): del text_files[ i ] for text_file in text_files: if file_name == text_file.file_name: break else: text_file = TextFile( file_name = file_name, text = read_file( file_name ) or '' ).set( modified = False ) text_files.append( text_file ) self.text_file = text_file do_later( self.set, file_name = '' )
def object_ok_changed ( self, info ): """ Handles the user clicking the OK button. """ if self.is_save_file and exists( self.file_name ): do_later( self._file_already_exists ) else: info.ui.dispose( True )
def _editing_completed(self, control, hint): """ Handles an in-cell edit being completed. """ # Clean up the cell editor (if necessary): handler = getattr(control, "_handler", None) if handler is not None: del control._handler handler.closed(None, True) editor = getattr(control, "_editor", None) if editor is not None: del control._editor editor.dispose() grid = self.control if grid is not None: # Restore the size of the edited grid row (if necessary): row = getattr(control, "_row", None) if row is not None: header = grid.verticalHeader() header.resizeSection(row, header.defaultSectionSize()) # Restore the size of the edited grid column (if necessary): column = getattr(control, "_column", None) if column is not None: do_later(self._restore_column_width, column, control._width) self.editing -= 1 if self.editing == 0: self._edit_row = self._editor = None self.update_editor()
def _get_source_files(self): """ Adds the next batch of source files to the list. """ files = self.find_source_files.source_files() if len(files) > 0: self.source_files.extend(files) do_later(self._get_source_files)
def _edit_colors ( self, event ): """ Displays a pop-up color editor based upon the currently selected color palette cells. """ self._cell1, self.cell1 = self.cell1, None self._cell2, self.cell2 = self.cell2, None r1, c1 = self._cell1 r2, c2 = self._cell2 self.color1 = self._color_at( r1, c1, UseDefaultColor ) color = self._color_at( r2, c2, UseNone ) self.linked = (color is None) if self.linked: dr, dc = abs( r2 - r1 ), abs( c2 - c1 ) self.linked = (max( dr, dc ) > 0) color = self.color1 self.divisions = min( dr, dc ) + 1 self.color2 = self._complementary_color_for( color, self.divisions ) else: self.color2 = color do_later( self._color_gradient ) if (not event.shift_down) and (self._cell1 == self._cell2): self.edit_facets( parent = self.control )
def _file_position_set(self, file_position): """ Handles the 'file_position' facet being changed. """ if file_position is not None: # Reset the current file position to None, so we are ready for a # new one: do_later(self.set, file_position=None) viewers = self.viewers for i, viewer in enumerate(viewers): if ( (file_position.name == viewer.name) and (file_position.file_name == viewer.file_name) and (file_position.lines == viewer.lines) and (file_position.object == viewer.object) ): viewer.selected_line = file_position.line self.selected = viewer return # Create the viewer: viewer = AnFBIViewer(**file_position.get("name", "file_name", "line", "lines", "object")) # Make sure the # of viewers doesn't exceed the maximum allowed: if len(viewers) >= self.max_viewers: del viewers[0] # Add the new viewer to the list of viewers (which will cause it to # appear as a new notebook page): viewers.append(viewer)
def object_resized_changed ( self, info ): """ Force the user interface to be rebuilt when the underlying object list is resized. """ if info.initialized: info.initialized = False do_later( self._rebuild_ui, info )
def _item_set ( self, item ): """ Handles the 'item' facet being changed. """ if isinstance( item, HasPayload ): item = item.payload if isinstance( item, FacetsNode ): item = item.value if item is not None: inspectors = [] self._file_names = [] description = '' for klass in item.__class__.__mro__: module = klass.__module__.split( '.' ) module_name = module[ -1 ] if module_name != '__builtin__': module_name += '.py' if len( description ) > 0: description += ' -> ' description += '%s[%s]' % ( klass.__name__, module_name ) inspector = self.inspector_for( join( * module ), item ) if inspector is not None: inspectors.append( inspector ) self._file_names.append( inspector.file_name ) self.inspectors = inspectors self.description = description do_later( self.set, item = None ) #-- EOF ------------------------------------------------------------------------
def _object_set ( self, value ): """ Handles the 'object' facet being changed. """ if value is not None: # Reset the current object to None, so we are ready for a new one: do_later( self.set, object = None ) name = title = '' if isinstance( value, HasPayload ): name = value.payload_name title = value.payload_full_name value = value.payload viewers = self.viewers for i, viewer in enumerate( viewers ): if value is viewer.object: if i == (len( viewers ) - 1): return del viewers[ i ] break else: # Create the viewer: viewer = AnObjectViewer( name = name, title = title ).set( object = value ) # Make sure the # of viewers doesn't exceed the maximum allowed: if len( viewers ) >= self.max_viewers: del viewers[0] # Add the new viewer to the list of viewers (which will cause it to # appear as a new notebook page): viewers.append( viewer )
def _on_add_perspective ( self, info ): """ Allows the user to add a new perspective. """ ap = ChangePerspective( tools = self ) if ap.edit_facets().result: name = user_name_for( ap.name ) self.perspective_names.append( name ) do_later( self.facet_set, perspective_name = name )
def _input_image_set ( self, image ): """ Handles the 'input_image' facet being changed. """ if image is not None: root, ext = splitext( image.name.lstrip( '@' ) ) self.output_file_name = '%s_knifed%s' % ( root, ext or '.png' ) if not self.auto_reset: do_later( self._reset_image_zoom_editor )
def write ( self, buffer ): """ Handles 'write' calls to the file. """ if self.owner.passthru: self.file.write( buffer ) self.buffer += buffer do_later( self._parse_lines )
def _path_set ( self, path ): if ((not self._ignore_set) and (path is not None) and (path[:1] != '?')): if path[:1] == '.': path = path[1:] do_later( self._update_path, path )
def __init__ ( self, **facets ): """ Initializes the object. """ super( ObjectDebugger, self ).__init__( **facets ) self.module = CBModuleFile( path = self.file_name, python_path = self.python_path, object = self.object ) do_later( self.select_object )
def feature_bar_closed ( self ): """ Finishes the processing of a feature popup. """ if self.feature_mode == FEATURE_DROP_VISIBLE: self.feature_mode = FEATURE_DROP else: self.feature_mode = FEATURE_NORMAL do_later( self._redraw_control )
def click ( self ): """ Handles the user left clicking on the feature image. """ from facets.extra.tools.vip_shell import VIPShell shell = VIPShell( values = { 'info': DebugInfo( dock_control = self.dock_control ) } ) do_later( shell.set, command = 'info' ) shell.edit_facets()
def _profile_set ( self, file_position ): """ Handles the 'profile' facet being changed. """ if file_position is not None: do_later( self.set, profile = None ) if file_position.class_name != '': if file_position.method_name != '': self.add_method( file_position ) else: self.add_class( file_position )
def _error_buffer_modified ( self ): """ Handles new data being written to 'stderr' by making sure that it gets processed in the future by the UI thread. We don't process it now because the data for a traceback tends to get written in small chunks. Deferring it should allow for all of the data to be accumulated in the 'error_buffer' before being processed' """ do_later( self._process_error_buffer ) #-- EOF ------------------------------------------------------------------------
def _output_image_modified ( self ): """ Handles any facet affecting the output image being changed. """ # If the input image is too large, schedule the update for later; # otherwise do it now. This helps makes the tool more responsive when # working with larger images using the editing widgets: image = self.input_image if (image is not None) and ((image.width * image.height) > 300000): do_later( self._update_image ) else: self._update_image()
def _timer_pop ( self ): """ Handles the timer event popping. """ # Restore the normal appearance of the control: self.control.screen_graphics = None # Notify the owner that we are done: self.owner.flashed = self # Cancel our timer later: do_later( self._terminate )
def _source_files_modified(self): root = self.root if self.root != "" else getcwd() if isfile(root): root = dirname(root) self.find_source_files = FindSourceFiles( root=root, file_type=self.file_type, recursive=self.recursive, live_search=self.filter ) self.selected = None self.source_files = [] do_later(self._get_source_files)
def add_paths ( self, paths ): """ Adds paths to the work queue. """ paths = [ cb_path.path for cb_path in paths if cb_path.path not in self.paths ] if len( paths ) > 0: self.paths.extend( paths ) if self.lock is None: self.lock = Lock() do_later( self.start_thread ) self.init_queue( paths )
def _value_modified ( self, value ): """ Handles the history object's 'value' facet being changed. """ if not self._dont_update: history = self.history try: self._dont_update = True self.value = history.value history.error = False except: history.error = True do_later( self.set, _dont_update = False )
def _load_history(self, restore=None, select=True): """ Loads the current history list into the control. """ control = self.control control.Freeze() if restore is None: restore = control.GetValue() control.Clear() for value in self.history: control.Append(value) self._restore = True do_later(self._thaw_value, restore, select)
def _load_history ( self, restore = None, select = True ): """ Loads the current history list into the control. """ control = self.control control.frozen = True if restore is None: restore = control.value control.clear() for value in self.history: control.add_item( value ) self._restore = True do_later( self._thaw_value, restore, select )
def _handle_click(self, column, allow_shift=True): """ Perform 'special' click handling on either a cell or column header. Returns True if special handling occurred, or False to indicate that normal handling can proceed. """ modifiers = int(QApplication.keyboardModifiers()) control = modifiers & Qt.ControlModifier if allow_shift and (modifiers & Qt.ShiftModifier): do_later(self._hide_show_section, column, control) return True if control: self.column_width(column) self.set_column_widths() return True return False
def _create_control ( self, parent ): """ Creates the toolkit-specific control for the widget. """ # Base-class constructor: self.control = stc = _Scintilla( self, parent ) # Use the Python lexer with default settings: lexer = Qsci.QsciLexerPython( stc ) stc.setLexer( lexer ) # Mark the maximum line size: stc.setEdgeMode( Qsci.QsciScintilla.EdgeLine ) stc.setEdgeColumn( 80 ) # Display line numbers in the margin: if self.show_line_numbers: stc.setMarginLineNumbers( 1, True ) stc.setMarginWidth( 1, 45 ) else: stc.setMarginWidth( 1, 4 ) stc.setMarginsBackgroundColor( QtCore.Qt.white ) # Create 'tabs' out of spaces! stc.setIndentationsUseTabs( False ) # One 'tab' is 4 spaces: stc.setTabWidth( 4 ) # Line ending mode: stc.setEolMode( Qsci.QsciScintilla.EolUnix ) stc.connect( stc, QtCore.SIGNAL( 'modificationChanged(bool)' ), self._on_dirty_modified ) stc.connect( stc, QtCore.SIGNAL( 'textChanged()' ), self._on_text_modified ) # Load the editor's contents: self.load() # Make sure we check the font once initialization is complete: do_later( self._check_font ) return stc
def _on_rename_perspective ( self, info ): """ Allows the user to rename the current perspective. """ ap = ChangePerspective( tools = self ) if ap.edit_facets().result: new_name = user_name_for( ap.name ) old_name = self.perspective_name perspective = self.perspective perspective.dispose() perspective.id = '%s:%s' % ( self.application, new_name ) perspective.activate() self.perspective_cache[ new_name ] = perspective del self.perspective_cache[ old_name ] self.perspective_names.remove( old_name ) self.perspective_names.append( new_name ) do_later( self.facet_set, perspective_name = new_name )
def update_object ( self, event ): """ Handles the user selecting a new value from the combo box. """ name = event.value for item in self.items: if name == item.get_name(): id_item = id( item ) object = self._object_cache.get( id_item ) if object is None: object = item.get_object() if (not self.factory.editable) and item.is_factory: view = self.view_for( object, self.item_for( object ) ) view.ui( object, self.control, 'modal' ) if self.factory.cachable: self._object_cache[ id_item ] = object self.value = object do_later( self.resynch_editor ) break