[置顶]Logger

主博客:cnblogs.com/whlook

1. Qt:设置pixmap的尺寸

label->setPixmap(pixmap->scaled(300,200));

2. Qt:隐藏tabWidget的tab标签

tabWidget->tabBar()->hide();

3. 使用DOS命令在注册表添加键值

reg add HKLM\SYSTEM\ControlSet001\Services\NetBT\Parameters /v SMBDeviceEnabled /t REG_DWORD /d 0     #reg add 位置 键名 类型 值

4. NPOI使用的一个注意:如果要复制数学公式的话(比如有上下标),需要在同一个Workbook中复制,如果是不同workbook直接复制,只能复制字符串,格式不能复制过去(也就没了上下标)

cell2.CellStyle = cell1.CellStyle;
IRichTextString t = cell1.RichStringCellValue; // 注意要使用富文本
cell2.SetCellValue(t);

5. C#,将数值的字符串格式转换为数值格式 :

string val = "123";
double valNum= double.parse(val);

6. C++,获取鼠标的位置,操作鼠标进行虚拟点击

#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
    POINT x; // 保存位置
    SetCursorPos(10,10); // 设置鼠标的初始位置
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); // 左键按下
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); // 左键松开

    while (1)
    {
        GetCursorPos(&x); // 获取鼠标位置
        cout << x.x <<","<<x.y<< endl; // 输出位置
    }
}

7. Markdown语法简记

标题

#  一级标题
## 二级标题
...
###### 六级标题

列表

* 1
* 2
* 3

引用


> 该段文字为引用

链接


