Beispiel #1
0
 def __append_int_property ( self, parent_pid, name, label, format ):
     """ Append an integer property to the grid, taken into 
     account all special editors """
     editor = format[Format_Editor]
     if editor == Editor_Spinner:
         # Editor spinner
         prop = pg.wxIntProperty( name, label )
     elif editor == Editor_Slider:
         # Set to slider for integers
         format[Format_Editor] = Editor_Slider_Int
         prop = pg.wxIntProperty( name, label )
         self.MakeAnyControlById( prop.GetId() )
     elif format[Format_Enums] != None:
         # Enum editor
         enums = format[Format_Enums]
         enums_list = self.__get_enum_list(enums)
         prop = pg.wxEnumProperty(
                     name, 
                     label, 
                     enums_list[0], 
                     enums_list[1], 
                     1
                     )
     elif format[Format_Flags] != None:
         # Flags editor
         flags = format[Format_Flags] 
         #pid = self.append_group(parent_pid, name, format)
         labels_list = []
         values_list = []
         for flag in flags.split(','):
             label = self.__get_next_label()
             flag_string = flag.split(':')[0]
             flag_values = int(flag.split(':')[1])
             labels_list.append(flag_string)
             values_list.append(flag_values)
         pid = pg.wxFlagsProperty ( name, label, labels_list, values_list )
         return pid
     else:
         prop = pg.wxIntProperty( name, label )
     return prop
 def __draw_input_fields(self, arg, element, type):        
     for i in xrange(len(arg)):
         if type == "in":                            
             label = "label_in%d" % i
         else:
             label = "label_out%d" % i
             
         if arg[i] == 'i':
             element.append(pg.wxIntProperty('Integer', label))
             self.cmds_pg.Append(element[i])
         elif arg[i] == 'f':
             element.append(pg.wxFloatProperty('Float', label))
             self.cmds_pg.Append(element[i])
         elif arg[i] == 's':
             if type == "in":
                 element.append(pg.wxStringCallBackProperty('String', 
                                 label, '' ))
                 self.cmds_pg.Append(element[i])
                 dlg = browser.create_dialog(self, True)
                 element[i].SetCallBackDialog(dlg)
             else:                    
                 element.append(pg.wxStringProperty('String', label, ''))
                 self.cmds_pg.Append(element[i])
         elif arg[i] == 'b':
             element.append(pg.wxEnumProperty('Boolean', 
                                label,['True','False'],[1,0],2,0 ))
             self.cmds_pg.Append(element[i])
         elif arg[i] == 'o':
             if type == "in":
                 element.append(pg.wxStringCallBackProperty( 'Object', 
                                     label, '' ))
                 self.cmds_pg.Append(element[i])
                 dlg = browser.create_dialog(self, True)        
                 element[i].SetCallBackDialog(dlg)  
             else:
                 element.append(pg.wxStringProperty('Object', label, ''))
                 self.cmds_pg.Append(element[i])
         elif arg[i] == 'l':
             if type == "in":
                 element.append(pg.wxStringProperty('List', label, ''))
                 self.cmds_pg.Append(element[i])
             else:
                 element.append(pg.wxArrayStringProperty('List', label, ''))
                 self.cmds_pg.Append(element[i])
             
         else:
             element.append(pg.wxStringProperty('String', label,
                                                    'Unknow type!!!'))
             self.cmds_pg.Append(element[i])
