最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Python實(shí)現(xiàn)自動(dòng)關(guān)機(jī)小工具

 更新時(shí)間:2022年10月25日 08:10:33   作者:Python集中營(yíng)  
上班族經(jīng)常會(huì)遇到這樣情況,著急下班結(jié)果將關(guān)機(jī)誤點(diǎn)成重啟,或者臨近下班又通知開(kāi)會(huì),開(kāi)完會(huì)已經(jīng)遲了還要去給電腦關(guān)機(jī)。今天使用PyQt5做了個(gè)自動(dòng)關(guān)機(jī)的小工具,設(shè)置好關(guān)機(jī)時(shí)間然后直接提交即可,需要的可以參考一下

上班族經(jīng)常會(huì)遇到這樣情況,著急下班結(jié)果將關(guān)機(jī)誤點(diǎn)成重啟,或者臨近下班又通知開(kāi)會(huì),開(kāi)完會(huì)已經(jīng)遲了還要去給電腦關(guān)機(jī)。

今天使用PyQt5做了個(gè)自動(dòng)關(guān)機(jī)的小工具,設(shè)置好關(guān)機(jī)時(shí)間然后直接提交即可,下班就可以直接走人了。

有直接需要.exe可執(zhí)行應(yīng)用的話,直接到文末處獲取下載鏈接!

自動(dòng)關(guān)機(jī)小工具也支持了清除已經(jīng)設(shè)置好的關(guān)機(jī)時(shí)間,防止已經(jīng)設(shè)置好了關(guān)機(jī)時(shí)間重新調(diào)整時(shí)不知道怎么調(diào)整。

本應(yīng)用除了使用os的python標(biāo)準(zhǔn)庫(kù)來(lái)設(shè)置關(guān)機(jī),還引入了PyQt5的桌面應(yīng)用框架,通過(guò)實(shí)現(xiàn)自動(dòng)設(shè)置關(guān)機(jī)命令以及清除操作來(lái)完成。

# Importing the QThread, QDateTime, and pyqtSignal classes from the PyQt5.QtCore module.
from PyQt5.QtCore import QThread, QDateTime, pyqtSignal

# Importing the QIcon and QFont classes from the PyQt5.QtGui module.
from PyQt5.QtGui import QIcon, QFont

# Importing the QWidget, QLabel, QDateTimeEdit, QPushButton, QFormLayout, and QApplication classes from the
# PyQt5.QtWidgets module.
from PyQt5.QtWidgets import QWidget, QLabel, QDateTimeEdit, QPushButton, QFormLayout, QApplication

# Importing the os, sys, and time modules.
import os, sys, time

# Importing the images.py file.
import images

創(chuàng)建CloseCompUI的class類,用來(lái)實(shí)現(xiàn)自動(dòng)關(guān)機(jī)應(yīng)用的頁(yè)面布局,將UI相關(guān)以及對(duì)應(yīng)的槽函數(shù)寫(xiě)到這個(gè)類中。

# This class is a widget that contains a button and a text box. When the button is clicked, the text box is filled with
# the closest company name to the one entered
class CloseCompUI(QWidget):
    def __init__(self):
        """
        A constructor. It is called when an object is created from a class and it allows the class to initialize the
        attributes of a class.
        """
        super(CloseCompUI, self).__init__()
        self.init_ui()

    def init_ui(self):
        """
        This function initializes the UI.
        """
        self.setWindowTitle('自動(dòng)關(guān)機(jī)小工具  公眾號(hào):Python 集中營(yíng)')
        self.setWindowIcon(QIcon(':/comp.ico'))
        self.setFixedWidth(380)
        self.setFixedHeight(120)

        self.is_close = False

        self.shutdown_time_lab = QLabel()
        self.shutdown_time_lab.setText('設(shè)置關(guān)機(jī)時(shí)間:')

        self.shutdown_time_in = QDateTimeEdit(QDateTime.currentDateTime())
        self.shutdown_time_in.setDisplayFormat('yyyy-MM-dd HH:mm:ss')
        self.shutdown_time_in.setCalendarPopup(True)

        self.submit_btn = QPushButton()
        self.submit_btn.setText('提交關(guān)機(jī)')
        self.submit_btn.clicked.connect(self.submit_btn_click)

        self.clear_btn = QPushButton()
        self.clear_btn.setText('清除關(guān)機(jī)')
        self.clear_btn.clicked.connect(self.clear_btn_click)

        self.show_message_lab = QLabel()
        self.show_message_lab.setText('更多免費(fèi)小工具源碼獲取請(qǐng)前往公眾號(hào):Python 集中營(yíng)!')
        self.show_message_lab.setFont(QFont('黑體', 8))

        fbox = QFormLayout()
        fbox.addRow(self.shutdown_time_lab, self.shutdown_time_in)
        fbox.setSpacing(15)
        fbox.addRow(self.clear_btn, self.submit_btn)
        fbox.addRow(self.show_message_lab)

        self.thread_ = CloseCompThread(self)
        self.thread_.message.connect(self.show_message_lab_click)

        self.setLayout(fbox)

