当前位置: 首页>>代码示例>>Python>>正文


Python shipUtils.Locale类代码示例

本文整理汇总了Python中shipUtils.Locale的典型用法代码示例。如果您正苦于以下问题:Python Locale类的具体用法?Python Locale怎么用?Python Locale使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Locale类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: onData

    def onData(self, value):
        """Updates the 3D preview on data changes.

        Keyword arguments:
        value -- Edited value. This parameter is required in order to use this
        method as a callback function, but it is unuseful.
        """
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.length = self.widget(QtGui.QLineEdit, "Length")
        form.breadth = self.widget(QtGui.QLineEdit, "Breadth")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")

        qty = Units.Quantity(Locale.fromString(form.length.text()))
        val_min = 0.001
        val_max = self.bounds[0] / Units.Metre.Value
        val = qty.getValueAs('m').Value
        self.L = self.clampVal(form.length, val_min, val_max, val)
        qty = Units.Quantity(Locale.fromString(form.breadth.text()))
        val_min = 0.001
        val_max = self.bounds[1] / Units.Metre.Value
        val = qty.getValueAs('m').Value
        self.B = self.clampVal(form.breadth, val_min, val_max, val)
        qty = Units.Quantity(Locale.fromString(form.draft.text()))
        val_min = 0.001
        val_max = self.bounds[2] / Units.Metre.Value
        val = qty.getValueAs('m').Value
        self.T = self.clampVal(form.draft, val_min, val_max, val)
        self.preview.update(self.L, self.B, self.T)
开发者ID:3DPrinterGuy,项目名称:FreeCAD,代码行数:29,代码来源:TaskPanel.py

示例2: accept

 def accept(self):
     if not self.ship:
         return False
     self.save()
     # Plot data
     mw = self.getMainWindow()
     form = mw.findChild(QtGui.QWidget, "TaskPanel")
     form.draft = self.widget(QtGui.QLineEdit, "Draft")
     form.trim = self.widget(QtGui.QLineEdit, "Trim")
     draft = Units.Quantity(Locale.fromString(
         form.draft.text())).getValueAs('m').Value
     trim = Units.Quantity(Locale.fromString(
         form.trim.text())).getValueAs('deg').Value
     data = Hydrostatics.displacement(self.ship,
                                      draft,
                                      0.0,
                                      trim)
     disp = data[0]
     xcb = data[1].x
     data = Hydrostatics.areas(self.ship,
                               draft,
                               0.0,
                               trim)
     x = []
     y = []
     for i in range(0, len(data)):
         x.append(data[i][0])
         y.append(data[i][1])
     PlotAux.Plot(x, y, disp, xcb, self.ship)
     self.preview.clean()
     return True
开发者ID:Fabracoder,项目名称:FreeCAD_sf_master,代码行数:31,代码来源:TaskPanel.py

示例3: accept

    def accept(self):
        if not self.ship:
            return False
        self.save()
        # Plot data
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.num = self.widget(QtGui.QSpinBox, "Num")
        draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
        trim = Units.parseQuantity(Locale.fromString(form.trim.text()))
        num = form.num.value()

        disp, B, _ = Hydrostatics.displacement(self.ship,
                                               draft,
                                               Units.parseQuantity("0 deg"),
                                               trim)
        xcb = Units.Quantity(B.x, Units.Length)
        data = Hydrostatics.areas(self.ship,
                                  num,
                                  draft=draft,
                                  trim=trim)
        x = []
        y = []
        for i in range(0, len(data)):
            x.append(data[i][0].getValueAs("m").Value)
            y.append(data[i][1].getValueAs("m^2").Value)
        PlotAux.Plot(x, y, disp, xcb, self.ship)
        self.preview.clean()
        return True
开发者ID:3DPrinterGuy,项目名称:FreeCAD,代码行数:31,代码来源:TaskPanel.py

