SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2013-07-27 00:27:00

IrrationlArtist
Member
Registered: 2012-08-15
Posts: 15

Screen layout switching pipemenu

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 xml

In 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

Help fund CrunchBang, donate to the project!

#2 2013-07-27 01:06:33

samdraz
#! CrunchBanger
From: Earth
Registered: 2013-03-10
Posts: 232
Website

Re: Screen layout switching pipemenu

it would be great if it automatically lists the available resolutions which can taken from

xrandr -q

Offline

#3 2013-07-27 02:38:13

IrrationlArtist
Member
Registered: 2012-08-15
Posts: 15

Re: Screen layout switching pipemenu

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 xml

Sort of messy but I suppose it works.


signature.txt

Offline

#4 2013-07-27 02:50:10

samdraz
#! CrunchBanger
From: Earth
Registered: 2013-03-10
Posts: 232
Website

Re: Screen layout switching pipemenu

exactly ...thanks smile

still be nice if you add separator label for the saved layout too

 xml += "\n\t<separator label=\"Saved Layouts\"/>"

Last edited by samdraz (2013-07-27 02:51:49)

Offline

#5 2013-07-27 03:11:30

IrrationlArtist
Member
Registered: 2012-08-15
Posts: 15

Re: Screen layout switching pipemenu

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 xml

Thanks for the feedback.


signature.txt

Offline

#6 2013-07-27 03:19:19

samdraz
#! CrunchBanger
From: Earth
Registered: 2013-03-10
Posts: 232
Website

Re: Screen layout switching pipemenu

cool

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo