Exemple #1
0
class MainController(object):
    def __init__(self, app):
        self.splash_img = QtGui.QPixmap("UiFiles/splash.png")
        self.splash_screen = QtGui.QSplashScreen(
            self.splash_img, QtCore.Qt.WindowStaysOnTopHint)
        self.splash_screen.show()
        app.processEvents()
        time.sleep(1)
        app.processEvents()

        self.view = MainView()
        #create data
        self.img_data = ImgData()
        self.calibration_data = CalibrationData(self.img_data)
        self.mask_data = MaskData()
        self.spectrum_data = SpectrumData()
        self.phase_data = PhaseData()

        self.load_directories()
        #create controller
        self.calibration_controller = CalibrationController(
            self.working_dir, self.view.calibration_widget, self.img_data,
            self.mask_data, self.calibration_data)
        self.mask_controller = MaskController(self.working_dir,
                                              self.view.mask_widget,
                                              self.img_data, self.mask_data)
        self.integration_controller = IntegrationController(
            self.working_dir, self.view.integration_widget, self.img_data,
            self.mask_data, self.calibration_data, self.spectrum_data,
            self.phase_data)
        self.create_signals()
        self.set_title()
        self.raise_window()
        self.splash_screen.finish(self.view)

    def raise_window(self):
        self.view.show()
        self.view.setWindowState(self.view.windowState()
                                 & ~QtCore.Qt.WindowMinimized
                                 | QtCore.Qt.WindowActive)
        self.view.activateWindow()
        self.view.raise_()

    def create_signals(self):
        self.view.tabWidget.currentChanged.connect(self.tab_changed)
        self.view.closeEvent = self.close_event
        self.img_data.subscribe(self.set_title)
        self.spectrum_data.subscribe(self.set_title)

    def tab_changed(self, ind):
        if ind == 2:
            self.integration_controller.image_controller.plot_mask()
            self.integration_controller.view.calibration_lbl.setText(
                self.calibration_data.calibration_name)
            auto_scale_previous = self.integration_controller.image_controller._auto_scale
            self.integration_controller.image_controller._auto_scale = False
            self.integration_controller.spectrum_controller.image_changed()
            self.integration_controller.image_controller._auto_scale = auto_scale_previous
        elif ind == 1:
            self.mask_controller.plot_mask()
            self.mask_controller.plot_image()
        elif ind == 0:
            self.calibration_controller.plot_mask()
            try:
                self.calibration_controller.update_calibration_parameter()
            except TypeError:
                pass

    def set_title(self):
        img_filename = os.path.basename(self.img_data.filename)
        spec_filename = os.path.basename(self.spectrum_data.spectrum_filename)
        calibration_name = self.calibration_data.calibration_name
        str = 'Dioptas v' + __VERSION__
        if img_filename is '' and spec_filename is '':
            self.view.setWindowTitle(str)
            return

        if img_filename is not '' or spec_filename is not '':
            str += ' - ['
        if img_filename is not '':
            str += img_filename
        elif img_filename is '' and spec_filename is not '':
            str += spec_filename
        if not img_filename == spec_filename:
            str += ', ' + spec_filename
        if calibration_name is not None:
            str += ', calibration: ' + calibration_name
        str += ']'
        self.view.setWindowTitle(str)

    def load_directories(self):
        if os.path.exists('working_directories.csv'):
            reader = csv.reader(open('working_directories.csv', 'rb'))
            self.working_dir = dict(x for x in reader)
        else:
            self.working_dir = {
                'calibration': '',
                'mask': '',
                'image': '',
                'spectrum': '',
                'overlay': '',
                'phase': ''
            }

    def save_directories(self):
        writer = csv.writer(open('working_directories.csv', 'wb'))
        for key, value in self.working_dir.items():
            writer.writerow([key, value])

    def close_event(self, _):
        self.save_directories()
