Beispiel #1
0
    def __init__(self, parent, main_window):
        QtWidgets.QWidget.__init__(self, parent)
        self.main_window = main_window
        self.progress_dialog = ProgressDialog(self)
        self.most_recent_path = "~"

        self.control = main_window.control

        self.init_gui()
        self.guessed_volumes_for = set()
        self.last_shown_filename_with_frame = None
Beispiel #2
0
class FileTab(QtWidgets.QWidget):
    """
        tab 'file' in the main widget
    """

    def __init__(self, parent, main_window):
        QtWidgets.QWidget.__init__(self, parent)
        self.main_window = main_window
        self.progress_dialog = ProgressDialog(self)
        self.most_recent_path = "~"

        self.control = main_window.control

        self.init_gui()
        self.guessed_volumes_for = set()
        self.last_shown_filename_with_frame = None

    def init_gui(self):
        self.vbox = QtWidgets.QVBoxLayout()
        self.vbox.setSpacing(0)
        self.button_hbox = QtWidgets.QHBoxLayout()
        self.button_hbox.setSpacing(10)

        self.file_button = QtWidgets.QPushButton('Open', self)
        self.file_button.setDefault(True)
        self.file_button.clicked.connect(self.open_file_dialog)
        self.button_hbox.addWidget(self.file_button)

        self.delete_button = QtWidgets.QPushButton('Delete', self)
        self.delete_button.clicked.connect(self.remove_selected_files)
        self.delete_button.setDisabled(True)
        self.button_hbox.addWidget(self.delete_button)

        self.calculate_button = QtWidgets.QPushButton('Calculate', self)
        self.calculate_button.clicked.connect(self.calculate)
        self.calculate_button.setDisabled(True)
        self.button_hbox.addWidget(self.calculate_button)

        self.show_button = QtWidgets.QPushButton('Show', self)
        self.show_button.clicked.connect(self.show_selected_frame)
        self.show_button.setDisabled(True)
        self.button_hbox.addWidget(self.show_button)

        self.vbox.addLayout(self.button_hbox)

        self.button2_hbox = QtWidgets.QHBoxLayout()
        self.button2_hbox.setSpacing(10)

        self.select_all_button = QtWidgets.QPushButton('Select all frames', self)
        self.select_all_button.clicked.connect(self.select_all)
        self.select_all_button.setDisabled(True)
        self.button2_hbox.addWidget(self.select_all_button)

        self.select_nth_button = QtWidgets.QPushButton('Select every nth frame...', self)
        self.select_nth_button.clicked.connect(self.select_nth)
        self.select_nth_button.setDisabled(True)
        self.button2_hbox.addWidget(self.select_nth_button)

        self.vbox.addLayout(self.button2_hbox)

#        self.file_list = DragList(self)
#        self.file_list.itemDoubleClicked.connect(self.calculate)
#        self.file_list.itemSelectionChanged.connect(self.selection_changed)
#        self.vbox.addWidget(self.file_list)
#
#        for path in config.recent_files:
#            self.file_list.add_file(path)

        self.file_list = TreeList(self)
        self.vbox.addSpacing(10)
        self.vbox.addWidget(self.file_list)

        self.setLayout(self.vbox)

    def select_all(self):
        self.file_list.select_all()

    def select_nth(self):
        n, okay = QtWidgets.QInputDialog.getInt(self, "Set n", "", 1, 1)
        if okay:
            self.file_list.select_nth(n)

    def show_selected_frame(self):
        self.last_shown_filename_with_frame = self.file_list.show_selected_frame()

    def selection_changed(self):
        sel = self.file_list.get_selection()
        if not sel or len(self.file_list.get_selection()) > 1:
            return

    def remove_selected_files(self):
        self.enable_files_in_menu()
        self.file_list.remove_selected_files()

    def enable_files_in_menu(self):
        actions = self.main_window.recent_files_submenu.actions()
        selected = self.file_list.selectedItems()
        if not selected:
            return
        text = None
        subitem = selected[0]
        item = subitem.parent()

        # if sheet contains only one frame and this is deleted, the parent will be also deleted
        if subitem.text(0).startswith("frame") and ((item.childCount() == 1) or (item.childCount() == len(selected))):
            text = item.text(0)
            for action in actions:
                if action.text().endswith(text):
                    action.setEnabled(True)
                    item.takeChild(item.indexOfChild(subitem))
                    self.file_list.removeItemWidget(subitem, 0)
                    self.file_list.takeTopLevelItem(self.file_list.indexOfTopLevelItem(item))
                    self.file_list.removeItemWidget(item, 0)
                    del self.file_list.path_dict[text]
        else:
            for sel in selected:
                # tree_list elements get only reenabled in menu if the whole sheet is removed from file_list
                if sel.text(0).startswith("frame"):
                    continue

                for action in actions:
                    if action.text() == self.file_list.path_dict[sel.text(0)]:
                        action.setEnabled(True)

    def disable_files_in_menu_and_open(self, path):
        for action in self.main_window.recent_files_submenu.actions():
            if action.text() == path:
                action.setDisabled(True)
        try:
            self.file_list.add_file(path)
        except ValueError as e:
            QtWidgets.QMessageBox.information(self, 'Information', e.message, QtWidgets.QMessageBox.Ok)
            return

    def open_file_dialog(self):
        filenames = QtWidgets.QFileDialog.getOpenFileNames(self, 'Open dataset', self.most_recent_path)[0]
        for path in filenames:
            if path:
                self.disable_files_in_menu_and_open(path)
                self.main_window.update_submenu_recent_files()

    def calculationcallback(self, func, settings):
        def enable_screenshot_button_on_success(self, was_successful):
            if was_successful():
                self.file_list._enable_screenshot_button()

        thread = CalculationThread(self, func, settings)
        thread.finished.connect(functools.partial(self.control.update,
                                                  was_successful=lambda: not thread.exited_with_errors))
        thread.finished.connect(functools.partial(self.main_window.updatestatus,
                                                  was_successful=lambda: not thread.exited_with_errors))
        thread.finished.connect(functools.partial(enable_screenshot_button_on_success, self,
                                                  was_successful=lambda: not thread.exited_with_errors))
        thread.start()
        self.progress_dialog.exec_()

    def calculate(self, file_frame_dict=None):
        if not file_frame_dict:
            file_frame_dict = self.file_list.get_selection()
        dia = CalculationSettingsDialog(self, file_frame_dict)
        settings, ok = dia.calculation_settings()

        if ok:
            self.control.calculationcallback = self.calculationcallback
            self.control.calculate(settings)
            self.last_shown_filename_with_frame = (file_frame_dict.keys()[-1],
                                                   file_frame_dict.values()[-1][-1])