【python+pyside2】图形用户界面(跟pyqt5差不多)

在某站上看的白月黑羽的视频简单学习了一下,然后随便写了一个执行自动化脚本的工具(这功能有点鸡肋,写着玩的),记录一下代码。
在这里插入图片描述

import traceback
from PySide2 import QtCore
from PySide2.QtWidgets import QApplication, QAbstractItemView
from PySide2.QtUiTools import QUiLoader
from PySide2.QtGui import QIcon
from selenium import webdriver
import time
import warnings
from selenium.webdriver.chrome.options import Options
from threading import Thread

class Stats:

    def __init__(self):
        self.ui = QUiLoader().load('main.ui')
        self.ui.setWindowIcon(QIcon('icon.png'))
        self.ui.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowCloseButtonHint)
        self.ui.setFixedSize(self.ui.width(), self.ui.height())
        self.ui.listWidget_weixuan.addItems(
            [self.查询需求.__name__, self.新建项目.__name__, self.修改文档.__name__, self.等待时间.__name__])
        self.ui.listWidget_weixuan.setSelectionMode(QAbstractItemView.MultiSelection)
        self.ui.listWidget_yixuan.setSelectionMode(QAbstractItemView.MultiSelection)
        self.ui.pushButton_xuanze.clicked.connect(self.button_xuanze)
        self.ui.pushButton_quxiao.clicked.connect(self.button_quxiao)
        self.ui.pushButton_zhixing.clicked.connect(self.button_zhixing)

    def button_xuanze(self):
        a = self.ui.listWidget_weixuan.selectedItems()
        list1 = []
        for l in a:
            list1.append(l.text())
        self.ui.listWidget_yixuan.addItems(list1)

        a = self.ui.listWidget_weixuan.selectedIndexes()
        list = []
        for i in a:
            list.append(i.row())
        for j in range(len(list)):
            list.sort()
            self.ui.listWidget_weixuan.takeItem(list[j] - j)

    def button_quxiao(self):
        a = self.ui.listWidget_yixuan.selectedItems()
        list1 = []
        for l in a:
            list1.append(l.text())
        self.ui.listWidget_weixuan.addItems(list1)

        a = self.ui.listWidget_yixuan.selectedIndexes()
        list = []
        for i in a:
            list.append(i.row())
        for j in range(len(list)):
            list.sort()
            self.ui.listWidget_yixuan.takeItem(list[j] - j)


    def button_zhixing(self):
        thread = Thread(target=self.test)
        thread.start()
    def test(self):
        self.ui.progressBar.setRange(0,0)
        count = self.ui.listWidget_yixuan.count()

        for i in range(count):
            a = self.ui.listWidget_yixuan.item(i).text()
            code ='stats.' + a + '()'
            exec(code)
        self.ui.progressBar.setRange(100, 100)
        # self.ui.progressBar.reset()


    def 查询需求(self):
        try:
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('******************查询需求******************')
            time.sleep(1)
            warnings.simplefilter('ignore', ResourceWarning)
            # chrome_options = Options()
            # chrome_options.add_argument('--headless')
            # self.driver = webdriver.Chrome(options=chrome_options)
            self.driver=webdriver.Chrome()
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('浏览器打开正常')
            time.sleep(1)
            self.driver.maximize_window()
            self.driver.implicitly_wait(15)
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('窗口最大化正常')
            time.sleep(1)
            self.driver.get('http:******点赞并回复可见********')
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('登陆禅道')
            time.sleep(1)
            self.driver.find_element_by_xpath('//*[@id="account"]').send_keys('********')
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('输入用户名')
            time.sleep(1)
            self.driver.find_element_by_xpath('//*[@id="loginPanel"]/div/div[2]/form/table/tbody/tr[2]/td/input').send_keys(
                '*********')
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('输入密码')
            time.sleep(1)
            self.driver.quit()
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('关闭浏览器')
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('******************执行结束******************')
            time.sleep(1)
        except Exception as e:
            self.driver.quit()
            self.ui.textBrowser_jieguo.append(traceback.format_exc())
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('******************执行失败******************')
            time.sleep(1)

    def 新建项目(self):
        try:
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('******************新建项目******************')
            time.sleep(1)
            warnings.simplefilter('ignore', ResourceWarning)
            # chrome_options = Options()
            # chrome_options.add_argument('--headless')
            # self.driver = webdriver.Chrome(options=chrome_options)
            self.driver = webdriver.Chrome()
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('浏览器打开正常')
            time.sleep(1)
            self.driver.maximize_window()
            self.driver.implicitly_wait(15)
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('窗口最大化正常')
            time.sleep(1)
            self.driver.get('http:*******点赞并回复可见**********')
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('登陆禅道')
            time.sleep(1)
            self.driver.find_element_by_xpath('//*[@id="accountqqqqqqqqqqqqq"]').send_keys('******')
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('输入用户名')
            time.sleep(1)
            self.driver.find_element_by_xpath(
                '//*[@id="loginPanel"]/div/div[2]/form/table/tbody/tr[2]/td/input').send_keys(
                '*******')
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('输入密码')
            time.sleep(1)
            self.driver.quit()
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('关闭浏览器')
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('******************执行结束******************')
            time.sleep(1)
        except Exception as e:
            self.driver.quit()
            self.ui.textBrowser_jieguo.append(traceback.format_exc())
            time.sleep(1)
            self.ui.textBrowser_jieguo.append('******************执行失败******************')
            time.sleep(1)

    def 修改文档(self):
        pass

    def 等待时间(self):
        pass

app = QApplication([])
stats = Stats()
stats.ui.show()
app.exec_()

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值