RobotModel.py
Go to the documentation of this file.
00001 import rospkg
00002 
00003 __author__ = 'tom1231'
00004 from PyQt4.QtGui import *
00005 from BAL.Interface.DeviceFrame import DeviceFrame, EX_DEV, ROBOT_MODEL
00006 from lxml.etree import Element, SubElement, XML
00007 
00008 
00009 class RobotModel(DeviceFrame):
00010 
00011     def __init__(self, frame, data):
00012         DeviceFrame.__init__(self, EX_DEV, frame, data)
00013         self._filePath = ''
00014         self._filePathTmp = ''
00015         self._pkg = 'ric_description'
00016         self._pkgTmp = self._pkg
00017 
00018     def getName(self):
00019         return 'robot_model'
00020 
00021     def saveToFile(self, parent):
00022         SubElement(parent, 'param', {
00023           'name': 'robot_description',
00024           'command': "$(find xacro)/xacro.py '$(find %s)%s'" % (self._pkg, self._filePath)
00025         })
00026         SubElement(parent, 'node', {
00027             'name': 'robot_state_publisher',
00028             'pkg': 'robot_state_publisher',
00029             'type': 'state_publisher'
00030         })
00031 
00032     def add(self):
00033         if not self.nameIsValid():
00034             error = QErrorMessage()
00035             error.setWindowTitle("Same name error")
00036             error.showMessage("Name already taken.")
00037             error.exec_()
00038             self._isValid = False
00039             return
00040         if self._filePathTmp == '' or self._filePath == None:
00041             error = QErrorMessage()
00042             error.setWindowTitle("File path")
00043             error.showMessage("File path is empty.")
00044             error.exec_()
00045             self._isValid = False
00046             return
00047         self._isValid = True
00048         self._filePath = self._filePathTmp
00049         self._pkg = self._pkgTmp
00050 
00051     def showDetails(self, items=None):
00052         self._pkgTmp = self._pkg
00053         browse = QPushButton('Browse')
00054         self.pkg = QLineEdit(self._pkg)
00055 
00056         self.pkg.textChanged.connect(self.change)
00057         browse.clicked.connect(self.browse)
00058 
00059         self._frame.layout().addRow(QLabel('Package: '), self.pkg)
00060         self._frame.layout().addRow(QLabel('File path: '), browse)
00061 
00062     def change(self, text):
00063         self._pkgTmp = str(text)
00064 
00065     def browse(self):
00066         try:
00067             pkg = rospkg.RosPack().get_path(self._pkgTmp)
00068             filePath = str(QFileDialog.getOpenFileName(self._frame, self._frame.tr("File Path"), pkg, self._frame.tr("ALL (*.*)")))
00069             self._filePathTmp = "".join(filePath.rsplit(pkg))
00070         except:
00071             QMessageBox.critical(self._frame, "Error", "Can't find %s package." % self._pkgTmp)
00072 
00073     def fromDict(self, data):
00074         self._filePath = data['filePath']
00075         self._pkg = data['pkg']
00076 
00077     def toDict(self):
00078         data = dict()
00079 
00080         data['type'] = ROBOT_MODEL
00081         data['filePath'] = self._filePath
00082         data['pkg'] = self._pkg
00083 
00084         return data
00085 
00086     def printDetails(self):
00087         self._frame.layout().addRow(QLabel('Package: '), QLabel(self._pkg))
00088         self._frame.layout().addRow(QLabel('File path: '), QLabel(self._filePath))


ric_board
Author(s): RoboTiCan
autogenerated on Fri Oct 27 2017 03:02:31