def __init__(self): for port in list_ports.comports(include_links=True): print(port.device, port.name, port.description) self.__master = MainView(tap_handler=self.__toggle_did_change) self.__arduino = serial.Serial('/dev/tty.usbmodem1421', 115200) self.__master.protocol("WM_DELETE_WINDOW", self.__on_closing)
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 __init__(self): self.__master = MainView(tap_number_handler = self.__did_number_tapped, tap_operator_handler = self.__did_operator_tapped) self.__display_text = "0" self.__display_number = 0 self.__is_typing_number = True self.__master.display(self.__display_text)
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 __init__(self): for port in list_ports.comports(include_links=True): print(port.device, port.name, port.description) self.__master = MainView() self.__arduino = serial.Serial(self.Constants.port, self.Constants.baud) self.__master.protocol(self.Constants.close_event, self.__on_closing) self.__update_clock()
class MainApp(): def __init__(self): self.__master = MainView(send_handler = self.__send) self.__client = MessageManager() def run(self): self.__master.mainloop() def __send(self, phone, message): self.__client.send_message(phone, message)
class MainApp(): def __init__(self): self.__master = MainView(convert_handler = self.__convert) def run(self): self.__master.mainloop() def __convert(self, from_currency, to_currency, ammount): result = str(self.__currency.get_convertion(ammount)) self.__master.update_result(result)
class MainApp(): def __init__(self): self.__master = MainView(convert_handler=self.__convert) self.__currency = CurrencyManager.get_currency("USD") def run(self): self.__master.mainloop() def __convert(self, from_currency, to_currency, ammount): self.__currency = CurrencyManager.get_currency(from_currency) result = str(self.__currency.get_convertion(to_currency, ammount))
def __init__(self): self.__master = MainView( tap_number_handler=self.__did_number_tapped, tap_operator_handler=self.__did_operator_tapped) self.__brain = CalculatorBrain( update_handler=self.__result_was_updated) self.__display_text = "0" self.__display_number = 0 self.__is_typing_number = True self.__master.display(self.__display_text)
def __init__(self, sys_argv): super(App, self).__init__(sys_argv) self._model = Model() self._mainView = MainView() self._loginController = LoginController(self._model) self._loginView = LoginView(self._model, self._loginController) apply_stylesheet(self._loginView, theme='dark_cyan.xml') self._mainView.setScreen(self._loginView) self._mainView.show()
class MainApp(): def __init__(self): self.__currency = CurrencyManager.get_currency("USD") self.__menu = self.__currency.rates self.__master = MainView(convert_handler=self.__convert, menu=self.__menu) def run(self): self.__master.mainloop() def __convert(self, from_currency, to_currency, ammount): result = str(self.__currency.get_convertion(to_currency, ammount)) self.__master.update_result(result)
class MainApp(): def __init__(self): self.__master = MainView(convert_handler=self.__convert) self.__currency = CurrencyManager.get_currency( self.__master.Constants.default_from_currency) def run(self): self.__master.mainloop() def __convert(self, from_currency, to_currency, ammount): self.__currency = CurrencyManager.get_currency( self.__master.get_from_currency()) result = str(self.__currency.get_convertion(to_currency, ammount)) self.__master.update_result(result)
class MainApp(): def __init__(self): self.__master = MainView(convert_handler=self.__convert) def run(self): self.__master.mainloop() def __convert(self, from_currency, to_currency, ammount): self.initial_currency = from_currency self.initial_convertion = CurrencyManager.get_currency( self.initial_currency) result = str( self.initial_convertion.get_convertion(to_currency, ammount)) self.__master.update_result(result)
class MainApp(): def __init__(self): self.__get_currency("USD") self.__master = MainView(convert_handler = self.__convert, origin_currency = self.__get_currency, options = self.__currencies) def run(self): self.__master.mainloop() def __convert(self, from_currency, to_currency, ammount): result = str(self.__currency.get_convertion(to_currency, ammount)) self.__master.update_result(result) def __get_currency(self, value): self.__currency = CurrencyManager.get_currency(value) self.__currencies = self.__currency.rates
class MainApp(): def __init__(self): self.__master = MainView(convert_handler=self.__convert) self.__currency = CurrencyManager.get_currency( str(self.__master.currency_name)) def run(self): self.__master.mainloop() def __convert(self, from_currency, to_currency, ammount): self.__currency = CurrencyManager.get_currency(from_currency) if from_currency == to_currency: result = ammount else: result = str(self.__currency.get_convertion(to_currency, ammount)) self.__master.update_result(result)
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 __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.settings_directory = os.path.join(os.path.expanduser("~"), '.Dioptas') self.working_directories = {'calibration': '', 'mask': '', 'image': '', 'spectrum': '', 'overlay': '', 'phase': ''} self.load_settings() #create controller self.calibration_controller = CalibrationController(self.working_directories, self.view.calibration_widget, self.img_data, self.mask_data, self.calibration_data) self.mask_controller = MaskController(self.working_directories, self.view.mask_widget, self.img_data, self.mask_data) self.integration_controller = IntegrationController(self.working_directories, 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.view)
class MainApp(): def __init__(self): self.__master = MainView(convert_handler=self.__convert) self.__currency = CurrencyManager.get_currency( self.__master.origin_currency) def run(self): self.__master.mainloop() def __convert(self, from_currency, to_currency, ammount): self.__currency = CurrencyManager.get_currency(from_currency) try: result = str(self.__currency.get_convertion(to_currency, ammount)) self.__master.update_result(result) except Exception as NoneType: print('None Type error in Currency')
class MainApp(): def __init__(self): self.__master = MainView(convert_handler=self.__convert) self.__currency = CurrencyManager.get_currency( self.__master.Constants.exchange_rate) def run(self): self.__master.mainloop() def __convert(self, from_currency, to_currency, ammount): if from_currency == to_currency: return self.__master.update_result(ammount) try: if from_currency != self.__master.Constants.new_exchange_rate: self.__currency = CurrencyManager.get_currency( self.__master.Constants.new_exchange_rate) result = str(self.__currency.get_convertion(to_currency, ammount)) self.__master.update_result(result) except ValueError: return None
class MainApp(): class Constants: port = "/dev/tty.usbmodem1411" baud = 115200 close_event = "WM_DELETE_WINDOW" def __init__(self): for port in list_ports.comports(include_links=True): print(port.device, port.name, port.description) self.__master = MainView() self.__arduino = serial.Serial(self.Constants.port, self.Constants.baud) self.__master.protocol(self.Constants.close_event, self.__on_closing) self.__update_clock() def run(self): self.__master.mainloop() def __handle_data(self, data): clean_values = data.strip(' \n\r').split(",") position_value_horizontal = int(clean_values[1]) position_value_vertical = int(clean_values[3]) self.__master.drawing_line(position_value_horizontal, position_value_vertical) self.__master.Constants.positions(position_value_horizontal, position_value_vertical) def __update_clock(self): data = self.__arduino.readline().decode() self.__handle_data(data) self.__master.after(1, self.__update_clock) def __on_closing(self): self.__arduino.close() self.__master.destroy()
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)
class MainApp(): def __init__(self): for port in list_ports.comports(include_links=True): print(port.device, port.name, port.description) self.__master = MainView(tap_handler=self.__toggle_did_change) self.__arduino = serial.Serial('/dev/tty.usbmodem1421', 115200) self.__master.protocol("WM_DELETE_WINDOW", self.__on_closing) def run(self): self.__master.mainloop() def __toggle_did_change(self, state): value = str(1 if state else 0).encode('ascii') self.__arduino.write(value) def __on_closing(self): self.__arduino.close() self.__master.destroy()
class MainApp(): def __init__(self): self.__master = MainView(tap_number_handler = self.__did_number_tapped, tap_operator_handler = self.__did_operator_tapped) self.__display_text = "0" self.__display_number = 0 self.__is_typing_number = True self.__master.display(self.__display_text) def run(self): self.__master.mainloop() def __did_number_tapped(self, number): if self.__is_typing_number: self.__display_text = number.value if self.__display_text == Number.ZERO.value else self.__display_text + number.value else: self.__display_number = float(self.__display_text) self.__display_text = number.value self.__is_typing_number = True self.__update_diplay() def __did_operator_tapped(self, operator): if operator == UnaryOperator.DOT: self.__add_dot() else: self.__is_typing_number = False def __update_diplay(self): self.__master.display(self.__display_text) def __add_dot(self): if UnaryOperator.DOT.value in self.__display_text: return self.__display_text += UnaryOperator.DOT.value self.__update_diplay()
class MainController(object): """ Creates a the main controller for Dioptas. Loads all the data objects and connects them with the other controllers """ 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.settings_directory = os.path.join(os.path.expanduser("~"), '.Dioptas') self.working_directories = {'calibration': '', 'mask': '', 'image': '', 'spectrum': '', 'overlay': '', 'phase': ''} self.load_settings() #create controller self.calibration_controller = CalibrationController(self.working_directories, self.view.calibration_widget, self.img_data, self.mask_data, self.calibration_data) self.mask_controller = MaskController(self.working_directories, self.view.mask_widget, self.img_data, self.mask_data) self.integration_controller = IntegrationController(self.working_directories, 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.view) @staticmethod def raise_window(widget): widget.show() widget.setWindowState(widget.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive) widget.activateWindow() widget.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.mask_data.set_supersampling() 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.update_img() 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_in_view() except (TypeError, AttributeError): 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 ' + __VERSION__ if img_filename is '' and spec_filename is '': self.view.setWindowTitle(str + u' - © 2014 C. Prescher') self.view.integration_widget.img_frame.setWindowTitle(str + u' - © 2014 C. Prescher') 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 += ']' str += u' - © 2014 C. Prescher' self.view.setWindowTitle(str) self.view.integration_widget.img_frame.setWindowTitle(str) def load_settings(self): if os.path.exists(self.settings_directory): self.load_directories() self.load_xml_settings() def load_directories(self): working_directories_path = os.path.join(self.settings_directory, 'working_directories.csv') if os.path.exists(working_directories_path): reader = csv.reader(open(working_directories_path, 'r')) self.working_directories = dict(x for x in reader) def load_xml_settings(self): xml_settings_path = os.path.join(self.settings_directory, "settings.xml") if os.path.exists(xml_settings_path): tree = ET.parse(xml_settings_path) root = tree.getroot() filenames = root.find("filenames") calibration_path=filenames.find("calibration").text if os.path.exists(str(calibration_path)): self.calibration_data.load(calibration_path) def save_settings(self): if not os.path.exists(self.settings_directory): os.mkdir(self.settings_directory) self.save_directories() self.save_xml_settings() def save_directories(self): working_directories_path = os.path.join(self.settings_directory, 'working_directories.csv') writer = csv.writer(open(working_directories_path, 'w')) for key, value in list(self.working_directories.items()): writer.writerow([key, value]) writer.writerow([key, value]) def save_xml_settings(self): root = ET.Element("DioptasSettings") filenames = ET.SubElement(root, "filenames") calibration_filename = ET.SubElement(filenames, "calibration") calibration_filename.text = self.calibration_data.filename tree = ET.ElementTree(root) tree.write(os.path.join(self.settings_directory, "settings.xml")) def close_event(self, _): self.save_settings() QtGui.QApplication.closeAllWindows() QtGui.QApplication.quit()
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()
def __init__(self): self.__master = MainView(convert_handler = self.__convert)
def __init__(self): self.__master = MainView(convert_handler=self.__convert) self.__currency = CurrencyManager.get_currency( self.__master.Constants.exchange_rate)
class MainApp(): def __init__(self): self.__master = MainView( tap_number_handler=self.__did_number_tapped, tap_operator_handler=self.__did_operator_tapped) self.__brain = CalculatorBrain( update_handler=self.__result_was_updated) self.__display_text = "0" self.__display_number = 0 self.__is_typing_number = True self.__master.display(self.__display_text) def run(self): self.__master.mainloop() def __did_number_tapped(self, number): if self.__is_typing_number: self.__display_text = number.value if self.__display_text == Number.ZERO.value else self.__display_text + number.value else: self.__display_text = number.value self.__is_typing_number = True self.__update_diplay() def __did_operator_tapped(self, operator): if operator == UnaryOperator.DOT: self.__add_dot() else: self.__is_typing_number = False if operator == UnaryOperator.EQUAL: self.__stack_number() self.__brain.perform_pending_operation() elif isinstance(operator, BinaryOperator): self.__brain.perform_pending_operation() self.__stack_number() self.__brain.add_pending_operation(operator) elif isinstance(operator, UnaryOperator): self.__stack_number() self.__brain.perform_uniary_operation(operator) def __update_diplay(self): self.__master.display(self.__display_text) def __add_dot(self): if UnaryOperator.DOT.value in self.__display_text: return if self.__is_typing_number: self.__display_text += UnaryOperator.DOT.value else: self.__display_text = Number.ZERO.value + UnaryOperator.DOT.value self.__is_typing_number = True self.__update_diplay() def __result_was_updated(self): text_value = str(self.__brain.result) self.__display_text = text_value self.__update_diplay() def __stack_number(self): caster = float if UnaryOperator.DOT.value in self.__display_text else int self.__display_number = caster(self.__display_text) self.__brain.stack_number(self.__display_number)
def __init__(self): self.__master = MainView(convert_handler=self.__convert) self.__currency = CurrencyManager.get_currency("USD")
class MainApp(): class Constants: port = "COM8" baud = 115200 close_event = "WM_DELETE_WINDOW" heigth = 500 width = 600 def __init__(self): for port in list_ports.comports(include_links=True): print(port.device, port.name, port.description) self.__master = MainView() self.__brain = DrawBrain() self.__arduino = serial.Serial(self.Constants.port, self.Constants.baud) self.__master.protocol(self.Constants.close_event, self.__on_closing) self.__initial_position = False self.__update_clock() self.__color = None def run(self): self.__master.mainloop() def __handle_data(self, data): clean_values = data.strip(' \r\n').split(',') try: vertical_value = self.Constants.heigth - int(clean_values[0]) horizontal_value = int(clean_values[1]) except Exception: return else: if self.__initial_position: coordinates = self.__brain.coordinates(vertical_value, horizontal_value) self.__master.update_line(coordinates) else: self.__brain.start(vertical_value, horizontal_value) self.__initial_position = True self.__master.update_position('Posición: ' + str(horizontal_value) + ',' + str(clean_values[0])) def __update_clock(self): data = self.__arduino.readline().decode() self.__handle_data(data) self.__master.after(1, self.__update_clock) def __on_closing(self): self.__arduino.close() self.__master.destroy()
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()
class MainApp(): class Constants: port = 'COM3' baud = 115200 close_event = "WM_DELETE_WINDOW" def __init__(self): self.__master = MainView(tap_button_handler=self.__did_button_tap, tap_space_handler=self.__did_space_tap) self.__port = serial.Serial(self.Constants.port, self.Constants.baud) self.__master.protocol(self.Constants.close_event, self.__on_closing) self.__update_coordinate() def run(self): self.__master.mainloop() def __did_button_tap(self, color): self.__master.ChangeColor.line_color = color def __did_space_tap(self): self.__master.clean_screen() def __update_coordinate(self): coordinates = self.__port.readline().decode() self.__handle_coordinate(coordinates) self.__master.after(5, self.__update_coordinate) def __handle_coordinate(self, coordinate): clean_values = coordinate.strip(' \n\r').split(",") coordinate_y = int(clean_values[1]) coordinate_x = int(clean_values[3]) self.__master.update_canvas(coordinate_x, coordinate_y) def __on_closing(self): self.__port.close() self.__master.destroy()
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()
def __init__(self): self.__master = MainView(send_handler = self.__send) self.__client = MessageManager()
def __init__(self): self.__master = MainView(convert_handler=self.__convert) self.__currency = CurrencyManager.get_currency( self.__master.Constants.default_from_currency)
def __init__(self): self.__master = MainView(tap_button_handler=self.__did_button_tap, tap_space_handler=self.__did_space_tap) self.__port = serial.Serial(self.Constants.port, self.Constants.baud) self.__master.protocol(self.Constants.close_event, self.__on_closing) self.__update_coordinate()