+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2019-07(6)

2019-08(116)

2019-09(98)

2019-10(17)

2019-11(5)

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

发布于2020-09-15 21:35     阅读(885)     评论(0)     点赞(25)     收藏(2)


0

1

2

3

4

5

6

7

8

9

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

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_()

原文链接:https://blog.csdn.net/qq_42460470/article/details/108583274

0

1

2

3

4

5

6

7

8

9



所属网站分类: 技术文章 > 博客

作者:python是我的菜

链接: https://www.pythonheidong.com/blog/article/524674/f16d78561045bd514c8b/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

25 0
收藏该文
已收藏

评论内容:(最多支持255个字符)