Пример #1
0
    def __init__(self, myclasswithoptimizablevariables):
        # doc needs to be initialized first
        # self.doc = doc

        self.typeconverter = {
            "<class 'str'>": str,
            "<type 'str'>": str,
            "<class 'float'>": float,
            "<type 'float'>": float,
            "<class 'int'>": int,
            "<type 'int'>": int
        }

        self.ui_class = UIInterfaceClassWithOptimizableVariables(
            myclasswithoptimizablevariables)
        string_dict_from_query = self.ui_class.query_ui()

        pprint(string_dict_from_query)

        filename = getRelativeFilePath(__file__, 'Qt/dlg_cwov_edit.ui')
        # this will create a Qt widget from our ui file
        self.form = FreeCADGui.PySideUic.loadUi(filename)
        self.readTableFromList(
            self.form.tableWidget_annotations,
            [(k, v, True, type(v))
             for (k, v) in string_dict_from_query["annotations"].items()])
        self.readTableFromList(self.form.tableWidget_variables,
                               string_dict_from_query["variables_list"])
        self.form.lineEdit_kind.setText(string_dict_from_query["kind"])
        self.form.lineEdit_name.setText(string_dict_from_query["name"])
        self.form.lineEdit_unique_id.setText(
            string_dict_from_query["unique_id"])
    def __init__(self, myclasswithoptimizablevariables):
        # doc needs to be initialized first
        # self.doc = doc

        self.typeconverter = {
                "<class 'str'>": str,
                "<type 'str'>": str,
                "<class 'float'>": float,
                "<type 'float'>": float,
                "<class 'int'>": int,
                "<type 'int'>": int
                              }

        self.ui_class = UIInterfaceClassWithOptimizableVariables(
                myclasswithoptimizablevariables)
        string_dict_from_query = self.ui_class.queryUI()

        pprint(string_dict_from_query)

        filename = getRelativeFilePath(__file__, 'Qt/dlg_cwov_edit.ui')
        # this will create a Qt widget from our ui file
        self.form = FreeCADGui.PySideUic.loadUi(filename)
        self.readTableFromList(self.form.tableWidget_annotations,
                               [(k, v, True, type(v)) for (k, v) in
                                string_dict_from_query["annotations"].items()])
        self.readTableFromList(self.form.tableWidget_variables,
                               string_dict_from_query["variables_list"])
        self.form.lineEdit_kind.setText(string_dict_from_query["kind"])
        self.form.lineEdit_name.setText(string_dict_from_query["name"])
        self.form.lineEdit_unique_id.setText(string_dict_from_query["unique_id"])
Пример #3
0
                ("image", {})])]

raysdict = {
     "radius": dropletradius*0.05,
     "starty": dropletradius*0.9,
     "anglex": -12.*degree,
     "raster": raster.MeridionalFan()
     }

r_red = raytrace(s, sysseq, 11, raysdict, wave=wave_red)[0]
r_blue = raytrace(s, sysseq, 11, raysdict, wave=wave_blue)[0]

draw(s, [(r_red, "red"), (r_blue, "blue")])

system_dump = Serializer(s).serialization
system_gui_toplevel = UIInterfaceClassWithOptimizableVariables(
        s.elements["droplet"].surfaces["surf4"].shape).query_for_dictionary()

#pprint(system_gui_toplevel)
#pprint(system_dump)

fp = open("rainbow.yaml", "wt")
yaml.dump(system_dump, fp)
fp.close()


fp = open("rainbow.json", "wt")
json.dump(system_dump, fp, indent=4)
fp.close()


