import threading
|
|
import wx
|
|
import setting
|
from comment import CommentManager
|
|
def show_warning(content, click=None):
|
toastone = wx.MessageDialog(None, content, "提示", wx.YES_DEFAULT | wx.ICON_WARNING)
|
if toastone.ShowModal() == wx.ID_YES: # 如果点击了提示框的确定按钮
|
if click is not None:
|
click()
|
toastone.Destroy()
|
|
|
def show_info(content, click=None):
|
toastone = wx.MessageDialog(None, content, "提示", wx.YES_DEFAULT | wx.ICON_INFORMATION)
|
if toastone.ShowModal() == wx.ID_YES: # 如果点击了提示框的确定按钮
|
click()
|
toastone.Destroy()
|
|
class MainFrame(wx.Frame):
|
def __bind_event(self):
|
def on_select_chrome_file(event):
|
open_file_dialog = wx.FileDialog(self, "选择文件", "", "",
|
"所有文件 (*.exe)|*.exe",
|
wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
|
# 显示对话框并等待用户操作
|
if open_file_dialog.ShowModal() == wx.ID_OK:
|
# 获取用户选择的文件路径
|
path = open_file_dialog.GetPath()
|
self.text_chrome_path.SetValue(path)
|
# 销毁对话框
|
open_file_dialog.Destroy()
|
|
def on_select_chromdriver_file(event):
|
open_file_dialog = wx.FileDialog(self, "选择文件", "", "",
|
"所有文件 (*.exe)|*.exe",
|
wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
|
# 显示对话框并等待用户操作
|
if open_file_dialog.ShowModal() == wx.ID_OK:
|
# 获取用户选择的文件路径
|
path = open_file_dialog.GetPath()
|
self.text_chromedriver_path.SetValue(path)
|
# 销毁对话框
|
open_file_dialog.Destroy()
|
|
def start_comment(event):
|
threading.Thread(target=lambda: self.comment_manager.start_process_comment(), daemon=True).start()
|
|
def on_save(event):
|
# 保存配置
|
chrome_path = self.text_chrome_path.GetValue()
|
if not chrome_path:
|
show_warning("请填写谷歌浏览器路径")
|
return
|
chromedriver_path = self.text_chromedriver_path.GetValue()
|
if not chromedriver_path:
|
show_warning("请填写谷歌浏览器驱动路径")
|
return
|
like = self.cb_like.GetValue()
|
comment = self.cb_comment.GetValue()
|
comment_templates = self.text_comments.GetValue()
|
setting.set_click_like(like)
|
setting.set_chrome_path(chrome_path)
|
setting.set_chromedriver_path(chromedriver_path)
|
setting.set_comment_templates(comment_templates)
|
setting.set_reply_comment(comment)
|
show_info("保存成功")
|
self.Bind(wx.EVT_CLOSE, self.OnFrameClose)
|
self.btn_start_comment.Bind(wx.EVT_BUTTON, start_comment)
|
self.btn_chrome_path.Bind(wx.EVT_BUTTON, on_select_chrome_file)
|
self.btn_chromedriver_path.Bind(wx.EVT_BUTTON, on_select_chromdriver_file)
|
self.btn_save.Bind(wx.EVT_BUTTON, on_save)
|
|
def __init(self):
|
self.comment_manager = CommentManager()
|
self.cb_like.SetValue(setting.is_click_like())
|
self.cb_comment.SetValue(setting.is_reply_comment())
|
self.text_comments.SetValue(setting.get_comment_templates())
|
self.text_chrome_path.SetValue(setting.get_chrome_path())
|
self.text_chromedriver_path.SetValue(setting.get_chromedriver_path())
|
|
|
|
def __init__(self):
|
def create_label(text):
|
return wx.StaticText(self, wx.ID_ANY, text, size=wx.Size(150, -1), style=wx.ALIGN_RIGHT)
|
|
wx.Frame.__init__(self, None, -1, "视频号助手",
|
size=(600, 500))
|
self.SetBackgroundColour(wx.Colour(224, 224, 224))
|
boxsier = wx.BoxSizer(wx.VERTICAL)
|
# 浏览器地址
|
ss = wx.BoxSizer(wx.HORIZONTAL)
|
ss.Add(create_label("Chrome浏览器路径:"), 0, wx.ALIGN_CENTER_VERTICAL)
|
self.text_chrome_path = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(-1, -1))
|
ss.Add(self.text_chrome_path, 1, wx.RIGHT, 10)
|
self.btn_chrome_path = wx.Button(self, wx.ID_ANY, "选择文件")
|
ss.Add(self.btn_chrome_path, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
|
boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
|
# 浏览器驱动地址
|
ss = wx.BoxSizer(wx.HORIZONTAL)
|
ss.Add(create_label("Chrome浏览器驱动路径:"), 0, wx.ALIGN_CENTER_VERTICAL)
|
self.text_chromedriver_path = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(-1, -1))
|
ss.Add(self.text_chromedriver_path, 1, wx.RIGHT, 10)
|
self.btn_chromedriver_path = wx.Button(self, wx.ID_ANY, "选择文件")
|
ss.Add(self.btn_chromedriver_path, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
|
boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
|
|
# 是否点赞
|
ss = wx.BoxSizer(wx.HORIZONTAL)
|
ss.Add(create_label("是否点赞:"), 0, wx.ALIGN_CENTER_VERTICAL)
|
self.cb_like = wx.CheckBox(self, wx.ID_ANY, "")
|
ss.Add(self.cb_like, 0, wx.ALIGN_CENTER_VERTICAL)
|
boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
|
|
# 是否评论
|
ss = wx.BoxSizer(wx.HORIZONTAL)
|
ss.Add(create_label("是否评论:"), 0, wx.ALIGN_CENTER_VERTICAL)
|
self.cb_comment = wx.CheckBox(self, wx.ID_ANY, "")
|
ss.Add(self.cb_comment, 0, wx.ALIGN_CENTER_VERTICAL)
|
boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
|
|
# 评论内容
|
ss = wx.BoxSizer(wx.HORIZONTAL)
|
ss.Add(create_label("评论模版:"), 0)
|
self.text_comments = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(-1, 150), style=wx.TE_MULTILINE)
|
ss.Add(self.text_comments, 1, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
|
boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
|
boxsier.Add(wx.StaticText(self, wx.ID_ANY, "模版与内容之间采用#分隔,如: 谢谢$#[昵称]不客气\n变量:[昵称]\n备注:$-结尾 ^-开始"), 0, wx.LEFT,
|
150)
|
|
self.btn_save = wx.Button(self, wx.ID_ANY, "保存")
|
boxsier.Add(create_label(""))
|
boxsier.Add(self.btn_save, 0, wx.LEFT, 150)
|
|
self.btn_start_comment = wx.Button(self, wx.ID_ANY, "开始")
|
boxsier.Add(self.btn_start_comment)
|
self.SetSizer(boxsier)
|
self.__init()
|
self.__bind_event()
|
|
def OnFrameClose(self, evt):
|
print("页面关闭")
|
self.comment_manager.close()
|
evt.Skip()
|
|
|
class mainApp(wx.App):
|
|
def __init_data(self):
|
pass
|
|
def OnInit(self):
|
self.SetAppName("视频号助手")
|
self.__init_data()
|
|
MainFrame().Show()
|
|
return True
|
|
|
# cd D:\workspace\python\wechat_helper
|
# D:\workspace\python\wechat_helper\venv\Scripts\pyinstaller.exe main.spec
|
if __name__ == "__main__":
|
app = mainApp()
|
app.MainLoop()
|