Ejemplo n.º 1
0
class Form(QMainWindow, Ui_Form):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.img_name = ""
        self.choose_img_btn.clicked.connect(self.choose_img)
        self.enter_time.setCalendarPopup(True)
        self.enter_time.setDisplayFormat("yyyy-MM-dd hh:mm")
        self.inter = Interactor(DB_NAME, TABLE_NAME)

    def choose_img(self):
        self.img_name = QFileDialog.getOpenFileName(self, 'Выбрать картинку',
                                                    '', "Картинка(*.png)")[0]

    def accept(self):
        title = self.enter_title.text()
        prior = int(self.enter_prior.text())
        datetime = self.enter_time.text()
        if self.inter.exists(title, prior, datetime, self.img_name):
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)

            msg.setText("This notification already exists")
            msg.setWindowTitle("Info")
            msg.exec_()
            return
        self.inter.insert(title, prior, datetime, self.img_name)
        show_info("Напоминание создано успешно")
        self.close()

    def reject(self):
        self.close()
Ejemplo n.º 2
0
 def onKeyPress(self, e):
     print(e, e.key)
     for key in e.key.split("+"):
         self.press_keys[key] = True
         if key == "ctrl":
             self.press_keys["control"] = True
     if self.press_keys["r"]:
         self.press_keys["control"] = False
         self.press_keys["r"] = False
         inter = Interactor()
         ret = inter.SignalSelector(self.AllSignalNames,
                                    self.PlotSignalNames)
         if ret[0] == True:
             print(ret[1])
             self.set_plot_signals(ret[1])
             self.Refresh_Alls()
     elif self.press_keys["t"]:
         pass
     elif self.press_keys["y"]:
         for ax in self.main_axes:
             for line in ax.lines:
                 if line.get_marker() == "None":
                     print("marker set")
                     line.set_marker("o")
                     line.set_markersize(3)
                 else:
                     print("marker unset")
                     line.set_marker("None")
         self.Refresh_Alls()
     elif self.press_keys["u"]:
         pass
     elif self.press_keys["i"]:
         pass
     elif self.press_keys["f5"]:
         self.fig.canvas.draw()
Ejemplo n.º 3
0
 def __init__(self):
     self.client = docker.from_env(timeout=86400)
     self.preparer = Preparer()
     self.searcher = Searcher()
     self.trainer = Trainer()
     self.interactor = Interactor()
     self.generate_save_tag = lambda tag, save_id: hashlib.sha256(
         (tag + save_id).encode()).hexdigest()
Ejemplo n.º 4
0
 def __init__(self):
     super().__init__()
     self.setupUi(self)
     self.img_name = ""
     self.choose_img_btn.clicked.connect(self.choose_img)
     self.enter_time.setCalendarPopup(True)
     self.enter_time.setDisplayFormat("yyyy-MM-dd hh:mm")
     self.inter = Interactor(DB_NAME, TABLE_NAME)
Ejemplo n.º 5
0
 def __init__(self, **traits):
     # The only reason we need the constructor is to make sure our container
     # gets notified of our being added to it.
     if traits.has_key("container"):
         container = traits.pop("container")
         Interactor.__init__(self, **traits)
         container.add(self)
     else:
         Interactor.__init__(self, **traits)
     return
Ejemplo n.º 6
0
 def __init__(self):
     super().__init__()
     self.setupUi(self)
     self.addButton.clicked.connect(self.add_notif)
     self.pushButton.clicked.connect(self.show_notif)
     self.params = {
         "Пропущенные": "show_missed",
         "Предстоящие по времени": "show_by_time",
         "Предстоящие по приоритету": "show_by_prior"
     }
     self.comboBox.addItems(list(self.params.keys()))
     self.inter = Interactor(DB_NAME, TABLE_NAME)
     self.delete_missed_btn.clicked.connect(self.delete_missed)
Ejemplo n.º 7
0
class Manager:
    def __init__(self):
        self.client = docker.from_env(timeout=86400)
        self.preparer = Preparer()
        self.searcher = Searcher()
        self.trainer = Trainer()
        self.interactor = Interactor()
        self.generate_save_tag = lambda tag, save_id: hashlib.sha256(
            (tag + save_id).encode()).hexdigest()

    def set_preparer_config(self, preparer_config):
        self.preparer.set_config(preparer_config)

    def set_searcher_config(self, searcher_config):
        self.searcher.set_config(searcher_config)

    def set_trainer_config(self, trainer_config):
        self.trainer.set_config(trainer_config)

    def set_interactor_config(self, interactor_config):
        self.interactor.set_config(interactor_config)

    def prepare(self, preparer_config=None):
        if preparer_config:
            self.set_preparer_config(preparer_config)
        self.preparer.prepare(self.client, COLLECTION_PATH_GUEST,
                              self.generate_save_tag)

    def search(self, searcher_config=None):
        if searcher_config:
            self.set_searcher_config(searcher_config)
        self.searcher.search(self.client, OUTPUT_PATH_GUEST, TOPIC_PATH_HOST,
                             TOPIC_PATH_GUEST, TEST_SPLIT_PATH_GUEST,
                             self.generate_save_tag)

    def train(self, trainer_config=None):
        if trainer_config:
            self.set_trainer_config(trainer_config)
        self.trainer.train(self.client, TOPIC_PATH_GUEST,
                           TEST_SPLIT_PATH_GUEST, VALIDATION_SPLIT_PATH_GUEST,
                           self.generate_save_tag)

    def interact(self, interactor_config=None):
        if interactor_config:
            self.set_interactor_config(interactor_config)
        self.interactor.interact(self.client, self.generate_save_tag)
Ejemplo n.º 8
0
    def __init__(self, config, src_vocab):
        super(Matposer, self).__init__()
        self.config = config

        d_row, N, dropout = self.config.d_row, self.config.N, self.config.dropout
        d_model, d_ff = self.config.d_model, self.config.d_ff

        inter = Interactor(d_model, d_ff, out_row=d_row, dropout=dropout)
        ff = PositionwiseFeedForward(d_model, d_ff, dropout)
        position = PositionalEncoding(d_model, dropout)

        self.encoder = Encoder(
            EncoderLayer(d_model, deepcopy(inter), deepcopy(ff), dropout), N)
        self.src_embed = nn.Sequential(Embeddings(d_model, src_vocab),
                                       deepcopy(position))

        self.fc = nn.Linear(d_model, self.config.output_size)

        self.softmax = nn.Softmax()
Ejemplo n.º 9
0
class Main(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.addButton.clicked.connect(self.add_notif)
        self.pushButton.clicked.connect(self.show_notif)
        self.params = {
            "Пропущенные": "show_missed",
            "Предстоящие по времени": "show_by_time",
            "Предстоящие по приоритету": "show_by_prior"
        }
        self.comboBox.addItems(list(self.params.keys()))
        self.inter = Interactor(DB_NAME, TABLE_NAME)
        self.delete_missed_btn.clicked.connect(self.delete_missed)

    def add_notif(self):
        self.next = Form()
        self.next.show()

    def delete_missed(self):
        self.inter.delete_req(f"""DELETE FROM {TABLE_NAME} WHERE DATETIME(date_time) < DATETIME('now')""")
        show_info("Пропущенные напоминания удалены")

    def show_notif(self):
        func = self.params.get(self.comboBox.currentText())
        if func == "show_missed":
            self.show_missed()
        if func == "show_by_time":
            self.show_by_time()
        if func == "show_by_prior":
            self.show_by_prior()

    def clear_layout(self, layout):
        for i in range(layout.count()):
            layout_item = layout.itemAt(i)
            if layout_item and layout_item.__class__.__name__ == "QHBoxLayout":
                deleteItemsOfLayout(layout_item.layout())
                layout.removeItem(layout_item)
            elif not layout_item:
                self.clear_layout(layout.layout())

    def convert_to_layout(self, item):
        res = QHBoxLayout()
        lbl1 = QLabel()
        lbl1.setText(" ".join(
            ["Название: " + item[0], "   Приоритет: " + str(item[1]), "   Дата и время: " + item[2] + "   Картинка"]))
        res.addWidget(lbl1)
        lbl2 = QLabel()
        if item[3] != self.inter.alt_img:
            name = item[3]
            os.chdir("media")
            pixmap = QPixmap(name)
            pixmap = pixmap.scaled(64, 64, QtCore.Qt.KeepAspectRatio)
            os.chdir("..")
            lbl2.setPixmap(pixmap)
            lbl2.resize(100, 100)
            res.addWidget(lbl2)
        else:
            lbl1.setText(lbl1.text() + " " + self.inter.alt_img)
        return res

    def add_notifs_to_layout(self, arr):
        self.clear_layout(self.notifications_layout)
        if len(list(arr)) == 0:
            show_info("Напоминаний не найдено")
        for i in arr:
            self.notifications_layout.addLayout(self.convert_to_layout(i))

    def show_missed(self):
        res = self.inter.get("""SELECT * FROM {} WHERE DATETIME(date_time) < DATETIME('now')""".format(TABLE_NAME))
        self.add_notifs_to_layout(res)

    def show_by_time(self):
        res = self.inter.get(
            """SELECT * FROM {} WHERE DATETIME(date_time) > DATETIME('now') ORDER BY date_time""".format(TABLE_NAME))
        self.add_notifs_to_layout(res)

    def show_by_prior(self):
        res = self.inter.get(
            """SELECT * FROM {} WHERE DATETIME(date_time) > DATETIME('now') ORDER BY prior""".format(TABLE_NAME))
        self.add_notifs_to_layout(res)