Пример #1
0
    def _insert_image(self):
        filedialog = QFileDialog(self)
        filedialog.setOption(QFileDialog.DontUseNativeDialog)
        filedialog.setDefaultSuffix("*.jpg")
        filedialog.setDirectory(self._cfg.get(
            "TextEditor/LastPath", ".", system=True))

        type_files = (
            self.tr("JPEG (*.jpg)"),
            self.tr("GIF (*.gif)"),
            self.tr("PNG (*.png)"),
            self.tr("BMP (*.bmp)"),
            self.tr("All files (*)"),
        )
        filedialog.setNameFilters(type_files)

        if filedialog.exec_():
            path = filedialog.selectedFiles()[0]
            fmt = path.split(".")[-1]
            image = QImageReader(path).read()
            self._doc.ins_image(image, fmt, image.width(), image.height())
            self._cfg["SYSTEM", "TextEditor/LastPath"] = (
                os.path.dirname(path))
    def open_file_dialog(self):
        # in case a file is open already, close it properly first
        if self.machine:
            ret = self.close_file()
            if not ret:
                # user canceled closing of current file; can't open new one
                return

        # open dialog for selecting a gcode file to be loaded
        dialog = QFileDialog(self)
        dialog.setFileMode(QFileDialog.ExistingFile)
        filters = ["G-code (*.gcode)", "Any files (*)"]
        dialog.setNameFilters(filters)
        dialog.selectNameFilter(filters[0])
        dialog.setViewMode(QFileDialog.Detail)

        filename = None
        if dialog.exec_():
            filename = dialog.selectedFiles()

        if filename:
            self.run_in_background(self.load_data,
                                   after=self.show_layer,
                                   args=filename)
Пример #3
0
 def file_dialog(self, load_save_type=QFileDialog.AcceptSave):
     """Opens an file save dialog and returns the selected
         filename."""
     file_save_dialog = QFileDialog(self)
     file_save_dialog.setFileMode(QFileDialog.AnyFile)
     file_save_dialog.setAcceptMode(load_save_type)
     file_save_dialog.setNameFilters(
         ["MPDJ files (*.{})".format(FILE_SUFFIX)])
     file_save_dialog.selectNameFilter(
         "MPDJ files (*.{})".format(FILE_SUFFIX))
     file_save_dialog.setDefaultSuffix((FILE_SUFFIX))
     exec_value = file_save_dialog.exec()
     if exec_value == 0:
         return None
     file_names = file_save_dialog.selectedFiles()
     if len(file_names) != 1:
         message_box = QMessageBox()
         message_box.setText('Please select only one file!')
         message_box.setWindowTitle('Save error.')
         message_box.setStandardButtons(QMessageBox.Ok)
         message_box.setIcon(QMessageBox.Information)
         message_box.exec_()
         return None
     return file_names[0]