Exemplo n.º 1
0
    def save_report_to_csv_file(self):
        date = datetime.now().replace(microsecond=0).isoformat().replace(
            'T', '_').replace(':', '-')
        filename = get_save_file_name(
            self, 'Save Report To CSV File',
            os.path.join(get_home_path(),
                         'brickv_health_report_{0}.csv'.format(date)))

        if len(filename) == 0:
            return

        c = 0
        header = []

        while True:
            item = self.tree_view_model.horizontalHeaderItem(c)

            if item == None:
                break

            header.append(item.text())

            c += 1

        rows = [header] + self.collect_metric_values()

        try:
            with open(filename, 'w', newline='') as f:
                csv.writer(f).writerows(rows)
        except Exception as e:
            QMessageBox.critical(
                self, 'Save Report To CSV File',
                'Could not save report to CSV file:\n\n' + str(e),
                QMessageBox.Ok)
Exemplo n.º 2
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletCAN, *args)

        self.setupUi(self)

        self.can = self.device

        self.qtcb_frame_read.connect(self.cb_frame_read)
        self.can.register_callback(self.can.CALLBACK_FRAME_READ,
                                   self.qtcb_frame_read.emit)

        self.last_filename = os.path.join(get_home_path(), 'can_bricklet_history.log')

        self.filter_mask = 0
        self.filter1 = 0
        self.filter2 = 0

        self.frame_read_callback_was_enabled = None

        self.tree_frames.header().resizeSection(0, 150)
        self.tree_frames.header().resizeSection(1, 135)
        self.tree_frames.header().resizeSection(2, 135)
        self.tree_frames.header().resizeSection(3, 300)
        self.tree_frames.header().resizeSection(4, 100)

        self.edit_data.setValidator(HexValidator(max_bytes=8))

        self.combo_frame_type.currentIndexChanged.connect(self.frame_type_changed)
        self.combo_baud_rate.currentIndexChanged.connect(self.configuration_changed)
        self.combo_transceiver_mode.currentIndexChanged.connect(self.configuration_changed)
        self.spin_write_timeout.valueChanged.connect(self.configuration_changed)

        self.combo_filter_mode.currentIndexChanged.connect(self.filter_mode_changed)
        self.spin_filter_mask_extended.valueChanged.connect(self.mask_or_filter_changed)
        self.spin_filter_mask_standard.valueChanged.connect(self.mask_or_filter_changed)
        self.spin_filter_mask_data1.valueChanged.connect(self.mask_or_filter_changed)
        self.spin_filter_mask_data2.valueChanged.connect(self.mask_or_filter_changed)
        self.spin_filter1_extended.valueChanged.connect(self.mask_or_filter_changed)
        self.spin_filter1_standard.valueChanged.connect(self.mask_or_filter_changed)
        self.spin_filter1_data1.valueChanged.connect(self.mask_or_filter_changed)
        self.spin_filter1_data2.valueChanged.connect(self.mask_or_filter_changed)
        self.spin_filter2_extended.valueChanged.connect(self.mask_or_filter_changed)
        self.spin_filter2_standard.valueChanged.connect(self.mask_or_filter_changed)
        self.spin_filter2_data1.valueChanged.connect(self.mask_or_filter_changed)
        self.spin_filter2_data2.valueChanged.connect(self.mask_or_filter_changed)

        self.button_write_frame.clicked.connect(self.write_frame)
        self.button_clear_history.clicked.connect(self.tree_frames.clear)
        self.button_save_history.clicked.connect(self.save_history)
        self.button_save_configuration.clicked.connect(self.save_configuration)
        self.button_save_read_filter.clicked.connect(self.save_read_filter)

        self.error_log_timer = QTimer(self)
        self.error_log_timer.timeout.connect(self.update_error_log)
        self.error_log_timer.setInterval(1000)

        self.frame_type_changed()
        self.filter_mode_changed()
Exemplo n.º 3
0
    def private_key_browse_clicked(self):
        if len(self.wifi_private_key_url.text()) > 0:
            last_dir = os.path.dirname(os.path.realpath(self.wifi_private_key_url.text()))
        else:
            last_dir = get_home_path()

        filename = get_open_file_name(get_main_window(), 'Open Private Key', last_dir)

        if len(filename) > 0:
            self.wifi_private_key_url.setText(filename)
Exemplo n.º 4
0
    def sample_file_clicked(self):
        if len(self.sample_edit.text()) > 0:
            last_dir = os.path.dirname(os.path.realpath(self.sample_edit.text()))
        else:
            last_dir = get_home_path()

        filename = get_open_file_name(get_main_window(), "Open Sample Points", last_dir)

        if len(filename) > 0:
            self.sample_edit.setText(filename)
Exemplo n.º 5
0
    def sample_file_clicked(self):
        if len(self.sample_edit.text()) > 0:
            last_dir = os.path.dirname(os.path.realpath(self.sample_edit.text()))
        else:
            last_dir = get_home_path()

        filename = get_open_file_name(get_main_window(), "Open Sample Points", last_dir)

        if len(filename) > 0:
            self.sample_edit.setText(filename)
Exemplo n.º 6
0
    def firmware_browse_clicked(self):
        if len(self.edit_custom_firmware.text()) > 0:
            last_dir = os.path.dirname(os.path.realpath(self.edit_custom_firmware.text()))
        else:
            last_dir = get_home_path()

        filename = get_open_file_name(get_main_window(), 'Open Firmware', last_dir, '*.bin')

        if len(filename) > 0:
            self.edit_custom_firmware.setText(filename)
Exemplo n.º 7
0
    def plugin_browse_clicked(self):
        last_dir = get_home_path()

        if len(self.edit_custom_plugin.text()) > 0:
            last_dir = os.path.dirname(os.path.realpath(self.edit_custom_plugin.text()))

        filename = get_open_file_name(get_main_window(), 'Open Plugin', last_dir, '*.bin')

        if len(filename) > 0:
            self.edit_custom_plugin.setText(filename)
Exemplo n.º 8
0
    def client_certificate_browse_clicked(self):
        if len(self.wifi_client_certificate_url.text()) > 0:
            last_dir = os.path.dirname(os.path.realpath(self.wifi_client_certificate_url.text()))
        else:
            last_dir = get_home_path()

        filename = get_open_file_name(get_main_window(), 'Open Client Certificate', last_dir)

        if len(filename) > 0:
            self.wifi_client_certificate_url.setText(filename)
    def browse_archive(self):
        if len(self.edit_archive.text()) > 0:
            last_directory = os.path.dirname(os.path.realpath(self.edit_archive.text()))
        else:
            last_directory = get_home_path()

        filename = get_open_file_name(get_main_window(), 'Open Archive', last_directory, '*.tfrba')

        if len(filename) > 0:
            self.edit_archive.setText(filename)
            self.refresh_program_list()
Exemplo n.º 10
0
    def browse_archive(self):
        if len(self.edit_archive.text()) > 0:
            last_directory = os.path.dirname(os.path.realpath(self.edit_archive.text()))
        else:
            last_directory = get_home_path()

        filename = get_open_file_name(get_main_window(), 'Open Archive', last_directory, '*.tfrba')

        if len(filename) > 0:
            self.edit_archive.setText(filename)
            self.refresh_program_list()
Exemplo n.º 11
0
    def btn_browse_csv_file_name_clicked(self):
        if len(self.edit_csv_file_name.text()) > 0:
            last_dir = os.path.dirname(os.path.realpath(self.edit_csv_file_name.text()))
        else:
            last_dir = get_home_path()

        filename = get_save_file_name(self, 'Choose CSV File',
                                      last_dir, "CSV Files (*.csv)")

        if len(filename) > 0:
            if not filename.lower().endswith('.csv'):
                filename += '.csv'

            self.edit_csv_file_name.setText(filename)
Exemplo n.º 12
0
    def btn_browse_log_file_name_clicked(self):
        if len(self.edit_log_file_name.text()) > 0:
            last_dir = os.path.dirname(os.path.realpath(self.edit_log_file_name.text()))
        else:
            last_dir = get_home_path()

        filename = get_save_file_name(get_main_window(), 'Choose Log File',
                                      last_dir, "Log Files (*.log)")

        if len(filename) > 0:
            if not filename.lower().endswith('.log'):
                filename += '.log'

            self.edit_log_file_name.setText(filename)
Exemplo n.º 13
0
    def btn_browse_csv_file_name_clicked(self):
        if len(self.edit_csv_file_name.text()) > 0:
            last_dir = os.path.dirname(os.path.realpath(self.edit_csv_file_name.text()))
        else:
            last_dir = get_home_path()

        filename = get_save_file_name(get_main_window(), 'Choose CSV File',
                                      last_dir, "CSV Files (*.csv)")

        if len(filename) > 0:
            if not filename.lower().endswith('.csv'):
                filename += '.csv'

            self.edit_csv_file_name.setText(filename)
Exemplo n.º 14
0
    def btn_browse_log_file_name_clicked(self):
        if len(self.edit_log_file_name.text()) > 0:
            last_dir = os.path.dirname(os.path.realpath(self.edit_log_file_name.text()))
        else:
            last_dir = get_home_path()

        filename = get_save_file_name(self, 'Choose Log File',
                                      last_dir, "Log Files (*.log)")

        if len(filename) > 0:
            if not filename.lower().endswith('.log'):
                filename += '.log'

            self.edit_log_file_name.setText(filename)
    def __init__(self, display_name, source_name):
        self.display_name   = display_name
        self.source_name    = source_name # FIXME: need to handle rotated logs
        self.last_filename  = os.path.join(get_home_path(), display_name)
        self.content        = ''
        self.edit           = QPlainTextEdit()
        self.normal_font    = self.edit.font()
        self.monospace_font = QFont('monospace')

        self.edit.setUndoRedoEnabled(False)
        self.edit.setReadOnly(True)
        self.edit.setWordWrapMode(QTextOption.NoWrap)
        self.edit.setPlainText('Click "Refresh" to download {0}.'.format(display_name))

        self.monospace_font.setStyleHint(QFont.TypeWriter)
    def __init__(self, display_name, source_name):
        self.display_name   = display_name
        self.source_name    = source_name # FIXME: need to handle rotated logs
        self.last_filename  = os.path.join(get_home_path(), display_name)
        self.content        = ''
        self.edit           = QPlainTextEdit()
        self.normal_font    = self.edit.font()
        self.monospace_font = QFont('monospace')

        self.edit.setUndoRedoEnabled(False)
        self.edit.setReadOnly(True)
        self.edit.setWordWrapMode(QTextOption.NoWrap)
        self.edit.setPlainText('Click "Refresh" to download {0}.'.format(display_name))

        self.monospace_font.setStyleHint(QFont.TypeWriter)
Exemplo n.º 17
0
    def btn_save_config_clicked(self):
        filename = get_save_file_name(get_main_window(), 'Save Config',
                                      get_home_path(), 'JSON Files (*.json)')

        if len(filename) == 0:
            return

        if not filename.lower().endswith('.json'):
            filename += '.json'

        config = GuiConfigHandler.create_config(self)

        if not save_config(config, filename):
            QMessageBox.warning(get_main_window(), 'Save Config',
                                'Could not save config to file! See Debug tab for details.',
                                QMessageBox.Ok)
Exemplo n.º 18
0
    def btn_save_config_clicked(self):
        filename = get_save_file_name(self, 'Save Config',
                                      get_home_path(), 'JSON Files(*.json)')

        if len(filename) == 0:
            return

        if not filename.lower().endswith('.json'):
            filename += '.json'

        config = GuiConfigHandler.create_config(self)

        if not save_config(config, filename):
            QMessageBox.warning(self, 'Save Config',
                                'Could not save config to file! See Debug tab for details.',
                                QMessageBox.Ok)
Exemplo n.º 19
0
    def btn_load_config_clicked(self):
        filename = get_open_file_name(get_main_window(), 'Load Config',
                                      get_home_path(), 'JSON Files (*.json)')

        if len(filename) == 0:
            return

        config = load_and_validate_config(filename)

        if config == None:
            QMessageBox.warning(get_main_window(), 'Load Config',
                                'Could not load config from file! See Debug tab for details.',
                                QMessageBox.Ok)
            return

        self.update_setup_tab(config)
        self.update_devices_tab(config)
Exemplo n.º 20
0
    def btn_load_config_clicked(self):
        filename = get_open_file_name(self, 'Load Config',
                                      get_home_path(), 'JSON Files(*.json);;All Files(*)')

        if len(filename) == 0:
            return

        config = load_and_validate_config(filename)

        if config == None:
            QMessageBox.warning(self, 'Load Config',
                                'Could not load config from file! See Debug tab for details.',
                                QMessageBox.Ok)
            return

        self.update_setup_tab(config)
        self.update_devices_tab(config)
Exemplo n.º 21
0
    def __init__(self, context, update_main_ui_state, set_widget_enabled,
                 is_alive, show_upload_files_wizard, show_download_wizard):
        QWidget.__init__(self)

        self.setupUi(self)

        self.session = context.session
        self.script_manager = context.script_manager
        self.program = context.program
        self.update_main_ui_state = update_main_ui_state
        self.set_widget_enabled = set_widget_enabled
        self.is_alive = is_alive
        self.show_download_wizard = show_download_wizard
        self.bin_directory = posixpath.join(self.program.root_directory, 'bin')
        self.refresh_in_progress = False
        self.any_refresh_in_progress = False  # set from ProgramInfoMain.update_ui_state
        self.available_files = []
        self.available_directories = []
        self.folder_icon = QIcon(load_pixmap('folder-icon.png'))
        self.file_icon = QIcon(load_pixmap('file-icon.png'))
        self.tree_files_model = QStandardItemModel(self)
        self.tree_files_model_header = ['Name', 'Size', 'Last Modified']
        self.tree_files_proxy_model = FilesProxyModel(self)
        self.last_download_directory = get_home_path()

        self.tree_files_model.setHorizontalHeaderLabels(
            self.tree_files_model_header)
        self.tree_files_proxy_model.setSourceModel(self.tree_files_model)
        self.tree_files.setModel(self.tree_files_model)
        self.tree_files.setModel(self.tree_files_proxy_model)
        self.tree_files.setColumnWidth(0, 210)
        self.tree_files.setColumnWidth(1, 85)

        self.tree_files.selectionModel().selectionChanged.connect(
            self.update_ui_state)
        self.tree_files.activated.connect(self.rename_activated_file)
        self.button_upload_files.clicked.connect(show_upload_files_wizard)
        self.button_download_files.clicked.connect(
            self.download_selected_files)
        self.button_rename_file.clicked.connect(self.rename_selected_file)
        self.button_change_file_permissions.clicked.connect(
            self.change_permissions_of_selected_file)
        self.button_delete_files.clicked.connect(self.delete_selected_files)

        self.label_error.setVisible(False)
Exemplo n.º 22
0
    def save():
        date = datetime.datetime.now().replace(
            microsecond=0).isoformat().replace('T', '_').replace(':', '-')
        filename = get_save_file_name(
            window, 'Save Report To File',
            os.path.join(get_home_path(),
                         'brickv_error_report_{}.txt'.format(date)))

        if len(filename) == 0:
            return

        try:
            with open(filename, 'w') as f:
                f.write(error_message)
        except Exception as e:
            QMessageBox.critical(window, 'Save Report To File',
                                 'Could not save report to file:\n\n' + str(e),
                                 QMessageBox.Ok)
Exemplo n.º 23
0
    def __init__(self, title_prefix='', last_directory=None):
        ProgramPage.__init__(self)

        self.setupUi(self)

        self.edit_mode   = False
        self.folder_icon = QIcon(load_pixmap('folder-icon.png'))
        self.file_icon   = QIcon(load_pixmap('file-icon.png'))

        if last_directory != None:
            self.last_directory = last_directory
        else:
            self.last_directory = get_home_path()

        self.setTitle(title_prefix + 'Files')

        self.list_files.itemSelectionChanged.connect(self.update_ui_state)
        self.button_add_files.clicked.connect(self.show_add_files_dialog)
        self.button_add_directory.clicked.connect(self.show_add_directory_dialog)
        self.button_remove_selected_files.clicked.connect(self.remove_selected_files)
    def __init__(self):
        QWidget.__init__(self)

        self.setupUi(self)

        self.session             = None # Set from REDTabImportExport
        self.script_manager      = None # Set from REDTabImportExport
        self.image_version       = None # Set from REDTabImportExport
        self.first_tab_on_focus  = True
        self.refresh_in_progress = False
        self.last_directory      = get_home_path()
        self.progress            = None
        self.chunked_downloader  = None

        self.tree_programs.setColumnWidth(0, 150)
        self.tree_programs.setColumnWidth(1, 150)
        self.tree_programs.itemSelectionChanged.connect(self.update_ui_state)
        self.button_refresh_programs.clicked.connect(self.refresh_program_list)
        self.button_export.clicked.connect(self.export_archive)

        self.update_ui_state()
Exemplo n.º 25
0
    def __init__(self):
        QWidget.__init__(self)

        self.setupUi(self)

        self.session             = None # Set from REDTabImportExport
        self.script_manager      = None # Set from REDTabImportExport
        self.image_version       = None # Set from REDTabImportExport
        self.first_tab_on_focus  = True
        self.refresh_in_progress = False
        self.last_directory      = get_home_path()
        self.progress            = None
        self.chunked_downloader  = None

        self.tree_programs.setColumnWidth(0, 150)
        self.tree_programs.setColumnWidth(1, 150)
        self.tree_programs.itemSelectionChanged.connect(self.update_ui_state)
        self.button_refresh_programs.clicked.connect(self.refresh_program_list)
        self.button_export.clicked.connect(self.export_archive)

        self.update_ui_state()
Exemplo n.º 26
0
    def __init__(self, context, update_main_ui_state, set_widget_enabled, is_alive, show_upload_files_wizard, show_download_wizard):
        QWidget.__init__(self)

        self.setupUi(self)

        self.session                 = context.session
        self.script_manager          = context.script_manager
        self.program                 = context.program
        self.update_main_ui_state    = update_main_ui_state
        self.set_widget_enabled      = set_widget_enabled
        self.is_alive                = is_alive
        self.show_download_wizard    = show_download_wizard
        self.bin_directory           = posixpath.join(self.program.root_directory, 'bin')
        self.refresh_in_progress     = False
        self.any_refresh_in_progress = False # set from ProgramInfoMain.update_ui_state
        self.available_files         = []
        self.available_directories   = []
        self.folder_icon             = QIcon(load_pixmap('folder-icon.png'))
        self.file_icon               = QIcon(load_pixmap('file-icon.png'))
        self.tree_files_model        = QStandardItemModel(self)
        self.tree_files_model_header = ['Name', 'Size', 'Last Modified']
        self.tree_files_proxy_model  = FilesProxyModel(self)
        self.last_download_directory = get_home_path()

        self.tree_files_model.setHorizontalHeaderLabels(self.tree_files_model_header)
        self.tree_files_proxy_model.setSourceModel(self.tree_files_model)
        self.tree_files.setModel(self.tree_files_model)
        self.tree_files.setModel(self.tree_files_proxy_model)
        self.tree_files.setColumnWidth(0, 210)
        self.tree_files.setColumnWidth(1, 85)

        self.tree_files.selectionModel().selectionChanged.connect(self.update_ui_state)
        self.tree_files.activated.connect(self.rename_activated_file)
        self.button_upload_files.clicked.connect(show_upload_files_wizard)
        self.button_download_files.clicked.connect(self.download_selected_files)
        self.button_rename_file.clicked.connect(self.rename_selected_file)
        self.button_change_file_permissions.clicked.connect(self.change_permissions_of_selected_file)
        self.button_delete_files.clicked.connect(self.delete_selected_files)

        self.label_error.setVisible(False)
Exemplo n.º 27
0
    def __init__(self, title_prefix='', last_directory=None):
        ProgramPage.__init__(self)

        self.setupUi(self)

        self.edit_mode = False
        self.folder_icon = QIcon(load_pixmap('folder-icon.png'))
        self.file_icon = QIcon(load_pixmap('file-icon.png'))

        if last_directory != None:
            self.last_directory = last_directory
        else:
            self.last_directory = get_home_path()

        self.setTitle(title_prefix + 'Files')

        self.list_files.itemSelectionChanged.connect(self.update_ui_state)
        self.button_add_files.clicked.connect(self.show_add_files_dialog)
        self.button_add_directory.clicked.connect(
            self.show_add_directory_dialog)
        self.button_remove_selected_files.clicked.connect(
            self.remove_selected_files)
Exemplo n.º 28
0
    def __init__(self, context, update_main_ui_state, set_widget_enabled,
                 is_alive, show_download_wizard,
                 set_program_callbacks_enabled):
        QWidget.__init__(self)

        self.setupUi(self)

        self.session = context.session
        self.script_manager = context.script_manager
        self.program = context.program
        self.update_main_ui_state = update_main_ui_state
        self.set_widget_enabled = set_widget_enabled
        self.is_alive = is_alive
        self.show_download_wizard = show_download_wizard
        self.set_program_callbacks_enabled = set_program_callbacks_enabled
        self.log_directory = posixpath.join(self.program.root_directory, 'log')
        self.refresh_in_progress = False
        self.any_refresh_in_progress = False  # set from ProgramInfoMain.update_ui_state
        self.view_dialog = None
        self.file_icon = QIcon(load_pixmap('file-icon.png'))
        self.tree_logs_model = QStandardItemModel(self)
        self.tree_logs_model_header = ['Date/Time', 'Size']
        self.tree_logs_proxy_model = LogsProxyModel(self)
        self.last_download_directory = get_home_path()

        self.tree_logs_model.setHorizontalHeaderLabels(
            self.tree_logs_model_header)
        self.tree_logs_proxy_model.setSourceModel(self.tree_logs_model)
        self.tree_logs.setModel(self.tree_logs_proxy_model)
        self.tree_logs.setColumnWidth(0, 250)

        self.tree_logs.selectionModel().selectionChanged.connect(
            self.update_ui_state)
        self.tree_logs.activated.connect(self.view_activated_log)
        self.button_download_logs.clicked.connect(self.download_selected_logs)
        self.button_view_log.clicked.connect(self.view_selected_log)
        self.button_delete_logs.clicked.connect(self.delete_selected_logs)

        self.label_error.setVisible(False)
Exemplo n.º 29
0
    def __init__(self, context, update_main_ui_state, set_widget_enabled, is_alive,
                 show_download_wizard, set_program_callbacks_enabled):
        QWidget.__init__(self)

        self.setupUi(self)

        self.session                       = context.session
        self.script_manager                = context.script_manager
        self.program                       = context.program
        self.update_main_ui_state          = update_main_ui_state
        self.set_widget_enabled            = set_widget_enabled
        self.is_alive                      = is_alive
        self.show_download_wizard          = show_download_wizard
        self.set_program_callbacks_enabled = set_program_callbacks_enabled
        self.log_directory                 = posixpath.join(self.program.root_directory, 'log')
        self.refresh_in_progress           = False
        self.any_refresh_in_progress       = False # set from ProgramInfoMain.update_ui_state
        self.view_dialog                   = None
        self.file_icon                     = QIcon(load_pixmap('file-icon.png'))
        self.tree_logs_model               = QStandardItemModel(self)
        self.tree_logs_model_header        = ['Date/Time', 'Size']
        self.tree_logs_proxy_model         = LogsProxyModel(self)
        self.last_download_directory       = get_home_path()

        self.tree_logs_model.setHorizontalHeaderLabels(self.tree_logs_model_header)
        self.tree_logs_proxy_model.setSourceModel(self.tree_logs_model)
        self.tree_logs.setModel(self.tree_logs_proxy_model)
        self.tree_logs.setColumnWidth(0, 250)

        self.tree_logs.selectionModel().selectionChanged.connect(self.update_ui_state)
        self.tree_logs.activated.connect(self.view_activated_log)
        self.button_download_logs.clicked.connect(self.download_selected_logs)
        self.button_view_log.clicked.connect(self.view_selected_log)
        self.button_delete_logs.clicked.connect(self.delete_selected_logs)

        self.label_error.setVisible(False)
Exemplo n.º 30
0
    def __init__(self, parent, session, source_name):
        QDialog.__init__(self, parent)

        self.setupUi(self)
        self.setModal(True)

        self.source_name   = source_name
        self.last_filename = os.path.join(get_home_path(), posixpath.split(source_name)[1])
        self.log_file      = None
        self.content       = None

        source_name_parts = posixpath.split(source_name)[1].split('_')

        if source_name_parts[0] == 'continuous':
            date_time       = 'Continuous ({0})'.format(source_name_parts[1])
            self.continuous = True
        else:
            try:
                timestamp = int(source_name_parts[1].split('+')[0]) / 1000000
            except ValueError:
                timestamp = 0

            date_time       = '{0} ({1})'.format(timestamp_to_date_at_time(timestamp), source_name_parts[2])
            self.continuous = False

        self.rejected.connect(self.abort_download)
        self.progress_download.setRange(0, 0)
        self.label_date_time.setText(date_time)
        self.button_save.clicked.connect(self.save_content)
        self.button_close.clicked.connect(self.reject)

        self.button_save.setEnabled(False)

        def cb_open(dummy):
            def cb_read_status(bytes_read, max_length):
                self.progress_download.setValue(bytes_read)

            def cb_read(result):
                self.log_file.release()
                self.log_file = None

                self.label_download.setVisible(False)
                self.progress_download.setVisible(False)

                if result.error != None:
                    self.log(u'Error: ' + Qt.escape(unicode(result.error)), bold=True)
                    return

                try:
                    self.content = result.data.decode('utf-8')
                except UnicodeDecodeError:
                    # FIXME: maybe add a encoding guesser here or try some common encodings if UTF-8 fails
                    self.log(u'Error: Log file is not UTF-8 encoded', bold=True)
                    return

                self.button_save.setEnabled(True)

                if self.continuous:
                    content = self.content.lstrip()
                else:
                    content = self.content

                self.edit_content.setPlainText('')

                font = QFont('monospace')
                font.setStyleHint(QFont.TypeWriter)

                self.edit_content.setFont(font)
                self.edit_content.setPlainText(content)

            self.progress_download.setRange(0, self.log_file.length)
            self.log_file.read_async(self.log_file.length, cb_read, cb_read_status)

        def cb_open_error():
            self.label_download.setVisible(False)
            self.progress_download.setVisible(False)
            self.log(u'Error: Could not open log file', bold=True)

        self.log_file = REDFile(session)

        async_call(self.log_file.open,
                   (source_name, REDFile.FLAG_READ_ONLY | REDFile.FLAG_NON_BLOCKING, 0, 0, 0),
                   cb_open, cb_open_error)
Exemplo n.º 31
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletCANV2, *args)

        self.setupUi(self)

        self.can = self.device

        self.qtcb_frame_read.connect(self.cb_frame_read)
        self.can.register_callback(self.can.CALLBACK_FRAME_READ,
                                   self.qtcb_frame_read.emit)

        self.last_filename = os.path.join(get_home_path(), 'can_bricklet_v2_history.log')

        self.frame_read_callback_was_enabled = None

        self.tree_frames.header().resizeSection(0, 150)
        self.tree_frames.header().resizeSection(1, 170)
        self.tree_frames.header().resizeSection(2, 300)
        self.tree_frames.header().resizeSection(3, 100)

        self.edit_data.setValidator(HexValidator(max_bytes=8))

        self.combo_frame_type.currentIndexChanged.connect(self.frame_type_changed)
        self.spin_baud_rate.valueChanged.connect(self.transceiver_configuration_changed)
        self.spin_sample_point.valueChanged.connect(self.transceiver_configuration_changed)
        self.combo_transceiver_mode.currentIndexChanged.connect(self.transceiver_configuration_changed)

        self.spin_write_buffer_size.valueChanged.connect(self.queue_configuration_changed)
        self.spin_write_buffer_timeout.valueChanged.connect(self.queue_configuration_changed)
        self.spin_write_backlog_size.valueChanged.connect(self.queue_configuration_changed)
        self.edit_read_buffer_sizes.textEdited.connect(self.queue_configuration_changed)
        self.spin_read_backlog_size.valueChanged.connect(self.queue_configuration_changed)

        for i in range(32):
            self.combo_filter_buffer.addItem(str(i))

        self.combo_filter_buffer.currentIndexChanged.connect(self.read_filter_buffer_changed)
        self.combo_filter_mode.currentIndexChanged.connect(self.read_filter_mode_changed)
        self.spin_filter_mask.valueChanged.connect(self.read_filter_configuration_changed)
        self.spin_filter_identifier.valueChanged.connect(self.read_filter_configuration_changed)

        self.button_write_frame.clicked.connect(self.write_frame)
        self.button_clear_history.clicked.connect(self.tree_frames.clear)
        self.button_save_history.clicked.connect(self.save_history)
        self.button_save_transceiver_configuration.clicked.connect(self.save_transceiver_configuration)
        self.button_reset_transceiver_configuration.clicked.connect(self.reset_transceiver_configuration)
        self.button_save_queue_configuration.clicked.connect(self.save_queue_configuration)
        self.button_reset_queue_configuration.clicked.connect(self.reset_queue_configuration)
        self.button_save_read_filter_configuration.clicked.connect(self.save_read_filter_configuration)
        self.button_reset_read_filter_configuration.clicked.connect(self.reset_read_filter_configuration)

        self.error_log_timer = QTimer(self)
        self.error_log_timer.timeout.connect(self.update_error_log)
        self.error_log_timer.setInterval(1000)

        self.frame_type_changed()
        self.read_filter_buffer_changed()
        self.read_filter_mode_changed()
        self.read_filter_configuration_changed()

        self.com_led_off_action = QAction('Off', self)
        self.com_led_off_action.triggered.connect(lambda: self.can.set_communication_led_config(BrickletCANV2.COMMUNICATION_LED_CONFIG_OFF))
        self.com_led_on_action = QAction('On', self)
        self.com_led_on_action.triggered.connect(lambda: self.can.set_communication_led_config(BrickletCANV2.COMMUNICATION_LED_CONFIG_ON))
        self.com_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.com_led_show_heartbeat_action.triggered.connect(lambda: self.can.set_communication_led_config(BrickletCANV2.COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT))
        self.com_led_show_communication_action = QAction('Show Com', self)
        self.com_led_show_communication_action.triggered.connect(lambda: self.can.set_communication_led_config(BrickletCANV2.COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION))

        self.extra_configs += [(1, 'Com LED:', [self.com_led_off_action,
                                                self.com_led_on_action,
                                                self.com_led_show_heartbeat_action,
                                                self.com_led_show_communication_action])]

        self.error_led_off_action = QAction('Off', self)
        self.error_led_off_action.triggered.connect(lambda: self.can.set_error_led_config(BrickletCANV2.ERROR_LED_CONFIG_OFF))
        self.error_led_on_action = QAction('On', self)
        self.error_led_on_action.triggered.connect(lambda: self.can.set_error_led_config(BrickletCANV2.ERROR_LED_CONFIG_ON))
        self.error_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.error_led_show_heartbeat_action.triggered.connect(lambda: self.can.set_error_led_config(BrickletCANV2.ERROR_LED_CONFIG_SHOW_HEARTBEAT))
        self.error_led_show_transceiver_state_action = QAction('Show Transceiver State', self)
        self.error_led_show_transceiver_state_action.triggered.connect(lambda: self.can.set_error_led_config(BrickletCANV2.ERROR_LED_CONFIG_SHOW_TRANSCEIVER_STATE))
        self.error_led_show_error_action = QAction('Show Error', self)
        self.error_led_show_error_action.triggered.connect(lambda: self.can.set_error_led_config(BrickletCANV2.ERROR_LED_CONFIG_SHOW_ERROR))

        self.extra_configs += [(1, 'Error LED:', [self.error_led_off_action,
                                                  self.error_led_on_action,
                                                  self.error_led_show_heartbeat_action,
                                                  self.error_led_show_transceiver_state_action,
                                                  self.error_led_show_error_action])]
Exemplo n.º 32
0
Arquivo: can.py Projeto: fk0815/brickv
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletCAN, *args)

        self.setupUi(self)

        self.can = self.device

        self.qtcb_frame_read.connect(self.cb_frame_read)
        self.can.register_callback(self.can.CALLBACK_FRAME_READ,
                                   self.qtcb_frame_read.emit)

        self.last_filename = os.path.join(get_home_path(),
                                          'can_bricklet_history.log')

        self.filter_mask = 0
        self.filter1 = 0
        self.filter2 = 0

        self.frame_read_callback_was_enabled = None

        self.tree_frames.header().resizeSection(0, 150)
        self.tree_frames.header().resizeSection(1, 135)
        self.tree_frames.header().resizeSection(2, 135)
        self.tree_frames.header().resizeSection(3, 300)
        self.tree_frames.header().resizeSection(4, 100)

        self.edit_data.setValidator(HexValidator(max_bytes=8))

        self.combo_frame_type.currentIndexChanged.connect(
            self.frame_type_changed)
        self.combo_baud_rate.currentIndexChanged.connect(
            self.configuration_changed)
        self.combo_transceiver_mode.currentIndexChanged.connect(
            self.configuration_changed)
        self.spin_write_timeout.valueChanged.connect(
            self.configuration_changed)

        self.combo_filter_mode.currentIndexChanged.connect(
            self.filter_mode_changed)
        self.spin_filter_mask_extended.valueChanged.connect(
            self.mask_or_filter_changed)
        self.spin_filter_mask_standard.valueChanged.connect(
            self.mask_or_filter_changed)
        self.spin_filter_mask_data1.valueChanged.connect(
            self.mask_or_filter_changed)
        self.spin_filter_mask_data2.valueChanged.connect(
            self.mask_or_filter_changed)
        self.spin_filter1_extended.valueChanged.connect(
            self.mask_or_filter_changed)
        self.spin_filter1_standard.valueChanged.connect(
            self.mask_or_filter_changed)
        self.spin_filter1_data1.valueChanged.connect(
            self.mask_or_filter_changed)
        self.spin_filter1_data2.valueChanged.connect(
            self.mask_or_filter_changed)
        self.spin_filter2_extended.valueChanged.connect(
            self.mask_or_filter_changed)
        self.spin_filter2_standard.valueChanged.connect(
            self.mask_or_filter_changed)
        self.spin_filter2_data1.valueChanged.connect(
            self.mask_or_filter_changed)
        self.spin_filter2_data2.valueChanged.connect(
            self.mask_or_filter_changed)

        self.button_write_frame.clicked.connect(self.write_frame)
        self.button_clear_history.clicked.connect(self.tree_frames.clear)
        self.button_save_history.clicked.connect(self.save_history)
        self.button_save_configuration.clicked.connect(self.save_configuration)
        self.button_save_read_filter.clicked.connect(self.save_read_filter)

        self.error_log_timer = QTimer(self)
        self.error_log_timer.timeout.connect(self.update_error_log)
        self.error_log_timer.setInterval(1000)

        self.frame_type_changed()
        self.filter_mode_changed()
Exemplo n.º 33
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletCANV2, *args)

        self.setupUi(self)

        self.can = self.device

        self.qtcb_frame_read.connect(self.cb_frame_read)
        self.can.register_callback(self.can.CALLBACK_FRAME_READ,
                                   self.qtcb_frame_read.emit)

        self.last_filename = os.path.join(get_home_path(),
                                          'can_bricklet_v2_history.log')

        self.frame_read_callback_was_enabled = False

        self.tree_frames.header().resizeSection(0, 150)
        self.tree_frames.header().resizeSection(1, 170)
        self.tree_frames.header().resizeSection(2, 300)
        self.tree_frames.header().resizeSection(3, 100)

        self.edit_data.setValidator(HexValidator(max_bytes=8))

        self.combo_frame_type.currentIndexChanged.connect(
            self.frame_type_changed)
        self.spin_baud_rate.valueChanged.connect(
            self.transceiver_configuration_changed)
        self.spin_sample_point.valueChanged.connect(
            self.transceiver_configuration_changed)
        self.combo_transceiver_mode.currentIndexChanged.connect(
            self.transceiver_configuration_changed)

        self.spin_write_buffer_size.valueChanged.connect(
            self.queue_configuration_changed)
        self.spin_write_buffer_timeout.valueChanged.connect(
            self.queue_configuration_changed)
        self.spin_write_backlog_size.valueChanged.connect(
            self.queue_configuration_changed)
        self.edit_read_buffer_sizes.textEdited.connect(
            self.queue_configuration_changed)
        self.spin_read_backlog_size.valueChanged.connect(
            self.queue_configuration_changed)

        for i in range(32):
            self.combo_filter_buffer.addItem(str(i))

        self.combo_filter_buffer.currentIndexChanged.connect(
            self.read_filter_buffer_changed)
        self.combo_filter_mode.currentIndexChanged.connect(
            self.read_filter_mode_changed)
        self.spin_filter_mask.valueChanged.connect(
            self.read_filter_configuration_changed)
        self.spin_filter_identifier.valueChanged.connect(
            self.read_filter_configuration_changed)

        self.button_write_frame.clicked.connect(self.write_frame)
        self.button_clear_history.clicked.connect(self.tree_frames.clear)
        self.button_save_history.clicked.connect(self.save_history)
        self.button_save_transceiver_configuration.clicked.connect(
            self.save_transceiver_configuration)
        self.button_reset_transceiver_configuration.clicked.connect(
            self.reset_transceiver_configuration)
        self.button_save_queue_configuration.clicked.connect(
            self.save_queue_configuration)
        self.button_reset_queue_configuration.clicked.connect(
            self.reset_queue_configuration)
        self.button_save_read_filter_configuration.clicked.connect(
            self.save_read_filter_configuration)
        self.button_reset_read_filter_configuration.clicked.connect(
            self.reset_read_filter_configuration)

        self.error_log_timer = QTimer(self)
        self.error_log_timer.timeout.connect(self.update_error_log)
        self.error_log_timer.setInterval(1000)

        self.frame_type_changed()
        self.read_filter_buffer_changed()
        self.read_filter_mode_changed()
        self.read_filter_configuration_changed()

        self.com_led_off_action = QAction('Off', self)
        self.com_led_off_action.triggered.connect(
            lambda: self.can.set_communication_led_config(
                BrickletCANV2.COMMUNICATION_LED_CONFIG_OFF))
        self.com_led_on_action = QAction('On', self)
        self.com_led_on_action.triggered.connect(
            lambda: self.can.set_communication_led_config(
                BrickletCANV2.COMMUNICATION_LED_CONFIG_ON))
        self.com_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.com_led_show_heartbeat_action.triggered.connect(
            lambda: self.can.set_communication_led_config(
                BrickletCANV2.COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT))
        self.com_led_show_communication_action = QAction('Show Com', self)
        self.com_led_show_communication_action.triggered.connect(
            lambda: self.can.set_communication_led_config(
                BrickletCANV2.COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION))

        self.extra_configs += [(1, 'Com LED:', [
            self.com_led_off_action, self.com_led_on_action,
            self.com_led_show_heartbeat_action,
            self.com_led_show_communication_action
        ])]

        self.error_led_off_action = QAction('Off', self)
        self.error_led_off_action.triggered.connect(
            lambda: self.can.set_error_led_config(BrickletCANV2.
                                                  ERROR_LED_CONFIG_OFF))
        self.error_led_on_action = QAction('On', self)
        self.error_led_on_action.triggered.connect(
            lambda: self.can.set_error_led_config(BrickletCANV2.
                                                  ERROR_LED_CONFIG_ON))
        self.error_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.error_led_show_heartbeat_action.triggered.connect(
            lambda: self.can.set_error_led_config(
                BrickletCANV2.ERROR_LED_CONFIG_SHOW_HEARTBEAT))
        self.error_led_show_transceiver_state_action = QAction(
            'Show Transceiver State', self)
        self.error_led_show_transceiver_state_action.triggered.connect(
            lambda: self.can.set_error_led_config(
                BrickletCANV2.ERROR_LED_CONFIG_SHOW_TRANSCEIVER_STATE))
        self.error_led_show_error_action = QAction('Show Error', self)
        self.error_led_show_error_action.triggered.connect(
            lambda: self.can.set_error_led_config(BrickletCANV2.
                                                  ERROR_LED_CONFIG_SHOW_ERROR))

        self.extra_configs += [(1, 'Error LED:', [
            self.error_led_off_action, self.error_led_on_action,
            self.error_led_show_heartbeat_action,
            self.error_led_show_transceiver_state_action,
            self.error_led_show_error_action
        ])]
Exemplo n.º 34
0
    def __init__(self, session, script_manager, image_version, executable_versions, program):
        QWidget.__init__(self)

        self.setupUi(self)

        self.session             = session
        self.script_manager      = script_manager
        self.image_version       = image_version
        self.executable_versions = executable_versions
        self.program             = program
        self.root_directory      = self.program.root_directory

        self.last_upload_files_wizard_directory = get_home_path()

        self.program.scheduler_state_changed_callback = self.scheduler_state_changed
        self.program.process_spawned_callback         = self.process_spawned

        if self.program.last_spawned_process != None:
            self.program.last_spawned_process.state_changed_callback = self.process_state_changed

        self.first_show_event            = True
        self.tab_is_alive                = True
        self.program_refresh_in_progress = False

        self.edit_general_wizard   = None
        self.edit_language_wizard  = None
        self.edit_arguments_wizard = None
        self.edit_stdio_wizard     = None
        self.edit_schedule_wizard  = None
        self.upload_files_wizard   = None
        self.download_wizard       = None

        self.button_refresh.clicked.connect(self.refresh_info)

        self.button_start_program.clicked.connect(self.start_program)
        self.button_kill_process.clicked.connect(self.kill_process)
        self.button_continue_schedule.clicked.connect(self.continue_schedule)
        self.button_send_stdin_pipe_input.clicked.connect(self.send_stdin_pipe_input)

        self.check_show_environment.stateChanged.connect(self.update_ui_state)

        self.button_edit_general.clicked.connect(self.show_edit_general_wizard)
        self.button_edit_language.clicked.connect(self.show_edit_language_wizard)
        self.button_edit_arguments.clicked.connect(self.show_edit_arguments_wizard)
        self.button_edit_stdio.clicked.connect(self.show_edit_stdio_wizard)
        self.button_edit_schedule.clicked.connect(self.show_edit_schedule_wizard)

        # create language info widget
        language_api_name = self.program.cast_custom_option_value('language', unicode, '<unknown>')

        try:
            language = Constants.get_language(language_api_name)
        except:
            language = None

        if language != None:
            language_info_classes = {
                Constants.LANGUAGE_C:          ProgramInfoC,
                Constants.LANGUAGE_CSHARP:     ProgramInfoCSharp,
                Constants.LANGUAGE_DELPHI:     ProgramInfoDelphi,
                Constants.LANGUAGE_JAVA:       ProgramInfoJava,
                Constants.LANGUAGE_JAVASCRIPT: ProgramInfoJavaScript,
                Constants.LANGUAGE_OCTAVE:     ProgramInfoOctave,
                Constants.LANGUAGE_PERL:       ProgramInfoPerl,
                Constants.LANGUAGE_PHP:        ProgramInfoPHP,
                Constants.LANGUAGE_PYTHON:     ProgramInfoPython,
                Constants.LANGUAGE_RUBY:       ProgramInfoRuby,
                Constants.LANGUAGE_SHELL:      ProgramInfoShell,
                Constants.LANGUAGE_VBNET:      ProgramInfoVBNET
            }

            if language_info_classes[language] != None:
                context = ProgramInfoContext(self.session, self.script_manager, self.executable_versions, self.program)

                self.widget_language = language_info_classes[language](context)
                self.layout_language.addWidget(self.widget_language)
            else:
                self.widget_language = None
        else:
            self.widget_language = None

        self.current_language_action = None

        self.button_language_action.setVisible(False)

        def is_alive():
            return self.tab_is_alive

        # create logs info widget
        context = ProgramInfoContext(self.session, self.script_manager, self.executable_versions, self.program)

        self.widget_logs = ProgramInfoLogs(context, self.update_ui_state, self.set_widget_enabled, is_alive, self.show_download_wizard, self.set_program_callbacks_enabled)
        self.layout_logs.addWidget(self.widget_logs)

        # create files info widget
        context = ProgramInfoContext(self.session, self.script_manager, self.executable_versions, self.program)

        self.widget_files = ProgramInfoFiles(context, self.update_ui_state, self.set_widget_enabled, is_alive, self.show_upload_files_wizard, self.show_download_wizard)
        self.layout_files.addWidget(self.widget_files)

        self.update_ui_state()
Exemplo n.º 35
0
    def __init__(self, parent):
        QDialog.__init__(self, parent)

        self._gui_logger = GUILogger("GUILogger", logging.INFO)
        self._gui_job = None
        EventLogger.add_logger(self._gui_logger)

        # FIXME better way to find interval and uids in tree_widget?!
        self.__tree_interval_tooltip = "Update interval in seconds"
        self.__tree_uid_tooltip = "UID cannot be empty"
        self.data_logger_thread = None
        self.tab_debug_warning = False

        self.device_dialog = None

        self.host_infos = None
        self.last_host = None
        self.host_index_changing = None

        self.setupUi(self)

        self.model_data = QStandardItemModel(self)
        self.model_data.setHorizontalHeaderLabels(['Time', 'Name', 'UID', 'Var', 'Raw', 'Unit'])
        self.table_data.setModel(self.model_data)
        self.table_data.setColumnWidth(0, 160)
        self.table_data.setColumnWidth(1, 170)
        self.table_data.setColumnWidth(2, 50)
        self.table_data.setColumnWidth(3, 110)
        self.table_data.setColumnWidth(4, 70)
        self.table_data.setColumnWidth(5, 100)

        self.model_devices = QStandardItemModel(self)
        self.model_devices.setHorizontalHeaderLabels(['Device', 'Value'])
        self.tree_devices.setModel(self.model_devices)
        self.tree_devices.setColumnWidth(0, 300)

        self.widget_initialization()

        self.btn_start_logging.setIcon(QIcon(load_pixmap('data_logger/start-icon.png')))

        timestamp = int(time.time())
        self.edit_csv_file_name.setText(os.path.join(get_home_path(), 'logger_data_{0}.csv'.format(timestamp)))
        self.edit_log_file_name.setText(os.path.join(get_home_path(), 'logger_debug_{0}.log'.format(timestamp)))

        self.combo_data_time_format.addItem(utils.timestamp_to_de(timestamp) + ' (DD.MM.YYYY HH:MM:SS)', 'de')
        self.combo_data_time_format.addItem(utils.timestamp_to_us(timestamp) + ' (MM/DD/YYYY HH:MM:SS)', 'us')
        self.combo_data_time_format.addItem(utils.timestamp_to_iso(timestamp) + ' (ISO 8601)', 'iso')
        self.combo_data_time_format.addItem(utils.timestamp_to_unix(timestamp) + ' (Unix)', 'unix')

        self.combo_debug_time_format.addItem(utils.timestamp_to_de(timestamp) + ' (DD.MM.YYYY HH:MM:SS)', 'de')
        self.combo_debug_time_format.addItem(utils.timestamp_to_us(timestamp) + ' (MM/DD/YYYY HH:MM:SS)', 'us')
        self.combo_debug_time_format.addItem(utils.timestamp_to_iso(timestamp) + ' (ISO 8601)', 'iso')
        self.combo_debug_time_format.addItem(utils.timestamp_to_unix(timestamp) + ' (Unix)', 'unix')

        self.combo_log_level.addItem('Debug', 'debug')
        self.combo_log_level.addItem('Info', 'info')
        self.combo_log_level.addItem('Warning', 'warning')
        self.combo_log_level.addItem('Error', 'error')
        self.combo_log_level.addItem('Critical', 'critical')
        self.combo_log_level.setCurrentIndex(0) # debug

        self.combo_debug_level.addItem('Debug', logging.DEBUG)
        self.combo_debug_level.addItem('Info', logging.INFO)
        self.combo_debug_level.addItem('Warning', logging.WARNING)
        self.combo_debug_level.addItem('Error', logging.ERROR)
        self.combo_debug_level.addItem('Critical', logging.CRITICAL)
        self.combo_debug_level.setCurrentIndex(1) # info

        self.update_ui_state()
Exemplo n.º 36
0
    def __init__(self, parent, host_infos):
        QDialog.__init__(self, parent, get_modeless_dialog_flags())

        self._gui_logger = GUILogger("GUILogger", logging.INFO)
        self._gui_job = None
        EventLogger.add_logger(self._gui_logger)

        self.data_logger_thread = None
        self.tab_debug_warning = False
        self.device_dialog = None
        self.last_host_index = -1

        self.setupUi(self)

        self.model_data = QStandardItemModel(self)
        self.model_data.setHorizontalHeaderLabels(['Time', 'Name', 'UID', 'Var', 'Raw', 'Unit'])
        self.table_data.setModel(self.model_data)
        self.table_data.setColumnWidth(0, 160)
        self.table_data.setColumnWidth(1, 170)
        self.table_data.setColumnWidth(2, 50)
        self.table_data.setColumnWidth(3, 110)
        self.table_data.setColumnWidth(4, 70)
        self.table_data.setColumnWidth(5, 100)

        self.model_devices = QStandardItemModel(self)
        self.model_devices.setHorizontalHeaderLabels(['Device', 'Value'])
        self.tree_devices.setModel(self.model_devices)
        self.tree_devices.setColumnWidth(0, 300)

        self.signal_initialization()

        self.check_authentication.stateChanged.connect(self.authentication_state_changed)
        self.label_secret.hide()
        self.edit_secret.hide()
        self.edit_secret.setEchoMode(QLineEdit.Password)
        self.check_secret_show.hide()
        self.check_secret_show.stateChanged.connect(self.secret_show_state_changed)

        self.btn_start_logging.setIcon(QIcon(load_pixmap('data_logger/start-icon.png')))

        self.example_timestamp = time.time()

        self.edit_csv_file_name.setText(os.path.join(get_home_path(), 'logger_data_{0}.csv'.format(int(self.example_timestamp))))
        self.edit_log_file_name.setText(os.path.join(get_home_path(), 'logger_debug_{0}.log'.format(int(self.example_timestamp))))

        self.combo_data_time_format.addItem(utils.timestamp_to_de(self.example_timestamp) + ' (DD.MM.YYYY HH:MM:SS)', 'de')
        self.combo_data_time_format.addItem(utils.timestamp_to_de_msec(self.example_timestamp) + ' (DD.MM.YYYY HH:MM:SS,000)', 'de-msec')
        self.combo_data_time_format.insertSeparator(self.combo_data_time_format.count())
        self.combo_data_time_format.addItem(utils.timestamp_to_us(self.example_timestamp) + ' (MM/DD/YYYY HH:MM:SS)', 'us')
        self.combo_data_time_format.addItem(utils.timestamp_to_us_msec(self.example_timestamp) + ' (MM/DD/YYYY HH:MM:SS.000)', 'us-msec')
        self.combo_data_time_format.insertSeparator(self.combo_data_time_format.count())
        self.combo_data_time_format.addItem(utils.timestamp_to_iso(self.example_timestamp) + ' (ISO 8601)', 'iso')
        self.combo_data_time_format.addItem(utils.timestamp_to_iso_msec(self.example_timestamp) + ' (ISO 8601 + Milliseconds)', 'iso-msec')
        self.combo_data_time_format.insertSeparator(self.combo_data_time_format.count())
        self.combo_data_time_format.addItem(utils.timestamp_to_unix(self.example_timestamp) + ' (Unix)', 'unix')
        self.combo_data_time_format.addItem(utils.timestamp_to_unix_msec(self.example_timestamp) + ' (Unix + Milliseconds)', 'unix-msec')
        self.combo_data_time_format.insertSeparator(self.combo_data_time_format.count())

        t = utils.timestamp_to_strftime(self.example_timestamp, self.edit_data_time_format_strftime.text())
        if len(t) == 0:
            t = '<empty>'

        self.combo_data_time_format.addItem((t + ' (strftime)'), 'strftime')

        self.combo_debug_time_format.addItem(utils.timestamp_to_de(self.example_timestamp) + ' (DD.MM.YYYY HH:MM:SS)', 'de')
        self.combo_debug_time_format.addItem(utils.timestamp_to_us(self.example_timestamp) + ' (MM/DD/YYYY HH:MM:SS)', 'us')
        self.combo_debug_time_format.addItem(utils.timestamp_to_iso(self.example_timestamp) + ' (ISO 8601)', 'iso')
        self.combo_debug_time_format.addItem(utils.timestamp_to_unix(self.example_timestamp) + ' (Unix)', 'unix')

        self.combo_log_level.addItem('Debug', 'debug')
        self.combo_log_level.addItem('Info', 'info')
        self.combo_log_level.addItem('Warning', 'warning')
        self.combo_log_level.addItem('Error', 'error')
        self.combo_log_level.addItem('Critical', 'critical')
        self.combo_log_level.setCurrentIndex(0) # debug

        self.combo_debug_level.addItem('Debug', logging.DEBUG)
        self.combo_debug_level.addItem('Info', logging.INFO)
        self.combo_debug_level.addItem('Warning', logging.WARNING)
        self.combo_debug_level.addItem('Error', logging.ERROR)
        self.combo_debug_level.addItem('Critical', logging.CRITICAL)
        self.combo_debug_level.setCurrentIndex(1) # info

        for host_info in host_infos:
            self.combo_host.addItem(host_info.host, (host_info.port, host_info.use_authentication, host_info.secret))

        self._host_index_changed(0)

        self.update_ui_state()
