Exemple #1
0
 def __button_clicked(self):
     sender = self.sender()
     index = int(sender.property(Resources.ReminderEventTab_Property_Id))
     event_id = int(sender.property(Resources.ReminderEventTab_Property_EventId))
     self.__manager.set_done(index, event_id)
     Tools.write_verbose_class_method_name(self, ReminderEventTab.__button_clicked, "index", str(index))
     self.__remove_row(index)
Exemple #2
0
 def __before_delete(self, row: int):
     record = self.model.record(row)
     index = record.value(0)
     self.__db.exec(Resources.EventManager_DELETE_ReminderEvent % index)
     self.__db.exec(Resources.EventManager_DELETE_Event % index)
     Tools.write_verbose_class_method_name(self,
                                           EventManager.__before_delete,
                                           "deleted", str(index))
Exemple #3
0
 def enabled(self, value: bool):
     """
     Sets editor is enabled.
     :param value: New value.
     """
     self.__editor.setEnabled(value)
     Tools.write_verbose_class_method_name(self, "enabled", "set_enabled",
                                           str(value))
Exemple #4
0
 def __save_clicked(self):
     self.__manager.save()
     self.__set_columns_checkbox([
         Resources.EventManager_Column_IsCyclic_Index,
         Resources.EventManager_Column_IsActive_Index
     ])
     self.save_clicked_signal.emit()
     Tools.write_verbose_class_name(self, "Save clicked")
Exemple #5
0
 def checked(self, value: bool):
     """
     Sets editor is checked.
     :param value: New value.
     """
     self.__editor.setChecked(value)
     Tools.write_verbose_class_method_name(self, "checked", "set_checked",
                                           str(value))
Exemple #6
0
 def remove_rows(self, selected_indexes: list):
     """
     Delete selected rows.
     :param selected_indexes Selected rows' indexes.
     """
     for item in selected_indexes:
         self.__remove_row(item)
         Tools.write_verbose_class_name(self,
                                        "Row with id = %s removed" % item)
Exemple #7
0
 def set_property(self, name: str, value: QVariant):
     """
     Sets property.
     :param name: Property's name.
     :param value: New Value.
     """
     self.__editor.setProperty(name, value)
     Tools.write_verbose_class_method_name(self, CheckBoxEdit.set_property,
                                           name, str(value.value()))
Exemple #8
0
 def __insert_reminder_events(self, record: QSqlRecord):
     index = record.value(0)
     start_date = record.value(
         Resources.EventManager_Column_StartDate_Index)
     count = record.value(Resources.EventManager_Column_Count_Index)
     Tools.write_verbose_class_method_name(
         self, EventManager.__insert_reminder_events, "event_id",
         str(index))
     self.__insert_missing_reminder_events(index, start_date, count)
Exemple #9
0
 def checked(self):
     """
     Returns whether editor is checked.
     :return: True if editor is checked, otherwise False.
     """
     result = self.__editor.isChecked()
     Tools.write_verbose_class_method_name(self, "checked", "get_checked",
                                           str(result))
     return result
Exemple #10
0
 def reload_slot(self):
     """
     Reloads view's content.
     """
     self.__view.clearContents()
     self.__manager.refresh_data()
     self.__fill_content()
     self.__set_header_titles(Resources.ReminderEventTab_Columns_Names)
     Tools.write_verbose_class_name(self, "View reloaded")
Exemple #11
0
    def __get_last_id(self) -> int:
        query = self.__db.exec(Resources.EventManager_SELECT_MaxId)
        query.next()
        index = query.value(0)
        if not index:
            index = 0

        Tools.write_verbose_class_method_name(self, EventManager.__get_last_id,
                                              "last_id", str(index))
        return int(index)
Exemple #12
0
 def setEditorData(self, editor: QWidget, index: QModelIndex):
     """
     Sets data to an editor.
     :param editor: Editor.
     :param index: Model's index.
     """
     value = index.data()
     editor.setValue(value)
     Tools.write_verbose_class_method_name(
         self, ItemDelegateSpinBoxEdit.setEditorData, "value", str(value))
Exemple #13
0
 def get_property(self, name: str) -> QVariant:
     """
     Returns property's value.
     :param name: Property's name.
     :return: Value.
     """
     result = self.__editor.property(name)
     Tools.write_verbose_class_method_name(self, CheckBoxEdit.get_property,
                                           name, str(result))
     return result