def draw_input_fields(inspector_win, arg, element, type):        
    for i in xrange(len(arg)):
        if type == "in":                            
            label = "label_in%d" % i
        else:
            label = "label_out%d" % i
            
        if arg[i] == 'i':
            element.append(pg.wxIntProperty('Integer', label))
            inspector_win.cmds_pg.Append(element[i])
        elif arg[i] == 'f':
            element.append(pg.wxFloatProperty('Float', label))
            inspector_win.cmds_pg.Append(element[i])
        elif arg[i] == 's':
            if type == "in":
                element.append(pg.wxStringCallBackProperty('String', 
                                label, '' ))
                inspector_win.cmds_pg.Append(element[i])
                dlg = browser.create_dialog(inspector_win, True)
                element[i].SetCallBackDialog(dlg)                                               
            else:                    
                element.append(pg.wxStringProperty('String', label, ''))
                inspector_win.cmds_pg.Append(element[i])
        elif arg[i] == 'b':
            element.append(pg.wxEnumProperty('Boolean', 
                               label,['True','False'],[1,0],2 ))
            inspector_win.cmds_pg.Append(element[i])
        elif arg[i] == 'o':
            if type == "in":
                element.append(pg.wxStringCallBackProperty( 'Object', 
                                    label, '' ))
                inspector_win.cmds_pg.Append(element[i])
                dlg = browser.create_dialog(inspector_win, True)        
                element[i].SetCallBackDialog(dlg)  
            else:
                element.append(pg.wxStringProperty('Object', label, ''))
                inspector_win.cmds_pg.Append(element[i])
        elif arg[i] == 'l':
            if type == "in":
                element.append(pg.wxStringProperty('List', label, ''))
                inspector_win.cmds_pg.Append(element[i])
            else:
                element.append(pg.wxArrayStringProperty('List', label, ''))
                inspector_win.cmds_pg.Append(element[i])
            
        else:
            element.append(pg.wxStringProperty('String', label,
                                                   'Unknow type!!!'))
            inspector_win.cmds_pg.Append(element[i])
    def draw_state_commands(self, obj):
        self.cmds_pg.Clear()

        if obj is None:
            self.Disable()
            return
        else:
            self.Enable()

        # Get the commands

        inspector = pynebula.new(
                            "nobjinspector",
                            "/editor/inspector"
                            )
        inspector.initcmdsstate(obj)

        # Navigate over the commands and build the interface. We need
        # the command definition to put it in the category. So first create
        # the grid properties  but do not append them until the category
        # is placed with the full description.

        cmds_count = inspector.getcmdscount() 
        self.cmd_list = list()       # Command list
        self.cmd_name_list = list()  # Store the categories
        self.undo_list = list()

        if cmds_count == 0:
            self.cmds_pg.Append(
                pg.wxPropertyCategory(
                    str("State is EMPTY"), 
                    str("nostate")
                    )
                )

        self.prev_state = list() # Storage state when the inspector is call
        for num_cmd in xrange(cmds_count):
            cmds_name_desc = inspector.getcmdname(num_cmd) + str(" (")
            undo_cmd = inspector.getcmdname(num_cmd) + str("(")
            args_count = inspector.getinargscount(num_cmd)
            self.element = list()   # Start argument list            

            for num_arg in xrange(args_count):                
                label = "label_in" + str(num_cmd) + "-" + str(num_arg+1)
                arg_type = inspector.gettype(num_cmd, num_arg+1)

                # Type is Int

                if arg_type == 1:
                    value = inspector.geti(num_cmd, num_arg+1)
                    self.element.append(
                        pg.wxIntProperty(
                            'Integer', 
                            label
                            )
                        )
                    value_as_string = str(value)
                    self.element[num_arg].SetValueFromString(
                        value_as_string, 
                        0
                        )
                    self.prev_state.append(value_as_string)
                    cmds_name_desc = cmds_name_desc + value_as_string + ", "
                    undo_cmd = undo_cmd + value_as_string + ","

                # Type is Float

                elif arg_type == 2:
                    value = inspector.getf(num_cmd, num_arg+1)
                    self.element.append(
                        pg.wxFloatProperty(
                            'Float', 
                            label
                            )
                        )
                    value_as_string = str(value)    
                    self.element[num_arg].SetValueFromString(
                        value_as_string,
                        0
                        )
                    self.prev_state.append(value_as_string)
                    undo_cmd = undo_cmd + value_as_string + ","
                    temp = value_as_string.rsplit('.')
                    value = temp[0] + '.' + temp[1][:2]
                    cmds_name_desc = cmds_name_desc + value_as_string + ", "

                # Type if String

                elif arg_type == 3:
                    value = inspector.gets(num_cmd, num_arg+1)
                    self.element.append(
                        pg.wxStringProperty(
                            'String',
                            label, 
                            ''
                            )
                        )
                    value_as_string = str(value)
                    self.element[num_arg].SetValueFromString(
                        value_as_string,
                        0
                        )
                    self.prev_state.append(value_as_string)
                    cmds_name_desc = cmds_name_desc +\
                                   '"' + value_as_string + '"' + ", "
                    undo_cmd = undo_cmd + '"' + value_as_string + '"' + ","

                # Type is Boolean

                elif arg_type == 4:
                    value = inspector.getb(num_cmd, num_arg+1)
                    self.element.append(
                        pg.wxEnumProperty(
                            'Boolean', 
                            label,
                            ['True','False'],
                            [1,0],
                            2 
                            )
                        )
                    if value == 1:
                        self.element[num_arg].SetValueFromString(
                            str("True"), 
                            0
                            )
                        cmds_name_desc = cmds_name_desc + str('True') + ", "
                        self.prev_state.append('True')
                    else:
                        self.element[num_arg].SetValueFromString(
                            str("False"), 
                            0
                            )
                        cmds_name_desc = cmds_name_desc + str('False') + ", "
                        self.prev_state.append('False')
                    undo_cmd = undo_cmd + str(value) + ","

                # Type is Object

                elif arg_type == 5:
                    value = inspector.geto(num_cmd, num_arg+1)             
                    self.element.append(
                        pg.wxStringProperty(
                            'Object', 
                            label, 
                            ''
                            )
                        )
                    full_name_as_string = str( value.getfullname() )
                    self.element[num_arg].SetValueFromString(
                        full_name_as_string,
                        0
                        )
                    self.prev_state.append(full_name_as_string)
                    cmds_name_desc = cmds_name_desc +\
                                   str(value.getname()) + ", "
                    undo_cmd = undo_cmd + "lookup(" + \
                                            full_name_as_string + "),"

                # Type not implemented

                else:
                    cjr.show_error_message("Unknown type!!!")

            # Write the command definition into the category and attach it

            if args_count > 0:
                cmds_name_desc = cmds_name_desc[:-2] + ")"
                undo_cmd = undo_cmd[:-1] + ")"
            else:
                cmds_name_desc = cmds_name_desc + ")"
                undo_cmd = undo_cmd + ")"

            category = pg.wxPropertyCategory(
                                cmds_name_desc, 
                                "cmdLabel%d" % num_cmd
                                )
            self.cmds_pg.Append(category)
            self.cmd_name_list.append(
                inspector.getcmdprotoname(num_cmd)
                )

            # Show the arguments (append to grid) recently created 
            # and append them to a command list

            for num_arg in xrange(args_count):
                self.cmds_pg.Append(self.element[num_arg])
            
            self.cmd_list.append(self.element)

            self.undo_list.append(undo_cmd)

        pynebula.delete("/editor/inspector")

        # Make de object the current

        nebulagui.nebula_object = obj
        self.object = obj

        # Refresh control
        self.cmds_pg.Refresh()
