FEM: Read materials from user settings directory
That commit also adds python function getUserAppDataDir that calls Application::getUserAppDataDir() Signed-off-by: Przemo Firszt <przemo@firszt.eu>
This commit is contained in:
parent
b7bb4346da
commit
54ae984650
|
@ -279,6 +279,7 @@ private:
|
|||
static PyObject* sAddExportType (PyObject *self,PyObject *args,PyObject *kwd);
|
||||
static PyObject* sGetExportType (PyObject *self,PyObject *args,PyObject *kwd);
|
||||
static PyObject* sGetResourceDir (PyObject *self,PyObject *args,PyObject *kwd);
|
||||
static PyObject* sGetUserAppDataDir (PyObject *self,PyObject *args,PyObject *kwd);
|
||||
static PyObject* sGetHomePath (PyObject *self,PyObject *args,PyObject *kwd);
|
||||
|
||||
static PyObject* sLoadFile (PyObject *self,PyObject *args,PyObject *kwd);
|
||||
|
|
|
@ -80,6 +80,8 @@ PyMethodDef Application::Methods[] = {
|
|||
"Get the name of the module that can export the filetype"},
|
||||
{"getResourceDir", (PyCFunction) Application::sGetResourceDir ,1,
|
||||
"Get the root directory of all resources"},
|
||||
{"getUserAppDataDir", (PyCFunction) Application::sGetUserAppDataDir ,1,
|
||||
"Get the root directory of user settings"},
|
||||
{"getHomePath", (PyCFunction) Application::sGetHomePath ,1,
|
||||
"Get the home path, i.e. the parent directory of the executable"},
|
||||
|
||||
|
@ -525,6 +527,15 @@ PyObject* Application::sGetResourceDir(PyObject * /*self*/, PyObject *args,PyObj
|
|||
return Py::new_reference_to(datadir);
|
||||
}
|
||||
|
||||
PyObject* Application::sGetUserAppDataDir(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
|
||||
Py::String user_data_dir(Application::getUserAppDataDir(),"utf-8");
|
||||
return Py::new_reference_to(user_data_dir);
|
||||
}
|
||||
|
||||
PyObject* Application::sGetHomePath(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
|
||||
|
|
|
@ -139,6 +139,10 @@ class _MechanicalMaterialTaskPanel:
|
|||
if new_index != -1:
|
||||
self.form.comboBox_MaterialsInDir.setCurrentIndex(new_index)
|
||||
self.set_mat_params_in_combo_box(matmap)
|
||||
else:
|
||||
print "Cannot find previously used material \'{}\' - setting to \'None\'".format(material_name)
|
||||
i = self.form.comboBox_MaterialsInDir.findText('None')
|
||||
self.chooseMat(i)
|
||||
|
||||
def print_mat_data(self, matmap):
|
||||
print 'material data:'
|
||||
|
@ -197,5 +201,11 @@ class _MechanicalMaterialTaskPanel:
|
|||
material_name = os.path.basename(i[:-l])
|
||||
self.form.comboBox_MaterialsInDir.addItem(material_name)
|
||||
|
||||
user_mat_dir = FreeCAD.getUserAppDataDir() + "/Materials"
|
||||
user_mat_path_list = glob.glob(user_mat_dir + '/*' + mat_file_extension)
|
||||
for i in user_mat_path_list:
|
||||
material_name = os.path.basename(i[:-l])
|
||||
self.form.comboBox_MaterialsInDir.addItem(material_name)
|
||||
self.pathList = self.pathList + user_mat_path_list
|
||||
|
||||
FreeCADGui.addCommand('Fem_MechanicalMaterial',_CommandMechanicalMaterial())
|
||||
|
|
Loading…
Reference in New Issue
Block a user