Ejemplo n.º 1
0
    def createTable(self, submodule):
        h = 411
        w = 891

        from procedural_city_generation.additional_stuff.Param import paramsFromJson, jsonFromParams
        from procedural_city_generation.additional_stuff.Singleton import Singleton
        params = paramsFromJson(os.getcwd() +
                                "/procedural_city_generation/inputs/" +
                                submodule + ".conf")

        table = QtGui.QTableWidget(getattr(self.ui, submodule + "_frame"))
        save_button = QtGui.QPushButton(getattr(self.ui, submodule + "_frame"),
                                        text="Save")
        save_button.setGeometry(QtCore.QRect(w - 100, h, 100, 31))
        save_button.hide()
        default_button = QtGui.QPushButton(getattr(self.ui,
                                                   submodule + "_frame"),
                                           text="Reset Defaults")
        default_button.setGeometry(QtCore.QRect(w - 260, h, 150, 31))
        default_button.hide()
        table.hide()
        table.setGeometry(QtCore.QRect(0, 0, w, h))
        table.setColumnCount(6)
        table.setHorizontalHeaderItem(0,
                                      QtGui.QTableWidgetItem("Parameter Name"))
        table.setColumnWidth(0, int(0.2 * w))
        table.setHorizontalHeaderItem(1, QtGui.QTableWidgetItem("Description"))
        table.setColumnWidth(1, int(0.5 * w))
        table.setHorizontalHeaderItem(2,
                                      QtGui.QTableWidgetItem("Default Value"))
        table.setColumnWidth(2, int(0.125 * w))
        table.setHorizontalHeaderItem(3, QtGui.QTableWidgetItem("Value"))
        table.setColumnWidth(3, int(0.125 * w))
        table.setHorizontalHeaderItem(4, QtGui.QTableWidgetItem("min"))
        table.setColumnWidth(4, int(0.1 * w))
        table.setHorizontalHeaderItem(5, QtGui.QTableWidgetItem("max"))
        table.setColumnWidth(5, int(0.1 * w))
        table.setRowCount(len(params))

        i = 0
        for parameter in params:
            g = QtGui.QTableWidgetItem(str(parameter.name))
            g.setFlags(g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem(i, 0, g)

            g = QtGui.QTableWidgetItem(str(parameter.description))
            g.setFlags(g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem(i, 1, g)

            g = QtGui.QTableWidgetItem(str(parameter.default))
            g.setFlags(g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem(i, 2, g)

            g = QtGui.QTableWidgetItem(str(parameter.value))
            table.setItem(i, 3, g)

            s = "" if parameter.value_lower_bound is None else str(
                parameter.value_lower_bound)
            g = QtGui.QTableWidgetItem(s)
            g.setFlags(g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem(i, 4, g)

            s = "" if parameter.value_upper_bound is None else str(
                parameter.value_upper_bound)
            g = QtGui.QTableWidgetItem(s)
            g.setFlags(g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem(i, 5, g)
            i += 1

        getattr(self.ui, submodule + "_Options").clicked.connect(table.show)
        getattr(self.ui,
                submodule + "_Options").clicked.connect(save_button.show)
        getattr(self.ui,
                submodule + "_Options").clicked.connect(default_button.show)
        setattr(self.ui, submodule + "_table", table)

        def save_params():
            for i, param in enumerate(params):
                it = table.item(i, 3).text()
                try:
                    it = eval(str(it))
                except:
                    it = str(it)
                param.setValue(it)
                Singleton(submodule).kill()
            jsonFromParams(
                os.getcwd() + "/procedural_city_generation/inputs/" +
                submodule + ".conf", params)
            print("Save successful")
            save_button.hide()
            default_button.hide()
            table.hide()
            print(UI.donemessage)

        save_button.clicked.connect(save_params)
        setattr(self.ui, submodule + "_save_button", save_button)

        def default_params():
            for i, param in enumerate(params):
                table.item(i, 3).setText(_fromUtf8(str(param.default)))

        default_button.clicked.connect(default_params)
        setattr(self.ui, submodule + "_default_button", default_button)
Ejemplo n.º 2
0
    def createTable(self, submodule):
        """ Creates the Options Table as PyQT4 Objects when called with a submodule. Very messy code, needs to be rewritten.
        Parameters
        ----------
        submodule: String, name of submodule
        """

        #Initial Pixel Width and Height of Options Table - should be replaced by getWindowSize()-like
        h = 411
        w = 891

        from procedural_city_generation.additional_stuff.Param import paramsFromJson, jsonFromParams
        from procedural_city_generation.additional_stuff.Singleton import Singleton

        #Load Parameters from .conf
        params = paramsFromJson(os.getcwd() +
                                "/procedural_city_generation/inputs/" +
                                submodule + ".conf")

        #Add Buttons and assign functions
        table = QtWidgets.QTableWidget(getattr(self.ui, submodule + "_frame"))
        save_button = QtWidgets.QPushButton(getattr(self.ui,
                                                    submodule + "_frame"),
                                            text="Save")
        save_button.setGeometry(QtCore.QRect(w - 100, h, 100, 31))
        save_button.hide()
        default_button = QtWidgets.QPushButton(getattr(self.ui,
                                                       submodule + "_frame"),
                                               text="Reset Defaults")
        default_button.setGeometry(QtCore.QRect(w - 260, h, 150, 31))
        default_button.hide()
        table.hide()

        #Set Table Geometry, code looks repetitive and should be reworked
        table.setGeometry(QtCore.QRect(0, 0, w, h))
        table.setColumnCount(6)
        table.setHorizontalHeaderItem(
            0, QtWidgets.QTableWidgetItem("Parameter Name"))
        table.setColumnWidth(0, int(0.2 * w))
        table.setHorizontalHeaderItem(
            1, QtWidgets.QTableWidgetItem("Description"))
        table.setColumnWidth(1, int(0.5 * w))
        table.setHorizontalHeaderItem(
            2, QtWidgets.QTableWidgetItem("Default Value"))
        table.setColumnWidth(2, int(0.125 * w))
        table.setHorizontalHeaderItem(3, QtWidgets.QTableWidgetItem("Value"))
        table.setColumnWidth(3, int(0.125 * w))
        table.setHorizontalHeaderItem(4, QtWidgets.QTableWidgetItem("min"))
        table.setColumnWidth(4, int(0.1 * w))
        table.setHorizontalHeaderItem(5, QtWidgets.QTableWidgetItem("max"))
        table.setColumnWidth(5, int(0.1 * w))
        table.setRowCount(len(params))

        #Fill out Table with Parameters. Code Looks repetitive, should be reworked
        i = 0
        for parameter in params:
            g = QtWidgets.QTableWidgetItem(str(parameter.name))
            g.setFlags(g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem(i, 0, g)

            g = QtWidgets.QTableWidgetItem(str(parameter.description))
            g.setFlags(g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem(i, 1, g)

            g = QtWidgets.QTableWidgetItem(str(parameter.default))
            g.setFlags(g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem(i, 2, g)

            g = QtWidgets.QTableWidgetItem(str(parameter.value))
            table.setItem(i, 3, g)

            s = "" if parameter.value_lower_bound is None else str(
                parameter.value_lower_bound)
            g = QtWidgets.QTableWidgetItem(s)
            g.setFlags(g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem(i, 4, g)

            s = "" if parameter.value_upper_bound is None else str(
                parameter.value_upper_bound)
            g = QtWidgets.QTableWidgetItem(s)
            g.setFlags(g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem(i, 5, g)
            i += 1

#Connect functions to buttons
        getattr(self.ui, submodule + "_Options").clicked.connect(table.show)
        getattr(self.ui,
                submodule + "_Options").clicked.connect(save_button.show)
        getattr(self.ui,
                submodule + "_Options").clicked.connect(default_button.show)
        setattr(self.ui, submodule + "_table", table)

        def save_params():
            for i, param in enumerate(params):
                it = table.item(i, 3).text()
                try:
                    it = eval(str(it))
                except:
                    it = str(it)
                param.setValue(it)
                Singleton(submodule).kill()
            jsonFromParams(
                os.getcwd() + "/procedural_city_generation/inputs/" +
                submodule + ".conf", params)
            print("Save successful")
            save_button.hide()
            default_button.hide()
            table.hide()
            print(UI.donemessage)

        save_button.clicked.connect(save_params)
        setattr(self.ui, submodule + "_save_button", save_button)

        def default_params():
            for i, param in enumerate(params):
                table.item(i, 3).setText(_fromUtf8(str(param.default)))

        default_button.clicked.connect(default_params)
        setattr(self.ui, submodule + "_default_button", default_button)
Ejemplo n.º 3
0
    def createTable(self,submodule):
        w=881
        h=400

        from procedural_city_generation.additional_stuff.Param import paramsFromJson,jsonFromParams
        from procedural_city_generation.additional_stuff.Singleton import Singleton
        params=paramsFromJson(os.getcwd()+"/procedural_city_generation/inputs/"+submodule+".conf")


        table=QtGui.QTableWidget(getattr(self.ui,submodule+"_frame"))


        save_button=QtGui.QPushButton(getattr(self.ui,submodule+"_frame"), text="Save")
        save_button.setGeometry(QtCore.QRect(w-100, h, 100, 31))
        save_button.hide()
        table.hide()
        table.setGeometry(QtCore.QRect(0,0,w,h))        
        table.setColumnCount(6)
        table.setHorizontalHeaderItem(0, QtGui.QTableWidgetItem("Parameter Name"))
        table.setColumnWidth(0, int(0.2*w))
        table.setHorizontalHeaderItem(1, QtGui.QTableWidgetItem("Description"))
        table.setColumnWidth(1, int(0.5*w))
        table.setHorizontalHeaderItem(2, QtGui.QTableWidgetItem("Default Value"))
        table.setColumnWidth(2, int(0.125*w))
        table.setHorizontalHeaderItem(3, QtGui.QTableWidgetItem("Value"))
        table.setColumnWidth(3, int(0.125*w))
        table.setHorizontalHeaderItem(4, QtGui.QTableWidgetItem("min"))
        table.setColumnWidth(4, int(0.1*w))
        table.setHorizontalHeaderItem(5, QtGui.QTableWidgetItem("max"))
        table.setColumnWidth(5, int(0.1*w))
        table.setRowCount(len(params))

        i=0
        for parameter in params:
            g=QtGui.QTableWidgetItem(str(parameter.name) )
            g.setFlags( g.flags() & ~QtCore.Qt.ItemIsEditable )
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem( i, 0 , g)
             
            g=QtGui.QTableWidgetItem(str(parameter.description))
            g.setFlags( g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem( i, 1 , g)
             
            g=QtGui.QTableWidgetItem(str(parameter.default))
            g.setFlags( g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem( i, 2 , g)
             
            g=QtGui.QTableWidgetItem(str(parameter.value))
            table.setItem( i, 3 , g)

            s = "" if parameter.value_lower_bound is None else str(parameter.value_lower_bound)
            g=QtGui.QTableWidgetItem(s)
            g.setFlags( g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem( i, 4 , g)

            s = "" if parameter.value_upper_bound is None else str(parameter.value_upper_bound)
            g=QtGui.QTableWidgetItem(s)
            g.setFlags( g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem( i, 5 , g)
            i+=1



        getattr(self.ui,submodule+"_Options").clicked.connect(table.show)
        getattr(self.ui,submodule+"_Options").clicked.connect(save_button.show)
        setattr(self.ui,submodule+"_table",table)

        def save_params():
            for i,param in enumerate(params):
                it=table.item(i,3).text()
                try:
                    it=eval(str(it))
                except:
                    it=str(it)
                param.setValue(it)
                Singleton(submodule).kill()
            jsonFromParams(os.getcwd()+"/procedural_city_generation/inputs/"+submodule+".conf",params)
            print "Save successful"
            save_button.hide()
            table.hide()
            print UI.donemessage

        save_button.clicked.connect(save_params)
        setattr(self.ui,submodule+"_save_button",save_button)
Ejemplo n.º 4
0
    def createTable(self, submodule):
	""" Creates the Options Table as PyQT4 Objects when called with a submodule. Very messy code, needs to be rewritten.
	Parameters
	----------
	submodule: String, name of submodule
	"""
	
	#Initial Pixel Width and Height of Options Table - should be replaced by getWindowSize()-like
        h=411
        w=891

        from procedural_city_generation.additional_stuff.Param import paramsFromJson, jsonFromParams
        from procedural_city_generation.additional_stuff.Singleton import Singleton
	
	#Load Parameters from .conf
        params=paramsFromJson(os.getcwd()+"/procedural_city_generation/inputs/"+submodule+".conf")
        
	#Add Buttons and assign functions
        table=QtGui.QTableWidget(getattr(self.ui, submodule+"_frame"))
        save_button=QtGui.QPushButton(getattr(self.ui, submodule+"_frame"), text="Save")
        save_button.setGeometry(QtCore.QRect(w-100, h, 100, 31))
        save_button.hide()
        default_button=QtGui.QPushButton(getattr(self.ui, submodule+"_frame"), text="Reset Defaults")
        default_button.setGeometry(QtCore.QRect(w-260, h, 150, 31))
        default_button.hide()
        table.hide()

	#Set Table Geometry, code looks repetitive and should be reworked
        table.setGeometry(QtCore.QRect(0, 0, w, h))
        table.setColumnCount(6)
        table.setHorizontalHeaderItem(0, QtGui.QTableWidgetItem("Parameter Name"))
        table.setColumnWidth(0, int(0.2*w))
        table.setHorizontalHeaderItem(1, QtGui.QTableWidgetItem("Description"))
        table.setColumnWidth(1, int(0.5*w))
        table.setHorizontalHeaderItem(2, QtGui.QTableWidgetItem("Default Value"))
        table.setColumnWidth(2, int(0.125*w))
        table.setHorizontalHeaderItem(3, QtGui.QTableWidgetItem("Value"))
        table.setColumnWidth(3, int(0.125*w))
        table.setHorizontalHeaderItem(4, QtGui.QTableWidgetItem("min"))
        table.setColumnWidth(4, int(0.1*w))
        table.setHorizontalHeaderItem(5, QtGui.QTableWidgetItem("max"))
        table.setColumnWidth(5, int(0.1*w))
        table.setRowCount(len(params))
	
	#Fill out Table with Parameters. Code Looks repetitive, should be reworked
        i=0
        for parameter in params:
            g=QtGui.QTableWidgetItem(str(parameter.name) )
            g.setFlags( g.flags() & ~QtCore.Qt.ItemIsEditable )
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem( i, 0 , g)
             
            g=QtGui.QTableWidgetItem(str(parameter.description))
            g.setFlags( g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem( i, 1 , g)
             
            g=QtGui.QTableWidgetItem(str(parameter.default))
            g.setFlags( g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem( i, 2 , g)
             
            g=QtGui.QTableWidgetItem(str(parameter.value))
            table.setItem( i, 3 , g)

            s = "" if parameter.value_lower_bound is None else str(parameter.value_lower_bound)
            g=QtGui.QTableWidgetItem(s)
            g.setFlags( g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem( i, 4 , g)

            s = "" if parameter.value_upper_bound is None else str(parameter.value_upper_bound)
            g=QtGui.QTableWidgetItem(s)
            g.setFlags( g.flags() & ~QtCore.Qt.ItemIsEditable)
            g.setBackground(QtGui.QBrush(QtGui.QColor(235, 235, 235)))
            table.setItem( i, 5 , g)
            i+=1


	#Connect functions to buttons
        getattr(self.ui, submodule+"_Options").clicked.connect(table.show)
        getattr(self.ui, submodule+"_Options").clicked.connect(save_button.show)
        getattr(self.ui, submodule+"_Options").clicked.connect(default_button.show)
        setattr(self.ui, submodule+"_table", table)

        def save_params():
            for i, param in enumerate(params):
                it=table.item(i, 3).text()
                try:
                    it=eval(str(it))
                except:
                    it=str(it)
                param.setValue(it)
                Singleton(submodule).kill()
            jsonFromParams(os.getcwd()+"/procedural_city_generation/inputs/"+submodule+".conf", params)
            print("Save successful")
            save_button.hide()
            default_button.hide()
            table.hide()
            print(UI.donemessage)

        save_button.clicked.connect(save_params)
        setattr(self.ui, submodule+"_save_button", save_button)

        def default_params():
            for i, param in enumerate(params):
                table.item(i, 3).setText(_fromUtf8(str(param.default)))


        default_button.clicked.connect(default_params)
        setattr(self.ui, submodule+"_default_button", default_button)