示例4: save

    def save(self):
        """ Saves the data into ship instance. """
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.num = self.widget(QtGui.QSpinBox, "Num")

        draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
        trim = Units.parseQuantity(Locale.fromString(form.trim.text()))
        num = form.num.value()

        props = self.ship.PropertiesList
        try:
            props.index("AreaCurveDraft")
        except ValueError:
            try:
                tooltip = str(QtGui.QApplication.translate(
                    "ship_areas",
                    "Areas curve tool draft selected [m]",
                    None))
            except:
                tooltip = "Areas curve tool draft selected [m]"
            self.ship.addProperty("App::PropertyLength",
                                  "AreaCurveDraft",
                                  "Ship",
                                  tooltip)
        self.ship.AreaCurveDraft = draft
        try:
            props.index("AreaCurveTrim")
        except ValueError:
            try:
                tooltip = str(QtGui.QApplication.translate(
                    "ship_areas",
                    "Areas curve tool trim selected [deg]",
                    None))
            except:
                tooltip = "Areas curve tool trim selected [deg]"
            self.ship.addProperty("App::PropertyAngle",
                                  "AreaCurveTrim",
                                  "Ship",
                                  tooltip)
        self.ship.AreaCurveTrim = trim
        try:
            props.index("AreaCurveNum")
        except ValueError:
            try:
                tooltip = str(QtGui.QApplication.translate(
                    "ship_areas",
                    "Areas curve tool number of points",
                    None))
            except:
                tooltip = "Areas curve tool number of points"
            self.ship.addProperty("App::PropertyInteger",
                                  "AreaCurveNum",
                                  "Ship",
                                  tooltip)
        self.ship.AreaCurveNum = num
开发者ID:AjinkyaDahale,项目名称:FreeCAD,代码行数:58,代码来源:TaskPanel.py

示例5: accept

    def accept(self):
        if self.lc is None:
            return False
        self.save()

        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.angle = self.widget(QtGui.QLineEdit, "Angle")
        form.n_points = self.widget(QtGui.QSpinBox, "NumPoints")
        form.var_trim = self.widget(QtGui.QCheckBox, "VariableTrim")

        roll = Units.Quantity(Locale.fromString(form.angle.text()))
        n_points = form.n_points.value()
        var_trim = form.var_trim.isChecked()

        rolls = []
        for i in range(n_points):
            rolls.append(roll * i / float(n_points - 1))

        points = Tools.gz(self.lc, rolls, var_trim)
        gzs = []
        drafts = []
        trims = []
        for p in points:
            gzs.append(p[0].getValueAs("m").Value)
            drafts.append(p[1].getValueAs("m").Value)
            trims.append(p[2].getValueAs("deg").Value)

        PlotAux.Plot(rolls, gzs, drafts, trims)

        return True
开发者ID:caceres,项目名称:FreeCAD,代码行数:31,代码来源:TaskPanel.py

示例6: save

    def save(self):
        """ Saves the data into ship instance. """
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")

        draft = Units.Quantity(Locale.fromString(
            form.draft.text())).getValueAs('m').Value
        trim = Units.Quantity(Locale.fromString(
            form.trim.text())).getValueAs('deg').Value

        props = self.ship.PropertiesList
        try:
            props.index("AreaCurveDraft")
        except ValueError:
            try:
                tooltip = str(QtGui.QApplication.translate(
                    "ship_areas",
                    "Areas curve tool draft selected [m]",
                    None,
                    QtGui.QApplication.UnicodeUTF8))
            except:
                tooltip = "Areas curve tool draft selected [m]"
            self.ship.addProperty("App::PropertyLength",
                                  "AreaCurveDraft",
                                  "Ship",
                                  tooltip)
        self.ship.AreaCurveDraft = '{} m'.format(draft)
        try:
            props.index("AreaCurveTrim")
        except ValueError:
            try:
                tooltip = str(QtGui.QApplication.translate(
                    "ship_areas",
                    "Areas curve tool trim selected [deg]",
                    None,
                    QtGui.QApplication.UnicodeUTF8))
            except:
                tooltip = "Areas curve tool trim selected [deg]"
            self.ship.addProperty("App::PropertyAngle",
                                  "AreaCurveTrim",
                                  "Ship",
                                  tooltip)
        self.ship.AreaCurveTrim = '{} deg'.format(trim)
开发者ID:Fabracoder,项目名称:FreeCAD_sf_master,代码行数:45,代码来源:TaskPanel.py

