Пример #1
0
    def __init__(self, *args, **kwargs):
        super().__init__()

        self.ini = "resources.ini"

        icons_path = read_cfg(self.ini, 'image')
        self.icons = {}
        for key, value in icons_path.items():
            self.icons[key] = QtGui.QIcon(value)
        self.msg = read_cfg(self.ini, "msg")

        self.db = args[0] if args else kwargs["db"]
        self.keys = args[1] if args else kwargs["keys"]
        self.username = args[2] if args else kwargs["username"]
        self.ver = "v." + args[3] if args else kwargs["version"]
        # self.app_style = args[4] if args else kwargs["app_style"]

        self.widgets = {}
        self.tbl = None
        self.last_widget = None
        self.passwd_length = 6  # starting length for password
        # set tables_name name for data base
        self.tables_name = read_cfg(self.ini, "table_db")

        self.create_widgets()
        self.set_signals()
        self.set_layouts()
        self.set_window()

        self.show_accounts(self.tables_name["emails"])
        self.tray_icon.show()
        self.show()
Пример #2
0
    def create_widgets(self, account, slots, icon):
        """

        :param account: itarable object of string
        :param slots: list of dict
        :param icon: QtGui.QIcon
        :return:
        """
        tool_tip = read_cfg(self.ini, "tool_tip")

        menu = QtGui.QMenu()
        for i, slot in enumerate(slots):
            self.actions.append(
                QtGui.QAction(slot["icon"],
                              slot["name"], self)
            )
            self.connect(self.actions[i], QtCore.SIGNAL('triggered()'),
                         partial(slot["method"], self))
            menu.addAction(self.actions[i])

        if len(account) > 5:
            self.email = QtGui.QLabel(account[5])
            self.email.setToolTip(account[5])
            self.email.setTextInteractionFlags(
                QtCore.Qt.TextSelectableByKeyboard |
                QtCore.Qt.TextSelectableByMouse)
            self.email.setObjectName("labelEmail")
            self.widgets.append(self.email)

        holder_text = read_cfg(self.ini, "holder_text")
        self.service = QtGui.QLineEdit(account[1])
        self.service.setPlaceholderText(holder_text["service"])
        self.service.setMaxLength(50)
        # self.service.setProperty("mandatoryField", True)
        self.widgets.append(self.service)

        self.login = QtGui.QLineEdit(account[2])
        self.login.setPlaceholderText(holder_text["login"])
        self.login.setMaxLength(100)
        self.widgets.append(self.login)

        self.passwd = QtGui.QLineEdit(account[3])
        self.passwd.setObjectName("password")
        self.passwd.setPlaceholderText(holder_text["passwd"])
        self.passwd.setEchoMode(QtGui.QLineEdit.Password)
        self.passwd.setToolTip(tool_tip["passwd"])
        self.widgets.append(self.passwd)

        self.forgot = QtGui.QLineEdit(account[4])
        self.forgot.setMaxLength(500)
        self.forgot.setPlaceholderText(holder_text["forgot"])
        self.widgets.append(self.forgot)

        btn_name = read_cfg(self.ini, "btn_name")
        self.get = QtGui.QPushButton(icon, btn_name["actions"])
        self.get.setMenu(menu)
        self.get.setToolTip(tool_tip["action"])
        self.widgets.append(self.get)
Пример #3
0
    def __init__(self, *args, **kwargs):
        """
        Инстанс именно этого класса указан как self в параметрах выше
        :param args: db, keys, username, ver, app
        :param kwargs:
        :return:
        """
        super().__init__()
        # read settings
        self.ini = "resources.ini"
        icons_path = read_cfg(self.ini, 'image')
        self.tables_name = read_cfg(self.ini, "table_db")
        self.msg = read_cfg(self.ini, "msg")
        # get passed parameters
        self.db = args[0] if args else kwargs["db"]
        self.keys = args[1] if args else kwargs["keys"]
        self.username = args[2] if args else kwargs["username"]
        self.ver = "v." + args[3] if args else kwargs["version"]
        self.app = args[4] if args else kwargs["app"]
        # setup default parameters
        self.widgets = {}
        self.tbl = None
        self.last_widget = None
        self.passwd_length = 6  # starting length for password
        self.empty_label = [False, None]

        # TODO костыль !
        buf = read_cfg(self.ini, "animation_color")
        keys = buf.keys()
        self.animation_color = {}
        for key in keys:
            if key in "css" or key in "increment":
                self.animation_color[key] = buf[key]
                continue
            i = buf[key].split(",")
            for j in range(len(i)):
                i[j] = int(i[j])
            self.animation_color[key] = i

        self.icons = {}
        for key, value in icons_path.items():
            self.icons[key] = QtGui.QIcon(value)

        self.create_widgets()
        self.set_signals()
        self.set_layouts()
        self.set_window()
        self.tray_icon.show()
        self.show()
Пример #4
0
    def create_widgets(self):
        btn_caption = read_cfg(self.ini, "btn_name")
        tool_tip = read_cfg(self.ini, "tool_tip")

        self.tray_icon = QtGui.QSystemTrayIcon(self.icons["window"],
                                               parent=self)
        self.main_menu = QtGui.QMenu(parent=self)
        self.btn_add = QtGui.QPushButton(self.icons["add"], btn_caption["add"],
                                         parent=self)
        self.btn_add.setToolTip(tool_tip["add"])

        self.btn_genpasswd = QtGui.QPushButton(self.icons["random"],
                                               btn_caption["gen"], parent=self)
        self.btn_genpasswd.setObjectName("btnPwd")

        self.email_label = QtGui.QLabel(parent=self)

        self.edit = QtGui.QLineEdit(parent=self)
        self.edit.setObjectName("editPwd")
        self.edit.setToolTip(tool_tip["edit_pwd"])

        self.status_bar = QtGui.QStatusBar(parent=self)
        self.status_bar.addPermanentWidget(self.email_label)
        self.status_bar.addPermanentWidget(
            QtGui.QLabel(self.username, parent=self)
        )
        self.status_bar.addPermanentWidget(QtGui.QLabel(self.ver, parent=self))

        # setup main menu for btn_show
        menu_btn_show = QtGui.QMenu()
        for key, table in self.tables_name.items():
            try:
                action = QtGui.QAction(self.icons[key], table, self,
                                       triggered=partial(
                                           self.hide_show_accounts,
                                           table))
                action.setToolTip(tool_tip[key])
                menu_btn_show.addAction(action)
            except KeyError:
                continue

        self.btn_show = QtGui.QPushButton(self.icons["down"],
                                          btn_caption["show"], parent=self)
        self.btn_show.setToolTip(tool_tip["show"])
        self.btn_show.setMenu(menu_btn_show)
        values = chain(self.animation_color["hide"],
                       self.animation_color["hide"])
        qss = get_style_sheet(target=(self.animation_color["css"],))
        self.setStyleSheet(qss.format(*values))
Пример #5
0
    def form_add(self):
        # show form for add account
        if threading.active_count() > 4:
            return
        self.show_label_empty(False)
        btn_caption = read_cfg(self.ini, "btn_name")

        if self.tbl in self.tables_name["accounts"] and \
                not self.db.get_email_id():
            self.show_msg(self.msg["msg_form_add_error_1"])
            return
        account = ("add", None, None, None, None,)
        slots = (
            dict(name=btn_caption["commit"], method=self.box_commit,
                 icon=self.icons["commit"]),
            dict(name=btn_caption["del"], method=self.box_del,
                 icon=self.icons["del"])
        )
        index = "add"
        try:
            print(self.widgets[index])
            self.show_msg(self.msg["msg_form_add_error_2"])
        except KeyError:
            self.widgets[index] = BoxLayout(self.tbl,
                                            account,
                                            slots,
                                            self.icons["down"])
            self.box_connect(self.widgets[index])
            self.scroll_layout.addRow(self.widgets[index])
            self.animation_object(self.widgets[index], reverse=True)
Пример #6
0
    def form_add(self):
        # show form for add account
        btn_caption = read_cfg(self.ini, "btn_name")

        if self.tbl in self.tables_name["accounts"] and \
                not self.db.get_email_id():
            self.show_msg("First you need to choose email")
            return
        account = ("add", None, None, None, None,)
        slots = (
            dict(name=btn_caption["commit"], method=self.box_commit,
                 icon=self.icons["commit"]),
            dict(name=btn_caption["del"], method=self.box_del,
                 icon=self.icons["del"])
        )
        index = "add"
        try:
            print(self.widgets[index])
            self.show_msg("The form of addition is already displayed")
        except KeyError:
            self.widgets[index] = BoxLayout(self.tbl,
                                            account,
                                            slots,
                                            self.icons["down"])
            self.box_connect(self.widgets[index])
            self.scroll_layout.addRow(self.widgets[index])
            t = Thread(target=self.th)
            t.setDaemon(True)
            t.start()
Пример #7
0
 def set_window(self):
     wnd_params = read_cfg(self.ini, "window")
     self.setWindowIcon(self.icons["window"])
     self.setWindowTitle(wnd_params["name"])
     size = wnd_params["size"][1:-1].split(",")
     self.resize(int(size[1]), int(size[0]))
     self.setWindowFlags(self.windowFlags() |
                         QtCore.Qt.WindowStaysOnTopHint)
Пример #8
0
 def __init__(self):
     """
     Подключаемся к БД. Создаем курсор.
     :return:
     """
     db_config = read_cfg(file="config.ini",
                          section="mysql")
     self.tables = read_cfg("resources.ini", "table_db")
     try:
         super().__init__(**db_config)
         self.cursor = self.cursor()
         self.__userid = None
         self.__emailid = None
         self.__email_login = None
         self.all = False
         self.username = None
     except Error as e:
         print(e)
         raise RuntimeError()
Пример #9
0
    def box_flag_change(self, *args):
        args[0].flag = not args[0].flag
        tool_tip = read_cfg(self.ini, "tool_tip")
        btn_name = read_cfg(self.ini, "btn_name")
        if args[0].flag:
            self.box_connect(args[0])
            args[0].actions[0].setIcon(self.icons["unlocked"])
            args[0].actions[0].setText(btn_name["hide_pwd"])
            args[0].actions[0].setToolTip(tool_tip["hide_pwd"])

            args[0].passwd.setEchoMode(QtGui.QLineEdit.Normal)
            args[0].passwd.setText(args[1])
        else:
            self.box_connect(args[0], False)
            args[0].actions[0].setIcon(self.icons["locked"])
            args[0].actions[0].setText(btn_name["show_pwd"])
            args[0].actions[0].setToolTip(tool_tip["show_pwd"])

            args[0].passwd.setEchoMode(QtGui.QLineEdit.Password)
            args[0].passwd.setText(args[2] if len(args) == 3 else args[1])
Пример #10
0
    def __init__(self, db, app, parent=None):
        """

        :param db: instance db.DataBase
        :param app: QtGui.QApplication
        :param parent:
        :return:
        """
        super().__init__(parent)
        self.db = db
        self.pubkey = None
        self.privkey = None
        self.pubkey_in_md5 = None
        self.username = None
        self.app = app
        self.res = read_cfg("resources.ini", "welcome")
        self.icon_wnd = QtGui.QIcon(self.res["icon"])

        self.setWindowTitle(self.res["title"])
        self.setWindowIcon(self.icon_wnd)
        self.setFixedSize(250, 200)

        self.label = QtGui.QLabel(self.res["msg_welcome"])
        self.label.setObjectName("welcome")
        self.label.setWordWrap(True)

        self.edit = QtGui.QLineEdit()
        self.edit.setPlaceholderText(self.res["edit_holder_text"])

        self.btn_ok = QtGui.QPushButton(self.res["btn_ok"])

        self.btn_cancel = QtGui.QPushButton(self.res["btn_cancel"])

        self.box_label = QtGui.QHBoxLayout()
        self.box_label.addWidget(self.label)

        self.box_edit = QtGui.QHBoxLayout()
        self.box_edit.addWidget(self.edit)

        self.box_buttons = QtGui.QHBoxLayout()
        self.box_buttons.addWidget(self.btn_ok)
        self.box_buttons.addWidget(self.btn_cancel)

        self.vbox = QtGui.QVBoxLayout()
        self.vbox.addLayout(self.box_label)
        self.vbox.addLayout(self.box_edit)
        self.vbox.addLayout(self.box_buttons)

        self.setLayout(self.vbox)
        self.set_signals()
        self.set_animation()
        self.show()