Exemple #14
0
 def __before_insert(self, record: QSqlRecord):
     index = record.value(0)
     self.__insert_reminder_events(record)
     self.__added_items.remove(index)
     Tools.write_verbose_class_method_name(self,
                                           EventManager.__before_insert,
                                           "added_items.remove", str(index))
     Tools.write_verbose_class_method_name(self,
                                           EventManager.__before_insert,
                                           "added_items.remained",
                                           str(self.__added_items))
Exemple #15
0
    def __remove_row(self, index: int):
        row = -1
        # looking for row's number in view for given reminder id
        for row_number in range(self.__view.rowCount()):
            item = int(self.__view.item(row_number, 0).text())
            if item == index:
                row = row_number
                break

        self.__view.removeRow(row)
        Tools.write_verbose_class_method_name(self, ReminderEventTab.__remove_row, "__view.removeRow", str(row))
Exemple #16
0
 def insert_row(self) -> int:
     """
     Inserts empty row to model.
     :return: Row's index in table.
     """
     rows_count = self.model.rowCount()
     new_record = self.__get_new_record()
     self.model.insertRecord(rows_count, new_record)
     Tools.write_verbose_class_name(
         self, "Row inserted at position %s" % rows_count)
     return rows_count
Exemple #17
0
    def __set_next_id(self, record: QSqlRecord):
        if self.__added_items:
            new_id = self.__added_items[-1] + 1
        else:  # list is empty
            new_id = self.__last_id + 1

        record.setValue(0, QVariant(new_id))
        self.__added_items.append(new_id)
        self.__last_id = new_id
        Tools.write_verbose_class_method_name(self, EventManager.__set_next_id,
                                              "new_id", str(new_id))
Exemple #18
0
 def __before_update(self, row: int, record: QSqlRecord):
     del row
     index = record.value(0)
     query = self.__db.exec(Resources.EventManager_SELECT_Event % index)
     query.next()
     old_record = query.record()
     self.__update_active(old_record, record)
     self.__update_count(old_record, record)
     Tools.write_verbose_class_method_name(self,
                                           EventManager.__before_update,
                                           "updated", str(index))
Exemple #19
0
 def set_done(self, reminder_id: int, event_id: int):
     """
     Sets flag IsDone on 1 for a given Id and adds next events to the reminder.
     :param reminder_id: Reminder event Id.
     :param event_id: Event Id.
     """
     self.__db.exec(Resources.ReminderManager_UPDATE_ReminderEventIsDone %
                    str(reminder_id))
     self.__add_events_to_reminder(reminder_id, event_id)
     Tools.write_verbose_class_method_name(self, ReminderManager.set_done,
                                           "reminder_id", str(reminder_id))
Exemple #20
0
    def exec(self, query_string: str) -> QSqlQuery:
        """
        Executes query.
        :param query_string: Query to execute.
        :return: Executed query.
        """
        query = self.__get_query()
        Tools.write_verbose(query_string)
        query.exec(query_string)
        Tools.write_log(query.lastError().text())

        return query
Exemple #21
0
 def setModelData(self, editor: QWidget, model: QAbstractItemModel,
                  index: QModelIndex):
     """
     Sets data from editor back to model.
     :param editor: Editor.
     :param model: Model.
     :param index: Model's index.
     """
     value = editor.value()
     model.setData(index, value)
     Tools.write_verbose_class_method_name(
         self, ItemDelegateSpinBoxEdit.setModelData, "value", str(value))
Exemple #22
0
 def setModelData(self, editor: QWidget, model: QAbstractItemModel,
                  index: QModelIndex):
     """
     Sets data from editor back to model.
     :param editor: Editor.
     :param model: Model.
     :param index: Model's index.
     """
     date = editor.date().toString(Resources.FORMAT_DATE_STORE)
     model.setData(index, date)
     Tools.write_verbose_class_method_name(
         self, ItemDelegateDateEdit.setModelData, "date", str(date))
