Exemplo n.º 1
0
    def __init__(self, chb_names, parent=None):
        """Set up the ui and create connections."""
        super().__init__(parent)
        self.setWindowTitle(_QCoreApplication.translate('', "Select Tabs"))
        self.resize(250, 400)
        self.setFont(_font)

        main_layout = _QVBoxLayout()
        vertical_layout = _QVBoxLayout()
        group_box = _QGroupBox(
            _QCoreApplication.translate('', "Select Tabs to Show"))
        group_box.setLayout(vertical_layout)
        group_box.setFont(_font_bold)
        main_layout.addWidget(group_box)
        self.setLayout(main_layout)

        self.chb_names = chb_names
        for name in self.chb_names:
            name_split = name.split('_')
            label = ' '.join([s.capitalize() for s in name_split])
            chb = _QCheckBox(_QCoreApplication.translate('', label))
            setattr(self, 'chb_' + name, chb)
            vertical_layout.addWidget(chb)
            chb.setFont(_font)

        self.pbt_apply = _QPushButton(
            _QCoreApplication.translate('', "Apply Changes"))
        self.pbt_apply.setMinimumSize(_QSize(0, 40))
        self.pbt_apply.setFont(_font_bold)
        vertical_layout.addWidget(self.pbt_apply)

        self.pbt_apply.clicked.connect(self.emit_tab_selection_signal)
Exemplo n.º 2
0
 def check_driver_connection(self):
     if not _driver.connected:
         msg = _QCoreApplication.translate('', 'Driver not connected.')
         title = _QCoreApplication.translate('', 'Failure')
         _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
         return False
     return True       
Exemplo n.º 3
0
    def enable_encoder_reading(self):
        """Enable encoder reading."""
        try:
            encoder_res = self.advanced_options.integrator_encoder_resolution

            if self.ui.chb_encoder.isChecked():
                if not self.check_integrator_connection():
                    self.stop_encoder_update = True
                    self.ui.lcd_encoder.setEnabled(False)
                    self.ui.chb_encoder.setChecked(False)
                    return

                if _integrator.configure_encoder_reading(encoder_res):
                    self.stop_encoder_update = False
                    self.timer.start(self._update_encoder_interval*1000)
                    self.ui.lcd_encoder.setEnabled(True)
                else:
                    msg = _QCoreApplication.translate(
                        '', 'Failed to configure encoder reading.')
                    title = _QCoreApplication.translate('', 'Failure')
                    _QMessageBox.critical(
                        self, title, msg, _QMessageBox.Ok)
                    self.stop_encoder_update = True
                    self.ui.lcd_encoder.setEnabled(False)
                    self.ui.chb_encoder.setChecked(False)
            else:
                self.ui.lcd_encoder.setEnabled(False)
                self.stop_encoder_update = True
                self.timer.stop()

        except Exception:
            _traceback.print_exc(file=_sys.stdout)
            self.ui.lcd_encoder.setEnabled(False)
            self.stop_encoder_update = True
            self.timer.stop()
Exemplo n.º 4
0
 def retranslateUi(self, Form):
     Form.setWindowTitle(QCoreApplication.translate("Form", u"About", None))
     self.textBrowser.setHtml(
         QCoreApplication.translate(
             "Form",
             u"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
             "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
             "p, li { white-space: pre-wrap; }\n"
             "</style></head><body style=\" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;\">\n"
             "<p align=\"center\" style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:16pt;\">Brightness Controller v2.3.4</span></p>\n"
             "<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt; font-weight:600;\">Author: </span><span style=\" font-family:'Sans'; font-size:9pt;\">Amit Seal Ami, </span></p>\n"
             "<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-s"
             "ize:9pt;\">Bangladesh,</span></p>\n"
             "<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">[email protected]</span></p>\n"
             "<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt; font-weight:600;\">Contributors</span></p>\n"
             "<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">Significant contributors are listed alphabetically.</span></p>\n"
             "<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">- Archisman Panigrahi</span></p>\n"
             "<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:"
             "0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">- Jahan Addison</span></p>\n"
             "<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">- Zlatan Vasovi\u0107</span></p>\n"
             "<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt; font-weight:600;\">Special thanks to:</span></p>\n"
             "<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">- 2to3 tool for porting to Python 3</span></p>\n"
             "<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">- Numerous Stack Overflow users</span></p>\n"
             "<p style=\" margin-top:12px; margi"
             "n-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">For full list of authors and details, please check </span><a href=\"https://github.com/lordamit/Brightness\"><span style=\" font-family:'Noto Sans'; font-size:10pt; text-decoration: underline; color:#3484e2;\">https://github.com/lordamit/Brightness</span></a></p></body></html>",
             None))
