Example #1
0
	def Notify(self, app_name, id, icon, summary, body, actions, hints, timeout):
		print 'Notify: [%d] app_name: %s, icon: %s, actions: %s, hints: %s' % (id, app_name, icon, repr(actions), repr(hints))
		if not timeout:
			notify('libnotify called with timeout %s' % repr(timeout))
			timeout = 5000
		notify('%s: %s' % (summary, body), timeout = timeout / 1000.0, colours='msgcolors')
		return 0
Example #2
0
def receive_msg(account, name, message, conversation, flags):
    alias = resolve_buddy_name(account, name)

    #notify("%s: %s" % (alias, strip_html(message)), key='purple-'+name, colours=[wmii.WMII_MSGCOLOURS, wmii.WMII_MSG1COLOURS])
    notify("%s: %s" % (alias, strip_html(message)),
           key='purple-' + name,
           colours='msgcolors')
Example #3
0
def _find_window(args='', recover=False):
	# Yes, there are five different "clients" here (hey, I only named two of these!):
	# client = wmii plan9 filesystem client
	# /client = directory in the wmii plan9 filesystem listing all the X11 clients
	# c = A directory in the wmii /client plan9 directory, which refers to an X11 client
	# Client = class representing an X11 client in wmii to abstract the plan9 filesystem interface
	# window = An instantiated Client
	# oh_god_no_more_clients = plea for better naming conventions
	# Tags, Tag & tag = more sensible
	from pygmi import client, Client, Tags, Tag
	import threading

	if not args:
		notify('Usage: find_window title', 'find_window')
		return

	found = False
	for c in client.readdir('/client'):
		window = Client(c.name)
		if window.label.find(args) >= 0:
			if not found:
				found = True
				if recover:
					for tag in window.tags:
						Tag(tag).send(window, "0:1")
				if '+' not in window.tags:
					tag = Tag(window.tags)
					Tags().select(tag)
					tag.selclient = window
					continue
			thread = threading.Thread(target=flash_window, args=(window,), name='flash_window %s' % hex(window.id))
			thread.daemon = True
			thread.start()
	if not found:
		notify('No windows found matching "%s"' % args, 'find_window')
Example #4
0
def setResolution(devices, resolution, internalDisplay, disabledDevices = None,
    layout=None):
  """
  Call xrandr to set the resolution of all given devices to resolution
  """
  command=['xrandr']
  for device in devices:
    command += ['--output', device, '--mode', resolution]
    if layout is None or isInternalDisplay(device):
      command += ['--pos', '0x0']
    elif layout is not None:
      command += [layout, internalDisplay]
    if resolution not in devices[device]:
      xrandr = subprocess.Popen(['xrandr', '--addmode', device, resolution],
          stderr=subprocess.PIPE)
      err = xrandr.stderr.read()
      # FIXME: On nvidia we get a non-fatal error, we should not return failure or we will mess up xautolock disabling, etc
      wait(xrandr)
      if (err != ''):
        notify(err.replace('\n','') + ' (' + device + ')', colours='errcolors')
        return 1
  if disabledDevices is not None:
    for device in disabledDevices:
      command += ['--output', device, '--off', '--pos', '0x0']
  xrandr = subprocess.Popen(command, stderr=subprocess.PIPE)
  err = xrandr.stderr.read()
  ret = xrandr.wait()
  if (err != ''):
    notify(err.replace('\n','') + ' (' + device + ')', colours='errcolors')
  return ret
Example #5
0
def register_xf86_keys(keybinder):
    try:
        inhibit_power_button()
    except Exception as e:
        notify('%s inhibiting systemd handle-power-key & handle-lid-switch: %s' % \
          (e.__class__.__name__, str(e)), timeout = 5000)
        raise
    keybinder.bind_key(0, 'XF86_PowerOff', power_button)
Example #6
0
def register_xf86_keys(keybinder):
	try:
		inhibit_power_button()
	except Exception as e:
		notify('%s inhibiting systemd handle-power-key & handle-lid-switch: %s' % \
				(e.__class__.__name__, str(e)), timeout = 5000)
                raise
	keybinder.bind_key(0, 'XF86_PowerOff', power_button)