上面的就是已經(jīng)設(shè)置好的界面布局及需要的組件信息,然后將組件信息以及信號(hào)量關(guān)聯(lián)到槽函數(shù)上實(shí)現(xiàn)相應(yīng)的動(dòng)態(tài)操作。

下面是所有相關(guān)的槽函數(shù),同樣這些槽函數(shù)是放在CloseCompUI的class中的。

def show_message_lab_click(self, message):
    self.show_message_lab.setText(message + ',公眾號(hào):Python 集中營(yíng)!')

def submit_btn_click(self):
    if self.shutdown_time_in.text():
        self.is_close = True
        self.thread_.start()
    else:
        self.show_message_lab_click('請(qǐng)先設(shè)置關(guān)機(jī)時(shí)間')

def clear_btn_click(self):
    self.is_close = False
    self.thread_.start()

創(chuàng)建CloseCompThread的class類,作為單獨(dú)的子線程獨(dú)立運(yùn)行不影響主線程的執(zhí)行,將所有的業(yè)務(wù)模塊(具體的關(guān)機(jī)實(shí)現(xiàn))寫(xiě)到該線程中。

# This class is a QThread that runs a function that takes a list of strings and returns a list of strings
class CloseCompThread(QThread):
    message = pyqtSignal(str)

    def __init__(self, parent=None):
        """
        A constructor that initializes the class.

        :param parent: The parent widget
        """
        super(CloseCompThread, self).__init__(parent)
        self.parent = parent
        self.working = True

    def __del__(self):
        """
        If the shutdown time is set, the shutdown thread is started, otherwise the message is displayed
        """
        self.working = False
        self.wait()

    def run(self):
        """
        *|CURSOR_MARCADOR|*
        """
        try:
            is_close = self.parent.is_close
            print(is_close)
            if is_close is True:
                shutdown_time_in = self.parent.shutdown_time_in.text()
                t = time.strptime(shutdown_time_in, "%Y-%m-%d %H:%M:%S")
                t1 = int(time.mktime(t))
                t0 = int(time.time())
                num = t1 - t0
                if num > 0:
                    os.system('shutdown -s -t %d' % num)
                    self.message.emit("此電腦將在%s關(guān)機(jī)" % shutdown_time_in)
                else:
                    self.message.emit("關(guān)機(jī)時(shí)間不能小于當(dāng)前操作系統(tǒng)時(shí)間")
            else:
                os.system('shutdown -a')
                self.message.emit("已經(jīng)清除自動(dòng)關(guān)機(jī)設(shè)置")
        except:
            self.message.emit("提交/清除自動(dòng)關(guān)機(jī)出現(xiàn)錯(cuò)誤")

開(kāi)發(fā)子線程CloseCompThread的業(yè)務(wù)實(shí)現(xiàn)后基本上已經(jīng)大功告成了,接下來(lái)使用main函數(shù)直接整個(gè)桌面啟動(dòng)就OK了。

# A common idiom in Python to use this to guard the main body of your code.
if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = CloseCompUI()
    main.show()
    sys.exit(app.exec_())

上述自動(dòng)關(guān)機(jī)小工具應(yīng)用中所有的代碼塊已經(jīng)過(guò)測(cè)試,可以直接啟動(dòng)使用。應(yīng)用中只使用了一個(gè)PyQt5的python非標(biāo)準(zhǔn)庫(kù)需要安裝,其他的不需要安裝。

