def format_value(self, value): do_format = self.format if do_format is None: do_format = FORMAT_FLOATS if do_format: # float formating self.realValue = value f = prettify_data(value) self.lastValue = str(f) display = f # self.SetToolTipString(str(value)) else: self.realValue = None if value is None: value = "#None#" display = str(value) # self.SetToolTipString(str(value)) return display
def _create_argument_code(self, indentLevel): """_create_argument_code( indentLevel) Creates the list of arguments for a component's init function. This sets all the items in the component's _field_list, as long as they are different from the default values. They are formatted to be indented twice beyond indentLevel, with line breaks between each. To create a single-line argument list, strip out all '\n' characters. """ dummy = self.__class__() argIndent = _INDENT * (indentLevel + 2) attributes = ['gname'] for item in self._field_list: attributes.append(item[0]) attributes.append('enabled') attribute_code = [] for attr in attributes: store = True try: val = getattr(self, attr) dummyval = getattr(dummy, attr) if val == dummyval: store = False except: store = False if store: output = prettify_data(val) if type(val) == str or type(val) == unicode: output = repr(output) attribute_code += [''.join([attr, '=', output])] joiner = ''.join([',\n', argIndent]) code = joiner.join(attribute_code) if attribute_code: code = ''.join(['\n', argIndent, code]) else: code = '' return code
def _create_argument_code(self, indentLevel): """_create_argument_code( indentLevel) Creates the list of arguments for a component's init function. This sets all the items in the component's _field_list, as long as they are different from the default values. They are formatted to be indented twice beyond indentLevel, with line breaks between each. To create a single-line argument list, strip out all '\n' characters. """ dummy = self.__class__() argIndent = _INDENT * (indentLevel + 2) attributes = ['gname'] for item in self._field_list: attributes.append(item[0]) attributes.append('enabled') attribute_code = [] for attr in attributes: store = True try: val = getattr(self, attr) dummyval = getattr(dummy, attr) if val == dummyval: store = False except: store = False if store: output = prettify_data( val) if type(val) == str or type(val) == unicode: output = repr(output) attribute_code += [''.join([attr, '=', output])] joiner = ''.join([',\n',argIndent]) code = joiner.join(attribute_code) if attribute_code: code = ''.join(['\n',argIndent,code]) else: code = '' return code
def create_attribute_code(self, obj, storageDict, indentLevel=0, prefix='', attributeList=None): if attributeList is None: attributeList, instanceAttrList = self.create_attribute_lists( obj, storageDict) storageDict = self.prepare_storageDict(obj, storageDict) baseIndent = _INDENT*indentLevel codeList = [] dummy = self.get_dummy(storageDict['base_class']) # create code for requested attributes, if possible for attr in attributeList: # make sure we can actually get this attribute try: val = getattr(obj, attr) except: continue # don't bother with callable objects if callable(val): continue if dummy: # if we have a dummy, only store object attributes that are # different from the dummy's values dummyval = not val try: dummyval = getattr(dummy, attr) except: pass if dummyval == val: continue # For objects that are not builtins, see if they are # sub-objects. A sub-object is an object that is built into # an object at creation time. #continue # the code below MIGHT work, but is untested # ###################################################### # if getattr(dummyval, '__class__', 0) is \ # getattr(val, '__class__', 1): # # it's a sub-object. Try to code_exporter it # name = storageDict['storage_name'] # self.create_subobject_code(val, name, attr, # indentLevel) # # continue # else: # continue # continue # ####################################################### if getattr(val, '__module__', None): # this is some kind of non builtin object if val.__class__ == ComponentSet: #if it's components store 'em component_code = \ self.create_component_code( obj, storageDict, indentLevel) codeList += [component_code] continue else: #otherwise only store builtins for now continue output = prettify_data(val) if type(val) == str or type(val) == unicode: output = repr(output) line = [baseIndent, prefix, attr, ' = ', output, '\n'] codeList += line return ''.join(codeList)
def create_attribute_code(self, obj, storageDict, indentLevel=0, prefix='', attributeList=None): if attributeList is None: attributeList, instanceAttrList = self.create_attribute_lists( obj, storageDict) storageDict = self.prepare_storageDict(obj, storageDict) baseIndent = _INDENT * indentLevel codeList = [] dummy = self.get_dummy(storageDict['base_class']) # create code for requested attributes, if possible for attr in attributeList: # make sure we can actually get this attribute try: val = getattr(obj, attr) except: continue # don't bother with callable objects if callable(val): continue if dummy: # if we have a dummy, only store object attributes that are # different from the dummy's values dummyval = not val try: dummyval = getattr(dummy, attr) except: pass if dummyval == val: continue # For objects that are not builtins, see if they are # sub-objects. A sub-object is an object that is built into # an object at creation time. #continue # the code below MIGHT work, but is untested # ###################################################### # if getattr(dummyval, '__class__', 0) is \ # getattr(val, '__class__', 1): # # it's a sub-object. Try to code_exporter it # name = storageDict['storage_name'] # self.create_subobject_code(val, name, attr, # indentLevel) # # continue # else: # continue # continue # ####################################################### if getattr(val, '__module__', None): # this is some kind of non builtin object if val.__class__ == ComponentSet: #if it's components store 'em component_code = \ self.create_component_code( obj, storageDict, indentLevel) codeList += [component_code] continue else: #otherwise only store builtins for now continue output = prettify_data(val) if type(val) == str or type(val) == unicode: output = repr(output) line = [baseIndent, prefix, attr, ' = ', output, '\n'] codeList += line return ''.join(codeList)
def display_component(self, component): """Create text to describe component""" #TODO: this is just an ugly, hacked version. Need a nice display format #title if component is None: self.infosizer.Clear(True) text = wx.StaticText(self, -1, "") self.infosizer.Add(text,0) return if isinstance( component, Component): instance = component component = component.__class__ else: instance = False self.Freeze() self.infosizer.Clear(True) textlist = [] textlist.append(component.__name__) textlist.append('\n\n') if component.__doc__: textlist.append(component.__doc__) textlist.append('\n\n') if component._set: textlist+=['Set: ',component._set,'\n'] if component._type: textlist+=['Type: ',component._type,'\n'] if component._class_list: textlist+=['For Class: ',] c = 0 for cls in component._class_list: if c: textlist.append(' ') textlist+=[cls.__name__, ' (',cls.__module__,'.',cls.__name__,')\n'] if component._field_list: textlist.append('\n') textlist+=['Fields:'] text=''.join(textlist) text = wx.StaticText(self, -1, text) self.infosizer.Add(text,0,wx.WEST,5) dummy = component() for item in component._field_list: textlist = [] textlist+=['\n',item[0],': (Default='] data = getattr(dummy,item[0]) if type(data) in [str, unicode]: info = repr(data) else: info = prettify_data(data) textlist+=[info,')'] if instance: textlist+=[' (Current='] data = getattr(instance,item[0]) if type(data) in [str, unicode]: info = repr(data) else: info = prettify_data(data) textlist+=[info, ')'] text=''.join(textlist) text = wx.StaticText(self, -1, text) self.infosizer.Add(text,0,wx.WEST,15) doc = '' if len(item) > 1: if type(item[1]) in types.StringTypes: doc = item[1] elif len(item) > 2: doc = item[2].get('doc', '') text = wx.StaticText(self, -1, doc) self.infosizer.Add(text,0,wx.WEST,35) text = wx.StaticText(self, -1, '\nMethods:') self.infosizer.Add(text,0,wx.WEST,5) for item in dir(component): attr = getattr(component, item) if isinstance(attr, component_method): text = ''.join(['\n',item,':']) text = wx.StaticText(self, -1, text) self.infosizer.Add(text,0,wx.WEST,15) if attr.__doc__: text = wx.StaticText(self, -1, attr.__doc__) self.infosizer.Add(text,0,wx.WEST,35) self.infosizer.Layout() self.infosizer.MinSize = self.infosizer.Size self.SetupScrolling() if self.IsFrozen(): self.Thaw()
def display_component(self, component): """Create text to describe component""" #TODO: this is just an ugly, hacked version. Need a nice display format #title if component is None: self.infosizer.Clear(True) text = wx.StaticText(self, -1, "") self.infosizer.Add(text, 0) return if isinstance(component, Component): instance = component component = component.__class__ else: instance = False self.Freeze() self.infosizer.Clear(True) textlist = [] textlist.append(component.__name__) textlist.append('\n\n') if component.__doc__: textlist.append(component.__doc__) textlist.append('\n\n') if component._set: textlist += ['Set: ', component._set, '\n'] if component._type: textlist += ['Type: ', component._type, '\n'] if component._class_list: textlist += [ 'For Class: ', ] c = 0 for cls in component._class_list: if c: textlist.append(' ') textlist += [ cls.__name__, ' (', cls.__module__, '.', cls.__name__, ')\n' ] if component._field_list: textlist.append('\n') textlist += ['Fields:'] text = ''.join(textlist) text = wx.StaticText(self, -1, text) self.infosizer.Add(text, 0, wx.WEST, 5) dummy = component() for item in component._field_list: textlist = [] textlist += ['\n', item[0], ': (Default='] data = getattr(dummy, item[0]) if type(data) in [str, unicode]: info = repr(data) else: info = prettify_data(data) textlist += [info, ')'] if instance: textlist += [' (Current='] data = getattr(instance, item[0]) if type(data) in [str, unicode]: info = repr(data) else: info = prettify_data(data) textlist += [info, ')'] text = ''.join(textlist) text = wx.StaticText(self, -1, text) self.infosizer.Add(text, 0, wx.WEST, 15) doc = '' if len(item) > 1: if type(item[1]) in types.StringTypes: doc = item[1] elif len(item) > 2: doc = item[2].get('doc', '') text = wx.StaticText(self, -1, doc) self.infosizer.Add(text, 0, wx.WEST, 35) text = wx.StaticText(self, -1, '\nMethods:') self.infosizer.Add(text, 0, wx.WEST, 5) for item in dir(component): attr = getattr(component, item) if isinstance(attr, component_method): text = ''.join(['\n', item, ':']) text = wx.StaticText(self, -1, text) self.infosizer.Add(text, 0, wx.WEST, 15) if attr.__doc__: text = wx.StaticText(self, -1, attr.__doc__) self.infosizer.Add(text, 0, wx.WEST, 35) self.infosizer.Layout() self.infosizer.MinSize = self.infosizer.Size self.SetupScrolling() if self.IsFrozen(): self.Thaw()