Example #7
0
def register_xf86_keys(keybinder):
	try:
		fake_gnome_settings_daemon()
	except Exception as e:
		notify('%s trying to start fake "gnome-settings-daemon": %s.  Power button will not be caught!' % \
				(e.__class__.__name__, str(e)), timeout = 5000)
		return
	keybinder.bind_key(0, 'XF86_PowerOff', power_button)
Example #8
0
def alsa_vol_mute():
    m = def_mixer()
    v = m.getmute()[0]
    v = not v
    m.setmute(v)

    names = ', '.join([m.mixer()] + sync_mixers(mute=v))
    notify("%s: %s" % (names, 'MUTE' if m.getmute()[0] else 'on'), key='mixer')
Example #9
0
def fixX11():
	notify("Applying X11 settings")
	_launch(['xinput', 'set-float-prop', 'Primax Lenovo Laser Mouse', 'Device Accel Constant Deceleration', '2'])
	_launch(['xinput', 'set-float-prop', 'Dell BT Mouse', 'Device Accel Constant Deceleration', '2'])
	_launch("setxkbmap -option terminate:ctrl_alt_bksp".split())
	_launch("setxkbmap -option keypad:pointerkeys".split())

	wacom.apply_profile('Wacom Intuos3 9x12 pad', 'gimp')
Example #10
0
def toggle_device(device):
	enabled = int(get_xinput_prop(device, enabled_prop))
	if enabled:
		disable_device(device)
	else:
		enable_device(device)
	enabled = int(get_xinput_prop(device, enabled_prop))
	notify('%s %s' % (device, 'enabled' if enabled else 'disabled'), 'trackpad')
Example #11
0
def vol_mute():
	m = def_mixer()
	v = m.getmute()[0]
	v = not v
	m.setmute(v)

	names = ', '.join([ m.mixer() ] + sync_mixers(mute=v))
	notify("%s: %s" % (names, 'MUTE' if m.getmute()[0] else 'on'), key='mixer')
Example #12
0
def register_xf86_keys(keybinder):
    try:
        fake_gnome_settings_daemon()
    except Exception as e:
        notify('%s trying to start fake "gnome-settings-daemon": %s.  Power button will not be caught!' % \
          (e.__class__.__name__, str(e)), timeout = 5000)
        return
    keybinder.bind_key(0, 'XF86_PowerOff', power_button)
Example #13
0
def toggle_auto_suspend():
	import os
	file = '/tmp/noautosuspend'
	if os.path.exists(file):
		os.remove(file)
		notify('Auto Suspend Enabled', 'suspend')
	else:
		open(file, 'w').close()
		notify('Auto Suspend Disabled', 'suspend')
Example #14
0
def _toggle_device(device):
    enabled = int(get_xinput_prop(device, enabled_prop))
    if enabled:
        disable_device(device)
    else:
        enable_device(device)
    enabled = int(get_xinput_prop(device, enabled_prop))
    notify('%s %s' % (device, 'enabled' if enabled else 'disabled'),
           'trackpad')
Example #15
0
def toggle_audio_grab():
	global audio_keys_grabbed
	if audio_keys_grabbed:
		notify("Releasing grab on XF86Audio keys")
		release_audio_keys()
	else:
		notify("Grabbing XF86Audio keys")
		grab_audio_keys()
	audio_keys_grabbed = not audio_keys_grabbed
	keys.mode = keys.mode
Example #16
0
def toggle_volume_grab():
	global volume_keys_grabbed
	if volume_keys_grabbed:
		notify("Releasing grab on XF86Audio volume keys")
		release_volume_keys()
	else:
		notify("Grabbing XF86Audio volume keys")
		grab_volume_keys()
	volume_keys_grabbed = not volume_keys_grabbed
	keys.mode = keys.mode
Example #17
0
def unload():
	global _notify

	notify('WARNING: libnotify.py unload called, but it is untested!')

	# NOTE: I haven't quite figured out how to unregister the service. This
	# at least drops the well known name (which should happen automatically
	# when bus_name is no longer referenced), but our connection to the bus
	# continues to expose the notification interface, and reloading the
	# plugin will fail to register it
	bus = wmiidbus.get_session_bus()
	bus.release_name('org.freedesktop.Notifications')
	_notify = None
Example #18
0
def command(command):
	(name, player) = music_player_running()
	if player is None:
		notify('No supported music player running')
		music_status.active = False
		return

	if command not in player.commands:
		if command in ['Volume Up', 'Volume Down', 'Mute']:
			import mixer
			# This redirection is getting silly... XF86Keys ->
			# mixer -> music -> mixer... and every time we change
			# the name of the command...
			getattr(mixer, 'vol_%s'%command.split()[-1].lower())()
		else:
			notify('%s: Unimplemented' % name)
		return

	ret = player.commands[command]()
	if ret is not None:
		notify('%s: %s' % (name, ret), key='music')
	else:
		notify('%s: %s' % (name, command), key='music')

	init_status(player)
Example #19
0
def fixX11():
	import threading

	notify("Applying X11 settings")
	_launch("setxkbmap -option terminate:ctrl_alt_bksp".split())
	_launch("setxkbmap -option keypad:pointerkeys".split())

	wacom.apply_profile('Wacom Intuos3 9x12 pad', 'gimp')

	subprocess.call('dispwin -I /home/dss/colorhug/results/samsung/samsung.icc'.split())

	t = threading.Timer(xmodmap_delay, do_xmodmap)
	t.daemon = True
	t.start()
Example #20
0
def command(command):
    (name, player) = music_player_running()
    if player is None:
        notify('No supported music player running')
        music_status.active = False
        return

    if command not in player.commands:
        if command in ['Volume Up', 'Volume Down', 'Mute']:
            import mixer
            # This redirection is getting silly... XF86Keys ->
            # mixer -> music -> mixer... and every time we change
            # the name of the command...
            getattr(mixer, 'vol_%s' % command.split()[-1].lower())()
        else:
            notify('%s: Unimplemented' % name)
        return

    ret = player.commands[command]()
    if ret is not None:
        notify('%s: %s' % (name, ret), key='music')
    else:
        notify('%s: %s' % (name, command), key='music')

    init_status(player)
Example #21
0
 def dispatch(self, fd, eventmask):
     (method, args, kwargs) = self._fds[fd]
     try:
         method(*args, **kwargs)
     except Exception as e:
         import sys, traceback
         traceback.print_exc()
         try:
             notify(
                 "i3companion: %s: %s in %s.%s(). Refer to %s for backtrace"
                 % (e.__class__.__name__, str(e), method.__module__,
                    method.__name__, describe_fd(sys.stderr)),
                 timeout=5000)
         except Exception as e:
             print >> sys.stderr, 'i3companion: Additional error while reporting error:'
             traceback.print_exc()
Example #22
0
def music_status(self):
    if not hasattr(self, 'status') or not hasattr(self, 'status_failures'):
        return None  # Not initialised yet
    try:
        status = self.status()
    except:
        self.status_failures += 1
        if self.status_failures > 60:
            notify('Too many failures getting music player status')
            self.status_failures = 0
            self.active = False
        return None
    self.status_failures = 0
    if status:
        return status
    return None
Example #23
0
def music_status(self):
	if not hasattr(self, 'status') or not hasattr(self, 'status_failures'):
		return None # Not initialised yet
	try:
		status = self.status()
	except:
		self.status_failures += 1
		if self.status_failures > 60:
			notify('Too many failures getting music player status')
			self.status_failures = 0
			self.active = False
		return None
	self.status_failures = 0
	if status:
		return status
	return None
Example #24
0
def apply_profile(device, profile):
	if device not in mappings:
		raise AttributeError('%s mapping not found' % device)
	if profile not in mappings[device]:
		raise AttributeError('%s profile for %s not found' % (profile, device))
	notify("Applying %s, %s profile" % (device, profile), 'wacom')

	# Work around a bug in the wacom stack causing the buttons to override
	# the strips (similar, but opposite to above bug note) by doing
	# everything twice:
	for i in range(2):
		for (prop, action) in mappings[device][profile]:
			# Wait for termination to avoid race:
			try:
				subprocess.call(['xsetwacom', 'set', device] + prop.split() + [action])
			except OSError:
				notify('xsetwacom not found', 'wacom')
Example #25
0
def power_button():
	# FIXME: Do this asynchronousely
	import subprocess
	dmenu = subprocess.Popen(['dmenu', '-l', '6', '-p',
		'Power Button Pressed! What would you like to do?'],
		stdin=subprocess.PIPE, stdout=subprocess.PIPE)
	dmenu.stdin.write('\n'.join(zip(*power_button_actions)[0]))
	dmenu.stdin.close()
	dmenu.wait()
	action = dmenu.stdout.read()

	d = dict(power_button_actions)
	if action not in d:
		notify('Unrecognised action: %s' % action)
		return

	d[action]()
