You are not logged in.
Pages: 1
So I made a pipemenu for switching screen layouts.
#!/usr/bin/python
import os, sys
from glob import glob
layouts = []
h = os.getenv("HOME")
if not os.path.isdir(h+"/.screenlayout"):
os.system("mkdir ~/.screenlayout/")
else:
d = h+"/.screenlayout/"
for x in glob(d + "*.sh"):
fname = x[x.rfind("/")+1:x.rfind(".")]
layouts.append( (x, fname) )
#print (x, fname)
xml = "<openbox_pipe_menu>"
for path, name in layouts:
xml = xml + "\n\t<item label=\"%s\">\n\t\t<action name=\"Execute\">\n\t\t\t<command>\n\t\t\t\tsh %s\n\t\t\t</command>\n\t\t</action>\n\t</item>" % (name, path)
xml = xml + "\n</openbox_pipe_menu>"
print xmlIn arandr, you can click Layout > Save As... and it will save an xrandr command inside a .sh file in the directory ~/.screenlayout/. I have an external monitor hooked up to my laptop, but when I want to bring my laptop somewhere I have to fiddle with the screen layout all the time, so this pipemenu saves me a lot of mucking around.
Just thought I'd share and see if anyone was interested.
signature.txt
Offline
Is this what you were asking for?
#!/usr/bin/python
import os, sys
from glob import glob
t = os.system("xrandr -q > /tmp/res.txt")
monitors = []
if t == 0:
res = open("/tmp/res.txt")
count = -1
for line in res.readlines():
if line.find(" connected ") == -1:
if line[:3] == " ":
pos = line.find(" ", 4)
ares = line[3:pos]
monitors[count][1].append(ares)
else:
pos = line.find(" ")
mon = line[:pos]
monitors.append([mon, []])
count += 1
xml = "<openbox_pipe_menu>"
layouts = []
h = os.getenv("HOME")
if not os.path.isdir(h+"/.screenlayout"):
os.system("mkdir ~/.screenlayout/")
else:
d = h+"/.screenlayout/"
for x in glob(d + "*.sh"):
fname = x[x.rfind("/")+1:x.rfind(".")]
layouts.append( (x, fname) )
for path, name in layouts:
xml += "\n\t<item label=\"%s\">\n\t\t<action name=\"Execute\">\n\t\t\t<command>\n\t\t\t\tsh %s\n\t\t\t</command>\n\t\t</action>\n\t</item>" % (name, path)
for monitor, slist in monitors:
xml += "\n\t<separator label=\"%s\"/>" % (monitor)
for size in slist:
xml += "\n\t<item label=\"%s\">\n\t\t<action name=\"Execute\">\n\t\t\t<command>\n\t\t\t\txrandr --output %s --mode %s\n\t\t\t</command>\n\t\t</action>\n\t</item>" % (size, monitor, size)
xml = xml + "\n</openbox_pipe_menu>"
print xmlSort of messy but I suppose it works.
signature.txt
Offline
Offline
Alright, I also forgot to clean up my opened files, so I added that too. Here's the final script:
#!/usr/bin/python
import os, sys
from glob import glob
t = os.system("xrandr -q > /tmp/res.txt")
monitors = []
if t == 0:
res = open("/tmp/res.txt")
count = -1
for line in res.readlines():
if line.find(" connected ") == -1:
if line[:3] == " ":
pos = line.find(" ", 4)
ares = line[3:pos]
monitors[count][1].append(ares)
else:
pos = line.find(" ")
mon = line[:pos]
monitors.append([mon, []])
count += 1
res.close()
os.system('rm -rf /tmp/res.txt')
xml = "<openbox_pipe_menu>\n\t<separator label=\"Saved Layouts\"/>"
layouts = []
h = os.getenv("HOME")
if not os.path.isdir(h+"/.screenlayout"):
os.system("mkdir ~/.screenlayout/")
else:
d = h+"/.screenlayout/"
for x in glob(d + "*.sh"):
fname = x[x.rfind("/")+1:x.rfind(".")]
layouts.append( (x, fname) )
for path, name in layouts:
xml += "\n\t<item label=\"%s\">\n\t\t<action name=\"Execute\">\n\t\t\t<command>\n\t\t\t\tsh %s\n\t\t\t</command>\n\t\t</action>\n\t</item>" % (name, path)
for monitor, slist in monitors:
xml += "\n\t<separator label=\"%s\"/>" % (monitor)
for size in slist:
xml += "\n\t<item label=\"%s\">\n\t\t<action name=\"Execute\">\n\t\t\t<command>\n\t\t\t\txrandr --output %s --mode %s\n\t\t\t</command>\n\t\t</action>\n\t</item>" % (size, monitor, size)
xml += "\n</openbox_pipe_menu>"
print xmlThanks for the feedback.
signature.txt
Offline
Pages: 1
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.