import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QLabel, QProgressBar
from PyQt5.QtCore import Qt, QTimer
import PyQt5.QtWidgets as wid
from PyQt5.QtGui import QFont, QPalette, QColor, QPainter
from keras.callbacks import Callback
from PyQt5.QtWidgets import QMainWindow, QDesktopWidget, QApplication
from PyQt5.QtCore import QRect
import win32gui
import win32con
class set_window_foreground:
def __init__(self, window: QMainWindow):
self.hwnd_map = None
self.window = window
self.get_process_count = 0
def get_all_hwnd(self, hwnd, mouse):
"""
获取后台运行的所有程序
"""
if (win32gui.IsWindow(hwnd) and
win32gui.IsWindowEnabled(hwnd) and
win32gui.IsWindowVisible(hwnd)):
self.hwnd_map.update({hwnd: win32gui.GetWindowText(hwnd)})
def list_window(self):
try:
self.hwnd_map = {}
win32gui.EnumWindows(self.get_all_hwnd, 0)
except Exception as exx:
print("\nlll", exx)
def get_center_pos(rect: QRect):
x = rect.x()
y = rect.y()
center_x = int(x + rect.width() / 2)
center_y = int(y + rect.height() / 2)
return [center_x, center_y]
def Window_top(self):
"""
设置指定窗口置顶
"""
try:
if (self.get_process_count < 10):
self.list_window()
self.get_process_count += 1
App_name = str(self.window.windowTitle())
for h, t in self.hwnd_map.items():
if t != "":
if t.find(App_name) != -1:
# h 为想要放到最前面的窗口句
win32gui.BringWindowToTop(h)
# shell = win32com.client.Dispatch("WScript.Shell")
# shell.SendKeys('%')
# 被其他窗口遮挡,调用后放到最前面
win32gui.SetWindowPos(h,
win32con.HWND_TOPMOST,
self.window.geometry().x(),
self.window.geometry().y(),
self.window.geometry().width(),
self.window.geometry().height(),
win32con.SWP_SHOWWINDOW | win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
# 解决被最小化的情况
#win32gui.ShowWindow(h, win32con.SW_RESTORE)
except Exception as ee:
print("\nWindow_top", ee)
def cancel_Window_top(self):
"""
取消指定窗口置顶
"""
try:
App_name = str(self.window.windowTitle())
for h, t in self.hwnd_map.items():
if t != "":
if t.find(App_name) != -1:
# h 为想要放到最前面的窗口句柄
print(h, t)
# win32gui.BringWindowToTop(h)
# shell = win32com.client.Dispatch("WScript.Shell")
# shell.SendKeys('%')
# 取消置顶
win32gui.SetWindowPos(h,
win32con.HWND_NOTOPMOST,
self.window.geometry().x(),
self.window.geometry().y(),
self.window.geometry().width(),
self.window.geometry().height(),
win32con.SWP_SHOWWINDOW)
# 解决被最小化的情况
win32gui.ShowWindow(h, win32con.SW_RESTORE)
except Exception as ee:
print("\ncancel_Window_top:", ee)
class TrainingProgressWindow(QMainWindow):
def update_window(self):
self.window_control.Window_top()
def update_background(self):
if (self.flash_count > 10):
self.timer_blink.stop()
self.close()
self.blink_state = (self.blink_state + 1) % 2
self.setStyleSheet("")
self.repaint()
self.flash_count += 1
def paintEvent(self, event):
painter = QPainter(self)
if self.blink_state == 0:
painter.setBrush(QColor(255, 255, 0))
else:
painter.setBrush(QColor(78, 79, 79))
painter.drawRect(self.rect())
def __init__(self):
super().__init__()
self.flash_count = 0
self.blink_state = 0
self.timer_blink = QTimer()
self.timer_blink.timeout.connect(self.update_background)
self.window_control = set_window_foreground(self)
self.setWindowTitle("Training Progress")
self.timer = QTimer()
self.timer.timeout.connect(self.update_window)
self.time_out = 2000
self.timer.start(self.time_out)
screen = QDesktopWidget().screenGeometry()
self.setGeometry(screen.width() - 300, screen.height() - 300, 300, 200)
layout = QVBoxLayout()
self.label_train = QLabel("Training Progress: 0%")
font = QFont("Comic Sans MS", 15)
self.label_train.setFont(font)
self.label_train.setStyleSheet('color: white;')
layout.addWidget(self.label_train)
self.progress_bar_epoch = QProgressBar()
self.progress_bar_epoch.setValue(0)
self.progress_bar_epoch.setMaximum(100)
self.progress_bar_epoch.setStyleSheet("QProgressBar {"
"border: 2px solid white;"
"border-radius: 10px;"
"text-align: right;}"
"QProgressBar::chunk {"
"background-color: #05B8CC;"
# "foreground-color: rgb(177, 177, 177);"
"width: 10px;"
"margin: 0.5px;}")
# 获取QProgressBar对象的QPalette对象
palette = self.progress_bar_epoch.palette()
# 设置进度条控件的文本颜色为红色
palette.setColor(QPalette.Text, QColor("white"))
# 将修改后的QPalette对象应用到进度条控件上
self.progress_bar_epoch.setPalette(palette)
layout.addWidget(self.progress_bar_epoch)
self.label_batch = QLabel("Step Progress: 0%")
self.label_batch.setFont(font)
self.label_batch.setStyleSheet('color: white;')
layout.addWidget(self.label_batch)
self.progress_bar_batch = QProgressBar()
self.progress_bar_batch.setValue(0)
self.progress_bar_batch.setMaximum(100)
self.progress_bar_batch.setStyleSheet("QProgressBar {"
"border: 2px solid white;"
"border-radius: 10px;"
"text-align: right;}"
"QProgressBar::chunk {"
"background-color: #05B8CC;"
# "foreground-color: rgb(177, 177, 177);"
"width: 10px;"
"margin: 0.5px;}")
# 获取QProgressBar对象的QPalette对象
palette = self.progress_bar_batch.palette()
# 设置进度条控件的文本
没有合适的资源?快使用搜索试试~ 我知道了~
深度学习使用Tensorflow和Keras对本地数据集进行图像分类以及性能调优
共9个文件
py:4个
pyc:2个
dfas:1个
需积分: 0 6 下载量 109 浏览量
2023-11-17
11:38:19
上传
评论
收藏 218.15MB ZIP 举报
温馨提示
深度学习使用Tensorflow和Keras对本地数据集进行图像分类以及性能调优
资源推荐
资源详情
资源评论
收起资源包目录
TensorFlowFlowerClassify.zip (9个子文件)
TensorFlowFlowerClassify - Copy
set_window_foreground.py 4KB
dataset.zip 218.67MB
dfas 2KB
Start.py 8KB
__pycache__
preview
Pytorch
ImageIO
Tensorflow
OpenCV
Matplotlib
PIL
Plotly
set_window_foreground.cpython-310.pyc 3KB
progress_window.cpython-310.pyc 8KB
window_blink.py 1KB
Figure_1.png 57KB
progress_window.py 10KB
共 9 条
- 1
资源评论
精英的英
- 粉丝: 412
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功