Пример #1
0
def getOpenFiles(parent, labeltext, path,
                 filefilter = None, multiple = True):
    kwargs = {'options': QFileDialog.ReadOnly,
              'caption': labeltext,
              'dir': path, # why does pyside have different kwarg keys?
              'filter': makeFilter(filefilter)}
    if multiple:
        res = QFileDialog.getOpenFileNames(parent, **kwargs)
        if isList(res) and isList(res[0]):
            res = res[0]
        elif not isList(res):
            res = list(res)
        return res
    else:
        return [QFileDialog.getOpenFileName(parent, **kwargs)]
def load_from_file():
    global current_name
    file_name, _ = QFileDialog.getOpenFileName(
        main_window, main_window.tr('Load program from file'), None,
        main_window.tr('Puppet Talk (*.pt)'))
    if file_name is None or file_name == '':
        return

    print 'load_from_file', file_name
    handle = open(file_name, 'rb')
    storage = SimpleFormat(handle)

    count = storage.deserialize_data()
    tabs = main_window.PoseList_tabWidget.count()
    for index in range(tabs):
        model = models[index]
        if index < count:
            model.action_sequence().deserialize(storage)
            model.reset()
        else:
            model.remove_all_actions()
    handle.close()

    current_name = os.path.splitext(os.path.basename(file_name))[0]

    update_sequence_duration()
Пример #3
0
def save_to_file():
    file_name, _ = QFileDialog.getSaveFileName(main_window, main_window.tr('Save program to file'), 'example.pt', main_window.tr('Puppet Talk (*.pt)'))
    if file_name is None or file_name == '':
        return False

    save_to_filename(file_name)
    return True
Пример #4
0
def load_from_file():
    global current_name
    file_name, _ = QFileDialog.getOpenFileName(
        main_window, main_window.tr("Load program from file"), None, main_window.tr("Puppet Talk (*.pt)")
    )
    if file_name is None or file_name == "":
        return

    print "load_from_file", file_name
    handle = open(file_name, "rb")
    storage = SimpleFormat(handle)

    count = storage.deserialize_data()
    tabs = main_window.PoseList_tabWidget.count()
    for index in range(tabs):
        model = models[index]
        if index < count:
            model.action_sequence().deserialize(storage)
            model.reset()
        else:
            model.remove_all_actions()
    handle.close()

    current_name = os.path.splitext(os.path.basename(file_name))[0]

    update_sequence_duration()
Пример #5
0
def getSaveFile(parent, labeltext, path, filefilter):
    fileList = QFileDialog.getSaveFileName(
        parent,
        caption = labeltext,
        directory = path,
        filter = makeFilter(filefilter))
    return fileList
Пример #6
0
def getSaveDirectory(parent, labeltext, path):
    if not os.path.isdir(path):
        path = os.path.dirname(path)
    dirList = QFileDialog.getExistingDirectory(
        parent,
        caption = labeltext,
        directory = path)
    return dirList
def save_to_file():
    file_name, _ = QFileDialog.getSaveFileName(
        main_window, main_window.tr('Save program to file'), 'example.pt',
        main_window.tr('Puppet Talk (*.pt)'))
    if file_name is None or file_name == '':
        return False

    save_to_filename(file_name)
    return True
Пример #8
0
def save_to_file():
    file_name, _ = QFileDialog.getSaveFileName(
        main_window, main_window.tr("Save program to file"), "example.pt", main_window.tr("Puppet Talk (*.pt)")
    )
    if file_name is None or file_name == "":
        return False

    save_to_filename(file_name)
    return True
    def _save_image(self):
        file_name, _ = QFileDialog.getSaveFileName(self._widget, self.tr('Save as image'), 'rospackgraph.png', self.tr('Image (*.bmp *.jpg *.png *.tiff)'))
        if file_name is None or file_name == '':
            return

        img = QImage((self._scene.sceneRect().size() * 2.0).toSize(), QImage.Format_ARGB32_Premultiplied)
        painter = QPainter(img)
        painter.setRenderHint(QPainter.Antialiasing)
        self._scene.render(painter)
        painter.end()
        img.save(file_name)
    def _save_dot(self):
        file_name, _ = QFileDialog.getSaveFileName(self._widget, self.tr('Save as DOT'), 'rospackgraph.dot', self.tr('DOT graph (*.dot)'))
        if file_name is None or file_name == '':
            return

        file = QFile(file_name)
        if not file.open(QIODevice.WriteOnly | QIODevice.Text):
            return

        file.write(self._current_dotcode)
        file.close()
