2014-04-20 16:07:04 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
EditScriptAction.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'April 2014'
|
|
|
|
__copyright__ = '(C) 201, Victor Olaya'
|
|
|
|
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
|
|
|
import os
|
|
|
|
import shutil
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
from PyQt4.QtGui import QIcon, QFileDialog, QMessageBox
|
2014-04-20 16:07:04 +02:00
|
|
|
from processing.gui.ToolboxAction import ToolboxAction
|
|
|
|
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm
|
|
|
|
from processing.modeler.WrongModelException import WrongModelException
|
|
|
|
from processing.modeler.ModelerUtils import ModelerUtils
|
|
|
|
|
|
|
|
class AddModelFromFileAction(ToolboxAction):
|
|
|
|
|
|
|
|
def __init__(self):
|
2014-10-03 21:56:24 +03:00
|
|
|
self.name = self.tr('Add model from file', 'AddModelFromFileAction')
|
|
|
|
self.group = self.tr('Tools', 'AddModelFromFileAction')
|
2014-04-20 16:07:04 +02:00
|
|
|
|
|
|
|
def getIcon(self):
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
return QIcon(os.path.dirname(__file__) + '/../images/model.png')
|
2014-05-02 10:32:37 +02:00
|
|
|
|
2014-04-20 16:07:04 +02:00
|
|
|
def execute(self):
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
filename = QFileDialog.getOpenFileName(self.toolbox,
|
2014-10-03 21:56:24 +03:00
|
|
|
self.tr('Open model', 'AddModelFromFileAction'), None,
|
|
|
|
self.tr('Processing model files (*.model *.MODEL)', 'AddModelFromFileAction'))
|
2014-04-20 16:07:04 +02:00
|
|
|
if filename:
|
|
|
|
try:
|
2014-08-22 11:27:57 +02:00
|
|
|
ModelerAlgorithm.fromFile(filename)
|
2014-04-20 16:07:04 +02:00
|
|
|
except WrongModelException:
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
QMessageBox.warning(
|
|
|
|
self.toolbox,
|
|
|
|
self.tr('Error reading model', 'AddModelFromFileAction'),
|
|
|
|
self.tr('The selected file does not contain a valid model', 'AddModelFromFileAction'))
|
2014-04-20 16:07:04 +02:00
|
|
|
return
|
2014-06-08 00:21:12 +02:00
|
|
|
except:
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
QMessageBox.warning(self.toolbox,
|
2014-10-03 21:56:24 +03:00
|
|
|
self.tr('Error reading model', 'AddModelFromFileAction'),
|
|
|
|
self.tr('Cannot read file', 'AddModelFromFileAction'))
|
2014-04-20 16:07:04 +02:00
|
|
|
destFilename = os.path.join(ModelerUtils.modelsFolder(), os.path.basename(filename))
|
|
|
|
shutil.copyfile(filename,destFilename)
|
2014-10-03 21:56:24 +03:00
|
|
|
self.toolbox.updateProvider('model')
|