示例7: onUpdate

    def onUpdate(self):
        """ Method called when the data update is requested. """
        if not self.ship:
            return
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.output = self.widget(QtGui.QTextEdit, "OutputData")

        draft = Units.Quantity(Locale.fromString(
            form.draft.text())).getValueAs('m').Value
        trim = Units.Quantity(Locale.fromString(
            form.trim.text())).getValueAs('deg').Value

        # Calculate the drafts at each perpendicular
        angle = math.radians(trim)
        L = self.ship.Length.getValueAs('m').Value
        B = self.ship.Breadth.getValueAs('m').Value
        draftAP = draft + 0.5 * L * math.tan(angle)
        if draftAP < 0.0:
            draftAP = 0.0
        draftFP = draft - 0.5 * L * math.tan(angle)
        if draftFP < 0.0:
            draftFP = 0.0
        # Calculate the involved hydrostatics
        data = Hydrostatics.displacement(self.ship,
                                         draft,
                                         0.0,
                                         trim)
        # Setup the html string
        string = 'L = {0} [m]<BR>'.format(L)
        string = string + 'B = {0} [m]<BR>'.format(B)
        string = string + 'T = {0} [m]<HR>'.format(draft)
        string = string + 'Trim = {0} [degrees]<BR>'.format(trim)
        string = string + 'T<sub>AP</sub> = {0} [m]<BR>'.format(draftAP)
        string = string + 'T<sub>FP</sub> = {0} [m]<HR>'.format(draftFP)
        dispText = QtGui.QApplication.translate(
            "ship_areas",
            'Displacement',
            None,
            QtGui.QApplication.UnicodeUTF8)
        string = string + dispText + ' = {0} [ton]<BR>'.format(data[0])
        string = string + 'XCB = {0} [m]'.format(data[1].x)
        form.output.setHtml(string)
开发者ID:Fabracoder,项目名称:FreeCAD_sf_master,代码行数:45,代码来源:TaskPanel.py

示例8: clampVal

 def clampVal(self, widget, val_min, val_max, val):
     if val >= val_min and val <= val_max:
         return val
     input_format = USys.getLengthFormat()
     val = min(val_max, max(val_min, val))
     qty = Units.Quantity('{} m'.format(val))
     widget.setText(Locale.toString(input_format.format(
         qty.getValueAs(USys.getLengthUnits()).Value)))
     return val
开发者ID:3DPrinterGuy,项目名称:FreeCAD,代码行数:9,代码来源:TaskPanel.py

示例9: onUpdate

    def onUpdate(self):
        """ Method called when the data update is requested. """
        if not self.ship:
            return
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.output = self.widget(QtGui.QTextEdit, "OutputData")

        draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
        trim = Units.parseQuantity(Locale.fromString(form.trim.text()))

        # Calculate the drafts at each perpendicular
        angle = trim.getValueAs("rad").Value
        L = self.ship.Length.getValueAs('m').Value
        B = self.ship.Breadth.getValueAs('m').Value
        draftAP = draft + 0.5 * self.ship.Length * math.tan(angle)
        if draftAP < 0.0:
            draftAP = 0.0
        draftFP = draft - 0.5 * self.ship.Length * math.tan(angle)
        if draftFP < 0.0:
            draftFP = 0.0
        # Calculate the involved hydrostatics
        disp, B, _ = Hydrostatics.displacement(self.ship,
                                               draft,
                                               Units.parseQuantity("0 deg"),
                                               trim)
        xcb = Units.Quantity(B.x, Units.Length)
        # Setup the html string
        string = u'L = {0}<BR>'.format(self.ship.Length.UserString)
        string += u'B = {0}<BR>'.format(self.ship.Breadth.UserString)
        string += u'T = {0}<HR>'.format(draft.UserString)
        string += u'Trim = {0}<BR>'.format(trim.UserString)
        string += u'T<sub>AP</sub> = {0}<BR>'.format(draftAP.UserString)
        string += u'T<sub>FP</sub> = {0}<HR>'.format(draftFP.UserString)
        dispText = QtGui.QApplication.translate(
            "ship_areas",
            'Displacement',
            None,
            QtGui.QApplication.UnicodeUTF8)
        string += dispText + u' = {0}<BR>'.format(disp.UserString)
        string += u'XCB = {0}'.format(xcb.UserString)
        form.output.setHtml(string)
开发者ID:3DPrinterGuy,项目名称:FreeCAD,代码行数:44,代码来源:TaskPanel.py