Пример #11
0
    def _handle_start_following(self):

        #make sure server is available before sending goal
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        if (not self._client.wait_for_server(rospy.Duration.from_sec(10))):
            QApplication.restoreOverrideCursor()
            msg_box = QMessageBox()
            msg_box.setText("Timeout while looking for path following control server.")
            msg_box.exec_()
            return
        QApplication.restoreOverrideCursor()

        #get path file to load
        filename = QFileDialog.getOpenFileName(self, self.tr('Load Path from File'), '.', self.tr('Path File {.txt} (*.txt)'))
        if filename[0] != '':
            try:
                handle = open(filename[0])
            except IOError as e:
                qWarning(str(e))
                return

        # load path from file
        path_reader=csv.reader(open(filename[0],'rb'),delimiter=';')

        # parse path file and convert to numbers
        temp = [row[0].split() for row in path_reader]
        lines= [[float(num) for num in row] for row in temp]

        # first line of file is radius
        radius = lines[0]
        # remove radius
        del(lines[0])

        now = rospy.Time.now()
        goal = auxos_messages.msg.PlanThenFollowDubinsPathGoal()

        goal.path.header.stamp = now
        goal.path.header.frame_id = self.path_frame_id # TODO: fix this!!!
        for line in lines:
            pose_msg = PoseStamped()
            pose_msg.header.stamp = now
            pose_msg.header.frame_id = goal.path.header.frame_id
            pose_msg.pose.position.x = line[0]
            pose_msg.pose.position.y = line[1]
            quat = qfe(0, 0, psi2theta(line[2]))
            pose_msg.pose.orientation.x = quat[0]
            pose_msg.pose.orientation.y = quat[1]
            pose_msg.pose.orientation.z = quat[2]
            pose_msg.pose.orientation.w = quat[3]
            goal.path.poses.append(pose_msg)

        self._client.send_goal(goal, self._handle_path_complete, self._handle_active, self._handle_feedback)

        print("start following")
