Pages

Sunday, March 14, 2010

Rotate screen app for my netbook with Python

I got my little python screen rotate app (script) to work today. I had stop messing with it, one because I have been studying, two creating keyboard shortcuts satisfied my needs. That aside I was still curious to figure out how to make it work here are two screen shots of it working.









































Nothing all that impressive I am sure, but; I learned something which is always cool. Now to figure out how to make it a drop down menu as a gtk applet. Below is the messy script.





#!/usr/bin/env python
#
# Rotate Button

import sys
import os
import pygtk
pygtk.require('2.0')
import gtk

class ToggleButton:
    # Our callback.
    def call(self, widget, data=None):
        os.system ('xrandr -o normal')
    #first try a second button
    def call2(self, widget, data=None):
        os.system ('xrandr -o right')
    # This callback quits the program
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

    def __init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)

        # Set the window title
        self.window.set_title("Normal")

        # Set a handler for delete_event that immediately
        # exits GTK.
        self.window.connect("delete_event", self.delete_event)

        # Sets the border width of the window.
        self.window.set_border_width(20)

        # Create a vertical box
        vbox = gtk.VBox(True, 2)

        # Put the vbox in the main window
        self.window.add(vbox)

        # Create "Normal" button
        button = gtk.Button("Normal")

        # When the button is clicked, we call the xrandr -o function
        # and the program exits
        button.connect("clicked", self.call, "Normal")

        # Insert the Normal button
        vbox.pack_start(button, True, True, 2)

        button.show()
        vbox.show()
        self.window.show()

       # Create "Right" button
        button = gtk.Button("Right")

        # When the button is clicked, we call the xrandr -o function
        # and the program exits
        button.connect("clicked", self.call2, "Right")

        # Insert the Right button
        vbox.pack_start(button, True, True, 2)

        button.show()
        vbox.show()
        self.window.show()


        # Create "Quit" button
        button = gtk.Button("Quit")

        # When the button is clicked, we call the main_quit function
        # and the program exits
        button.connect("clicked", lambda wid: gtk.main_quit())

        # Insert the quit button
        vbox.pack_start(button, True, True, 2)

        button.show()
        vbox.show()
        self.window.show()


def main():
    gtk.main()
    return 0      

if __name__ == "__main__":
    ToggleButton()
    main()