到此這篇關(guān)于基于Python實(shí)現(xiàn)自動(dòng)關(guān)機(jī)小工具的文章就介紹到這了,更多相關(guān)Python自動(dòng)關(guān)機(jī)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 基于PyQt5制作一個(gè)數(shù)據(jù)圖表生成器

    基于PyQt5制作一個(gè)數(shù)據(jù)圖表生成器

    這篇文章主要介紹了如何利用PyQT5制作一個(gè)數(shù)據(jù)圖表生成器,可以通過(guò)Pyecharts模塊生成可視化的html數(shù)據(jù)圖表,感興趣的小伙伴可以跟隨小編學(xué)習(xí)一下
    2022-02-02
  • python pandas中DataFrame類型數(shù)據(jù)操作函數(shù)的方法

    python pandas中DataFrame類型數(shù)據(jù)操作函數(shù)的方法

    下面小編就為大家分享一篇python pandas中DataFrame類型數(shù)據(jù)操作函數(shù)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-04-04
  • 教你使用Python?的?Template?類生成文件報(bào)告

    教你使用Python?的?Template?類生成文件報(bào)告

    這篇文章主要介紹了用?Python?的?Template?類生成文件報(bào)告,在閱讀本文時(shí),您不僅學(xué)習(xí)了Python字符串的基本知識(shí),Template類以及使用它的原因,而且還實(shí)現(xiàn)了第一個(gè)文件報(bào)告腳本,需要的朋友可以參考下
    2022-08-08
  • python數(shù)據(jù)結(jié)構(gòu)之二叉樹(shù)的建立實(shí)例

    python數(shù)據(jù)結(jié)構(gòu)之二叉樹(shù)的建立實(shí)例

    這篇文章主要介紹了python數(shù)據(jù)結(jié)構(gòu)之二叉樹(shù)的建立實(shí)例,采用了類似遞歸方式建立,需要的朋友可以參考下
    2014-04-04
  • python 發(fā)送qq郵件的示例

    python 發(fā)送qq郵件的示例

    這篇文章主要介紹了python 發(fā)送qq郵件的示例,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下
    2021-03-03
  • 基于Python?+?PyQt搭建可視化頁(yè)面的詳細(xì)教程

    基于Python?+?PyQt搭建可視化頁(yè)面的詳細(xì)教程

    PyQt是一個(gè)Python綁定庫(kù),它是基于Qt庫(kù)的,PyQt提供了一整套豐富的組件,包括窗口、按鈕、菜單、列表框等,以及事件處理、布局管理、網(wǎng)絡(luò)通信等多種功能,本文介紹了基于Python?+?PyQt搭建可視化頁(yè)面的詳細(xì)教程,需要的朋友可以參考下
    2024-07-07
  • Python MySQL 日期時(shí)間格式化作為參數(shù)的操作

    Python MySQL 日期時(shí)間格式化作為參數(shù)的操作

    這篇文章主要介紹了Python MySQL 日期時(shí)間格式化作為參數(shù)的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03
  • PyTorch搭建CNN實(shí)現(xiàn)風(fēng)速預(yù)測(cè)

    PyTorch搭建CNN實(shí)現(xiàn)風(fēng)速預(yù)測(cè)

    PyTorch是一個(gè)開(kāi)源的Python機(jī)器學(xué)習(xí)庫(kù),基于Torch,用于自然語(yǔ)言處理等應(yīng)用程序。它不僅能夠?qū)崿F(xiàn)強(qiáng)大的GPU加速,同時(shí)還支持動(dòng)態(tài)神經(jīng)網(wǎng)絡(luò)。本文將介紹PyTorch搭建CNN如何實(shí)現(xiàn)風(fēng)速預(yù)測(cè),感興趣的可以學(xué)習(xí)一下
    2021-12-12
  • pytorch模型的保存加載與續(xù)訓(xùn)練詳解

    pytorch模型的保存加載與續(xù)訓(xùn)練詳解

    這篇文章主要為大家介紹了pytorch模型的保存加載與續(xù)訓(xùn)練詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • python3實(shí)現(xiàn)指定目錄下文件sha256及文件大小統(tǒng)計(jì)

    python3實(shí)現(xiàn)指定目錄下文件sha256及文件大小統(tǒng)計(jì)

    這篇文章主要為大家詳細(xì)介紹了python3實(shí)現(xiàn)指定目錄下文件sha256及文件大小統(tǒng)計(jì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-02-02

最新評(píng)論

蒲江县| 天镇县| 延川县| 曲沃县| 晋中市| 大宁县| 清原| 台南县| 佛坪县| 定安县| 黄冈市| 舟山市| 崇文区| 剑川县| 霍林郭勒市| 霍州市| 宜丰县| 昆明市| 新竹市| 铜梁县| 海盐县| 西贡区| 儋州市| 榆林市| 宜兰县| 垣曲县| 天门市| 苗栗市| 陇西县| 上犹县| 沈丘县| 买车| 莲花县| 隆昌县| 中超| 贡山| 康乐县| 平南县| 鄯善县| 呼和浩特市| 寿宁县|