Exemplo n.º 5
0
 def retranslateUi(self, Form):
     Form.setWindowTitle(QCoreApplication.translate("Form", u"Help", None))
     self.textBrowser.setHtml(
         QCoreApplication.translate(
             "Form",
             u"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
             "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
             "p, li { white-space: pre-wrap; }\n"
             "</style></head><body style=\" font-family:'Padauk'; font-size:12pt; font-weight:400; font-style:normal;\">\n"
             "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">Using Brightness Controller is easy. Most of the parts are self explanatory. Only the advanced parts are discussed here.</span></p>\n"
             "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans'; font-size:9pt;\"><br /></p>\n"
             "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt; font-weight:600"
             ";\">Reverse Control</span></p>\n"
             "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">Check it only when your primary display is being detected as secondary display. This reverses the control of your monitor. Only available when multiple displays are connected.</span></p>\n"
             "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans'; font-size:9pt;\"><br /></p>\n"
             "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt; font-weight:600;\">Color Temperature</span></p>\n"
             "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">Assigns color temperature, also kn"
             "own as color tones to display.</span></p>\n"
             "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans'; font-size:9pt;\"><br /></p>\n"
             "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt; font-weight:600;\">Save Settings</span></p>\n"
             "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">Saves your current color configurations.</span></p>\n"
             "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans'; font-size:9pt;\"><br /></p>\n"
             "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" fon"
             "t-family:'Sans'; font-size:9pt; font-weight:600;\">Save Settings As Default</span></p>\n"
             "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">Saves your current color configurations as the default that will load on each start of the application</span></p>\n"
             "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans'; font-size:9pt;\"><br /></p>\n"
             "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt; font-weight:600;\">Load Settings</span></p>\n"
             "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Sans'; font-size:9pt;\">Loads your saved color configuration.</span></p></body>"
             "</html>", None))
