def create_default_agui(attribute, obj, window, family=None, aguidata={}): """Create a default attribute gui for a aguilist entry attribute: the attribute of obj obj: the object we're making an agui for window: the parent of the agui family: see get_attribute_family aguidata: this dictionary will update the default aguidata dictionary """ value = getattr(obj, attribute) aguiDefaultDict = get_agui_default_dict() if isclass(value): attributeClass = value else: attributeClass = get_type(value) if aguiDefaultDict.has_key(attributeClass): guiType = attributeClass else: if not family: # figure out what gui to use family = get_attribute_family(obj, attribute) guiType = family agui = aguiDefaultDict[guiType][0] if len(aguiDefaultDict[guiType]) > 1: aguidatadefault = aguiDefaultDict[guiType][1] else: aguidatadefault = {} aguidatadefault.update(aguidata) attributegui = get_agui(agui, attribute, window, aguidata=aguidatadefault) return attributegui
def create_default_agui(attribute, obj, window, family = None, aguidata = {}): """Create a default attribute gui for a aguilist entry attribute: the attribute of obj obj: the object we're making an agui for window: the parent of the agui family: see get_attribute_family aguidata: this dictionary will update the default aguidata dictionary """ value = getattr(obj, attribute) aguiDefaultDict = get_agui_default_dict() if isclass(value): attributeClass = value else: attributeClass = get_type(value) if aguiDefaultDict.has_key(attributeClass): guiType = attributeClass else: if not family: # figure out what gui to use family = get_attribute_family(obj, attribute) guiType = family agui = aguiDefaultDict[guiType][0] if len(aguiDefaultDict[guiType]) > 1: aguidatadefault = aguiDefaultDict[guiType][1] else: aguidatadefault = {} aguidatadefault.update(aguidata) attributegui = get_agui(agui, attribute, window, aguidata=aguidatadefault) return attributegui
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 setup(self, attribute, window, aguidata): """setup(attribute, window, aguidata) Setup agui. Called on creation and when a cached agui is re-used on another object. Allows an agui to change object, window, or aguidata without recreating all controls. """ if attribute is not None: self.attribute = attribute if aguidata is not None: self.aguidata = aguidata if window is not None: self.window = window if self.control.GetParent() != self.window: self.control.Reparent(self.window) if self.control.IsFrozen(): self.control.Thaw() self.control.Show() if self.label.GetParent() != self.window: self.label.Reparent(self.window) if self.label.IsFrozen(): self.label.Thaw() self.label.Show() aguidata.setdefault('read_only', False) aguidata.setdefault('refresh_all', True) aguidata.setdefault('wait_for_set', True) aguidata.setdefault('undo', True) #label if hasattr(self.label, 'textCtrl'): labelText = aguidata.get( 'label', ''.join([PUGFRAME_ATTRIBUTE_PREFIX, attribute])) self.label.textCtrl.SetLabel(labelText) #tooltip self.tooltip = None if aguidata.has_key('doc'): self.tooltip = aguidata['doc'] else: try: # check if this is a property if isclass(window.object): cls = window.object else: cls = get_type(window.object) prop = getattr(cls, attribute, None) if type(prop) == property: self.tooltip = prop.__doc__ except: pass if self.tooltip: self.set_label_tooltip(self.tooltip) else: self.doc_to_tooltip() self.match_control_size() #background color if aguidata.has_key('background_color'): backgroundColor = aguidata['background_color'] try: self.label.SetBackgroundColour(backgroundColor) self.control.SetBackgroundColour(backgroundColor) except: pass # context help self.setup_context_help(self.label, window) self.setup_context_help(self.control, window) #info if aguidata.has_key('agui_info_dict'): aguidata['agui_info_dict']['agui'] = self
def setup(self, attribute, window, aguidata): """setup(attribute, window, aguidata) Setup agui. Called on creation and when a cached agui is re-used on another object. Allows an agui to change object, window, or aguidata without recreating all controls. """ if attribute is not None: self.attribute = attribute if aguidata is not None: self.aguidata = aguidata if window is not None: self.window = window if self.control.GetParent() != self.window: self.control.Reparent(self.window) if self.control.IsFrozen(): self.control.Thaw() self.control.Show() if self.label.GetParent() != self.window: self.label.Reparent(self.window) if self.label.IsFrozen(): self.label.Thaw() self.label.Show() aguidata.setdefault('read_only',False) aguidata.setdefault('refresh_all', True) aguidata.setdefault('wait_for_set', True) aguidata.setdefault('undo', True) #label if hasattr(self.label, 'textCtrl'): labelText = aguidata.get('label', ''.join([PUGFRAME_ATTRIBUTE_PREFIX,attribute])) self.label.textCtrl.SetLabel( labelText) #tooltip self.tooltip = None if aguidata.has_key('doc'): self.tooltip = aguidata['doc'] else: try: # check if this is a property if isclass(window.object): cls = window.object else: cls = get_type(window.object) prop = getattr(cls, attribute, None) if type(prop) == property: self.tooltip = prop.__doc__ except: pass if self.tooltip: self.set_label_tooltip(self.tooltip) else: self.doc_to_tooltip() self.match_control_size() #background color if aguidata.has_key('background_color'): backgroundColor = aguidata['background_color'] try: self.label.SetBackgroundColour(backgroundColor) self.control.SetBackgroundColour(backgroundColor) except: pass # context help self.setup_context_help(self.label, window) self.setup_context_help(self.control, window) #info if aguidata.has_key('agui_info_dict'): aguidata['agui_info_dict']['agui'] = self
def create_pugview_aguilist(obj, window, pugview, filterUnderscore=2): """create_pugview_pug(obj, window, pugview, filterUnderscore) -> aguilist aguilist is a list of pug aguis for obj obj: object to be examined window: the pugFrame object pugview: pugview to be used. filterUnderscore: 2 = don't show __attributes, 1 = don't show _attributes either Create a gui based on pugview. A class' pugview can be created as follows: pugview = \ { 'name': mySpecialView # the name of this pugview # if this is not defined, 'Pugview #' will be assigned 'size': (400, 300) # the start size of the pug frame, in pixels # if this is not defined, default size will be assigned 'defaults':{ 'int':[Number,{'decimals':0}] # attribute class name:[agui,aguidata (dict is standard)] }, # defaults are used if agui is unspecified in 'attributes' # if the default isn't found in this list, uses the create_raw_gui defaults # this is optional 'attributes':[ ['<attribute>',<agui> or '<tooltip>',<aguidata>], ['gname'], # 'gname' is attribute. use agui from 'defaults' ['position',Vector2,{'decimals':3}], # Vector2 is agui ['ratio','tooltip blabla'], # 'tooltip blabla' is tooltip. Default agui ['notmesswith', None, {'read_only':True}], # use agui from 'defaults' ['*'] ] # list of attributes to display. ['*'] = list all remaining using defaults # if this is not defined, ['*'] is assumed 'create_pug_list_function': fn # a custom aguilist creation function can be specified here # this is optional # fn(obj, window, filterUnderscore) will be called # arguments are as per this function 'skip_menus': ['menu_name',...] # a list of menus that will NOT be shown in the menubar. Standard menus # include 'View' and 'Export', but more can be added with # app.set_global_menus or manually. 'info_function': fn # a custom info function can be specified here # this is optional # fn( obj, window, objectPath) -> info frame # arguments are as per this function. objectPath is a string representing # the programatic path to obj. If fn opens a frame, it should return it. 'no_source': bool # if True, no 'View source code' option will be shown in View menu 'no_shell': bool # if True, no 'Open shell' option will be shown in View menu } import pug pug.add_pugview(myClass, pugview) Additionally, an instance or class can have a '_pug_pugview_class' attribute which contains the class whose pugviews can be used. For example: class otherClass( myClass): _pug_pugview_class = myClass """ if _DEBUG: print "create_pugview_aguilist: begin" if type(pugview) and pugview.has_key('create_pug_list_function'): aguilist = pugview['create_pug_list_function'](obj, window, filterUnderscore) else: dirList = dir(obj) if pugview.has_key('attributes'): attributeList = pugview['attributes'] else: attributeList = [['*']] # show all if pugview.has_key('defaults'): defaultDict = pugview['defaults'] else: defaultDict = {} aguilist = [] # go through list of attributes in pugview if _DEBUG: print obj for entry in attributeList: attributegui = None attribute = entry[0] if _DEBUG: print "create_pugview_aguilist: attr -", attribute if attribute == '*': #create default gui for all attributes we haven't made a gui for for attribute in dirList: # test underscores if filterUnderscore: if do_filter_underscore(attribute, filterUnderscore): continue attributegui = create_default_agui(attribute, obj, window) if attributegui: aguilist.append(attributegui) continue # make sure we have an attribute, or a non-attr agui entry if not (attribute) and len(entry) == 1: continue # TODO: make a warning list viewable in the pugframe for this: tooltip = None agui = None if len(entry) > 1: # do we have the agui type or a doc string? if type(entry[1]) in types.StringTypes: tooltip = entry[1] elif entry[1]: agui = entry[1] # do we have special info for the agui? if len(entry) > 2: aguidata = entry[2].copy() else: aguidata = {} if tooltip: aguidata['doc'] = tooltip if agui: # create the agui attributegui = get_agui(agui, attribute, window, aguidata=aguidata) else: # no specified agui, so figure out the default try: attributeValue = getattr(obj, attribute) except: continue if isclass(attributeValue): attributeClass = attributeValue else: attributeClass = get_type(attributeValue) if defaultDict.has_key(attributeClass): info = defaultDict[attributeClass] agui = info[0] if len(info) > 2: aguidata = info[2].copy() else: aguidata = {} if tooltip: aguidata['doc'] = tooltip attributegui = get_agui(agui, attribute, window, aguidata=aguidata) else: if len(entry) > 2: aguidata = entry[2].copy() else: aguidata = {} if tooltip: aguidata['doc'] = tooltip attributegui = create_default_agui(attribute, obj, window, aguidata=aguidata) if attributegui: aguilist.append(attributegui) if entry[0] in dirList: dirList.remove(entry[0]) if _DEBUG: print "create_pugview_aguilist: end" return aguilist
def create_pugview_aguilist(obj, window, pugview, filterUnderscore = 2): """create_pugview_pug(obj, window, pugview, filterUnderscore) -> aguilist aguilist is a list of pug aguis for obj obj: object to be examined window: the pugFrame object pugview: pugview to be used. filterUnderscore: 2 = don't show __attributes, 1 = don't show _attributes either Create a gui based on pugview. A class' pugview can be created as follows: pugview = \ { 'name': mySpecialView # the name of this pugview # if this is not defined, 'Pugview #' will be assigned 'size': (400, 300) # the start size of the pug frame, in pixels # if this is not defined, default size will be assigned 'defaults':{ 'int':[Number,{'decimals':0}] # attribute class name:[agui,aguidata (dict is standard)] }, # defaults are used if agui is unspecified in 'attributes' # if the default isn't found in this list, uses the create_raw_gui defaults # this is optional 'attributes':[ ['<attribute>',<agui> or '<tooltip>',<aguidata>], ['gname'], # 'gname' is attribute. use agui from 'defaults' ['position',Vector2,{'decimals':3}], # Vector2 is agui ['ratio','tooltip blabla'], # 'tooltip blabla' is tooltip. Default agui ['notmesswith', None, {'read_only':True}], # use agui from 'defaults' ['*'] ] # list of attributes to display. ['*'] = list all remaining using defaults # if this is not defined, ['*'] is assumed 'create_pug_list_function': fn # a custom aguilist creation function can be specified here # this is optional # fn(obj, window, filterUnderscore) will be called # arguments are as per this function 'skip_menus': ['menu_name',...] # a list of menus that will NOT be shown in the menubar. Standard menus # include 'View' and 'Export', but more can be added with # app.set_global_menus or manually. 'info_function': fn # a custom info function can be specified here # this is optional # fn( obj, window, objectPath) -> info frame # arguments are as per this function. objectPath is a string representing # the programatic path to obj. If fn opens a frame, it should return it. 'no_source': bool # if True, no 'View source code' option will be shown in View menu 'no_shell': bool # if True, no 'Open shell' option will be shown in View menu } import pug pug.add_pugview(myClass, pugview) Additionally, an instance or class can have a '_pug_pugview_class' attribute which contains the class whose pugviews can be used. For example: class otherClass( myClass): _pug_pugview_class = myClass """ if _DEBUG: print "create_pugview_aguilist: begin" if type(pugview) and pugview.has_key('create_pug_list_function'): aguilist = pugview['create_pug_list_function'](obj, window, filterUnderscore) else: dirList = dir(obj) if pugview.has_key('attributes'): attributeList = pugview['attributes'] else: attributeList = [['*']] # show all if pugview.has_key('defaults'): defaultDict = pugview['defaults'] else: defaultDict = {} aguilist = [] # go through list of attributes in pugview if _DEBUG: print obj for entry in attributeList: attributegui = None attribute = entry[0] if _DEBUG: print "create_pugview_aguilist: attr -", attribute if attribute == '*': #create default gui for all attributes we haven't made a gui for for attribute in dirList: # test underscores if filterUnderscore: if do_filter_underscore(attribute, filterUnderscore): continue attributegui = create_default_agui(attribute, obj, window) if attributegui: aguilist.append(attributegui) continue # make sure we have an attribute, or a non-attr agui entry if not(attribute) and len(entry) == 1: continue # TODO: make a warning list viewable in the pugframe for this: tooltip = None agui = None if len(entry) > 1: # do we have the agui type or a doc string? if type(entry[1]) in types.StringTypes: tooltip = entry[1] elif entry[1]: agui = entry[1] # do we have special info for the agui? if len(entry) > 2: aguidata = entry[2].copy() else: aguidata = {} if tooltip: aguidata['doc'] = tooltip if agui: # create the agui attributegui = get_agui(agui, attribute, window, aguidata=aguidata) else: # no specified agui, so figure out the default try: attributeValue = getattr(obj,attribute) except: continue if isclass(attributeValue): attributeClass = attributeValue else: attributeClass = get_type(attributeValue) if defaultDict.has_key(attributeClass): info = defaultDict[attributeClass] agui = info[0] if len(info) > 2: aguidata = info[2].copy() else: aguidata = {} if tooltip: aguidata['doc'] = tooltip attributegui = get_agui(agui, attribute, window, aguidata=aguidata) else: if len(entry) > 2: aguidata = entry[2].copy() else: aguidata = {} if tooltip: aguidata['doc'] = tooltip attributegui = create_default_agui(attribute, obj, window, aguidata=aguidata) if attributegui: aguilist.append(attributegui) if entry[0] in dirList: dirList.remove(entry[0]) if _DEBUG: print "create_pugview_aguilist: end" return aguilist