普通链接:
[链接文字](http://...)
插入图片:
![logo](http://...)

代码

`print 'hello'`
使用三个`表示代码段

分割线

***

文字

加粗:
**test**
斜体
*test*

表格

标题1|标题2|
:----|:----|
内容1| 内容2|

效果:

标题1标题2
内容1内容2

8. vs2013:右键->生成依赖项->生成自定义->选择CUDA就可以在属性页中添加CUDA的项,然后对于.cu文件,可以右键修改属性,选择CUDA编译器。

9. caffe 查询GPU信息

caffe device_query --gpu=0 #第一块gpu

10.卷积层的输出大小计算公式

11.python:if __name__ == '__main__'

使得python文件既可以被导入,也可以独立执行

12.python:文件操作

f = open('test.txt','w')
print>>f,'hello'#带换行
print>>f,'world'
f.write('test')#不带换行
f.close

13.python:路径操作

import os
cwdPath = os.getcwd() #获取程序路径
os.listdir("d:/test")#获得test目录下的所有文件名

14.C#:生成dll

csc /target:library /out:xxx.dll xxx.cs
csc /target:library /out:xxx.dll /reference:yyy.dll xxx.cs  #引用了其他dll

15.C++:获取当前程序路径

#include <direct.h>
...
char path[MAX_LENGTH];
getcwd(path,MAX_LENGTH);
cout<< path <<endl;

16.C++:键盘操作

#include <conio.h>
...
while(!kbhit()) // 等待按键按下
int ascii = getch(); //获得按键的ascii码

17.CNN:momentum

Momentum technique is an approach which provides an update rule that is motivated from the physical perspective of optimization. Imagine a ball in a hilly terrain is trying to reach the deepest valley. When the slope of the hill is very high, the ball gains a lot of momentum and is able to pass through slight hills in its way. As the slope decreases the momentum and speed of the ball decreases, eventually coming to rest in the deepest position of valley.

18.CMD:关闭和启用本地连接(需要管理员运行):

netsh interface set interface "本地连接" disabled [enabled] #关闭和启用

19.Python:创建和删除文件夹:

#创建文件夹
import os
if os.path.exists("test_folder") == false:
    os.mkdir("test_folder")
#删除文件夹
if os.path.exists("test_folder"):
    os.removedirs("test_folder")

20.Python:使用matplotlib读取和显示图片

import matplotlib.pyplot as plt #显示
import matplotlib.image as mimg #读取

img = mimg.imread('test.jpg')

plt.imshow(img)
plt.axis('off') #关闭坐标轴
plt.show()

21. Linux:设置shell密码

sudo passwd #然后设置密码,然后可以使用 su root 登录
import os import time import win32com.client import win32gui import win32con from pythoncom import CoInitialize, CoUninitialize # 显式导入COM函数 import threading import psutil import pyautogui from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains # 移除独立的日志配置,使用 app.py 的日志系统 class PPTController: """控制PPT的全屏播放和翻页""" _is_active = False # 类属性,标记是否有活跃的PPT _is_ready = False # 类属性,标记PPT是否已经准备好(即已经全屏并开始放映) _presentation = None # 当前打开的演示文稿对象 _application = None # PowerPoint应用程序对象 _lock = threading.Lock() # 添加线程锁 _logger = None # 日志记录器 _com_initialized = False # 标记COM是否已初始化 @classmethod def set_logger(cls, logger): """设置日志记录器""" cls._logger = logger @classmethod def open_fullscreen(cls, ppt_path): """打开PPT并全屏播放(新增循环播放功能)""" # 如果已经有打开的PPT,先关闭 if cls._is_active: cls.close() try: with cls._lock: # 使用线程锁确保线程安全 # 初始化 COM try: CoInitialize() cls._com_initialized = True if cls._logger: cls._logger.debug("COM初始化成功") except Exception as e: if cls._logger: cls._logger.error(f"COM初始化失败: {str(e)}") return False, f"COM初始化失败: {str(e)}" # 检查文件是否存在 if not os.path.exists(ppt_path): if cls._logger: cls._logger.error(f"PPT文件不存在: {ppt_path}") # 清理COM资源 cls._safe_uninitialize() return False, "PPT文件不存在" # 尝试使用PowerPoint,如果失败则尝试WPS try: cls._application = win32com.client.Dispatch("PowerPoint.Application") if cls._logger: cls._logger.info("使用Microsoft PowerPoint打开文件") is_powerpoint = True # 标记是否为PowerPoint except Exception as e: if cls._logger: cls._logger.warning(f"无法启动PowerPoint, 尝试WPS: {str(e)}") try: cls._application = win32com.client.Dispatch("KWPP.Application") if cls._logger: cls._logger.info("使用WPS演示打开文件") is_powerpoint = False # 标记为WPS except Exception as e2: if cls._logger: cls._logger.error(f"无法启动WPS: {str(e2)}") # 清理资源 cls._safe_uninitialize() return False, f"无法启动PowerPoint或WPS: {str(e)}" cls._application.Visible = True # 打开演示文稿 try: cls._presentation = cls._application.Presentations.Open(ppt_path, WithWindow=True) except Exception as e: if cls._logger: cls._logger.error(f"打开PPT文件失败: {str(e)}") # 清理资源 cls._cleanup_resources() return False, f"打开PPT文件失败: {str(e)}" # 全屏放映(新增循环设置) try: slide_show_settings = cls._presentation.SlideShowSettings # 设置循环播放:PowerPoint和WPS的属性名不同,需分别处理 if is_powerpoint: # PowerPoint中,LoopUntilStopped=True 表示循环播放直到手动停止 slide_show_settings.LoopUntilStopped = True else: # WPS中,Loop=True 表示循环播放 slide_show_settings.Loop = True # 启动放映 slide_show_settings.Run() except Exception as e: if cls._logger: cls._logger.error(f"启动幻灯片放映失败: {str(e)}") # 清理资源 cls._cleanup_resources() return False, f"启动幻灯片放映失败: {str(e)}" # 最大化并置顶窗口 time.sleep(1) # 等待窗口创建 cls.maximize_window() cls._is_active = True cls._is_ready = True if cls._logger: cls._logger.info(f"PPT已全屏循环播放: {ppt_path}") return True, "PPT已全屏循环播放" except Exception as e: # 异常时清理资源 cls._cleanup_resources() if cls._logger: cls._logger.error(f"打开PPT失败: {str(e)}") return False, f"打开PPT失败: {str(e)}" @classmethod def _cleanup_resources(cls): """清理PPT相关资源""" if cls._presentation: try: cls._presentation.Close() cls._presentation = None except: pass if cls._application: try: cls._application.Quit() cls._application = None except: pass # 反初始化COM cls._safe_uninitialize() cls._is_active = False cls._is_ready = False @classmethod def _safe_uninitialize(cls): """安全地反初始化COM""" if cls._com_initialized: try: CoUninitialize() cls._com_initialized = False if cls._logger: cls._logger.debug("已反初始化COM") except Exception as e: if cls._logger: cls._logger.warning(f"反初始化COM失败: {str(e)}") else: if cls._logger: cls._logger.debug("COM未初始化,无需反初始化") @classmethod def maximize_window(cls): if not cls._presentation: return False try: def enum_windows_callback(hwnd, _): window_title = win32gui.GetWindowText(hwnd) if "PowerPoint Slide Show" in window_title or "WPS 演示" in window_title: # 先最大化窗口 win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE) # 再设置窗口置顶(HWND_TOPMOST表示置顶,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE表示不改变位置和大小) win32gui.SetWindowPos( hwnd, win32con.HWND_TOPMOST, # 置顶标记 0, 0, 0, 0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE # 不改变位置和大小 ) if cls._logger: cls._logger.info(f"最大化并置顶窗口: {window_title}") win32gui.EnumWindows(enum_windows_callback, None) return True except Exception as e: if cls._logger: cls._logger.warning(f"最大化并置顶窗口失败: {str(e)}") return False @classmethod def navigate(cls, direction): """翻页操作:通过模拟键盘上下键实现(核心修改)""" if not cls._is_active or not cls._application or not cls._presentation: return False, "没有活跃的PPT或对象已失效" if not cls._is_ready: return False, "PPT正在加载中,请稍后" try: with cls._lock: # 检查放映窗口是否存在(确保PPT处于放映状态) if not hasattr(cls._presentation, 'SlideShowWindow') or cls._presentation.SlideShowWindow is None: return False, "幻灯片放映已终止,请重新打开" # 模拟键盘按键(上箭头=上一页,下箭头=下一页) if direction == 'next': pyautogui.press('down') # 模拟下箭头键 if cls._logger: cls._logger.info("模拟下箭头键,切换到下一页") return True, "已模拟下箭头键,切换到下一页" elif direction == 'previous': pyautogui.press('up') # 模拟上箭头键 if cls._logger: cls._logger.info("模拟上箭头键,切换到上一页") return True, "已模拟上箭头键,切换到上一页" else: return False, "无效的翻页方向" except Exception as e: if cls._logger: cls._logger.error(f"翻页失败: {str(e)}") return False, f"翻页失败: {str(e)}" @classmethod def close(cls): """关闭当前打开的PPT""" with cls._lock: # 使用线程锁确保线程安全 cls._cleanup_resources() if cls._logger: cls._logger.info("PPT已关闭") @classmethod def is_active(cls): """检查是否有活跃的PPT""" return cls._is_active @classmethod def is_ready(cls): """检查PPT是否准备好(可翻页)""" return cls._is_ready class WebController: """控制网页的全屏显示""" _driver = None # WebDriver实例 _lock = threading.Lock() # 添加线程锁 _logger = None # 日志记录器 @classmethod def set_logger(cls, logger): """设置日志记录器""" cls._logger = logger @classmethod def open_fullscreen(cls, url, browser_type='chrome'): """ 在浏览器中全屏打开网页 :param url: 要打开的URL :param browser_type: 浏览器类型,支持 'chrome', 'edge', 'firefox' :return: (成功与否, 消息) """ with cls._lock: # 使用线程锁确保线程安全 # 关闭已存在的浏览器实例 if cls._driver: try: cls._driver.quit() except: pass cls._driver = None try: # 根据浏览器类型创建driver if browser_type.lower() in ['chrome', 'googlechrome']: chrome_options = Options() chrome_options.add_argument("--kiosk") # 全屏模式 chrome_options.add_argument("--disable-infobars") chrome_options.add_experimental_option("useAutomationExtension", False) chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"]) # 设置WebDriver服务 service = Service(executable_path='chromedriver.exe') cls._driver = webdriver.Chrome(service=service, options=chrome_options) elif browser_type.lower() in ['edge', 'microsoftedge']: edge_options = Options() edge_options.add_argument("--kiosk") # 全屏模式 edge_options.add_argument("--disable-infobars") # 设置WebDriver服务 service = Service(executable_path='msedgedriver.exe') cls._driver = webdriver.Edge(service=service, options=edge_options) elif browser_type.lower() in ['firefox', 'mozilla']: firefox_options = webdriver.FirefoxOptions() firefox_options.add_argument("--kiosk") # 全屏模式 # 设置WebDriver服务 service = Service(executable_path='geckodriver.exe') cls._driver = webdriver.Firefox(service=service, options=firefox_options) else: if cls._logger: cls._logger.error(f"不支持的浏览器类型: {browser_type}") return False, f"不支持的浏览器类型: {browser_type}" # 打开URL cls._driver.get(url) # 确保全屏 try: # 尝试按F11实现全屏(某些浏览器需要) ActionChains(cls._driver).key_down(Keys.F11).perform() time.sleep(0.5) # 等待全屏生效 except: pass if cls._logger: cls._logger.info(f"已在{browser_type}中全屏打开: {url}") return True, f"已在{browser_type}中全屏打开" except Exception as e: if cls._logger: cls._logger.error(f"打开网页失败: {str(e)}") return False, f"打开网页失败: {str(e)}" @classmethod def close(cls): """关闭浏览器""" with cls._lock: # 使用线程锁确保线程安全 if cls._driver: try: cls._driver.quit() cls._driver = None if cls._logger: cls._logger.info("浏览器已关闭") return True except Exception as e: if cls._logger: cls._logger.error(f"关闭浏览器失败: {str(e)}") return False return True def kill_process_by_name(process_names, logger=None): """根据进程名杀死进程""" for proc in psutil.process_iter(['name']): try: if proc.info['name'] in process_names: proc.kill() if logger: logger.info(f"已结束进程: {proc.info['name']}") except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess) as e: if logger: logger.warning(f"无法结束进程: {e}") except Exception as e: if logger: logger.error(f"结束进程时出错: {e}") def cleanup_processes(logger=None): """清理可能残留的进程""" # 清理PPT相关进程 kill_process_by_name([ "POWERPNT.EXE", # PowerPoint "wpp.exe", # WPS演示 "et.exe", # WPS表格 "wps.exe", # WPS文字 "chrome.exe", # Chrome "msedge.exe", # Edge "firefox.exe" # Firefox ], logger=logger) 如果 不使用pycom 有没有办法控制ppt
最新发布
08-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值