Exemplo n.º 6
0
def translation_context(name, category=u'core'):

	"""
	desc:
		A factory that generates a translation method with a fixed context.

	arguments:
		name:
			desc:	The name to use for the context.
			type:	str

	keywords:
		name:
			desc:	The category to use for the context.
			type:	str

	returns:
		desc:	A translation function.
		type:	FunctionType
	"""

	_context = u'%s_%s' % (category, name)
	if os.environ[u'QT_API'] == u'pyqt5':
		# PyQt5 3 doesn't require an encoding
		return lambda s, context=None: QCoreApplication.translate(_context,
			s)
	return lambda s, context=None: QCoreApplication.translate(_context, s,
		encoding=QCoreApplication.UnicodeUTF8)
    def save_to_file(self):
        """Save table values to file."""
        df = _utils.table_to_data_frame(self.tbl_table)
        if df is None:
            msg = _QCoreApplication.translate('', 'Empty table.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
            return

        filename = _QFileDialog.getSaveFileName(
            self,
            caption='Save measurements file.',
            directory=self.directory,
            filter="Text files (*.txt *.dat)")

        if isinstance(filename, tuple):
            filename = filename[0]

        if len(filename) == 0:
            return

        try:
            if (not filename.endswith('.txt')
                    and not filename.endswith('.dat')):
                filename = filename + '.txt'
            df.to_csv(filename, sep='\t')

        except Exception:
            _traceback.print_exc(file=_sys.stdout)
            msg = _QCoreApplication.translate('',
                                              'Failed to save data to file.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
    def edit_comment(self):
        try:
            table_name = self.twg_database.get_current_table_name()
            if table_name is None:
                return

            idn = self.twg_database.get_table_selected_id(table_name)
            if idn is None:
                return

            object_class = self._table_object_dict[table_name]
            obj = object_class(
                database_name=self.database_name,
                mongo=self.mongo, server=self.server)
            obj.db_read(idn)
            prev_comments = obj.comments

            title = _QCoreApplication.translate('', 'Edit Comments')
            label = _QCoreApplication.translate('', 'Comments:')
            new_comments, resp = _QInputDialog.getText(
                self, title, label, text=prev_comments)

            if not resp:
                return

            obj.comments = new_comments
            obj.db_update(idn)

            self.update_database_tables()

        except Exception:
            _traceback.print_exc(file=_sys.stdout)
Exemplo n.º 9
0
    def check_advanced_options(self):
        if not self.advanced_options.valid_data():
            msg = _QCoreApplication.translate(
                '', 'Invalid advanced options.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
            return False

        return True
Exemplo n.º 10
0
    def homing(self):
        self.stop = False

        try:
            if not self.check_driver_connection():
                return

            if not self.check_integrator_connection():
                return

            wait = 0.1

            driver_address = self.advanced_options.motor_driver_address
            resolution = self.advanced_options.motor_resolution
            rotation_direction = self.advanced_options.motor_rotation_direction
            velocity = self.advanced_options.motor_velocity
            acceleration = self.advanced_options.motor_acceleration

            mode = 0
            steps = int(int(resolution))

            if not _driver.config_motor(
                    driver_address,
                    mode,
                    rotation_direction,
                    resolution,
                    velocity,
                    acceleration,
                    steps):
                msg = _QCoreApplication.translate(
                    '', 'Failed to send configuration to motor.')
                title = _QCoreApplication.translate('', 'Failure')
                _QMessageBox.critical(
                    self, title, msg, _QMessageBox.Ok)
                return

            encoder_dir = self.advanced_options.integrator_encoder_direction

            _integrator.configure_homing(encoder_dir)
            _time.sleep(wait)

            if self.stop:
                return

            _driver.move_motor(driver_address)
            _time.sleep(wait)
            while not _driver.ready(driver_address) and not self.stop:
                _time.sleep(wait)
                _QApplication.processEvents()

        except Exception:
            _traceback.print_exc(file=_sys.stdout)
            msg = _QCoreApplication.translate('', 'Homing failed.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
            return
 def __init__(self, parent=None):
     super().__init__(parent=parent)
     self.main_widget = AdvancedOptionsWidget(parent=parent)
     self.main_layout = _QHBoxLayout()
     self.main_layout.addWidget(self.main_widget)
     self.setLayout(self.main_layout)
     self.setWindowTitle(_QCoreApplication.translate(
         '', "Advanced Options"))
     self.setWhatsThis(
         _QCoreApplication.translate(
             '', 'Advanced devices and measurement options.'))
Exemplo n.º 12
0
 def on_goto_cell(self):
     if isinstance(self.table_view.model, (TableModelForPandasDataframe, TableModelForNumpyArray)):
         min_row, max_row = 1, self.table_view.model.rowCount(None)
         current_row = self.table_view.currentIndex().row() + 1
         current_col = self.table_view.currentIndex().column() + 1
         row, _ = QInputDialog.getInt(self, QCoreApplication.translate('PMGTableViewer','Input Row'),
                                      QCoreApplication.translate('PMGTableViewer','Target Row No.:({min}~{max})').format(min=min_row, max=max_row),
                                      current_row,
                                      min_row, max_row, step=1)
         if _:
             self.table_view.on_goto_index(row - 1, 0)
     else:
         raise NotImplementedError
Exemplo n.º 13
0
    def move_motor(self):
        self.stop = False

        try:
            if not self.check_driver_connection():
                return

            driver_address = self.advanced_options.motor_driver_address
            resolution = self.advanced_options.motor_resolution
            rotation_direction = self.advanced_options.motor_rotation_direction
            velocity = self.advanced_options.motor_velocity
            acceleration = self.advanced_options.motor_acceleration
            mode = 0

            if self.ui.rbt_nr_steps.isChecked():
                steps = self.ui.sb_nr_steps.value()
            elif self.ui.rbt_encoder_position.isChecked():
                encoder_position = self.ui.sb_encoder_position.value()
                steps = self.get_steps_for_encoder_position(encoder_position)
                if steps is None:
                    return
            else:
                steps = int(int(resolution)*self.ui.sbd_nr_turns.value())

            if not _driver.config_motor(
                    driver_address,
                    mode,
                    rotation_direction,
                    resolution,
                    velocity,
                    acceleration,
                    steps):

                msg = _QCoreApplication.translate(
                    '', 'Failed to send configuration to motor.')
                title = _QCoreApplication.translate('', 'Failure')
                _QMessageBox.critical(
                    self, title, msg, _QMessageBox.Ok)
                return

            if not self.stop:
                _driver.move_motor(driver_address)

        except Exception:
            _traceback.print_exc(file=_sys.stdout)
            msg = _QCoreApplication.translate(
                '', 'Failed to move motor.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
            return
Exemplo n.º 14
0
    def stop_motor(self):
        self.stop = True

        try:
            driver_address = self.advanced_options.motor_driver_address
            _driver.stop_motor(driver_address)

        except Exception:
            _traceback.print_exc(file=_sys.stdout)
            msg = _QCoreApplication.translate(
                '', 'Failed to stop motor.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
            return
    def show(self, trigger_list, mx_list_1, mx_list_2):
        try:
            self.trigger_list = trigger_list
            self.mx_list_1 = mx_list_1
            self.mx_list_2 = mx_list_2
            self.config_and_plot_mag()
            self.calc_and_plot_fit()
            super().show()

        except Exception:
            _traceback.print_exc(file=_sys.stdout)
            msg = _QCoreApplication.translate(
                '', 'Failed to show trigger dialog.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
Exemplo n.º 16
0
    def on_change_row_col(self, operation: int):
        """
        The slot for editting row or columns
        Args:
            operation:

        Returns:

        """
        import pandas as pd
        import numpy as np
        pd_data: pd.DataFrame = self.model._data
        current_index = self.currentIndex()
        row, column = current_index.row(), current_index.column()
        if operation == self.INSERT_ROW:
            prev = pd_data.iloc[:row]
            lat = pd_data.iloc[row:]
            self.model._data = pd.concat([prev, pd.DataFrame([[]]), lat])
        elif operation == self.DELETE_ROW:
            self.model._data = pd_data.drop(index=[row], axis=1)
        elif operation == self.INSERT_COLUMN:
            col_name, _ = QInputDialog.getText(self, QCoreApplication.translate('PMTableView','Input Column Title'), QCoreApplication.translate('PMTableView','Title'))
            if _:
                pd_data.insert(column, col_name, np.nan)
        elif operation == self.DELETE_COLUMN:
            self.model._data = pd_data.drop(columns=[column], axis=0)
        else:
            raise NotImplementedError
        self.model.layoutChanged.emit()
        self.signal_need_save.emit(True)
Exemplo n.º 17
0
    def update_block_name(self):
        title = _QCoreApplication.translate(
            '', 'Information')
        label = _QCoreApplication.translate(
            '', 'Block Name:')
        text = _QInputDialog.getText(
            self, title, label, text=self.ui.le_block_name.text())

        if isinstance(text, tuple):
            if not text[1]:
                return False

            text = text[0]

        self.ui.le_block_name.setText(text)
        return True
Exemplo n.º 18
0
    def show_edit_dialog(self, row, col):
        import pandas as pd
        data = self.model._data
        if isinstance(data, pd.DataFrame):
            def on_edited(text):
                from pandas import Timestamp, Period, Interval
                try:
                    result = eval(text)
                    data.iloc[row, col] = result
                    self.signal_need_save.emit(True)
                except:
                    import traceback
                    QMessageBox.warning(self, QCoreApplication.translate('PMTableView','Warning'),
                                        traceback.format_exc())
                    return

            def on_move_current_cell(direction: int):
                target_row = row + direction
                if 0 <= target_row < self.model.rowCount(col):
                    self.setCurrentIndex(self.model.index(target_row, col))
                    self.show_edit_dialog(target_row, col)

            original_data = data.iloc[row, col]

            dlg = InputValueDialog(self)
            dlg.setWindowTitle(QCoreApplication.translate('PMTableView','Input New Value'))
            dlg.edit.setText(repr(original_data))
            dlg.signal_edit_finished.connect(on_edited)
            dlg.signal_move_cursor.connect(on_move_current_cell)
            global_pos = self.mapToGlobal(
                QPoint(self.columnViewportPosition(col) + 50, self.rowViewportPosition(row) + 50))
            dlg.setGeometry(global_pos.x(), global_pos.y(), dlg.width(), dlg.height())
            dlg.exec_()
    def clear_button_clicked(self):
        """Clear all values."""
        if len(self._xvalues) == 0:
            return

        msg = _QCoreApplication.translate('', 'Clear table data?')
        title = _QCoreApplication.translate('', 'Question')
        reply = _QMessageBox.question(self,
                                      title,
                                      msg,
                                      buttons=_QMessageBox.No
                                      | _QMessageBox.Yes,
                                      defaultButton=_QMessageBox.No)

        if reply == _QMessageBox.Yes:
            self.clear()
    def save_db(self, force=False):
        """Save parameters to database."""
        current_text = self.ui.cmb_idn.currentText()
        self.ui.cmb_idn.setCurrentIndex(-1)

        try:
            if self.update_configuration():

                if self.database_name is None:
                    msg = _QCoreApplication.translate(
                        '', 'Invalid database filename.')
                    title = _QCoreApplication.translate('', 'Failure')
                    _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
                    return False

                self.config.db_update_database(self.database_name,
                                               mongo=self.mongo,
                                               server=self.server)

                selected_config = self.config.copy()
                selected_config.clear()

                if len(current_text) != 0:
                    selected_idn = int(current_text)
                    selected_config.db_read(selected_idn)

                if self.config == selected_config and not force:
                    idn = selected_idn
                    self.config.idn = idn
                else:
                    idn = self.config.db_save()

                self.ui.cmb_idn.addItem(str(idn))
                self.ui.cmb_idn.setCurrentIndex(self.ui.cmb_idn.count() - 1)
                self.ui.pbt_load_db.setEnabled(False)
                return True

            else:
                return False

        except Exception:
            _traceback.print_exc(file=_sys.stdout)
            msg = _QCoreApplication.translate('',
                                              'Failed to save to database.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
            return False
Exemplo n.º 21
0
    def disconnect_devices(self, msgbox=True):
        """Disconnect bench devices."""
        try:
            _display.disconnect()
            _driver.disconnect()
            _multimeter.disconnect()
            _integrator.disconnect()
            _balance.disconnect()
            self.update_led_status()

        except Exception:
            _traceback.print_exc(file=_sys.stdout)
            if msgbox:
                msg = _QCoreApplication.translate(
                    '', 'Failed to disconnect devices.')
                title = _QCoreApplication.translate('', 'Failure')
                _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
Exemplo n.º 22
0
 def __init__(self, data=None):
     super().__init__()
     self.translator = create_translator(
         path=os.path.join(os.path.dirname(__file__), 'translations',
                           'qt_{0}.qm'.format(QLocale.system().name())))  # translator
     self.data = None
     self.menu = QMenu()
     self.action_insert_row = self.menu.addAction(QCoreApplication.translate('PMTableView','Insert Row'))
     self.action_insert_row.triggered.connect(lambda: self.on_change_row_col(self.INSERT_ROW))
     self.action_delete_row = self.menu.addAction(QCoreApplication.translate('PMTableView','Delete Row'))
     self.action_delete_row.triggered.connect(lambda: self.on_change_row_col(self.DELETE_ROW))
     self.action_insert_col = self.menu.addAction(QCoreApplication.translate('PMTableView','Insert Column'))
     self.action_insert_col.triggered.connect(lambda: self.on_change_row_col(self.INSERT_COLUMN))
     self.action_delete_col = self.menu.addAction(QCoreApplication.translate('PMTableView','Delete Column'))
     self.action_delete_col.triggered.connect(lambda: self.on_change_row_col(self.DELETE_COLUMN))
     # self.menu.addAction("aaaaaa")
     if data is not None:
         self.set_data(data)
Exemplo n.º 23
0
    def configure_integrator(self, gain):
        try:
            return _integrator.configure_measurement(
                self.advanced_options.integrator_channel,
                self.advanced_options.integrator_encoder_resolution,
                self.advanced_options.integrator_encoder_direction,
                self.advanced_options.integration_trigger,
                self.advanced_options.integration_points,
                self.advanced_options.integration_nr_turns,
                gain)

        except Exception:
            msg = _QCoreApplication.translate(
                '', 'Failed to configure integrator.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
            _traceback.print_exc(file=_sys.stdout)
            return False
    def load(self):
        """Load configuration to graphic interface."""
        try:
            for name in self.sb_names:
                sb = getattr(self.ui, 'sb_' + name)
                value = getattr(self.config, name)
                sb.setValue(value)

            for name in self.sbd_names:
                sbd = getattr(self.ui, 'sbd_' + name)
                value = getattr(self.config, name)
                sbd.setValue(value)

            for name in self.cmb_names:
                cmb = getattr(self.ui, 'cmb_' + name)
                value = getattr(self.config, name)
                cmb.setCurrentIndex(cmb.findText(str(value)))

            for name in self.le_names:
                le = getattr(self.ui, 'le_' + name)
                value = getattr(self.config, name)
                if value is None:
                    value = ''
                le.setText(str(value))

            for name in self.te_names:
                te = getattr(self.ui, 'te_' + name)
                value = getattr(self.config, name)
                if value is None:
                    value = ''
                te.setText(str(value))

            for name in self.chb_names:
                chb = getattr(self.ui, 'chb_' + name)
                value = getattr(self.config, name)
                chb.setChecked(value)

        except Exception:
            _traceback.print_exc(file=_sys.stdout)
            msg = _QCoreApplication.translate('',
                                              'Failed to load configuration.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
    def update_configuration(self, clear=True):
        """Update configuration parameters."""
        try:
            if clear:
                self.config.clear()

            for name in self.sb_names:
                sb = getattr(self.ui, 'sb_' + name)
                setattr(self.config, name, sb.value())

            for name in self.sbd_names:
                sbd = getattr(self.ui, 'sbd_' + name)
                setattr(self.config, name, sbd.value())

            for name in self.cmb_names:
                cmb = getattr(self.ui, 'cmb_' + name)
                setattr(self.config, name, cmb.currentText())

            for name in self.le_names:
                le = getattr(self.ui, 'le_' + name)
                setattr(self.config, name, le.text().strip())

            for name in self.te_names:
                te = getattr(self.ui, 'te_' + name)
                setattr(self.config, name, te.toPlainText().strip())

            for name in self.chb_names:
                chb = getattr(self.ui, 'chb_' + name)
                setattr(self.config, name, chb.isChecked())

            if self.config.valid_data():
                return True

            else:
                msg = _QCoreApplication.translate('', 'Invalid configuration.')
                title = _QCoreApplication.translate('', 'Failure')
                _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
                return False

        except Exception:
            _traceback.print_exc(file=_sys.stdout)
            self.config.clear()
            return False
Exemplo n.º 26
0
 def on_edited(text):
     from pandas import Timestamp, Period, Interval
     try:
         result = eval(text)
         data.iloc[row, col] = result
         self.signal_need_save.emit(True)
     except:
         import traceback
         QMessageBox.warning(self, QCoreApplication.translate('PMTableView','Warning'),
                             traceback.format_exc())
         return
Exemplo n.º 27
0
 def check_connection(self, monitor=False):
     """Check devices connection."""
     if not _multimeter.connected:
         if not monitor:
             _QMessageBox.critical(
                 self, 'Failure',
                 _QCoreApplication.translate('',
                                             'Multimeter not connected.'),
                 _QMessageBox.Ok)
         return False
     return True
Exemplo n.º 28
0
    def stop_measurement(self, silent=False):
        try:
            self.stop = True
            self.ui.pbt_start_measurement.setEnabled(True)
            _driver.stop_motor(
                self.advanced_options.motor_driver_address)
            if not silent:
                msg = _QCoreApplication.translate(
                    '', 'The user stopped the measurements.')
                title = _QCoreApplication.translate('', 'Abort')
                _QMessageBox.information(
                    self, title, msg, _QMessageBox.Ok)

        except Exception:
            self.stop = True
            _traceback.print_exc(file=_sys.stdout)
            msg = _QCoreApplication.translate(
                '', 'Failed to stop measurements.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
Exemplo n.º 29
0
    def move_half_turn(self):
        try:
            if self.stop:
                return False

            wait = 0.5

            motor_resolution = self.advanced_options.motor_resolution
            driver_address = self.advanced_options.motor_driver_address
            steps = int(int(motor_resolution)*0.5)

            _driver.stop_motor(driver_address)
            _time.sleep(wait)

            if not self.configure_driver(steps):
                return False

            if self.stop:
                return False

            _driver.move_motor(driver_address)
            _time.sleep(wait)

            while not _driver.ready(driver_address) and not self.stop:
                _time.sleep(wait)
                _QApplication.processEvents()

            _time.sleep(wait)

            if self.stop:
                return False

            return True

        except Exception:
            msg = _QCoreApplication.translate(
                '', 'Failed to move motor to initial position.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
            _traceback.print_exc(file=_sys.stdout)
            return False
Exemplo n.º 30
0
 def __init__(self, parent=None):
     """Set up the ui."""
     super().__init__(parent)
     self.setWindowTitle(_QCoreApplication.translate('', "Log"))
     self.resize(1000, 460)
     self.setFont(_font)
     self.te_text = _QTextEdit()
     self.te_text.setReadOnly(True)
     self.te_text.setVerticalScrollBarPolicy(_Qt.ScrollBarAlwaysOn)
     main_layout = _QHBoxLayout()
     main_layout.addWidget(self.te_text)
     self.setLayout(main_layout)
Exemplo n.º 31
0
	%--include: example.py--%
	~~~

license: |
	`QProgEdit` is released under the terms of the
	[General Public License v3](http://www.gnu.org/licenses/gpl-3.0.txt).
---
"""

version = __version__ = u'4.0.7'

from QProgEdit.py3compat import *

# A simple wrapper around the translate function
from qtpy.QtCore import QCoreApplication
_ = lambda s: QCoreApplication.translate(u'qprogedit', s)

import QProgEdit._qeditorconst as QEditorConst
import QProgEdit._qcolorscheme as QColorScheme
from QProgEdit._quiloader import QUiLoader
from QProgEdit._qsymboltreewidgetitem import QSymbolTreeWidgetItem
from QProgEdit._qeditorcfg import QEditorCfg
from QProgEdit._qeditorshortcut import QEditorShortcut
from QProgEdit._qlexer import QLexer
from QProgEdit._qlangmenu import QLangMenu
from QProgEdit._qeditor import QEditor
from QProgEdit._qeditorprefs import QEditorPrefs
from QProgEdit._qeditorfind import QEditorFind
from QProgEdit._qeditorstatus import QEditorStatus
from QProgEdit._qprogedit import QProgEdit
from QProgEdit._qtabcornerwidget import QTabCornerWidget