Пример #12
0
def fileDialog(parent, labeltext, path, directory = False,
               readOnly = True):
    """
    Opens a dialog to select one or more files for reading.

    Alternative to native file dialogs.
    """
    if directory and not os.path.isdir(path):
        path = os.path.dirname(path)
    dialog = QFileDialog(parent, labeltext, path)
    options = dialog.options() | QFileDialog.ReadOnly
    mode = dialog.fileMode()
    if directory:
        mode = QFileDialog.Directory
        options |= QFileDialog.ShowDirsOnly
    if not readOnly:
        options &= ~QFileDialog.ReadOnly
    dialog.setFileMode(mode)
    dialog.setOptions(options)
    dialog.setViewMode(QFileDialog.Detail)
    return dialog
    def _save_dot(self):
        file_name, _ = QFileDialog.getSaveFileName(
            self._widget, self.tr('Save as DOT'), 'rospackgraph.dot',
            self.tr('DOT graph (*.dot)'))
        if file_name is None or file_name == '':
            return

        file = QFile(file_name)
        if not file.open(QIODevice.WriteOnly | QIODevice.Text):
            return

        file.write(self._current_dotcode)
        file.close()
    def _save_svg(self):
        file_name, _ = QFileDialog.getSaveFileName(self._widget, self.tr('Save as SVG'), 'rospackgraph.svg', self.tr('Scalable Vector Graphic (*.svg)'))
        if file_name is None or file_name == '':
            return

        generator = QSvgGenerator()
        generator.setFileName(file_name)
        generator.setSize((self._scene.sceneRect().size() * 2.0).toSize())

        painter = QPainter(generator)
        painter.setRenderHint(QPainter.Antialiasing)
        self._scene.render(painter)
        painter.end()
    def _save_image(self):
        file_name, _ = QFileDialog.getSaveFileName(
            self._widget, self.tr('Save as image'), 'rospackgraph.png',
            self.tr('Image (*.bmp *.jpg *.png *.tiff)'))
        if file_name is None or file_name == '':
            return

        img = QImage((self._scene.sceneRect().size() * 2.0).toSize(),
                     QImage.Format_ARGB32_Premultiplied)
        painter = QPainter(img)
        painter.setRenderHint(QPainter.Antialiasing)
        self._scene.render(painter)
        painter.end()
        img.save(file_name)
    def _save_svg(self):
        file_name, _ = QFileDialog.getSaveFileName(
            self._widget, self.tr('Save as SVG'), 'rospackgraph.svg',
            self.tr('Scalable Vector Graphic (*.svg)'))
        if file_name is None or file_name == '':
            return

        generator = QSvgGenerator()
        generator.setFileName(file_name)
        generator.setSize((self._scene.sceneRect().size() * 2.0).toSize())

        painter = QPainter(generator)
        painter.setRenderHint(QPainter.Antialiasing)
        self._scene.render(painter)
        painter.end()
    def _load_dot(self, file_name=None):
        if file_name is None:
            file_name, _ = QFileDialog.getOpenFileName(self._widget, self.tr('Open graph from file'), None, self.tr('DOT graph (*.dot)'))
            if file_name is None or file_name == '':
                return

        try:
            fh = open(file_name, 'rb')
            dotcode = fh.read()
            fh.close()
        except IOError:
            return

        # disable controls customizing fetched ROS graph
        self._widget.graph_type_combo_box.setEnabled(False)
        self._widget.filter_line_edit.setEnabled(False)
        self._widget.quiet_check_box.setEnabled(False)

        self._update_graph_view(dotcode)
Пример #18
0
 def saveAsAction(self):
     '''
     Bound to the 'Save as' button of the translation window. Provides user
     with a file browser window for locating a desired destination directory
     and file name. Warns if file of same name already exists. Remembers the
     most recent Save-as directory, and initializes the subsequent file browser
     popups to begin with the latest saved-to directory. 
     '''
     # getSaveFileName() returns a tuple: (fileNames, selectedFilter).
     # We only allow selection of one file name, so only one filename is
     # returned. And we don't set filters, so we ignore the second part of
     # the returned couple:
     targetFile = QFileDialog.getSaveFileName(directory=self.recentDirSavedTo)[0];
     # Did they cancel out of the dialog?
     if len(targetFile) == 0:
         return;
     with open(targetFile, 'w') as fd:
         fd.write(self.pythonDisplay.toPlainText());
     # Next 'Save as' should open in the same directory: 
     self.recentDirSavedTo = os.path.dirname(targetFile);
    def _load_dot(self, file_name=None):
        if file_name is None:
            file_name, _ = QFileDialog.getOpenFileName(
                self._widget, self.tr('Open graph from file'), None,
                self.tr('DOT graph (*.dot)'))
            if file_name is None or file_name == '':
                return

        try:
            fh = open(file_name, 'rb')
            dotcode = fh.read()
            fh.close()
        except IOError:
            return

        # disable controls customizing fetched ROS graph
        self._widget.graph_type_combo_box.setEnabled(False)
        self._widget.filter_line_edit.setEnabled(False)
        self._widget.quiet_check_box.setEnabled(False)

        self._update_graph_view(dotcode)