Example #26
0
    def dispatch(self, fd, eventmask):
        (method, args, kwargs) = self._fds[fd]
        try:
            method(*args, **kwargs)
        except Exception as e:
            import sys, traceback

            traceback.print_exc()
            try:
                notify(
                    "i3companion: %s: %s in %s.%s(). Refer to %s for backtrace"
                    % (e.__class__.__name__, str(e), method.__module__, method.__name__, describe_fd(sys.stderr)),
                    timeout=5000,
                )
            except Exception as e:
                print >>sys.stderr, "i3companion: Additional error while reporting error:"
                traceback.print_exc()
Example #27
0
def main():
	import sys
	def usage():
		print 'usage: %s [-s]' % sys.argv[0]
	if len(sys.argv) > 1:
		if sys.argv[1] == '-s':
			spawnAutoLock()
			registerKeyBindings()
			from pygmi import events
			events.loop() # We are called from the command line to do setup, so start the event loop
			xautolock.wait() # Wait on xautolock since we were called directly from the command line
		elif sys.argv[1] == '-n':
			notify('Screen about to lock...', daemon = False)
		else:
			usage()
	else:
		locknow(False)
Example #28
0
def set_background(file = None):
	import os
	global background

	if file is not None and file != '':
		if os.path.isfile(file):
			background = os.path.expanduser(file)
		else:
			notify("set_background: %s not found" % file, 'background')
			return

	if background is None:
		return

	import threading
	t = threading.Thread(target=_set_background, name='Set-X-Background')
	t.daemon = True
	t.start()
Example #29
0
def apply_profile(device, profile):
    if device not in mappings:
        raise AttributeError('%s mapping not found' % device)
    if profile not in mappings[device]:
        raise AttributeError('%s profile for %s not found' % (profile, device))
    notify("Applying %s, %s profile" % (device, profile), 'wacom')

    # Work around a bug in the wacom stack causing the buttons to override
    # the strips (similar, but opposite to above bug note) by doing
    # everything twice:
    for i in range(2):
        for (prop, action) in mappings[device][profile]:
            # Wait for termination to avoid race:
            try:
                subprocess.call(['xsetwacom', 'set', device] + prop.split() +
                                [action])
            except OSError:
                notify('xsetwacom not found', 'wacom')
Example #30
0
def power_button():
    # FIXME: Do this asynchronousely
    import subprocess
    dmenu = subprocess.Popen([
        'dmenu', '-l', '6', '-p',
        'Power Button Pressed! What would you like to do?'
    ],
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE)
    dmenu.stdin.write('\n'.join(zip(*power_button_actions)[0]))
    dmenu.stdin.close()
    dmenu.wait()
    action = dmenu.stdout.read()

    d = dict(power_button_actions)
    if action not in d:
        notify('Unrecognised action: %s' % action)
        return

    d[action]()
Example #31
0
def _locknow(daemon = True):
	# NOTE: We are not necessarily in the same process that performed the
	# setup - don't import wmiirc!
	import threading, time
	from pygmi import Tags, keys
	tags = Tags()

	try:
		notify('Locking now', daemon = daemon)

		# Disable keyboard:
		keys.mode = 'passthrough'

		cur = tags.sel # NOTE: Only updated in Tags.__init__()
		tags.select('!lock')

		# xtrlock doesn't seem to like starting if a key that wmii has
		# grabbed is being held down. We change the key mode to
		# passthrough above to remove these grabs, but if the lock key
		# itself has not yet been released that won't help. Sleep here
		# to give the user plenty of time to remove their fingers (at
		# this point we have already switched tags so they have some
		# indication that the screen is about to lock):
		time.sleep(0.5)

		xtrlock = subprocess.Popen('xtrlock')
		#xtrlock = subprocess.Popen('strace xtrlock'.split()) # 'tis difficult to debug

		t = threading.Thread(target = keepScreenOff, args=[xtrlock], name='Keep-Screen-Off')
		t.daemon = True # Don't prevent termination
		t.start()
		# Just in case the user switched tags while we were waiting:
		tags.select('!lock')

		xtrlock.wait()

	finally:
		keys.mode = 'main'
		tags.select(cur)
Example #32
0
def alsa_vol(adjust):
    # FIXME: This is not the same scale as used by alsamixer
    m = def_mixer()
    nv = ov = m.getvolume()[0]
    small_adjust = adjust / abs(adjust)

    v = ov + adjust
    if v > 100: v = 100
    elif v < 0: v = 0

    while nv == ov:
        m.setvolume(v)
        nv = m.getvolume()[0]
        v = v + small_adjust
        if v > 100 or v < 0:
            break
    try:
        mute = m.getmute()[0] and ' [MUTE]' or ''
    except:
        mute = ''

    names = ', '.join([m.mixer()] + sync_mixers(vol=nv))
    notify("%s: %d%%%s" % (names, nv, mute), key='mixer')
Example #33
0
def vol(adjust):
	# FIXME: This is not the same scale as used by alsamixer
	m = def_mixer()
	nv = ov = m.getvolume()[0]
	small_adjust = adjust / abs(adjust)

	v = ov + adjust
	if v > 100: v = 100
	elif v < 0: v = 0

	while nv == ov:
		m.setvolume(v)
		nv = m.getvolume()[0]
		v = v + small_adjust
		if v > 100 or v < 0:
			break
	try:
		mute = m.getmute()[0] and ' [MUTE]' or ''
	except:
		mute = ''

	names = ', '.join([ m.mixer() ] + sync_mixers(vol=nv))
	notify("%s: %d%%%s" % (names, nv, mute), key='mixer')
Example #34
0
def action_set_background(file = ''):
	if file == '':
		if background == None:
			notify('No default background set!', 'background')
			return
		else:
			notify('setting default background...', 'background')
	else:
		notify('setting background to %s...' % file, 'background')
	set_background(file)
Example #35
0
#!/usr/bin/env python

from pluginmanager import notify, notify_exception

try:
	from xkeybinder import XKeyBinder
except ImportError:
	notify('i3companion: Please install python-Xlib and python-xpyb', timeout=5000)
	raise

from eventloop import EventLoop
import config

def main():
	loop = EventLoop()
	keybinder = XKeyBinder(loop)

	config.activate_key_bindings(keybinder)

	loop.run()

if __name__ == '__main__':
	main()
Example #36
0
def notify_brightness(input):
    for (name, brightness) in input:
        notify('%s: %i%%' % (name, brightness), key='backlight')
Example #37
0
def pulse_vol_mute():
    import pulse
    v = pulse.PulseAppVolume()
    (vol, mute) = v(None, toggle_mute=True)
    notify('Mixer: MUTE' if mute else 'Mixer: on', key='mixer')
Example #38
0
def pulse_vol(adjust):
    import pulse
    v = pulse.PulseAppVolume()
    (vol, mute) = v(None, adjust * pulse_adjust_factor)
    mute = mute and ' [MUTE]' or ''
    notify("Mixer: %d%%%s" % (vol / pulse_adjust_factor, mute), key='mixer')
Example #39
0
def fixX11():
	notify("Applying X11 settings")
	_launch("setxkbmap -option terminate:ctrl_alt_bksp".split())
	_launch("setxkbmap -option keypad:pointerkeys".split())

	wacom.apply_profile('Wacom Intuos3 9x12 pad', 'gimp')
Example #40
0
def receive_msg(account, name, message, conversation, flags):
  alias = resolve_buddy_name(account, name)

  #notify("%s: %s" % (alias, strip_html(message)), key='purple-'+name, colours=[wmii.WMII_MSGCOLOURS, wmii.WMII_MSG1COLOURS])
  notify("%s: %s" % (alias, strip_html(message)), key='purple-'+name, colours='msgcolors')
Example #41
0
	def GetServerInformation(self):
		notify('libnotify.py: Untested GetServerInformation called')
		return ('wmii', 'Ian Munsie', '0.1', None)
Example #42
0
def notify_brightness(input):
	for (name, brightness) in input:
		notify('%s: %i%%' % (name, brightness), key='backlight')
Example #43
0
	def GetCapabilities(self):
		notify('libnotify.py: Unimplemented GetCapabilities called')
		return []
Example #44
0
	def CloseNotification(self, id):
		notify('libnotify.py: Unimplemented CloseNotification called')
Example #45
0
def notify_kbd_backlight(val):
	notify('Keyboard Backlight: %i%%' % val, key = 'Keyboard Backlight')