Exemple #2
0
class MainController(object):
    def __init__(self):
        self.view = MainView()

        #create data
        self.img_data = ImgData()
        self.calibration_data = CalibrationData(self.img_data)
        self.mask_data = MaskData()
        self.spectrum_data = SpectrumData()
        self.phase_data = PhaseData()

        self.load_directories()
        #create controller
        self.calibration_controller = CalibrationController(self.working_dir,
                                                            self.view.calibration_widget,
                                                            self.img_data,
                                                            self.calibration_data)
        self.mask_controller = MaskController(self.working_dir,
                                              self.view.mask_widget,
                                              self.img_data,
                                              self.mask_data)
        self.integration_controller = IntegrationController(self.working_dir,
                                                            self.view.integration_widget,
                                                            self.img_data,
                                                            self.mask_data,
                                                            self.calibration_data,
                                                            self.spectrum_data,
                                                            self.phase_data)

        self.create_signals()
        self.raise_window()

    def raise_window(self):
        self.view.show()
        self.view.setWindowState(self.view.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
        self.view.activateWindow()
        self.view.raise_()

    def create_signals(self):
        self.view.tabWidget.currentChanged.connect(self.tab_changed)
        self.view.closeEvent = self.close_event

    def tab_changed(self, ind):
        if ind == 2:
            self.integration_controller.image_controller.plot_mask()
            self.integration_controller.view.calibration_lbl.setText(self.calibration_data.calibration_name)
            self.img_data.notify()
        elif ind == 1:
            self.mask_controller.plot_mask()
            self.mask_controller.plot_image()
        elif ind == 0:
            try:
                self.calibration_controller.update_calibration_parameter()
            except TypeError:
                pass

    def load_directories(self):
        if os.path.exists('working_directories.csv'):
            reader = csv.reader(open('working_directories.csv', 'rb'))
            self.working_dir = dict(x for x in reader)
        else:
            self.working_dir = {'calibration': '', 'mask': '', 'image': '', 'spectrum': '', 'overlay': '',
                                'phase': ''}

    def save_directories(self):
        writer = csv.writer(open('working_directories.csv', 'wb'))
        for key, value in self.working_dir.items():
            writer.writerow([key, value])

    def close_event(self, _):
        self.save_directories()
Exemple #3
0
class MainController(object):
    def __init__(self, app):
        self.splash_img = QtGui.QPixmap("UiFiles/splash.png")
        self.splash_screen = QtGui.QSplashScreen(self.splash_img, QtCore.Qt.WindowStaysOnTopHint)
        self.splash_screen.show()
        app.processEvents()
        time.sleep(1)
        app.processEvents()

        self.view = MainView()
        #create data
        self.img_data = ImgData()
        self.calibration_data = CalibrationData(self.img_data)
        self.mask_data = MaskData()
        self.spectrum_data = SpectrumData()
        self.phase_data = PhaseData()

        self.load_directories()
        #create controller
        self.calibration_controller = CalibrationController(self.working_dir,
                                                            self.view.calibration_widget,
                                                            self.img_data,
                                                            self.mask_data,
                                                            self.calibration_data)
        self.mask_controller = MaskController(self.working_dir,
                                              self.view.mask_widget,
                                              self.img_data,
                                              self.mask_data)
        self.integration_controller = IntegrationController(self.working_dir,
                                                            self.view.integration_widget,
                                                            self.img_data,
                                                            self.mask_data,
                                                            self.calibration_data,
                                                            self.spectrum_data,
                                                            self.phase_data)
        self.create_signals()
        self.set_title()
        self.raise_window()
        self.splash_screen.finish(self.view)

    def raise_window(self):
        self.view.show()
        self.view.setWindowState(self.view.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
        self.view.activateWindow()
        self.view.raise_()

    def create_signals(self):
        self.view.tabWidget.currentChanged.connect(self.tab_changed)
        self.view.closeEvent = self.close_event
        self.img_data.subscribe(self.set_title)
        self.spectrum_data.subscribe(self.set_title)

    def tab_changed(self, ind):
        if ind == 2:
            self.integration_controller.image_controller.plot_mask()
            self.integration_controller.view.calibration_lbl.setText(self.calibration_data.calibration_name)
            auto_scale_previous = self.integration_controller.image_controller._auto_scale
            self.integration_controller.image_controller._auto_scale = False
            self.integration_controller.spectrum_controller.image_changed()
            self.integration_controller.image_controller._auto_scale = auto_scale_previous
        elif ind == 1:
            self.mask_controller.plot_mask()
            self.mask_controller.plot_image()
        elif ind == 0:
            self.calibration_controller.plot_mask()
            try:
                self.calibration_controller.update_calibration_parameter()
            except TypeError:
                pass

    def set_title(self):
        img_filename = os.path.basename(self.img_data.filename)
        spec_filename = os.path.basename(self.spectrum_data.spectrum_filename)
        calibration_name = self.calibration_data.calibration_name
        str = 'Dioptas v' + __VERSION__
        if img_filename is '' and spec_filename is '':
            self.view.setWindowTitle(str)
            return

        if img_filename is not '' or spec_filename is not '':
            str += ' - ['
        if img_filename is not '':
            str += img_filename
        elif img_filename is '' and spec_filename is not '':
            str += spec_filename
        if not img_filename == spec_filename:
            str += ', ' + spec_filename
        if calibration_name is not None:
            str += ', calibration: ' + calibration_name
        str += ']'
        self.view.setWindowTitle(str)

    def load_directories(self):
        if os.path.exists('working_directories.csv'):
            reader = csv.reader(open('working_directories.csv', 'rb'))
            self.working_dir = dict(x for x in reader)
        else:
            self.working_dir = {'calibration': '', 'mask': '', 'image': '', 'spectrum': '', 'overlay': '',
                                'phase': ''}

    def save_directories(self):
        writer = csv.writer(open('working_directories.csv', 'wb'))
        for key, value in self.working_dir.items():
            writer.writerow([key, value])


    def close_event(self, _):
        self.save_directories()
Exemple #4
0
class MainController(object):
    def __init__(self):
        self.view = MainView()

        #create data
        self.img_data = ImgData()
        self.calibration_data = CalibrationData(self.img_data)
        self.mask_data = MaskData()
        self.spectrum_data = SpectrumData()
        self.phase_data = PhaseData()

        self.load_directories()
        #create controller
        self.calibration_controller = CalibrationController(
            self.working_dir, self.view.calibration_widget, self.img_data,
            self.calibration_data)
        self.mask_controller = MaskController(self.working_dir,
                                              self.view.mask_widget,
                                              self.img_data, self.mask_data)
        self.integration_controller = IntegrationController(
            self.working_dir, self.view.integration_widget, self.img_data,
            self.mask_data, self.calibration_data, self.spectrum_data,
            self.phase_data)

        self.create_signals()
        self.raise_window()

    def raise_window(self):
        self.view.show()
        self.view.setWindowState(self.view.windowState()
                                 & ~QtCore.Qt.WindowMinimized
                                 | QtCore.Qt.WindowActive)
        self.view.activateWindow()
        self.view.raise_()

    def create_signals(self):
        self.view.tabWidget.currentChanged.connect(self.tab_changed)
        self.view.closeEvent = self.close_event

    def tab_changed(self, ind):
        if ind == 2:
            self.integration_controller.image_controller.plot_mask()
            self.integration_controller.view.calibration_lbl.setText(
                self.calibration_data.calibration_name)
            self.img_data.notify()
        elif ind == 1:
            self.mask_controller.plot_mask()
            self.mask_controller.plot_image()
        elif ind == 0:
            try:
                self.calibration_controller.update_calibration_parameter()
            except TypeError:
                pass

    def load_directories(self):
        if os.path.exists('working_directories.csv'):
            reader = csv.reader(open('working_directories.csv', 'rb'))
            self.working_dir = dict(x for x in reader)
        else:
            self.working_dir = {
                'calibration': '',
                'mask': '',
                'image': '',
                'spectrum': '',
                'overlay': '',
                'phase': ''
            }

    def save_directories(self):
        writer = csv.writer(open('working_directories.csv', 'wb'))
        for key, value in self.working_dir.items():
            writer.writerow([key, value])

    def close_event(self, _):
        self.save_directories()