Exemple #1
0
def mk_pixiv_inputs(master=None):
    url = NamedInput(master, name="用户主页地址")
    username = NamedInput(master, name="Pixiv账户名(需要登录才能下载)")
    password = PasswordInput(master, name="登录密码")
    proxy = ProxyInput(master, name="代理地址(支持http/https/socks5, 可不填)")
    save_path = FileBrowse(master, store_name="pixiv_save_path")
    return url, username, password, proxy, save_path
Exemple #2
0
    def __init__(self, *args, **kwargs):
        super(PinryImporterGUI, self).__init__(*args, **kwargs)

        self._url = NamedInput(self, name="Pinry部署地址")
        self._min_size = NamedInput(self, name="最小上传大小(KB)(低于此值的文件不上传,不限制请留空)")
        self._username = NamedInput(self, name="用户名")
        self._password = PasswordInput(self, name="密码")
        self._csv_file = FilePathBrowse(self,
                                        store_name="import_csv",
                                        text_label="CSV文件文件路径")
        self.btn_group = self.build_buttons()
        self._importer = None
        self.progress = ProgressBar(self)
        self.status = StatusBar(self)
        self.start_update()
Exemple #3
0
def mk_normal_inputs(master=None, store_name=None, user_home_name=None):
    url = NamedInput(master, name=user_home_name or "用户主页地址 ")
    save_path = FileBrowse(master, store_name=store_name)
    return url, save_path
Exemple #4
0
class PinryImporterGUI(tk.Frame):

    title = "导入到Pinry"

    def __init__(self, *args, **kwargs):
        super(PinryImporterGUI, self).__init__(*args, **kwargs)

        self._url = NamedInput(self, name="Pinry部署地址")
        self._min_size = NamedInput(self, name="最小上传大小(KB)(低于此值的文件不上传,不限制请留空)")
        self._username = NamedInput(self, name="用户名")
        self._password = PasswordInput(self, name="密码")
        self._csv_file = FilePathBrowse(self,
                                        store_name="import_csv",
                                        text_label="CSV文件文件路径")
        self.btn_group = self.build_buttons()
        self._importer = None
        self.progress = ProgressBar(self)
        self.status = StatusBar(self)
        self.start_update()

    def _get_importer(self):
        min_size = self._min_size.get_input()
        if min_size:
            try:
                min_size = int(min_size)
            except Exception:
                info("最小文件上传大小应该是整数")
        else:
            min_size = None
        return PinryImporter(
            base_url=self._url.get_input(),
            username=self._username.get_input(),
            password=self._password.get_input(),
            min_upload_size_kb=min_size,
        )

    def build_buttons(self):
        btn_args = dict(height=1, )
        btn_group = tk.Frame(self)

        buttons = [
            tk.Button(btn_group, text=text, command=command, **btn_args)
            for text, command in (
                ("测试登录", self._test_login),
                ("开始导入", self._start_import),
            )
        ]

        for index, btn in enumerate(buttons):
            btn.grid(column=index, row=0, sticky=tk.N)

        btn_group.pack(fill=tk.BOTH, expand=1)
        return btn_group

    def _test_login(self):
        importer = self._get_importer()
        if importer.test_login() is True:
            info("登录成功")
        else:
            info("情检查用户名密码以及部署路径是否可访问")

    def _start_import(self):
        self._importer = self._get_importer()
        run_as_thread(self._importer.do_import,
                      self._csv_file.get_path(),
                      name="import2pinry")

    def start_update(self):
        run_as_thread(self._update_loop)

    def _update_loop(self):
        while True:
            time.sleep(0.1)
            self.update_progress()

    def update_progress(self):
        if self._importer is not None:
            self.progress.update_progress(
                self._importer.done_pins,
                self._importer.total_pins,
            )
            self.status.set(self._importer.status_text())
        else:
            self.progress.update_progress(0, 0)
            self.status.set("待机...")