Esempio n. 1
0
 def on_since_model_changed(self, event):
     # When model is updated (e.g. from console or by clicking a QRadioButton)
     now = time.time()
     if isinstance(event.date, timedelta):
         self.since_widget.setDateTime(
             QDateTime.fromSecsSinceEpoch(now + event.date.total_seconds()))
         self.until_widget.setDateTime(QDateTime.fromSecsSinceEpoch(now))
         if event.date == timedelta(minutes=-60):
             self.hour_widget.setChecked(True)
         if event.date == timedelta(days=-1):
             self.today_widget.setChecked(True)
         if event.date == timedelta(days=-7):
             self.week_widget.setChecked(True)
         if event.date == timedelta(days=-30):
             self.month_widget.setChecked(True)
         if event.date == timedelta(days=-365):
             self.year_widget.setChecked(True)
         if event.date == timedelta(seconds=-4861699200):
             self.since_widget.setDateTime(
                 QDateTime.fromSecsSinceEpoch(event.date.total_seconds()))
             self.until_widget.setDateTime(
                 QDateTime.fromSecsSinceEpoch(now))
             self.all_widget.setChecked(True)
     else:
         qdatetime = QDateTime()
         qdatetime.setSecsSinceEpoch(event.date.timestamp())
         self.since_widget.setDateTime(qdatetime)
         self.uncheck_radiobuttons
Esempio n. 2
0
    def __init__(self, *args, catalog, menuBar, zmq_address=None, **kwargs):
        super().__init__(*args, **kwargs)

        # Define models.
        search_state = SearchState(catalog=catalog)
        self.search_model = search_state.search_results_model
        # Define widgets.
        self.search_widget = SearchWidget()
        self.summary_widget = SummaryWidget()

        left_pane = QSplitter(Qt.Vertical)
        left_pane.addWidget(self.search_widget)
        left_pane.addWidget(self.summary_widget)

        layout = QHBoxLayout()
        splitter = QSplitter(Qt.Horizontal)
        layout.addWidget(splitter)
        splitter.addWidget(left_pane)

        self.setLayout(layout)

        def show_double_clicked_entry(index):
            search_state.search_results_model.emit_open_entries(None, [index])

        # Set models, connect signals, and set initial values.
        now = time.time()
        ONE_WEEK = 60 * 60 * 24 * 7
        self.search_widget.search_results_widget.setModel(
            search_state.search_results_model)
        self.search_widget.search_input_widget.search_bar.textChanged.connect(
            search_state.search_results_model.on_search_text_changed)
        self.search_widget.catalog_selection_widget.catalog_list.setModel(
            search_state.catalog_selection_model)
        self.search_widget.search_input_widget.until_widget.dateTimeChanged.connect(
            search_state.search_results_model.on_until_time_changed)
        self.search_widget.search_input_widget.until_widget.setDateTime(
            QDateTime.fromSecsSinceEpoch(now + ONE_WEEK))
        self.search_widget.search_input_widget.since_widget.dateTimeChanged.connect(
            search_state.search_results_model.on_since_time_changed)
        self.search_widget.search_input_widget.since_widget.setDateTime(
            QDateTime.fromSecsSinceEpoch(now - ONE_WEEK))
        self.search_widget.catalog_selection_widget.catalog_list.currentIndexChanged.connect(
            search_state.set_selected_catalog)
        self.search_widget.search_results_widget.selectionModel(
        ).selectionChanged.connect(
            search_state.search_results_model.emit_selected_result)
        self.search_widget.search_results_widget.doubleClicked.connect(
            show_double_clicked_entry)
        search_state.search_results_model.selected_result.connect(
            self.summary_widget.set_entries)
        search_state.search_results_model.valid_custom_query.connect(
            self.search_widget.search_input_widget.mark_custom_query)
        search_state.sig_update_header.connect(
            self.search_widget.search_results_widget.hide_hidden_columns)
        search_state.enabled = True
        search_state.search()
Esempio n. 3
0
 def on_reload(self, event):
     now = time.time()
     if isinstance(self.model.since, timedelta):
         self.since_widget.setDateTime(
             QDateTime.fromSecsSinceEpoch(now +
                                          self.model.since.total_seconds()))
     if isinstance(self.model.until, timedelta):
         self.until_widget.setDateTime(
             QDateTime.fromSecsSinceEpoch(now +
                                          self.model.until.total_seconds()))
