First tests of using InputField via Python

This commit is contained in:
jriegel 2014-02-09 20:50:07 +01:00
parent 58fda26298
commit d17fb3aa5d
4 changed files with 64 additions and 60 deletions

View File

@ -329,6 +329,17 @@ void InputField::setMinimum(double m)
Minimum = m;
}
void InputField::setUnitText(QString str)
{
Base::Quantity quant = Base::Quantity::parse(str);
setUnit(quant.getUnit());
}
QString InputField::getUnitText(void)
{
return actUnitStr;
}
// get the value of the minimum property
int InputField::historySize(void)const
{

View File

@ -52,6 +52,7 @@ class GuiExport InputField : public QLineEdit
Q_PROPERTY(double maximum READ maximum WRITE setMaximum )
Q_PROPERTY(double minimum READ minimum WRITE setMinimum )
Q_PROPERTY(int historySize READ historySize WRITE setHistorySize )
Q_PROPERTY(QString unit READ getUnitText WRITE setUnitText )
public:
@ -88,7 +89,10 @@ public:
int historySize(void)const;
/// set the value of the minimum property
void setHistorySize(int);
/// set the unit by a string (can be used in the *.ui file)
void setUnitText(QString);
/// get the unit as a string (can be used in the *.ui file)
QString getUnitText(void);
/// set the number portion selected (use after setValue())
void selectNumber(void);

View File

@ -128,20 +128,13 @@ class _ViewProviderMechanicalMaterial:
class _MechanicalMaterialTaskPanel:
'''The editmode TaskPanel for MechanicalMaterial objects'''
def __init__(self,obj):
# the panel has a tree widget that contains categories
# for the subcomponents, such as additions, subtractions.
# the categories are shown only if they are not empty.
form_class, base_class = uic.loadUiType(FreeCAD.getHomePath() + "Mod/Fem/MechanicalMaterial.ui")
self.obj = obj
self.formUi = form_class()
self.form = QtGui.QWidget()
self.formUi.setupUi(self.form)
self.form=FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Fem/MechanicalMaterial.ui")
self.params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem")
QtCore.QObject.connect(self.formUi.pushButton_MatWeb, QtCore.SIGNAL("clicked()"), self.goMatWeb)
QtCore.QObject.connect(self.formUi.comboBox_MaterialsInDir, QtCore.SIGNAL("currentIndexChanged(int)"), self.chooseMat)
QtCore.QObject.connect(self.form.pushButton_MatWeb, QtCore.SIGNAL("clicked()"), self.goMatWeb)
QtCore.QObject.connect(self.form.comboBox_MaterialsInDir, QtCore.SIGNAL("currentIndexChanged(int)"), self.chooseMat)
self.update()
@ -150,10 +143,11 @@ class _MechanicalMaterialTaskPanel:
matmap = self.obj.Material
matmap['Mechanical_youngsmodulus'] = str(self.formUi.spinBox_young_modulus.value() * 1e+6)
matmap['FEM_poissonratio'] = str(self.formUi.spinBox_poisson_ratio.value())
matmap['Mechanical_youngsmodulus'] = self.form.spinBox_young_modulus.text()
matmap['FEM_poissonratio'] = str(self.form.spinBox_poisson_ratio.value())
self.obj.Material = matmap
print matmap
def transferFrom(self):
@ -161,11 +155,11 @@ class _MechanicalMaterialTaskPanel:
matmap = self.obj.Material
if matmap.has_key('Mechanical_youngsmodulus'):
print float(matmap['Mechanical_youngsmodulus'])
self.formUi.spinBox_young_modulus.setValue(float(matmap['Mechanical_youngsmodulus'])/1e+6)
print matmap['Mechanical_youngsmodulus']
self.form.spinBox_young_modulus.setText(matmap['Mechanical_youngsmodulus'])
if matmap.has_key('FEM_poissonratio'):
print float(matmap['FEM_poissonratio'])
self.formUi.spinBox_poisson_ratio.setValue(float(matmap['FEM_poissonratio']))
#print float(matmap['FEM_poissonratio'])
self.form.spinBox_poisson_ratio.setValue(float(matmap['FEM_poissonratio']))
def isAllowedAlterSelection(self):
return False
@ -178,8 +172,8 @@ class _MechanicalMaterialTaskPanel:
def update(self):
'fills the widgets'
self.formUi.spinBox_young_modulus.setValue(0.0)
self.formUi.spinBox_poisson_ratio.setValue(0.0)
#self.form.spinBox_young_modulus.setValue(0.0)
#self.form.spinBox_poisson_ratio.setValue(0.0)
self.transferFrom()
self.fillMaterialCombo()
@ -187,10 +181,12 @@ class _MechanicalMaterialTaskPanel:
return
def accept(self):
print 'accept(self)'
self.transferTo()
FreeCADGui.ActiveDocument.resetEdit()
def reject(self):
print 'reject(self)'
FreeCADGui.ActiveDocument.resetEdit()
def saveMat(self):
@ -207,12 +203,12 @@ class _MechanicalMaterialTaskPanel:
def chooseMat(self,index):
if index == 0:return
import Material
print index
#print index
name = self.pathList[index-1]
print 'Import ', str(name)
#print 'Import ', str(name)
self.obj.Material = Material.importFCMat(str(name))
print self.obj.Material
#print self.obj.Material
self.transferFrom()
@ -221,13 +217,13 @@ class _MechanicalMaterialTaskPanel:
matmap = self.obj.Material
dirname = FreeCAD.ConfigGet("AppHomePath")+"data/Mod/Material/StandardMaterial"
self.pathList = glob.glob(dirname + '/*.FCMat')
self.formUi.comboBox_MaterialsInDir.clear()
self.form.comboBox_MaterialsInDir.clear()
if(matmap.has_key('General_name')):
self.formUi.comboBox_MaterialsInDir.addItem(matmap['General_name'])
self.form.comboBox_MaterialsInDir.addItem(matmap['General_name'])
else:
self.formUi.comboBox_MaterialsInDir.addItem('-> choose Material')
self.form.comboBox_MaterialsInDir.addItem('-> choose Material')
for i in self.pathList:
self.formUi.comboBox_MaterialsInDir.addItem(os.path.basename(i) )
self.form.comboBox_MaterialsInDir.addItem(os.path.basename(i) )

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>196</width>
<height>142</height>
<width>188</width>
<height>124</height>
</rect>
</property>
<property name="windowTitle">
@ -34,27 +34,17 @@
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Young's Modulus:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QDoubleSpinBox" name="spinBox_young_modulus">
<item row="0" column="1">
<widget class="Gui::InputField" name="spinBox_young_modulus">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -70,28 +60,31 @@
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="decimals">
<property name="unit" stdset="0">
<string>Pa</string>
</property>
<property name="decimals" stdset="0">
<number>3</number>
</property>
<property name="maximum">
<property name="maximum" stdset="0">
<double>2000.000000000000000</double>
</property>
<property name="singleStep">
<property name="singleStep" stdset="0">
<double>2.000000000000000</double>
</property>
<property name="value">
<property name="value" stdset="0">
<double>0.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_6">
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Young's Mod.(GPa)</string>
<string>Poisson Ratio:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="spinBox_poisson_ratio">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -122,17 +115,17 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Poisson Ratio</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::InputField</class>
<extends>QLineEdit</extends>
<header>Gui/InputField.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>