예제 #1
0
    def __init__(self, screen, compType, position):
        self.type = compType
        self.GUI = None #DrawObject

        self.compartment = Compartment(compType)
        self.screen = screen


        file_name = None
        if compType == "weapon":
            self.compartment.use = self.compartment.typeWeaponUse
            file_name = "cannon.png"
            
        elif compType == "shield":
            file_name = "shield.png"

        elif compType == "health":
            self.compartment.use = self.compartment.typeHealthUse
            file_name = "health.png"

        elif compType == "engine":
            self.compartment.use = self.compartment.typeEngineUse
            file_name = "engine.png"

        elif compType == "light":
            file_name = "light.png"

        self.GUI = Draw_Comp(file_name, self.screen, position)
    def changeType(self, event):
        #TODO: change types available for edges
        if self.nodes == None:  # if a node is selected rather than an edge
            if self.v.get() == "Create New":
                typeLabel = tkSimpleDialog.askstring(title="New Type",
                                                     prompt="Enter a new type")

                if typeLabel != None:
                    # select new 'type' in dropdown
                    self.optionList.insert(len(self.optionList) - 1, typeLabel)
                    self.v.set(self.optionList[len(self.optionList) - 2])

                    # redraw dropdown
                    self.dropdown.destroy()
                    self.dropdown = OptionMenu(self.propGroup,
                                               self.v,
                                               *self.optionList,
                                               command=self.changeType)
                    self.dropdown.config(highlightbackground=self.color,
                                         bg=self.color)
                    self.dropdown.grid(row=1,
                                       column=1,
                                       columnspan=2,
                                       padx=5,
                                       pady=5,
                                       sticky=E + W)

            elif self.v.get() == "Component":
                for widget in self.parent.grid_slaves():
                    if int(widget.grid_info()['row']) == 1:
                        widget.destroy()
                try:
                    self.leftFrame.dockedWindows.subNetworkExit()
                except AttributeError:
                    pass
                self.componentInfo = Component(self.parent, self.leftFrame,
                                               self.index, self.G,
                                               self.manager)

            elif self.v.get() == "Compartment":
                for widget in self.parent.grid_slaves():
                    if int(widget.grid_info()['row']) == 1 or int(
                            widget.grid_info()['row']) == 2:
                        widget.destroy()
                self.compartmentInfo = Compartment(self.parent, self.leftFrame,
                                                   self.index, self.G,
                                                   self.manager)