示例10: onData

    def onData(self, value):
        """ Method called when the tool input data is touched.
        @param value Changed value.
        """
        if not self.ship:
            return

        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")

        # Get the values (or fix them in bad setting case)
        try:
            draft = Units.Quantity(Locale.fromString(
                form.draft.text())).getValueAs('m').Value
        except:
            draft = self.ship.Draft.getValueAs(USys.getLengthUnits()).Value
            input_format = USys.getLengthFormat()
            qty = Units.Quantity('{} m'.format(draft))
            widget.setText(Locale.toString(input_format.format(
                qty.getValueAs(USys.getLengthUnits()).Value)))
        try:
            trim = Units.Quantity(Locale.fromString(
                form.trim.text())).getValueAs('deg').Value
        except:
            trim = 0.0
            input_format = USys.getAngleFormat()
            qty = Units.Quantity('{} deg'.format(trim))
            widget.setText(Locale.toString(input_format.format(
                qty.getValueAs(USys.getLengthUnits()).Value)))

        bbox = self.ship.Shape.BoundBox
        draft_min = bbox.ZMin / Units.Metre.Value
        draft_max = bbox.ZMax / Units.Metre.Value
        draft = self.clampLength(form.draft, draft_min, draft_max, draft)

        trim_min = -180.0
        trim_max = 180.0
        trim = self.clampAngle(form.trim, trim_min, trim_max, trim)

        self.onUpdate()
        self.preview.update(draft, trim, self.ship)
开发者ID:Fabracoder,项目名称:FreeCAD_sf_master,代码行数:43,代码来源:TaskPanel.py

示例11: accept

    def accept(self):
        """Create the ship instance"""
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.ship = self.widget(QtGui.QComboBox, "Ship")
        form.weight = self.widget(QtGui.QLineEdit, "Weight")

        ship = self.ships[form.ship.currentIndex()]
        density = Units.parseQuantity(Locale.fromString(form.weight.text()))

        Tools.createWeight(self.shapes, ship, density)
        return True
开发者ID:AjinkyaDahale,项目名称:FreeCAD,代码行数:12,代码来源:TaskPanel.py