Esempio n. 4
0
def set_txt_from_elt(el, param_dict):
    """
    get the value of the parameter from the text value of the xml element
    Parameters
    ----------
    el: xml element
    param_dict: dictionnary from which the parameter will be constructed

    """
    val_text = el.text
    param_type = el.get('type')
    if val_text is not None:
        if param_type == 'float':
            param_value = float(val_text)
        elif param_type == 'int':
            param_value = int(float(val_text))
        elif param_type == 'slide':
            param_value = float(val_text)
        elif param_type == 'itemselect':
            if val_text == 'None':
                param_value = dict(all_items=[], selected=[])
            else:
                param_value = dict(all_items=eval(el.get(
                    'all_items', val_text)),
                                   selected=eval(val_text))
        elif 'bool' in param_type or 'led' in param_type:  # covers 'bool' 'bool_push',  'led' and 'led_push'types
            param_value = bool(int(val_text))
        elif param_type == 'date_time':
            param_value = QDateTime.fromSecsSinceEpoch(int(val_text))
        elif param_type == 'date':
            param_value = QDateTime.fromSecsSinceEpoch(int(val_text)).date()
        elif param_type == 'table':
            param_value = eval(val_text)
        elif param_type == 'color':
            param_value = QtGui.QColor(*eval(val_text))
        elif param_type == 'list':
            try:
                param_value = eval(val_text)
            except Exception:
                param_value = val_text  # for back compatibility
        elif param_type == 'table_view':
            data_dict = json.loads(val_text)
            mod = importlib.import_module(data_dict['module'])
            _cls = getattr(mod, data_dict['classname'])
            param_value = _cls(data_dict['data'], header=data_dict['header'])
        else:
            param_value = val_text
        param_dict.update(dict(value=param_value))
Esempio n. 5
0
def setTicksLabels(values):
    strings = []
    for v in values:
        d = QDateTime()
        d = d.fromSecsSinceEpoch(v * 30 * 60)
        vstr = d.toString('HH:mm dd/MM/yy')
        strings.append(vstr)
    return strings
Esempio n. 6
0
    def __init__(self, *args,
                 catalog, search_result_row, menuBar,
                 zmq_address=None, **kwargs):
        super().__init__(*args, **kwargs)

        # Define models.
        search_state = SearchState(
            catalog=catalog,
            search_result_row=search_result_row)

        # Define widgets.
        self.search_widget = SearchWidget()
        self.summary_widget = SummaryWidget()

        left_pane = QVBoxLayout()
        left_pane.addWidget(self.search_widget)
        left_pane.addWidget(self.summary_widget)

        right_pane = QVBoxLayout()
        self.viewer = Viewer(menuBar=menuBar)

        right_pane.addWidget(self.viewer)

        layout = QHBoxLayout()
        layout.addLayout(left_pane)
        layout.addLayout(right_pane)
        self.setLayout(layout)

        def show_double_clicked_entry(index):
            search_state.search_results_model.emit_open_entries(None, [index])

        # Set models, connect signals, and set initial values.
        now = time.time()
        ONE_WEEK = 60 * 60 * 24 * 7
        self.search_widget.search_results_widget.setModel(
            search_state.search_results_model)
        self.search_widget.search_input_widget.search_bar.textChanged.connect(
            search_state.search_results_model.on_search_text_changed)
        self.search_widget.catalog_selection_widget.catalog_list.setModel(
            search_state.catalog_selection_model)
        self.search_widget.search_input_widget.until_widget.dateTimeChanged.connect(
            search_state.search_results_model.on_until_time_changed)
        self.search_widget.search_input_widget.until_widget.setDateTime(
            QDateTime.fromSecsSinceEpoch(now + ONE_WEEK))
        self.search_widget.search_input_widget.since_widget.dateTimeChanged.connect(
            search_state.search_results_model.on_since_time_changed)
        self.search_widget.search_input_widget.since_widget.setDateTime(
            QDateTime.fromSecsSinceEpoch(now - ONE_WEEK))
        self.search_widget.catalog_selection_widget.catalog_list.currentIndexChanged.connect(
            search_state.set_selected_catalog)
        self.search_widget.search_results_widget.selectionModel().selectionChanged.connect(
            search_state.search_results_model.emit_selected_result)
        self.search_widget.search_results_widget.doubleClicked.connect(
            show_double_clicked_entry)
        search_state.search_results_model.selected_result.connect(
            self.summary_widget.set_entries)
        search_state.search_results_model.open_entries.connect(
            self.viewer.show_entries)
        self.summary_widget.open.connect(self.viewer.show_entries)
        self.viewer.tab_titles.connect(self.summary_widget.cache_tab_titles)
        search_state.search_results_model.valid_custom_query.connect(
            self.search_widget.search_input_widget.mark_custom_query)
        search_state.enabled = True
        search_state.search()

        if zmq_address:
            self.consumer_thread = ConsumerThread(zmq_address=zmq_address)
            self.consumer_thread.documents.connect(self.viewer.consumer)
            self.consumer_thread.start()
Esempio n. 7
0
def as_qdatetime(datetime):
    "Create QDateTime set as specified by datetime."
    return QDateTime.fromSecsSinceEpoch(
        int(secs_since_epoch(datetime) - datetime.utcoffset() / timedelta(seconds=1))
    )