五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動態(tài)

Python PyQt5實戰(zhàn)項目之網(wǎng)速監(jiān)控器的實現(xiàn)

發(fā)布日期:2021-12-13 07:30 | 文章來源:源碼之家

簡介

看到了一個能夠輕松實現(xiàn)獲取系統(tǒng)運行的進程和系統(tǒng)利用率(包括CPU、內(nèi)存、磁盤、網(wǎng)絡(luò)等)信息的模塊–psutil模塊。這次利用psutil.net_io_counters()這個方法。

psutil模塊使用

>>> psutil.net_io_counters() # 獲取網(wǎng)絡(luò)讀寫字節(jié)/包的個數(shù)

snetio(bytes_sent=16775953, bytes_recv=712657945, packets_sent=216741, packets_recv=485775, errin=0, errout=0, dropin=0, dropout=0)

bytes_sent:上傳數(shù)據(jù)
bytes_recv: 接收數(shù)據(jù)

主界面

class NetWindows(QMainWindow):
 net_signal = pyqtSignal(str,str)
 def __init__(self):
  super(NetWindows,self).__init__()
  self.ui_init()  
  self.thread_init()

 def ui_init(self):
  self.setWindowTitle('網(wǎng)速')
  self.resize(200,80)
  self.setWindowOpacity(0.9) # 設(shè)置窗口透明度
  self.setWindowFlag(Qt.FramelessWindowHint) # 隱藏邊框
  self.setWindowFlag(Qt.WindowStaysOnTopHint) # 窗口始終顯示在最前面
  self.upload_icon = QLabel()
  self.upload_icon.setPixmap(QPixmap(':res/upload.png'))
  self.upload_icon.setScaledContents(True)
  self.download_icon = QLabel()
  self.download_icon.setPixmap(QPixmap(':res/download.png'))
  self.download_icon.setScaledContents(True)
  self.upload_text = QLabel()
  self.upload_text.setText('upload: ')
  self.download_text = QLabel()
  self.download_text.setText('download: ')
  self.upload_lab = QLabel()
  self.download_lab = QLabel()
  self.g_layout = QGridLayout()
  self.g_layout.addWidget(self.upload_icon,0,0,1,1)
  self.g_layout.addWidget(self.download_icon,1,0,1,1)
  self.g_layout.addWidget(self.upload_text,0,1,1,1)
  self.g_layout.addWidget(self.download_text,1,1,1,1)
  self.g_layout.addWidget(self.upload_lab,0,2,1,4)
  self.g_layout.addWidget(self.download_lab,1,2,1,4)
  self.widget = QWidget()
  self.widget.setLayout(self.g_layout)
  self.setCentralWidget(self.widget)
 def thread_init(self):
  self.net_thread = NetThread()
  self.net_thread.net_signal.connect(self.net_slot)
  self.net_thread.start(1000)
 def variate_init(self):
  self.upload_content = ''
  self.download_content = ''
 def net_slot(self,upload_content,download_content):
  self.upload_lab.setText(upload_content)
  self.download_lab.setText(download_content)
 
 def mousePressEvent(self, event):
  '''
  重寫按下事件
  ''' 
  self.start_x = event.x()
  self.start_y = event.y()
 def mouseMoveEvent(self, event):
  '''
  重寫移動事件
  '''  
  dis_x = event.x() - self.start_x
  dis_y = event.y() - self.start_y
  self.move(self.x()+dis_x, self.y()+dis_y)
  • mousePressEvent()

獲取鼠標按下時的坐標位置(相對于窗口左上角)

  • mouseMoveEvent()

當鼠標處于按下狀態(tài)并開始移動時,鼠標離窗口左上角的位置會不斷更新并保存在event.x()和event.y()中。
我們將更新后的x和y值不斷減去鼠標按下時的坐標位置,就可以知道鼠標移動的距離。最后再調(diào)用move方法將窗口當前坐標加上移動距離即可

網(wǎng)速線程

class NetThread(QThread):
 net_signal = pyqtSignal(str,str)
 def __init__(self):
  super(NetThread,self).__init__()
 def net_func(self):
  parameter = psutil.net_io_counters()
  recv1 = parameter[1] #接收數(shù)據(jù)
  send1 = parameter[0] #上傳數(shù)據(jù)
  time.sleep(1)  # 每隔1s監(jiān)聽端口接收數(shù)據(jù)
  parameter = psutil.net_io_counters()
  recv2 = parameter[1]
  send2 = parameter[0]
  self.upload_content = '{:.1f} kb/s.'.format((send2 - send1) / 1024.0)
  self.download_content = '{:.1f} kb/s.'.format((recv2 - recv1) / 1024.0)
 def run(self):
  while(1):