示例12: initValues

    def initValues(self):
        """ Set initial values for fields
        """
        selObjs = Gui.Selection.getSelection()
        if not selObjs:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A ship instance must be selected before using this tool (no"
                " objects selected)",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True
        for i in range(0, len(selObjs)):
            obj = selObjs[i]
            props = obj.PropertiesList
            try:
                props.index("IsShip")
            except ValueError:
                continue
            if obj.IsShip:
                if self.ship:
                    msg = QtGui.QApplication.translate(
                        "ship_console",
                        "More than one ship have been selected (the extra"
                        " ships will be ignored)",
                        None,
                        QtGui.QApplication.UnicodeUTF8)
                    App.Console.PrintWarning(msg + '\n')
                    break
                self.ship = obj
        if not self.ship:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A ship instance must be selected before using this tool (no"
                " valid ship found at the selected objects)",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True

        length_format = USys.getLengthFormat()
        angle_format = USys.getAngleFormat()

        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.num = self.widget(QtGui.QSpinBox, "Num")
        form.draft.setText(Locale.toString(length_format.format(
            self.ship.Draft.getValueAs(USys.getLengthUnits()).Value)))
        form.trim.setText(Locale.toString(angle_format.format(0.0)))
        # Try to use saved values
        props = self.ship.PropertiesList
        try:
            props.index("AreaCurveDraft")
            form.draft.setText(Locale.toString(length_format.format(
                self.ship.AreaCurveDraft.getValueAs(
                    USys.getLengthUnits()).Value)))
        except:
            pass
        try:
            props.index("AreaCurveTrim")
            form.trim.setText(Locale.toString(angle_format.format(
                self.ship.AreaCurveTrim.getValueAs(
                    USys.getAngleUnits()).Value)))
        except ValueError:
            pass
        try:
            props.index("AreaCurveNum")
            form.num.setValue(self.ship.AreaCurveNum)
        except ValueError:
            pass
        # Update GUI
        draft = Units.Quantity(form.draft.text()).getValueAs('m').Value
        trim = Units.Quantity(form.trim.text()).getValueAs('deg').Value
        self.preview.update(draft, trim, self.ship)
        self.onUpdate()
        return False
开发者ID:3DPrinterGuy,项目名称:FreeCAD,代码行数:79,代码来源:TaskPanel.py

示例13: initValues

    def initValues(self):
        """ Set initial values for fields
        """
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.minDraft = self.widget(QtGui.QLineEdit, "MinDraft")
        form.maxDraft = self.widget(QtGui.QLineEdit, "MaxDraft")
        form.nDraft = self.widget(QtGui.QSpinBox, "NDraft")

        selObjs = Gui.Selection.getSelection()
        if not selObjs:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A ship instance must be selected before using this tool (no"
                " objects selected)",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True
        for i in range(len(selObjs)):
            obj = selObjs[i]
            props = obj.PropertiesList
            try:
                props.index("IsShip")
            except ValueError:
                continue
            if obj.IsShip:
                if self.ship:
                    msg = QtGui.QApplication.translate(
                        "ship_console",
                        "More than one ship have been selected (the extra"
                        " ships will be ignored)",
                        None,
                        QtGui.QApplication.UnicodeUTF8)
                    App.Console.PrintWarning(msg + '\n')
                    break
                self.ship = obj

        if not self.ship:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A ship instance must be selected before using this tool (no"
                " valid ship found at the selected objects)",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True

        props = self.ship.PropertiesList

        length_format = USys.getLengthFormat()
        angle_format = USys.getAngleFormat()

        try:
            props.index("HydrostaticsTrim")
            form.trim.setText(Locale.toString(angle_format.format(
                self.ship.HydrostaticsTrim.getValueAs(
                    USys.getLengthUnits()).Value)))
        except ValueError:
            form.trim.setText(Locale.toString(angle_format.format(0.0)))

        try:
            props.index("HydrostaticsMinDraft")
            form.minDraft.setText(Locale.toString(length_format.format(
                self.ship.HydrostaticsMinDraft.getValueAs(
                    USys.getLengthUnits()).Value)))
        except ValueError:
            form.minDraft.setText(Locale.toString(length_format.format(
                0.9 * self.ship.Draft.getValueAs(USys.getLengthUnits()).Value)))
        try:
            props.index("HydrostaticsMaxDraft")
            form.maxDraft.setText(Locale.toString(length_format.format(
                self.ship.HydrostaticsMaxDraft.getValueAs(
                    USys.getLengthUnits()).Value)))
        except ValueError:
            form.maxDraft.setText(Locale.toString(length_format.format(
                1.1 * self.ship.Draft.getValueAs(USys.getLengthUnits()).Value)))

        try:
            props.index("HydrostaticsNDraft")
            form.nDraft.setValue(self.ship.HydrostaticsNDraft)
        except ValueError:
            pass

        return False
开发者ID:Fabracoder,项目名称:FreeCAD_sf_master,代码行数:86,代码来源:TaskPanel.py

示例14: onTableItem

    def onTableItem(self, row, column):
        """ Function called when an item of the table is touched.
        @param row Changed item row
        @param column Changed item column
        """
        if self.skip:
            return

        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.sections = self.widget(QtGui.QTableWidget, "Sections")
        form.sectionType = self.widget(QtGui.QComboBox, "SectionType")

        # Add an empty item at the end of the list
        nRow = form.sections.rowCount()
        item = form.sections.item(nRow - 1, 0)
        if item:
            if(item.text() != ''):
                form.sections.setRowCount(nRow + 1)

        ID = form.sectionType.currentIndex()
        if ID == 0:
            SectionList = self.LSections
        elif ID == 1:
            SectionList = self.BSections
        elif ID == 2:
            SectionList = self.TSections

        item = form.sections.item(row, column)
        # Look for deleted row (empty string)
        if not item.text():
            del SectionList[row]
            form.sections.removeRow(row)
            self.obj = self.preview.update(self.ship.Length.getValueAs('m').Value,
                                           self.ship.Breadth.getValueAs('m').Value,
                                           self.ship.Draft.getValueAs('m').Value,
                                           self.LSections,
                                           self.BSections,
                                           self.TSections,
                                           self.ship.Shape)
            return

        # Get the new section value
        try:
            qty = Units.Quantity(item.text())
            number = qty.getValueAs('m').Value
        except:
            number = 0.0

        string = '{} m'.format(number)
        item.setText(Locale.toString(string))
        # Regenerate the list
        del SectionList[:]
        for i in range(0, nRow):
            item = form.sections.item(i, 0)
            try:
                qty = Units.Quantity(item.text())
                number = qty.getValueAs('m').Value
            except:
                number = 0.0
            SectionList.append(number)

        self.obj = self.preview.update(self.ship.Length.getValueAs('m').Value,
                                       self.ship.Breadth.getValueAs('m').Value,
                                       self.ship.Draft.getValueAs('m').Value,
                                       self.LSections,
                                       self.BSections,
                                       self.TSections,
                                       self.ship.Shape)
开发者ID:itain,项目名称:FreeCAD,代码行数:69,代码来源:TaskPanel.py

示例15: initValues

    def initValues(self):
        """ Set initial values for fields
        """
        # Look for selected loading conditions (Spreadsheets)
        self.lc = None
        selObjs = Gui.Selection.getSelection()
        if not selObjs:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A loading condition instance must be selected before using" " this tool (no objects selected)",
                None,
                QtGui.QApplication.UnicodeUTF8,
            )
            App.Console.PrintError(msg + "\n")
            return True
        for i in range(len(selObjs)):
            obj = selObjs[i]
            try:
                if obj.TypeId != "Spreadsheet::Sheet":
                    continue
            except ValueError:
                continue
            # Check if it is a Loading condition:
            # B1 cell must be a ship
            # B2 cell must be the loading condition itself
            doc = App.ActiveDocument
            try:
                if obj not in doc.getObjectsByLabel(obj.get("B2")):
                    continue
                ships = doc.getObjectsByLabel(obj.get("B1"))
                if len(ships) != 1:
                    if len(ships) == 0:
                        msg = QtGui.QApplication.translate(
                            "ship_console",
                            "Wrong Ship label! (no instances labeled as" "'{}' found)",
                            None,
                            QtGui.QApplication.UnicodeUTF8,
                        )
                        App.Console.PrintError(msg + "\n".format(obj.get("B1")))
                    else:
                        msg = QtGui.QApplication.translate(
                            "ship_console",
                            "Ambiguous Ship label! ({} instances labeled as" "'{}' found)",
                            None,
                            QtGui.QApplication.UnicodeUTF8,
                        )
                        App.Console.PrintError(msg + "\n".format(len(ships), obj.get("B1")))
                    continue
                ship = ships[0]
                if ship is None or not ship.PropertiesList.index("IsShip"):
                    continue
            except ValueError:
                continue
            # Let's see if several loading conditions have been selected (and
            # prompt a warning)
            if self.lc:
                msg = QtGui.QApplication.translate(
                    "ship_console",
                    "More than one loading condition have been selected (the"
                    " extra loading conditions will be ignored)",
                    None,
                    QtGui.QApplication.UnicodeUTF8,
                )
                App.Console.PrintWarning(msg + "\n")
                break
            self.lc = obj
            self.ship = ship
        if not self.lc:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A loading condition instance must be selected before using"
                " this tool (no valid loading condition found at the selected"
                " objects)",
                None,
                QtGui.QApplication.UnicodeUTF8,
            )
            App.Console.PrintError(msg + "\n")
            return True

        # We have a valid loading condition, let's set the initial field values
        angle_format = USys.getAngleFormat()
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.angle = self.widget(QtGui.QLineEdit, "Angle")
        form.n_points = self.widget(QtGui.QSpinBox, "NumPoints")
        form.var_trim = self.widget(QtGui.QCheckBox, "VariableTrim")
        form.angle.setText(Locale.toString(angle_format.format(90.0)))
        # Try to use saved values
        props = self.ship.PropertiesList
        try:
            props.index("GZAngle")
            form.angle.setText(
                Locale.toString(angle_format.format(self.ship.GZAngle.getValueAs(USys.getAngleUnits()).Value))
            )
        except:
            pass
        try:
            props.index("GZNumPoints")
            form.n_points.setValue(self.ship.GZNumPoints)
        except ValueError:
#.........这里部分代码省略.........
开发者ID:caceres,项目名称:FreeCAD,代码行数:101,代码来源:TaskPanel.py


注:本文中的shipUtils.Locale类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。