Exemplo n.º 37
0
    def __init__(self, parent, host_infos):
        QDialog.__init__(self, parent, get_modeless_dialog_flags())

        self._gui_logger = GUILogger("GUILogger", logging.INFO)
        self._gui_job = None
        EventLogger.add_logger(self._gui_logger)

        self.data_logger_thread = None
        self.tab_debug_warning = False
        self.device_dialog = None
        self.last_host_index = -1

        self.setupUi(self)

        self.model_data = QStandardItemModel(self)
        self.model_data.setHorizontalHeaderLabels(
            ['Time', 'Name', 'UID', 'Var', 'Raw', 'Unit'])
        self.table_data.setModel(self.model_data)
        self.table_data.setColumnWidth(0, 160)
        self.table_data.setColumnWidth(1, 170)
        self.table_data.setColumnWidth(2, 50)
        self.table_data.setColumnWidth(3, 110)
        self.table_data.setColumnWidth(4, 70)
        self.table_data.setColumnWidth(5, 100)

        self.model_devices = QStandardItemModel(self)
        self.model_devices.setHorizontalHeaderLabels(['Device', 'Value'])
        self.tree_devices.setModel(self.model_devices)
        self.tree_devices.setColumnWidth(0, 300)

        self.signal_initialization()

        self.check_authentication.stateChanged.connect(
            self.authentication_state_changed)
        self.label_secret.hide()
        self.edit_secret.hide()
        self.edit_secret.setEchoMode(QLineEdit.Password)
        self.check_secret_show.hide()
        self.check_secret_show.stateChanged.connect(
            self.secret_show_state_changed)

        self.btn_start_logging.setIcon(
            QIcon(load_pixmap('data_logger/start-icon.png')))

        self.example_timestamp = time.time()

        self.edit_csv_file_name.setText(
            os.path.join(
                get_home_path(),
                'logger_data_{0}.csv'.format(int(self.example_timestamp))))
        self.edit_log_file_name.setText(
            os.path.join(
                get_home_path(),
                'logger_debug_{0}.log'.format(int(self.example_timestamp))))

        self.combo_data_time_format.addItem(
            utils.timestamp_to_de(self.example_timestamp) +
            ' (DD.MM.YYYY HH:MM:SS)', 'de')
        self.combo_data_time_format.addItem(
            utils.timestamp_to_de_msec(self.example_timestamp) +
            ' (DD.MM.YYYY HH:MM:SS,000)', 'de-msec')
        self.combo_data_time_format.insertSeparator(
            self.combo_data_time_format.count())
        self.combo_data_time_format.addItem(
            utils.timestamp_to_us(self.example_timestamp) +
            ' (MM/DD/YYYY HH:MM:SS)', 'us')
        self.combo_data_time_format.addItem(
            utils.timestamp_to_us_msec(self.example_timestamp) +
            ' (MM/DD/YYYY HH:MM:SS.000)', 'us-msec')
        self.combo_data_time_format.insertSeparator(
            self.combo_data_time_format.count())
        self.combo_data_time_format.addItem(
            utils.timestamp_to_iso(self.example_timestamp) + ' (ISO 8601)',
            'iso')
        self.combo_data_time_format.addItem(
            utils.timestamp_to_iso_msec(self.example_timestamp) +
            ' (ISO 8601 + Milliseconds)', 'iso-msec')
        self.combo_data_time_format.insertSeparator(
            self.combo_data_time_format.count())
        self.combo_data_time_format.addItem(
            utils.timestamp_to_unix(self.example_timestamp) + ' (Unix)',
            'unix')
        self.combo_data_time_format.addItem(
            utils.timestamp_to_unix_msec(self.example_timestamp) +
            ' (Unix + Milliseconds)', 'unix-msec')
        self.combo_data_time_format.insertSeparator(
            self.combo_data_time_format.count())

        t = utils.timestamp_to_strftime(
            self.example_timestamp, self.edit_data_time_format_strftime.text())
        if len(t) == 0:
            t = '<empty>'

        self.combo_data_time_format.addItem((t + ' (strftime)'), 'strftime')

        self.combo_debug_time_format.addItem(
            utils.timestamp_to_de(self.example_timestamp) +
            ' (DD.MM.YYYY HH:MM:SS)', 'de')
        self.combo_debug_time_format.addItem(
            utils.timestamp_to_us(self.example_timestamp) +
            ' (MM/DD/YYYY HH:MM:SS)', 'us')
        self.combo_debug_time_format.addItem(
            utils.timestamp_to_iso(self.example_timestamp) + ' (ISO 8601)',
            'iso')
        self.combo_debug_time_format.addItem(
            utils.timestamp_to_unix(self.example_timestamp) + ' (Unix)',
            'unix')

        self.combo_log_level.addItem('Debug', 'debug')
        self.combo_log_level.addItem('Info', 'info')
        self.combo_log_level.addItem('Warning', 'warning')
        self.combo_log_level.addItem('Error', 'error')
        self.combo_log_level.addItem('Critical', 'critical')
        self.combo_log_level.setCurrentIndex(0)  # debug

        self.combo_debug_level.addItem('Debug', logging.DEBUG)
        self.combo_debug_level.addItem('Info', logging.INFO)
        self.combo_debug_level.addItem('Warning', logging.WARNING)
        self.combo_debug_level.addItem('Error', logging.ERROR)
        self.combo_debug_level.addItem('Critical', logging.CRITICAL)
        self.combo_debug_level.setCurrentIndex(1)  # info

        for host_info in host_infos:
            self.combo_host.addItem(
                host_info.host, (host_info.port, host_info.use_authentication,
                                 host_info.secret))

        self._host_index_changed(0)

        self.update_ui_state()
Exemplo n.º 38
0
    def __init__(self, parent, session, source_name):
        QDialog.__init__(self, parent)

        self.setupUi(self)
        self.setModal(True)

        self.source_name   = source_name
        self.last_filename = os.path.join(get_home_path(), posixpath.split(source_name)[1])
        self.log_file      = None
        self.content       = None

        source_name_parts = posixpath.split(source_name)[1].split('_')

        if source_name_parts[0] == 'continuous':
            date_time       = 'Continuous ({0})'.format(source_name_parts[1])
            self.continuous = True
        else:
            try:
                timestamp = int(source_name_parts[1].split('+')[0]) / 1000000
            except ValueError:
                timestamp = 0

            date_time       = '{0} ({1})'.format(timestamp_to_date_at_time(timestamp), source_name_parts[2])
            self.continuous = False

        self.rejected.connect(self.abort_download)
        self.progress_download.setRange(0, 0)
        self.label_date_time.setText(date_time)
        self.button_save.clicked.connect(self.save_content)
        self.button_close.clicked.connect(self.reject)

        self.button_save.setEnabled(False)

        def cb_open(dummy):
            def cb_read_status(bytes_read, max_length):
                self.progress_download.setValue(bytes_read)

            def cb_read(result):
                self.log_file.release()
                self.log_file = None

                self.label_download.setVisible(False)
                self.progress_download.setVisible(False)

                if result.error != None:
                    self.log(u'Error: ' + Qt.escape(unicode(result.error)), bold=True)
                    return

                try:
                    self.content = result.data.decode('utf-8')
                except UnicodeDecodeError:
                    # FIXME: maybe add a encoding guesser here or try some common encodings if UTF-8 fails
                    self.log(u'Error: Log file is not UTF-8 encoded', bold=True)
                    return

                self.button_save.setEnabled(True)

                if self.continuous:
                    content = self.content.lstrip()
                else:
                    content = self.content

                self.edit_content.setPlainText('')

                font = QFont('monospace')
                font.setStyleHint(QFont.TypeWriter)

                self.edit_content.setFont(font)
                self.edit_content.setPlainText(content)

            self.progress_download.setRange(0, self.log_file.length)
            self.log_file.read_async(self.log_file.length, cb_read, cb_read_status)

        def cb_open_error():
            self.label_download.setVisible(False)
            self.progress_download.setVisible(False)
            self.log(u'Error: Could not open log file', bold=True)

        self.log_file = REDFile(session)

        async_call(self.log_file.open,
                   (source_name, REDFile.FLAG_READ_ONLY | REDFile.FLAG_NON_BLOCKING, 0, 0, 0),
                   cb_open, cb_open_error)
Exemplo n.º 39
0
    def __init__(self, session, script_manager, image_version, executable_versions, program):
        QWidget.__init__(self)

        self.setupUi(self)

        self.session             = session
        self.script_manager      = script_manager
        self.image_version       = image_version
        self.executable_versions = executable_versions
        self.program             = program
        self.root_directory      = self.program.root_directory

        self.last_upload_files_wizard_directory = get_home_path()

        self.program.scheduler_state_changed_callback      = self.scheduler_state_changed
        self.program.lite_scheduler_state_changed_callback = self.lite_scheduler_state_changed
        self.program.process_spawned_callback              = self.process_spawned
        self.program.lite_process_spawned_callback         = self.lite_process_spawned

        if self.program.last_spawned_process != None:
            self.program.last_spawned_process.state_changed_callback = self.process_state_changed

        if self.program.last_spawned_lite_process != None:
            self.program.last_spawned_lite_process.state_changed_callback = self.lite_process_state_changed

        self.first_show_event            = True
        self.tab_is_alive                = True
        self.program_refresh_in_progress = False

        self.edit_general_wizard   = None
        self.edit_language_wizard  = None
        self.edit_arguments_wizard = None
        self.edit_stdio_wizard     = None
        self.edit_schedule_wizard  = None
        self.upload_files_wizard   = None
        self.download_wizard       = None

        self.button_refresh.clicked.connect(self.refresh_info)

        self.button_start_program.clicked.connect(self.start_program)
        self.button_exit_process.clicked.connect(self.exit_process)
        self.button_kill_process.clicked.connect(self.kill_process)
        self.button_continue_schedule.clicked.connect(self.continue_schedule)
        self.button_send_stdin_pipe_input.clicked.connect(self.send_stdin_pipe_input)

        self.check_show_environment.stateChanged.connect(self.update_ui_state)

        self.button_edit_general.clicked.connect(self.show_edit_general_wizard)
        self.button_edit_language.clicked.connect(self.show_edit_language_wizard)
        self.button_edit_arguments.clicked.connect(self.show_edit_arguments_wizard)
        self.button_edit_stdio.clicked.connect(self.show_edit_stdio_wizard)
        self.button_edit_schedule.clicked.connect(self.show_edit_schedule_wizard)

        # create language info widget
        language_api_name = self.program.cast_custom_option_value('language', unicode, '<unknown>')

        try:
            language = Constants.get_language(language_api_name)
        except:
            language = None

        if language != None:
            language_info_classes = {
                Constants.LANGUAGE_C:          ProgramInfoC,
                Constants.LANGUAGE_CSHARP:     ProgramInfoCSharp,
                Constants.LANGUAGE_DELPHI:     ProgramInfoDelphi,
                Constants.LANGUAGE_JAVA:       ProgramInfoJava,
                Constants.LANGUAGE_JAVASCRIPT: ProgramInfoJavaScript,
                Constants.LANGUAGE_OCTAVE:     ProgramInfoOctave,
                Constants.LANGUAGE_PERL:       ProgramInfoPerl,
                Constants.LANGUAGE_PHP:        ProgramInfoPHP,
                Constants.LANGUAGE_PYTHON:     ProgramInfoPython,
                Constants.LANGUAGE_RUBY:       ProgramInfoRuby,
                Constants.LANGUAGE_SHELL:      ProgramInfoShell,
                Constants.LANGUAGE_VBNET:      ProgramInfoVBNET
            }

            if language_info_classes[language] != None:
                context = ProgramInfoContext(self.session, self.script_manager, self.executable_versions, self.program)

                self.widget_language = language_info_classes[language](context)
                self.layout_language.addWidget(self.widget_language)
            else:
                self.widget_language = None
        else:
            self.widget_language = None

        self.current_language_action = None

        self.button_language_action.setVisible(False)

        def is_alive():
            return self.tab_is_alive

        # create logs info widget
        context = ProgramInfoContext(self.session, self.script_manager, self.executable_versions, self.program)

        self.widget_logs = ProgramInfoLogs(context, self.update_ui_state, self.set_widget_enabled, is_alive, self.show_download_wizard, self.set_program_callbacks_enabled)
        self.layout_logs.addWidget(self.widget_logs)

        # create files info widget
        context = ProgramInfoContext(self.session, self.script_manager, self.executable_versions, self.program)

        self.widget_files = ProgramInfoFiles(context, self.update_ui_state, self.set_widget_enabled, is_alive, self.show_upload_files_wizard, self.show_download_wizard)
        self.layout_files.addWidget(self.widget_files)

        self.update_ui_state()
Exemplo n.º 40
0
    def __init__(self, parent):
        QDialog.__init__(self, parent)

        self._gui_logger = GUILogger("GUILogger", logging.INFO)
        self._gui_job = None
        EventLogger.add_logger(self._gui_logger)

        # FIXME better way to find interval and uids in tree_widget?!
        self.__tree_interval_tooltip = "Update interval in seconds"
        self.__tree_uid_tooltip = "UID cannot be empty"
        self.data_logger_thread = None
        self.tab_debug_warning = False

        self.device_dialog = None

        self.host_infos = None
        self.last_host = None
        self.host_index_changing = None

        self.setupUi(self)

        self.model_data = QStandardItemModel(self)
        self.model_data.setHorizontalHeaderLabels(
            ['Time', 'Name', 'UID', 'Var', 'Raw', 'Unit'])
        self.table_data.setModel(self.model_data)
        self.table_data.setColumnWidth(0, 160)
        self.table_data.setColumnWidth(1, 170)
        self.table_data.setColumnWidth(2, 50)
        self.table_data.setColumnWidth(3, 110)
        self.table_data.setColumnWidth(4, 70)
        self.table_data.setColumnWidth(5, 100)

        self.model_devices = QStandardItemModel(self)
        self.model_devices.setHorizontalHeaderLabels(['Device', 'Value'])
        self.tree_devices.setModel(self.model_devices)
        self.tree_devices.setColumnWidth(0, 300)

        self.widget_initialization()

        self.btn_start_logging.setIcon(
            QIcon(load_pixmap('data_logger/start-icon.png')))

        timestamp = int(time.time())
        self.edit_csv_file_name.setText(
            os.path.join(get_home_path(),
                         'logger_data_{0}.csv'.format(timestamp)))
        self.edit_log_file_name.setText(
            os.path.join(get_home_path(),
                         'logger_debug_{0}.log'.format(timestamp)))

        self.combo_data_time_format.addItem(
            utils.timestamp_to_de(timestamp) + ' (DD.MM.YYYY HH:MM:SS)', 'de')
        self.combo_data_time_format.addItem(
            utils.timestamp_to_us(timestamp) + ' (MM/DD/YYYY HH:MM:SS)', 'us')
        self.combo_data_time_format.addItem(
            utils.timestamp_to_iso(timestamp) + ' (ISO 8601)', 'iso')
        self.combo_data_time_format.addItem(
            utils.timestamp_to_unix(timestamp) + ' (Unix)', 'unix')

        self.combo_debug_time_format.addItem(
            utils.timestamp_to_de(timestamp) + ' (DD.MM.YYYY HH:MM:SS)', 'de')
        self.combo_debug_time_format.addItem(
            utils.timestamp_to_us(timestamp) + ' (MM/DD/YYYY HH:MM:SS)', 'us')
        self.combo_debug_time_format.addItem(
            utils.timestamp_to_iso(timestamp) + ' (ISO 8601)', 'iso')
        self.combo_debug_time_format.addItem(
            utils.timestamp_to_unix(timestamp) + ' (Unix)', 'unix')

        self.combo_log_level.addItem('Debug', 'debug')
        self.combo_log_level.addItem('Info', 'info')
        self.combo_log_level.addItem('Warning', 'warning')
        self.combo_log_level.addItem('Error', 'error')
        self.combo_log_level.addItem('Critical', 'critical')
        self.combo_log_level.setCurrentIndex(0)  # debug

        self.combo_debug_level.addItem('Debug', logging.DEBUG)
        self.combo_debug_level.addItem('Info', logging.INFO)
        self.combo_debug_level.addItem('Warning', logging.WARNING)
        self.combo_debug_level.addItem('Error', logging.ERROR)
        self.combo_debug_level.addItem('Critical', logging.CRITICAL)
        self.combo_debug_level.setCurrentIndex(1)  # info

        self.update_ui_state()