def __draw_input_fields(inspector, params, type):
    i = 0

    for param in params:
        if type == "in":
            label = "label_in%d" % i
        else:
            label = "label_out%d" % i

        param_type = inspector.xml.get_param_type(param)
        param_name = inspector.xml.get_param_name(param)

        # Get posible attributes

        editor = ""
        min_value = ""
        max_value = ""
        default_value = ""
        step = ""
        subtype = ""

        for attr in inspector.xml.get_param_attrs(param):
            attr_type = inspector.xml.get_attr_type(attr)

            if "editor" == attr_type:
                editor = inspector.xml.get_attr_value(attr)

            if "min" == attr_type:
                min_value = inspector.xml.get_attr_value(attr)

            if "max" == attr_type:
                max_value = inspector.xml.get_attr_value(attr)

            if "default" == attr_type:
                default_value = inspector.xml.get_attr_value(attr)

            if "step" == attr_type:
                step = inspector.xml.get_attr_value(attr)

            if "subtype" == attr_type:
                subtype = inspector.xml.get_attr_value(attr)

        if param_type == 'i':
            if "spin" == editor:
                element = pg.wxIntProperty(param_name, label)

            elif "color" == editor:
                element = pg.wxColourProperty(param_name, label, wx.RED)

            elif "slider" == editor:
                element = pg.wxIntProperty(param_name, label)

            elif "enum" == editor:
                test_labels = ["uno", "dos", "tres"]
                test_values = [1, 2, 3]
                element = pg.wxEnumProperty(param_name, label, test_labels,
                                            test_values)

            elif "flags" == editor:
                element = pg.wxIntProperty("flags", label)
            else:
                element = pg.wxIntProperty(param_name, label)

        elif param_type == 'f':
            element = pg.wxFloatProperty('Float', label)

        elif param_type == 's':
            if "" == editor:
                if type == "in":
                    element = check_string_subtypes(subtype, param_name, label)
                else:
                    element = pg.wxStringProperty(param_name, label, '')
            elif "font" == editor:
                element = pg.wxFontProperty(param_name, label, wx.NORMAL_FONT)

        elif param_type == 'b':
            element = pg.wxEnumProperty('Boolean', label, ['True', 'False'],
                                        [1, 0], 2)
        elif param_type == 'o':
            if type == "in":
                element = check_string_subtypes(subtype, param_name, label)
            else:
                element = pg.wxStringProperty(param_name, label, '')
        elif param_type == 'l':
            if type == "in":
                element = pg.wxStringProperty('List', label, '')
            else:
                element = pg.wxArrayStringProperty('List', label, '')

        else:
            element = pg.wxStringProperty('String', label, 'Unknow type!!!')

        inspector.cmds_pg.Append(element)

        if "spin" == editor or "slider" == editor:
            inspector.cmds_pg.MakeIntegerSpinControl(label)

        if "in" == type:
            inspector.in_elements.append(element)
        else:
            inspector.out_elements.append(element)

        i = i + 1
    def draw_state_commands(self, obj):
        self.cmds_pg.Clear()

        if obj is None:
            self.Disable()
            return
        else:
            self.Enable()

        # Get the commands

        inspector = pynebula.new("nobjinspector", "/editor/inspector")
        inspector.initcmdsstate(obj)

        # Navigate over the commands and build the interface. We need
        # the command definition to put it in the category. So first create
        # the grid properties  but do not append them until the category
        # is placed with the full description.

        cmds_count = inspector.getcmdscount()
        self.cmd_list = list()  # Command list
        self.cmd_name_list = list()  # Store the categories
        self.undo_list = list()

        if cmds_count == 0:
            self.cmds_pg.Append(
                pg.wxPropertyCategory(str("State is EMPTY"), str("nostate")))

        self.prev_state = list()  # Storage state when the inspector is call
        for num_cmd in xrange(cmds_count):
            cmds_name_desc = inspector.getcmdname(num_cmd) + str(" (")
            undo_cmd = inspector.getcmdname(num_cmd) + str("(")
            args_count = inspector.getinargscount(num_cmd)
            self.element = list()  # Start argument list

            for num_arg in xrange(args_count):
                label = "label_in" + str(num_cmd) + "-" + str(num_arg + 1)
                arg_type = inspector.gettype(num_cmd, num_arg + 1)

                # Type is Int

                if arg_type == 1:
                    value = inspector.geti(num_cmd, num_arg + 1)
                    self.element.append(pg.wxIntProperty('Integer', label))
                    value_as_string = str(value)
                    self.element[num_arg].SetValueFromString(
                        value_as_string, 0)
                    self.prev_state.append(value_as_string)
                    cmds_name_desc = cmds_name_desc + value_as_string + ", "
                    undo_cmd = undo_cmd + value_as_string + ","

                # Type is Float

                elif arg_type == 2:
                    value = inspector.getf(num_cmd, num_arg + 1)
                    self.element.append(pg.wxFloatProperty('Float', label))
                    value_as_string = str(value)
                    self.element[num_arg].SetValueFromString(
                        value_as_string, 0)
                    self.prev_state.append(value_as_string)
                    undo_cmd = undo_cmd + value_as_string + ","
                    temp = value_as_string.rsplit('.')
                    value = temp[0] + '.' + temp[1][:2]
                    cmds_name_desc = cmds_name_desc + value_as_string + ", "

                # Type if String

                elif arg_type == 3:
                    value = inspector.gets(num_cmd, num_arg + 1)
                    self.element.append(
                        pg.wxStringProperty('String', label, ''))
                    value_as_string = str(value)
                    self.element[num_arg].SetValueFromString(
                        value_as_string, 0)
                    self.prev_state.append(value_as_string)
                    cmds_name_desc = cmds_name_desc +\
                                   '"' + value_as_string + '"' + ", "
                    undo_cmd = undo_cmd + '"' + value_as_string + '"' + ","

                # Type is Boolean

                elif arg_type == 4:
                    value = inspector.getb(num_cmd, num_arg + 1)
                    self.element.append(
                        pg.wxEnumProperty('Boolean', label, ['True', 'False'],
                                          [1, 0], 2))
                    if value == 1:
                        self.element[num_arg].SetValueFromString(
                            str("True"), 0)
                        cmds_name_desc = cmds_name_desc + str('True') + ", "
                        self.prev_state.append('True')
                    else:
                        self.element[num_arg].SetValueFromString(
                            str("False"), 0)
                        cmds_name_desc = cmds_name_desc + str('False') + ", "
                        self.prev_state.append('False')
                    undo_cmd = undo_cmd + str(value) + ","

                # Type is Object

                elif arg_type == 5:
                    value = inspector.geto(num_cmd, num_arg + 1)
                    self.element.append(
                        pg.wxStringProperty('Object', label, ''))
                    full_name_as_string = str(value.getfullname())
                    self.element[num_arg].SetValueFromString(
                        full_name_as_string, 0)
                    self.prev_state.append(full_name_as_string)
                    cmds_name_desc = cmds_name_desc +\
                                   str(value.getname()) + ", "
                    undo_cmd = undo_cmd + "lookup(" + \
                                            full_name_as_string + "),"

                # Type not implemented

                else:
                    cjr.show_error_message("Unknown type!!!")

            # Write the command definition into the category and attach it

            if args_count > 0:
                cmds_name_desc = cmds_name_desc[:-2] + ")"
                undo_cmd = undo_cmd[:-1] + ")"
            else:
                cmds_name_desc = cmds_name_desc + ")"
                undo_cmd = undo_cmd + ")"

            category = pg.wxPropertyCategory(cmds_name_desc,
                                             "cmdLabel%d" % num_cmd)
            self.cmds_pg.Append(category)
            self.cmd_name_list.append(inspector.getcmdprotoname(num_cmd))

            # Show the arguments (append to grid) recently created
            # and append them to a command list

            for num_arg in xrange(args_count):
                self.cmds_pg.Append(self.element[num_arg])

            self.cmd_list.append(self.element)

            self.undo_list.append(undo_cmd)

        pynebula.delete("/editor/inspector")

        # Make de object the current

        nebulagui.nebula_object = obj
        self.object = obj

        # Refresh control
        self.cmds_pg.Refresh()
