SHARE
TWEET

Untitled

a guest Oct 20th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2.  
  3. """This is a simple python extension allows you to easily switch between monitors
  4.     It is supposed to be used like `stand up` and `stand down`
  5.     To install, create a folder called `standup` in
  6.     ~/.local/share/albert/org.albert.extension.python/modules/
  7.     and then add this file to it, along with the icons of your choice"""
  8.  
  9. from time import sleep
  10. import os
  11. from albertv0 import *
  12.  
  13.  
  14. up_monitor = 'DVI-I-1-1'
  15. down_monitor = 'HDMI-1'
  16. monitor_on = '--auto'
  17. monitor_off = '--off'
  18. standup_icon = os.path.dirname(__file__)+"/desk.svg"
  19. sitdown_icon = os.path.dirname(__file__)+"/chair.svg"
  20.  
  21. __iid__ = "PythonInterface/v0.1"
  22. __prettyname__ = "Standup"
  23. __version__ = "1.0"
  24. __trigger__ = "stand"
  25. __author__ = "luksfarris"
  26. __dependencies__ = ["whatever"]
  27.  
  28.  
  29. # Can be omitted
  30. def initialize():
  31.     pass
  32.  
  33.  
  34. # Can be omitted
  35. def finalize():
  36.     pass
  37.  
  38.  
  39. def handleQuery(query):
  40.     if not query.isTriggered:
  41.         return
  42.  
  43.     stand_item = Item()
  44.     stand_item.icon = standup_icon
  45.     stand_item.text = 'Stand Up'
  46.     stand_item.subtext = 'Moves to upper screen'
  47.  
  48.     def stand_command():
  49.         return os.system(f"xrandr --output {up_monitor} {monitor_on} && xrandr --output {down_monitor} {monitor_off}")
  50.  
  51.     stand_item.addAction(FuncAction("Standup", stand_command))
  52.  
  53.     sit_item = Item()
  54.     sit_item.icon = sitdown_icon
  55.     sit_item.text = 'Sit Down'
  56.     sit_item.subtext = 'Moves to lower screen'
  57.  
  58.     def sit_command():
  59.         os.system(f"xrandr --output {up_monitor} {monitor_off} && xrandr --output {down_monitor} {monitor_on}")
  60.  
  61.     sit_item.addAction(FuncAction("Sitdown", sit_command))
  62.  
  63.     if 'u' in query.string:
  64.         return [stand_item]
  65.     elif 'd' in query.string:
  66.         return [sit_item]
  67.     else:
  68.         return [stand_item, sit_item]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top