Пример #4
0
class ClassWithOptimizableVariablesTaskPanelEdit:
    """
    User interface to edit class with optimizable variables.
    """
    def __init__(self, myclasswithoptimizablevariables):
        # doc needs to be initialized first
        # self.doc = doc

        self.typeconverter = {
            "<class 'str'>": str,
            "<type 'str'>": str,
            "<class 'float'>": float,
            "<type 'float'>": float,
            "<class 'int'>": int,
            "<type 'int'>": int
        }

        self.ui_class = UIInterfaceClassWithOptimizableVariables(
            myclasswithoptimizablevariables)
        string_dict_from_query = self.ui_class.query_ui()

        pprint(string_dict_from_query)

        filename = getRelativeFilePath(__file__, 'Qt/dlg_cwov_edit.ui')
        # this will create a Qt widget from our ui file
        self.form = FreeCADGui.PySideUic.loadUi(filename)
        self.readTableFromList(
            self.form.tableWidget_annotations,
            [(k, v, True, type(v))
             for (k, v) in string_dict_from_query["annotations"].items()])
        self.readTableFromList(self.form.tableWidget_variables,
                               string_dict_from_query["variables_list"])
        self.form.lineEdit_kind.setText(string_dict_from_query["kind"])
        self.form.lineEdit_name.setText(string_dict_from_query["name"])
        self.form.lineEdit_unique_id.setText(
            string_dict_from_query["unique_id"])

    def accept(self):
        string_dict_from_query = self.ui_class.query_ui()

        var_list = self.writeTableToList(self.form.tableWidget_variables)
        annotations_dict = self.writeTableToList(
            self.form.tableWidget_annotations)
        string_dict_from_query["name"] = self.form.lineEdit_name.text()
        string_dict_from_query["variables_list"] = var_list
        string_dict_from_query["annotations"] = annotations_dict
        self.ui_class.modify_ui(string_dict_from_query)

        pprint(self.ui_class.query_for_dictionary())

        FreeCADGui.Control.closeDialog()

    def reject(self):
        FreeCADGui.Control.closeDialog()

    def readTableFromList(self, mytable, mylist):
        """
        mylist contains triples of (name, value, modifyable)
        """
        mytable.clear()
        mytable.setRowCount(0)
        for (ind, (name, string_value, modifyable,
                   var_type)) in enumerate(sorted(mylist, key=lambda x: x[0])):
            # sort list to get a reproducible table
            mytable.insertRow(ind)
            mytable.setItem(ind, 0, QTableWidgetItem(name))
            value_item = QTableWidgetItem(string_value)
            if not modifyable:
                value_item.setFlags(value_item.flags() & Qt.ItemIsEditable)
            mytable.setItem(ind, 1, value_item)
            type_item = QTableWidgetItem(str(var_type))
            type_item.setFlags(type_item.flags() & Qt.ItemIsEditable)

            mytable.setItem(ind, 2, type_item)

        header = mytable.horizontalHeader()

        try:
            # this is Qt4
            header.setResizeMode(0, QHeaderView.ResizeToContents)
            header.setResizeMode(1, QHeaderView.Stretch)
        except AttributeError:
            # this is Qt5
            header.setSectionResizeMode(0, QHeaderView.ResizeToContents)
            header.setSectionResizeMode(1, QHeaderView.Stretch)

    def writeTableToList(self, mytable):
        myvars = []
        for ind in range(mytable.rowCount()):
            var_name = mytable.item(ind, 0).text()
            var_type = self.typeconverter[mytable.item(ind, 2).text()]
            var_value = mytable.item(ind, 1).text()
            var_modifyable = mytable.item(ind, 1).flags() != Qt.ItemIsEditable
            myvars.append((var_name, var_value, var_modifyable, var_type))
        return myvars
Пример #5
0
b = bundles_step3(nrays=9, rpup=7.5, maxfield_deg=5.)
for i in np.arange(len(b)):
    r2 = s.seqtrace(b[i], seq)
    color = ["blue", "green", "red"][int(i / 3)]
    for r in r2:
        r.draw2d(axarr[3], color=color, plane_normal=pn, up=up)

b = bundles_step3(nrays=36, rpup=7.5, maxfield_deg=5.)
r2 = s.seqtrace(b[0], seq)
for r in r2:
    r.draw2d(ax2, color="blue", plane_normal=pn, up=up)

plt.show()

system_dump = s.getCompleteListForReconstruction()
system_gui_toplevel = UIInterfaceClassWithOptimizableVariables(
    s.elements["stdelem"].surfaces["elem2rear"].shape).queryForDictionary()