def __draw_input_fields(inspector, params, type):        
    i = 0        

    for param in params:
        if type == "in":                            
            label = "label_in%d" % i
        else:
            label = "label_out%d" % i

        param_type = inspector.xml.get_param_type(param)
        param_name = inspector.xml.get_param_name(param)

        # Get posible attributes

        editor = ""
        min_value = ""
        max_value = ""
        default_value = ""
        step = ""
        subtype = ""

        for attr in inspector.xml.get_param_attrs(param):
            attr_type = inspector.xml.get_attr_type(attr)

            if "editor" == attr_type:
                editor = inspector.xml.get_attr_value(attr)

            if "min" == attr_type:
                min_value = inspector.xml.get_attr_value(attr)

            if "max" == attr_type:
                max_value = inspector.xml.get_attr_value(attr)

            if "default" == attr_type:
                default_value = inspector.xml.get_attr_value(attr)

            if "step" == attr_type:
                step = inspector.xml.get_attr_value(attr)

            if "subtype" == attr_type:
                subtype = inspector.xml.get_attr_value(attr)

        if param_type == 'i':
            if "spin" == editor:
                element = pg.wxIntProperty(param_name, label)                

            elif "color" == editor:
                element = pg.wxColourProperty(param_name, label, wx.RED)

            elif "slider" == editor:
                element = pg.wxIntProperty(param_name, label)

            elif "enum" == editor:
                test_labels = ["uno", "dos", "tres"]
                test_values = [1, 2, 3]
                element = pg.wxEnumProperty(
                                param_name, 
                                label, 
                                test_labels, 
                                test_values)

            elif "flags" == editor:
                element = pg.wxIntProperty("flags", label)
            else:
                element = pg.wxIntProperty(param_name, label)
        
        elif param_type == 'f':
            element = pg.wxFloatProperty('Float', label) 

        elif param_type == 's':
            if "" == editor:
                if type == "in":
                    element = check_string_subtypes(subtype, param_name, label)
                else:
                    element = pg.wxStringProperty(param_name, label, '')
            elif "font" == editor:
                element = pg.wxFontProperty(param_name, label, wx.NORMAL_FONT)

        elif param_type == 'b':
            element = pg.wxEnumProperty('Boolean', 
                               label,['True','False'],[1,0],2)
        elif param_type == 'o':
            if type == "in":
                element = check_string_subtypes(subtype, param_name, label)
            else:
                element = pg.wxStringProperty(param_name, label, '')
        elif param_type == 'l':
            if type == "in":
                element = pg.wxStringProperty('List', label, '')
            else:
                element = pg.wxArrayStringProperty('List', label, '')
            
        else:
            element = pg.wxStringProperty('String', label,
                                                   'Unknow type!!!')

        inspector.cmds_pg.Append(element)

        if "spin" == editor or "slider" == editor:
            inspector.cmds_pg.MakeIntegerSpinControl(label)

        if "in" == type:                
            inspector.in_elements.append(element)
        else:
            inspector.out_elements.append(element)

        i = i + 1