self.net_func()
self.net_signal.emit(self.upload_content,self.download_content)
time.sleep(1)

全部代碼

import sys
import time
import psutil
from PyQt5.QtWidgets import QApplication, QHBoxLayout, QMainWindow, QWidget, QFrame, QLabel, QVBoxLayout, QGridLayout
from PyQt5.QtCore import Qt, pyqtSignal, QThread
from PyQt5.QtGui import QPixmap
import res
class NetWindows(QMainWindow):
 net_signal = pyqtSignal(str,str)
 def __init__(self):
  super(NetWindows,self).__init__()
  self.ui_init()  
  self.thread_init()

 def ui_init(self):
  self.setWindowTitle('網(wǎng)速')
  self.resize(200,80)
  self.setWindowOpacity(0.9) # 設(shè)置窗口透明度
  self.setWindowFlag(Qt.FramelessWindowHint) # 隱藏邊框
  self.setWindowFlag(Qt.WindowStaysOnTopHint) # 窗口始終顯示在最前面
  self.upload_icon = QLabel()
  self.upload_icon.setPixmap(QPixmap(':res/upload.png'))
  self.upload_icon.setScaledContents(True)
  self.download_icon = QLabel()
  self.download_icon.setPixmap(QPixmap(':res/download.png'))
  self.download_icon.setScaledContents(True)
  self.upload_text = QLabel()
  self.upload_text.setText('upload: ')
  self.download_text = QLabel()
  self.download_text.setText('download: ')
  self.upload_lab = QLabel()
  self.download_lab = QLabel()
  self.g_layout = QGridLayout()
  self.g_layout.addWidget(self.upload_icon,0,0,1,1)
  self.g_layout.addWidget(self.download_icon,1,0,1,1)
  self.g_layout.addWidget(self.upload_text,0,1,1,1)
  self.g_layout.addWidget(self.download_text,1,1,1,1)
  self.g_layout.addWidget(self.upload_lab,0,2,1,4)
  self.g_layout.addWidget(self.download_lab,1,2,1,4)
  self.widget = QWidget()
  self.widget.setLayout(self.g_layout)
  self.setCentralWidget(self.widget)
 def thread_init(self):
  self.net_thread = NetThread()
  self.net_thread.net_signal.connect(self.net_slot)
  self.net_thread.start(1000)
 def variate_init(self):
  self.upload_content = ''
  self.download_content = ''
 def net_slot(self,upload_content,download_content):
  self.upload_lab.setText(upload_content)
  self.download_lab.setText(download_content)
 
 def mousePressEvent(self, event):
  '''
  重寫按下事件
  ''' 
  self.start_x = event.x()
  self.start_y = event.y()
 def mouseMoveEvent(self, event):
  '''
  重寫移動事件
  '''  
  dis_x = event.x() - self.start_x
  dis_y = event.y() - self.start_y
  self.move(self.x()+dis_x, self.y()+dis_y)
class NetThread(QThread):
 net_signal = pyqtSignal(str,str)
 def __init__(self):
  super(NetThread,self).__init__()
 def net_func(self):
  parameter = psutil.net_io_counters()
  recv1 = parameter[1] #接收數(shù)據(jù)
  send1 = parameter[0] #上傳數(shù)據(jù)
  time.sleep(1)  # 每隔1s監(jiān)聽端口接收數(shù)據(jù)
  parameter = psutil.net_io_counters()
  recv2 = parameter[1]
  send2 = parameter[0]
  self.upload_content = '{:.1f} kb/s.'.format((send2 - send1) / 1024.0)
  self.download_content = '{:.1f} kb/s.'.format((recv2 - recv1) / 1024.0)
 def run(self):
  while(1):
self.net_func()
self.net_signal.emit(self.upload_content,self.download_content)
time.sleep(1)

if __name__ == '__main__':
 app = QApplication(sys.argv)
 dispaly = NetWindows()
 dispaly.show()
 netwidows = NetWindows()
 sys.exit(app.exec_())

成果展示

到此這篇關(guān)于Python PyQt5實戰(zhàn)項目之網(wǎng)速監(jiān)控器的實現(xiàn)的文章就介紹到這了,更多相關(guān)Python PyQt5 網(wǎng)速監(jiān)控器內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!

版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部