Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return print(f'{func_label} (type={vt}): {val:.2f} -> {func(val):.2f}')
if opts.conf: conf = conf_read(opts.conf)
for k,v in vars(opts).items(): setattr(conf, k, v)
del opts
logging.basicConfig(
level=logging.DEBUG if conf.debug else logging.WARNING,
format='%(asctime)s :: %(threadName)s %(levelname)s :: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S' )
log = get_logger('main')
print = ft.partial(print, file=sys.stderr, flush=True) # stdout is used by curses
log.debug('Initializing...')
while True:
with Pulse('pa-mixer-mk3', connect=False, threading_lock=True) as pulse:
pulse.connect(wait=conf.reconnect)
attic, streams = None, PAMixerStreams(pulse, conf, fatal=conf.fatal)
if conf.show_stored_values and pulse.stream_restore_test() is not None:
attic = PAMixerAttic(streams.update_wakeup, conf, fatal=conf.fatal)
with streams.update_wakeup_poller(streams.update_wakeup_handler) as poller_thread:
log.debug('Starting pulsectl event poller thread...')
poller_thread.start()
with PAMixerUI(streams, attic, conf) as curses_ui:
# Any output will mess-up curses ui, so try to close sys.stderr if possible
if not conf.verbose and not conf.debug and not conf.dump_stream_params:
sys.stderr.flush()
fd = os.open(os.devnull, os.O_WRONLY)
os.dup2(fd, sys.stderr.fileno())
elif keyId == Key.KILL.value:
focus.Kill();
elif keyId == Key.LAUNCH_TERMINAL.value:
psutil.Popen(["termite"],stdout=None,stderr=None);
elif keyId == Key.LAUNCH_BROWSER.value:
psutil.Popen(["firefox"],stdout=None,stderr=None);
elif keyId == Key.LAUNCH_BROWSER_PRIVATE.value:
psutil.Popen(["firefox","--private-window"],stdout=None,stderr=None);
elif keyId == Key.AUDIO_VOLUME_MUTE.value:
if "pulsectl" in sys.modules:
with pulsectl.Pulse('volume-increaser') as pulse:
for sink in pulse.sink_list():
pulse.mute(sink,not sink.mute);
elif keyId == Key.AUDIO_VOLUME_UP.value:
if "pulsectl" in sys.modules:
with pulsectl.Pulse('volume-increaser') as pulse:
for sink in pulse.sink_list():
pulse.volume_change_all_chans(sink,0.05);
elif keyId == Key.AUDIO_VOLUME_DOWN.value:
if "pulsectl" in sys.modules:
with pulsectl.Pulse('volume-increaser') as pulse:
for sink in pulse.sink_list():
pulse.volume_change_all_chans(sink,-0.05);
elif keyId == Key.MONITOR_BRIGHTNESS_UP.value:
def __init__(self, name):
self.instance = self.__class__.instances.get(name) or Pulse(name)
self.__class__.instances[name] = self.instance
def __init__(self, menu):
self.menu = menu
self.pulse_data = {}
if shutil.which('pulseaudio') is None:
self.pulse = None
return
check_pulseaudio = subprocess.run(['pulseaudio', '--check'],
check=False,
capture_output=True
)
if check_pulseaudio.returncode == 0:
try:
self.pulse = pulsectl.Pulse('neg-pulse-selector')
except Exception:
self.pulse = None
self.ioloop.add_callback(lambda: self.cmd_fetchFile(
inputFile, outputFile))
else:
msg = "Item not found in last locate results"
else:
msg = "Please specify which item of your locate command to fetch."
elif command == "set volume":
if number:
try:
volume = int(re.search(r'\d+', number).group())
except ValueError:
msg = "Invalid percentage: "+number
except AttributeError:
msg = "Invalid percentage: "+number
else:
with pulsectl.Pulse('setting-volume') as pulse:
for sink in pulse.sink_list():
pulse.volume_set_all_chans(sink, volume/100.0)
msg = "Volume set"
longMsg = "Volume set to "+str(volume)+"%"
else:
msg = "Please specify volume percentage"
elif command == "stop":
msg = "Not implemented yet"
elif command == "take a picture":
filename = os.path.join(os.environ["HOME"], "Dropbox",
datetime.datetime.now().strftime(
"LinuxControl-Picture-%Y-%m-%d-%Hh-%Mm-%Ss.png"))
msg = "Taking picture, saving in Dropbox"
longMsg = "Taking picture: " + filename
self.ioloop.add_callback(lambda: self.cmd_image(filename))
elif command == "screenshot":
elif keyId == Key.AUDIO_VOLUME_MUTE.value:
if "pulsectl" in sys.modules:
with pulsectl.Pulse('volume-increaser') as pulse:
for sink in pulse.sink_list():
pulse.mute(sink,not sink.mute);
elif keyId == Key.AUDIO_VOLUME_UP.value:
if "pulsectl" in sys.modules:
with pulsectl.Pulse('volume-increaser') as pulse:
for sink in pulse.sink_list():
pulse.volume_change_all_chans(sink,0.05);
elif keyId == Key.AUDIO_VOLUME_DOWN.value:
if "pulsectl" in sys.modules:
with pulsectl.Pulse('volume-increaser') as pulse:
for sink in pulse.sink_list():
pulse.volume_change_all_chans(sink,-0.05);
elif keyId == Key.MONITOR_BRIGHTNESS_UP.value:
psutil.Popen(["xbacklight","-inc","20"]);
elif keyId == Key.MONITOR_BRIGHTNESS_DOWN.value:
psutil.Popen(["xbacklight","-dec","20"]);
def pulse():
global __pulse
if __pulse is None:
__pulse = Pulse("deity")
return __pulse