Пример #11
0
    def __init__(self, db, parent=None):
        super(RegWnd, self).__init__(parent)

        self.res = read_cfg("resources.ini", "welcome")
        self.icon_wnd = QtGui.QIcon(self.res["icon"])

        self.setWindowTitle(self.res["title"])
        self.setWindowIcon(self.icon_wnd)
        self.setMaximumSize(250, 200)
        self.setMinimumSize(250, 200)

        self.label = QtGui.QLabel(self.res["msg_welcome"])
        self.label.setObjectName("welcome")
        self.label.setWordWrap(True)

        self.edit = QtGui.QLineEdit()
        self.edit.setPlaceholderText(self.res["edit_holder_text"])
        # self.edit.setMaxLength(20)

        self.btn_ok = QtGui.QPushButton(self.res["btn_ok"])

        self.btn_cancel = QtGui.QPushButton(self.res["btn_cancel"])

        self.box_label = QtGui.QHBoxLayout()
        self.box_label.addWidget(self.label)

        self.box_edit = QtGui.QHBoxLayout()
        self.box_edit.addWidget(self.edit)

        self.box_buttons = QtGui.QHBoxLayout()
        self.box_buttons.addWidget(self.btn_ok)
        self.box_buttons.addWidget(self.btn_cancel)

        self.vbox = QtGui.QVBoxLayout()
        self.vbox.addLayout(self.box_label)
        self.vbox.addLayout(self.box_edit)
        self.vbox.addLayout(self.box_buttons)

        self.setLayout(self.vbox)
        self.set_signals()

        self.db = db
        self.pubkey = None
        self.privkey = None
        self.pubkey_in_md5 = None
        self.username = None

        self.show()
Пример #12
0
        def create_slots(main):
            btn_caption = read_cfg(self.ini, "btn_name")
            slots_ = [
                dict(name=btn_caption["show_pwd"], method=main.box_get_passwd,
                     icon=main.icons["locked"]),
                dict(name=btn_caption["update"], method=main.box_update,
                     icon=main.icons["update"]),
                dict(name=btn_caption["del"], method=main.box_del,
                     icon=main.icons["trash"])
            ]

            if main.tables_name["emails"] in main.tbl:
                slots_.append(
                    dict(name=btn_caption["show_accounts"],
                         method=partial(
                             main.hide_show_accounts,
                             main.tables_name["accounts"]),
                         icon=main.icons["accounts_2"]
                         )
                )
            return slots_
Пример #13
0
    def generation_passwd(self):
        length = self.edit.text()
        if length and length.isdigit():
            self.passwd_length = int(length)
        elif not self.passwd_length:
            self.edit.setText("the length password is not specified")
            return
        tool_tip = read_cfg(self.ini, "tool_tip")
        self.btn_genpasswd.setToolTip(
            tool_tip["gen_pwd"].format(self.passwd_length))
        spec = '!@#$%&*?^'
        digits_ = digits
        all_symbols = spec + digits_ + ascii_letters

        count = 0
        res = []
        while count < self.passwd_length:
            res.append(choice(all_symbols))
            count += 1
        password = ''.join(res)
        self.edit.setText(password)
Пример #14
0
def check_version(version_info):
    def open_url(url):
        webbrowser.open(url)

    if version_info[0] not in __version__:
        text_update = read_cfg("resources.ini", "update")

        version_info = list(version_info)
        version_info.append(__version__)
        version_info.append("\n")

        info = text_update["text"].format(*version_info)

        app = QApplication([])

        btn_update = QPushButton(info, None)
        btn_update.clicked.connect(partial(open_url, version_info[1]))
        btn_update.show()

        app.exec_()
        return True
    else:
        return False