Exemple #23
0
 def refresh_data(self):
     """
     Repopulate model.
     """
     today_date = QDateTime().currentDateTime().toString(
         Resources.FORMAT_DATE_STORE)
     query = Resources.ReminderManager_SELECT_ReminderEventList % today_date
     self.model.setQuery(query)
     Tools.write_verbose_class_name(
         self, "Data refreshed for date %s" % today_date)
     Tools.write_verbose_class_method_name(self,
                                           ReminderManager.refresh_data,
                                           "query", query)
Exemple #24
0
    def __init_db(self):
        self.__db = QSqlDatabase.addDatabase(Config.DB_TYPE)
        self.db.setDatabaseName(self.__db_path)

        if not self.db.isValid():
            Tools.write_log(self.db.lastError().text())
        if self.db.isOpenError():
            Tools.write_log(self.db.lastError().text())

        self.db.open()
        tables = self.db.tables()

        if not tables:
            self.__create_db()
Exemple #25
0
    def setEditorData(self, editor: QWidget, index: QModelIndex):
        """
        Sets data to an editor.
        :param editor: Editor.
        :param index: Model's index.
        """
        date = Tools.get_date_from_string(str(index.data()))
        row = index.row()

        if row not in self.__minimum:
            self.__minimum[row] = date

        editor.setMinimumDate(self.__minimum[row])
        editor.setDate(date)
        Tools.write_verbose_class_method_name(
            self, ItemDelegateDateEdit.setEditorData, "date", str(date))
Exemple #26
0
    def __remove_row(self, item: QModelIndex):
        row_number = item.row()
        record = self.model.record(row_number)
        index = record.value(0)

        self.model.removeRow(row_number)
        if index in self.__added_items:  # the row was not saved in the database
            self.__added_items.remove(index)
            Tools.write_verbose_class_method_name(self,
                                                  EventManager.__remove_row,
                                                  "added_items.remove",
                                                  str(index))
            Tools.write_verbose_class_method_name(self,
                                                  EventManager.__remove_row,
                                                  "added_items.remained",
                                                  str(self.__added_items))
Exemple #27
0
    def __update_active(self, old_record: QSqlRecord, new_record: QSqlRecord):
        new_value = bool(
            new_record.value(Resources.EventManager_Column_IsActive_Index))
        if bool(old_record.value(
                Resources.EventManager_Column_IsActive_Index)) == new_value:
            return

        index = old_record.value(0)
        Tools.write_verbose_class_method_name(self,
                                              EventManager.__update_active,
                                              "event_id", str(index))

        if new_value is False:  # if change to inactive
            sql = Resources.Manager_DELETE_ReminderEvent % index
            self.__db.exec(sql)
        else:  # if change to active
            self.__insert_reminder_events(new_record)
Exemple #28
0
    def __add_events_to_reminder(self, index: int, event_id: int):
        event_info = self.__get_event_info(event_id)
        count_to_add = self.__get_event_count_to_add(event_info)
        Tools.write_verbose_class_method_name(
            self, ReminderManager.__add_events_to_reminder, "count_to_add",
            str(count_to_add))

        if count_to_add == 0:
            return

        start_date = self.__get_new_reminder_event_date(index, event_info)
        start_date = start_date.toString(Resources.FORMAT_DATE_STORE)

        for i in range(count_to_add):
            sql = Resources.Manager_INSERT_ReminderEvent % (event_id,
                                                            start_date)
            self.__db.exec(sql)
 def test(self):
     all_ok = 0
     # test_epoch = self._data.test_batch_number
     test_epoch = 100
     keep_prob = 0
     for now in range(test_epoch):
         images, labels = self._data.next_test(now)
         prediction, keep_prob = self._sess.run(
             [self._prediction, self._keep_prob],
             feed_dict={
                 self._images: images,
                 self._keep_prob: 1.0
             })
         all_ok += np.sum(np.equal(labels, prediction))
     all_number = test_epoch * self._batch_size
     Tools.print_info("the result is {} ({}/{}  keep_prob {})".format(
         all_ok / (all_number * 1.0), all_ok, all_number, keep_prob))
     pass
Exemple #30
0
    def __get_reminder_event_date(self, index: int) -> QDate:
        query = self.__db.exec(
            Resources.ReminderManager_SELECT_ReminderEventDate % str(index))
        query.next()
        date = query.value(0)
        if not date:
            date = ''

        return Tools.get_date_from_string(date)