from pprint import pprint

pprint(system_gui_toplevel)
pprint(system_dump)

fp = open("double_gauss.yaml", "wt")
yaml.dump(system_dump, fp)
fp.close()

fp = open("double_gauss.json", "wt")
json.dump(system_dump, fp, indent=4)
fp.close()
class ClassWithOptimizableVariablesTaskPanelEdit:
    """
    User interface to edit class with optimizable variables.
    """
    def __init__(self, myclasswithoptimizablevariables):
        # doc needs to be initialized first
        # self.doc = doc

        self.typeconverter = {
                "<class 'str'>": str,
                "<type 'str'>": str,
                "<class 'float'>": float,
                "<type 'float'>": float,
                "<class 'int'>": int,
                "<type 'int'>": int
                              }

        self.ui_class = UIInterfaceClassWithOptimizableVariables(
                myclasswithoptimizablevariables)
        string_dict_from_query = self.ui_class.queryUI()

        pprint(string_dict_from_query)

        filename = getRelativeFilePath(__file__, 'Qt/dlg_cwov_edit.ui')
        # this will create a Qt widget from our ui file
        self.form = FreeCADGui.PySideUic.loadUi(filename)
        self.readTableFromList(self.form.tableWidget_annotations,
                               [(k, v, True, type(v)) for (k, v) in
                                string_dict_from_query["annotations"].items()])
        self.readTableFromList(self.form.tableWidget_variables,
                               string_dict_from_query["variables_list"])
        self.form.lineEdit_kind.setText(string_dict_from_query["kind"])
        self.form.lineEdit_name.setText(string_dict_from_query["name"])
        self.form.lineEdit_unique_id.setText(string_dict_from_query["unique_id"])

    def accept(self):
        string_dict_from_query = self.ui_class.queryUI()

        var_list = self.writeTableToList(self.form.tableWidget_variables)
        annotations_dict = self.writeTableToList(
                self.form.tableWidget_annotations)
        string_dict_from_query["name"] = self.form.lineEdit_name.text()
        string_dict_from_query["variables_list"] = var_list
        string_dict_from_query["annotations"] = annotations_dict
        self.ui_class.modifyUI(string_dict_from_query)

        pprint(self.ui_class.queryForDictionary())

        FreeCADGui.Control.closeDialog()

    def reject(self):
        FreeCADGui.Control.closeDialog()

    def readTableFromList(self, mytable, mylist):
        """
        mylist contains triples of (name, value, modifyable)
        """
        mytable.clear()
        mytable.setRowCount(0)
        for (ind, (name, string_value, modifyable, var_type)) in enumerate(
                sorted(mylist, key=lambda x: x[0])):
            # sort list to get a reproducible table
            mytable.insertRow(ind)
            mytable.setItem(ind, 0, QTableWidgetItem(name))
            value_item = QTableWidgetItem(string_value)
            if not modifyable:
                value_item.setFlags(value_item.flags() & Qt.ItemIsEditable)
            mytable.setItem(ind, 1, value_item)
            type_item = QTableWidgetItem(str(var_type))
            type_item.setFlags(type_item.flags() & Qt.ItemIsEditable)

            mytable.setItem(ind, 2, type_item)

        header = mytable.horizontalHeader()

        try:
            # this is Qt4
            header.setResizeMode(0, QHeaderView.ResizeToContents)
            header.setResizeMode(1, QHeaderView.Stretch)
        except AttributeError:
            # this is Qt5
            header.setSectionResizeMode(0, QHeaderView.ResizeToContents)
            header.setSectionResizeMode(1, QHeaderView.Stretch)

    def writeTableToList(self, mytable):
        myvars = []
        for ind in range(mytable.rowCount()):
            var_name = mytable.item(ind, 0).text()
            var_type = self.typeconverter[mytable.item(ind, 2).text()]
            var_value = mytable.item(ind, 1).text()
            var_modifyable = mytable.item(ind, 1).flags() != Qt.ItemIsEditable
            myvars.append((var_name, var_value, var_modifyable, var_type))
        return myvars