python - Hide console when py-file only (no pyw) [ANKI add-on] -


i adjust music fiddler add-on anki srs windows users. anki runs add-ons with ending .py, not pyw. there way hide console automatically pops when run code.

if not, there way no unselect console windows (i have click on main anki windows after every 5 seconds because console closed again in selection).

the command use far opening windows example: os.system('"nircmd.exe changesysvolume"'+ change)

the complete code below console runs nircmd.exe , number of volume units system sound should change. there possibility adjust code?

# -*- coding: utf-8 -*- # music-fiddler (a plugin anki) # coded d_malik, malik6174@gmail.com # version 1 # license: gnu gpl, version 3 or later; http://www.gnu.org/copyleft/gpl.html  """ simple plugin fiddles music volume reinforce quick reviewing.  before using: - plugin made linux. require modification work on os. - ensure "amixer" command works on computer. if doesn't, you're going need     modify code somehow. don't ask me how.//amixer has been replaced nircmd.exe windows - change lines (in plugin source) marked "changeme" according preferences. """      import os aqt import mw aqt.utils import showinfo os import system aqt.qt import * anki.hooks import addhook      def resetmusictimer():     "boosts volume , starts music timer."     #changeme: next lines python dictionary associating deck names times (in         milliseconds) between volume-decrements.     #eg, when using deck "brainscience", volume decrement every 5 seconds. when using     deck without listed name, "other" used.     #change according decks. decks 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 string; can 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, can uncomment line.     os.system('"nircmd.exe changesysvolume 50000"') #changeme somehow, if amixer doesn't work      #changeme: set high want volume go each time it's boosted back.     #protip: music-playing program might have own "volume multiplier" can adjust easily.  def killmusicvolume():     #showinfo("killed") #to test changes, can uncomment line.     os.system('"nircmd.exe mutesysvolume 1"') #changeme somehow, if amixer doesn't work      #changeme: set how low volume should go when dies, eg due undoing card.  def decrementmusicvolume():     "when reviewing, decrements volume, sets timer call itself. when not reviewing, kills volume , stops timer."     if mw.state == "review":         #showinfo("music volume goes down") #to test changes, can uncomment line.         os.system('"nircmd.exe changesysvolume -5000"') #changeme somehow, if amixer doesn't work          mw.musictimer.start(mw.musictimetodecrement) #(start timer again)     else:         killmusicvolume()         mw.musictimer = none #(kill timer if you're not reviewing)  addhook("showquestion", resetmusictimer) 

it seems using subprocess module instead of os.system solve problem. please see how avoid console window .pyw file containing os.system call? , how hide console when use os.system() or subprocess.call()?.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -