gpt4 book ai didi

python - 只有 py 文件时隐藏控制台(没有 pyw)[ANKI 附加组件]

转载 作者:可可西里 更新时间:2023-11-01 14:36:02 26 4
gpt4 key购买 nike

我正准备为 Windows 用户调整 ANKI SRS 的 music fiddler 插件。Anki 仅运行以 .py 结尾的附加组件,而不是 pyw。有没有办法隐藏运行代码时自动弹出的控制台。

如果没有,有没有办法不取消选择控制台窗口(我基本上每五秒后必须单击主 anki 窗口,因为已经再次关闭的控制台正在选择中)。

我目前使用的打开窗口的命令例如是: os.system('"nircmd.exe changesysvolume"'+ change)

完整代码如下控制台运行 nircmd.exe 和系统声音应更改的音量单位数。是否可以调整代码?

# -*- coding: utf-8 -*-
# Music-Fiddler (a plugin for Anki)
# coded by D_Malik, malik6174@gmail.com
# Version 1
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html

"""
A simple plugin that fiddles with music volume to reinforce quick reviewing.

Before using:
- This plugin was made for Linux. It will require modification to work on another OS.
- Ensure that the "amixer" command works on your computer. If it doesn't, you're going to need to modify the code somehow. Don't ask me how.//Amixer has been replaced by nircmd.exe for windows
- Change all lines (in the plugin source) marked with "CHANGEME" according to your preferences.
"""

import os
from aqt import mw
from aqt.utils import showInfo
from os import system
from aqt.qt import *
from anki.hooks import addHook

def resetMusicTimer():
"Boosts volume back up and starts the music timer."
#CHANGEME: The next lines are a python dictionary associating deck names with times (in milliseconds) between volume-decrements.
#Eg, when using the deck "brainscience", volume will decrement every 5 seconds. When using a deck without a listed name, "other" is used.
#Change this according to your decks. Decks with shorter, easier cards need less time.
deckMusicTimes = {
"rocketsurgery" : 3000,
"brainscience" : 5000,
"other" : 5000,
}
if mw.col.decks.current()['name'] in deckMusicTimes:
mw.musicTimeToDecrement = deckMusicTimes[mw.col.decks.current()['name']]
else:
mw.musicTimeToDecrement = deckMusicTimes["other"]
boostMusicVolume()
mw.musicTimer = QTimer(mw)
mw.musicTimer.setSingleShot(True)
mw.musicTimer.start(mw.musicTimeToDecrement)
mw.connect(mw.musicTimer, SIGNAL("timeout()"), decrementMusicVolume)
#showInfo(mw.state)

def changeMusicVolume(change):
"Changes volume according to string; can be either absolute ('40') or change ('2%-')."
os.system('"nircmd.exe changesysvolume"'+ change) #CHANGEME somehow, if amixer doesn't work

def boostMusicVolume():
#showInfo("boosted") #To test changes, you can uncomment this line.
os.system('"nircmd.exe changesysvolume 50000"') #CHANGEME somehow, if amixer doesn't work
#CHANGEME: Set to however high you want your volume to go each time it's boosted back.
#Protip: your music-playing program might have its own "volume multiplier" that you can adjust easily.

def killMusicVolume():
#showInfo("killed") #To test changes, you can uncomment this line.
os.system('"nircmd.exe mutesysvolume 1"') #CHANGEME somehow, if amixer doesn't work
#CHANGEME: Set to how low volume should go when it dies, eg due to undoing a card.

def decrementMusicVolume():
"When reviewing, decrements volume, then sets a timer to call itself. When not reviewing, kills volume and stops timer."
if mw.state == "review":
#showInfo("music volume goes down") #To test changes, you can uncomment this line.
os.system('"nircmd.exe changesysvolume -5000"') #CHANGEME somehow, if amixer doesn't work
mw.musicTimer.start(mw.musicTimeToDecrement) #(start the timer again)
else:
killMusicVolume()
mw.musicTimer = None #(kill the timer if you're not reviewing)

addHook("showQuestion", resetMusicTimer)

最佳答案

关于python - 只有 py 文件时隐藏控制台(没有 pyw)[ANKI 附加组件],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23711016/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com