Greetings,
I've been given a task to create a bunch of thin-client systems. I found a Python script that acts as a window manager and provides a simple "Connect or Shut Down" interface. It works well, but now I've been asked to adapt it for two special situations.
1. Connect HERE, Connect THERE, or Shut Down." - easy enough, just duplicated the button declaration and action code. This is posted as Rev 1. What I can't seem to do is stack the buttons vertically in the window instead of horizontally.
2. Select a connection, click Connect, or Shutdown. I'm thinking a Combo box would work for that?
I'm fairly comfortable scripting, but am an absolute Python novice. I'd appreciate a hand to jump-start the revision 1 code changes, and a pointer to a good command reference (online or book) so I can tackle the revision 2 changes.
Thanks!
Glenn
Original Code:
#!/usr/bin/python
# original code - single RDP target
# Give the user the choice of rdesktop or powering
# down the workstation
# Set this to the host you intend to use as a
# Windows Remote Desktop server
windowsHost = "terminalserver.example.com"
import pygtk
pygtk.require('2.0')
import gtk
import os
import time
class ThinClientMenu:
#Instead of 'User' below, enter the name of the user that will signing into terminal services
def logOn(self, widget, data=None):
os.system("/usr/bin/rdesktop -f -u 'User' -a 16 " + windowsHost)
def powerOff(self, widget, data=None):
self.window.window.set_cursor(
gtk.gdk.Cursor(gtk.gdk.WATCH))
os.system("/sbin/poweroff")
# Fall asleep so the user doesn't try to
# do things while
# we are powering down the system
time.sleep(50000)
def __init__(self):
# create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_border_width(10)
self.vbox = gtk.VBox(False, 10)
self.hbox = gtk.HBox(False, 10)
self.window.add(self.vbox)
self.label = gtk.Label("Remote Desktop Workstation")
self.vbox.pack_start(self.label, True, True, 0)
self.logOnButton = gtk.Button("Log On to " + windowsHost)
self.powerOffButton = gtk.Button("Power Off")
self.logOnButton.connect("clicked",
self.logOn, None)
self.powerOffButton.connect("clicked",
self.powerOff, None)
self.hbox.pack_start(self.logOnButton,
True, True, 0)
self.hbox.pack_start(self.powerOffButton,
True, True, 0)
self.vbox.pack_start(self.hbox, True, True, 0)
screen = self.window.get_screen()
w = screen.get_width()
h = screen.get_height()
self.label.show()
self.logOnButton.show()
self.powerOffButton.show()
self.hbox.show()
self.vbox.show()
self.window.realize()
bw, bh = self.window.get_size()
self.window.move((w - bw) / 2, (h - bh) / 2)
# We are the window manager,
# have to pick a good cursor for
# ourselves
self.window.window.set_cursor(
gtk.gdk.Cursor(gtk.gdk.ARROW))
self.window.show()
# Set the background to a nice blue using the
# standard xsetroot utility
# (see "man xsetroot" for information)
os.system("xsetroot -solid DarkSlateBlue")
def main(self):
# All PyGTK applications must have a gtk.main().
# Control ends here
# and waits for an event to occur (like a
# key press or mouse event).
gtk.main()
if __name__ == "__main__":
thinClientMenu = ThinClientMenu()
thinClientMenu.main()
My revisions for 2-site connections - need to stack the buttons vertically, not horizontally.
#!/usr/bin/python
# first revision - added second RDP target & some comments
# Give the user the choice of rdesktop or powering
# down the workstation
# Set this to the host you intend to use as a
# Windows Remote Desktop server
windowsHost1 = "terminalserver1.example.com"
windowsHost2 = "terminalserver2.example.com"
import pygtk
pygtk.require('2.0')
import gtk
import os
import time
class ThinClientMenu:
# Leave USER (-u) option blank to prompt
def logOn1(self, widget, data=None):
os.system("/usr/bin/rdesktop -f -u 'User' -a 16 " + windowsHost1)
def logOn2(self, widget, data=None):
os.system("/usr/bin/rdesktop -f -u 'User' -a 16 " + windowsHost2)
def powerOff(self, widget, data=None):
self.window.window.set_cursor(
gtk.gdk.Cursor(gtk.gdk.WATCH))
os.system("/sbin/poweroff")
# Fall asleep so the user doesn't try to
# do things while
# we are powering down the system
time.sleep(50000)
def __init__(self):
# create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_border_width(10)
self.vbox = gtk.VBox(False, 10)
self.hbox = gtk.HBox(False, 10)
self.window.add(self.vbox)
self.label = gtk.Label("Remote Desktop Workstation")
self.vbox.pack_start(self.label, True, True, 0)
# define logon buttons & poweroff button
self.logOnButton1 = gtk.Button("Log On to " + windowsHost1)
self.logOnButton2 = gtk.Button("Log On to " + windowsHost2)
self.powerOffButton = gtk.Button("Power Off")
# define button actions
self.logOnButton1.connect("clicked", self.logOn1, None)
self.logOnButton2.connect("clicked", self.logOn2, None)
self.powerOffButton.connect("clicked", self.powerOff, None)
# set the buttons in the hbox
self.hbox.pack_start(self.logOnButton1, True, True, 0)
self.hbox.pack_start(self.logOnButton2, True, True, 0)
self.hbox.pack_start(self.powerOffButton, True, True, 0)
self.vbox.pack_start(self.hbox, True, True, 0)
screen = self.window.get_screen()
w = screen.get_width()
h = screen.get_height()
# make the objects visible
self.label.show()
self.logOnButton1.show()
self.logOnButton2.show()
self.powerOffButton.show()
self.hbox.show()
self.vbox.show()
self.window.realize()
# center the window
bw, bh = self.window.get_size()
self.window.move((w - bw) / 2, (h - bh) / 2)
# We are the window manager,
# have to pick a good cursor for
# ourselves
self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.ARROW))
self.window.show()
# Set the background to a nice blue using the
# standard xsetroot utility
# (see "man xsetroot" for information)
os.system("xsetroot -solid DarkSlateBlue")
def main(self):
# All PyGTK applications must have a gtk.main().
# Control ends here
# and waits for an event to occur (like a
# key press or mouse event).
gtk.main()
if __name__ == "__main__":
thinClientMenu = ThinClientMenu()
thinClientMenu.main()