def display_retvalue(self, retValue): do_retvalue = not self.aguidata.get('no_return_popup', False) if not do_retvalue: return if retValue is not None: if type(retValue) in BASIC_TYPES: retDlg = wx.MessageDialog( self.control, ''.join([self.attribute, ' returned:\n', str(retValue)]), 'Return Value', wx.OK) retDlg.ShowModal() else: retDlg = wx.MessageDialog( self.control, ''.join([ self.attribute, ' returned:\n', str(retValue), '\n\nUse pug to examine returned value?' ]), 'Return Value', wx.YES_NO | wx.NO_DEFAULT) showframe = None if retDlg.ShowModal() == wx.ID_YES: showframe = self.pug_frame( obj=retValue, objectpath=get_type_name(retValue), parent=self.window) try: retDlg.Destroy() if showframe: showframe.Raise() except: pass
def display_retvalue(self, retValue): do_retvalue = not self.aguidata.get('no_return_popup', False) if not do_retvalue: return if retValue is not None: if type(retValue) in BASIC_TYPES: retDlg = wx.MessageDialog(self.control, ''.join([self.attribute,' returned:\n', str(retValue)]), 'Return Value', wx.OK) retDlg.ShowModal() else: retDlg = wx.MessageDialog(self.control, ''.join([self.attribute,' returned:\n', str(retValue), '\n\nUse pug to examine returned value?']), 'Return Value', wx.YES_NO | wx.NO_DEFAULT) showframe = None if retDlg.ShowModal() == wx.ID_YES: showframe = self.pug_frame(obj=retValue, objectpath=get_type_name(retValue), parent=self.window) try: retDlg.Destroy() if showframe: showframe.Raise() except: pass
def label_text(self, obj): if hasattr(obj,'gname') and obj.gname and obj.gname == str(obj.gname): text = obj.gname else: text = get_type_name(obj) if text == 'type': text = str(obj) return text
def label_text(self, obj): if hasattr(obj, 'gname') and obj.gname and obj.gname == str(obj.gname): text = obj.gname else: text = get_type_name(obj) if text == 'type': text = str(obj) return text
def doc_to_tooltip(self): doc = '' value = self.get_attribute_value() if get_type(value) not in BASIC_TYPES: doc = getattr(value, '__doc__', '') elif value is not None: try: doc = get_type_name(value) except: pass try: self.set_label_tooltip(doc) except: if hasattr(self.label, 'text'): if self.label.GetToolTip(): self.set_label_tooltip(' ')
def doc_to_tooltip(self): doc = '' value = self.get_attribute_value() if get_type(value) not in BASIC_TYPES: doc = getattr(value,'__doc__','') elif value is not None: try: doc = get_type_name(value) except: pass try: self.set_label_tooltip(doc) except: if hasattr(self.label, 'text'): if self.label.GetToolTip(): self.set_label_tooltip(' ')
def prepare_storageDict(self, obj, storageDict=None, asClass=None): """prepare_storageDict(self, obj, storageDict=None): Set up storageDict. See CodeStorageExporter documentation for details. """ if storageDict and storageDict.get('defaults_set', False): return storageDict if storageDict == None: storageDict = self.get_custom_storageDict(obj) if asClass is not None: storageDict['as_class'] = asClass storageDict.setdefault('obj', obj) storageDict.setdefault('attributes', ['*']) storageDict.setdefault('init_method', '__init__') storageDict.setdefault('init_method_args', ['*args','**kwargs']) storageDict.setdefault('custom_export_func', None) storageDict.setdefault('as_class', False) storageDict.setdefault('skip_attributes', []) storageDict.setdefault('instance_attributes', []) storageDict.setdefault('base_class', None) storageDict.setdefault('instance_only_attributes', []) storageDict.setdefault('force_init_def', False) storageDict.setdefault('base_init', True) storageDict.setdefault('base_init_args', storageDict['init_method_args']) # set the default name if 'name' in storageDict: if not storageDict.get('name'): storageDict.pop('name') if getattr(obj, 'gname', None) and isinstance(obj, GnamedObject): storageDict['gname'] = obj.gname if not storageDict.get('name', None): storageDict['name'] = obj.gname else: storageDict['gname'] = None if storageDict['as_class']: storage_name = storageDict.get('name', get_type_name(obj)) else: if isinstance(obj, Component): suffix = '_component' else: suffix = '_instance' storage_name = storageDict.get('name', ''.join([get_type_name(obj), suffix]).lower()) if storage_name == get_type_name(obj): storage_name = storage_name + '_instance' storageDict['storage_name'] = \ self.create_valid_storage_name(storage_name) # base_class and import_module if storageDict['base_class']: obj_class = storageDict['base_class'] import_module = obj_class.__module__ else: if isclass(obj): #TODO: this won't work for multiple inheritance mro = getmro(obj) if len(mro) > 1: obj_class = mro[1] import_module = mro[1].__module__ else: obj_class = None import_module = None elif get_type_name(obj) == storageDict['storage_name']: if storageDict['as_class']: cls = obj.__class__ mro = getmro(cls) obj_class = mro[1] import_module = mro[1].__module__ else: storageDict['storage_name'] = ''.join( [storageDict['storage_name'],'_instance']) obj_class = obj.__class__ import_module = obj_class.__module__ else: obj_class = obj.__class__ import_module = obj_class.__module__ storageDict['base_class'] = obj_class storageDict.setdefault('import_module', import_module) storageDict.setdefault('defaults_set', True) return storageDict
def prepare_storageDict(self, obj, storageDict=None, asClass=None): """prepare_storageDict(self, obj, storageDict=None): Set up storageDict. See CodeStorageExporter documentation for details. """ if storageDict and storageDict.get('defaults_set', False): return storageDict if storageDict == None: storageDict = self.get_custom_storageDict(obj) if asClass is not None: storageDict['as_class'] = asClass storageDict.setdefault('obj', obj) storageDict.setdefault('attributes', ['*']) storageDict.setdefault('init_method', '__init__') storageDict.setdefault('init_method_args', ['*args', '**kwargs']) storageDict.setdefault('custom_export_func', None) storageDict.setdefault('as_class', False) storageDict.setdefault('skip_attributes', []) storageDict.setdefault('instance_attributes', []) storageDict.setdefault('base_class', None) storageDict.setdefault('instance_only_attributes', []) storageDict.setdefault('force_init_def', False) storageDict.setdefault('base_init', True) storageDict.setdefault('base_init_args', storageDict['init_method_args']) # set the default name if 'name' in storageDict: if not storageDict.get('name'): storageDict.pop('name') if getattr(obj, 'gname', None) and isinstance(obj, GnamedObject): storageDict['gname'] = obj.gname if not storageDict.get('name', None): storageDict['name'] = obj.gname else: storageDict['gname'] = None if storageDict['as_class']: storage_name = storageDict.get('name', get_type_name(obj)) else: if isinstance(obj, Component): suffix = '_component' else: suffix = '_instance' storage_name = storageDict.get( 'name', ''.join([get_type_name(obj), suffix]).lower()) if storage_name == get_type_name(obj): storage_name = storage_name + '_instance' storageDict['storage_name'] = \ self.create_valid_storage_name(storage_name) # base_class and import_module if storageDict['base_class']: obj_class = storageDict['base_class'] import_module = obj_class.__module__ else: if isclass(obj): #TODO: this won't work for multiple inheritance mro = getmro(obj) if len(mro) > 1: obj_class = mro[1] import_module = mro[1].__module__ else: obj_class = None import_module = None elif get_type_name(obj) == storageDict['storage_name']: if storageDict['as_class']: cls = obj.__class__ mro = getmro(cls) obj_class = mro[1] import_module = mro[1].__module__ else: storageDict['storage_name'] = ''.join( [storageDict['storage_name'], '_instance']) obj_class = obj.__class__ import_module = obj_class.__module__ else: obj_class = obj.__class__ import_module = obj_class.__module__ storageDict['base_class'] = obj_class storageDict.setdefault('import_module', import_module) storageDict.setdefault('defaults_set', True) return storageDict
def set_object(self, object, objectPath="", overrideText=None): self.objectPath = objectPath self.object = object self.SetTitle(" - ".join(["Help", objectPath])) if self.flexGridSizer: self.flexGridSizer.Clear(True) self.flexGridSizer.Destroy() if overrideText: flex = self.scrollPanel.Sizer = wx.FlexGridSizer(1, 1, 0, 0) control = wx.StaticText(self.scrollPanel, -1, label=overrideText) flex.Add(control) self.scrollPanel.SetupScrolling() return info = [] doc = getdoc(object) module = getmodule(object) builtin = module and module.__name__ == "__builtin__" if hasattr(object, "__class__"): isInstance = True classmodule = getmodule(object.__class__) if classmodule and classmodule.__name__ == "__builtin__": builtin = True if isInstance: mro = getmro(object.__class__) elif isclass(object): mro = getmro(object) else: mro = None if objectPath: info += ["Object:", objectPath] if doc and (isroutine(object) or not builtin): info += ["Doc:", doc] info += ["Value:", repr(object)] info += ["Type:", get_type_name(object)] if module: info += ["Module:", str(module)] if mro and not builtin and not isroutine(object): info += ["MRO:", str(mro)] rows = int(len(info) * 0.5) flex = self.scrollPanel.Sizer = wx.FlexGridSizer(rows, 2, 8, 3) flex.AddGrowableCol(1) for i in range(rows): flex.AddGrowableRow(i) flex.SetFlexibleDirection(wx.BOTH) label = True for data in info: control = wx.StaticText(self.scrollPanel, -1, label=data) flex.Add(control) if label: control.SetForegroundColour((150, 150, 150)) label = not label self.flexGridSizer = flex self.SetMinSize((150, 60)) self.SetClientSize((flex.MinSize[0] + self.Sizer.MinSize[0], flex.MinSize[1] + self.Sizer.MinSize[1])) width, height = (self.Size[0] + 20, self.Size[1]) maxheight = height maxwidth = width if height > 300: height = 300 if width > 600: width = 600 self.SetSize((width, height)) self.SetMaxSize((maxwidth, maxheight)) self.scrollPanel.SetupScrolling()