Commit 18d769e6 authored by Michael Weinrich's avatar Michael Weinrich
Browse files

simple GUI for the TestSuite (not yet working)

parent 905e77b8
#! /usr/bin/env python
# Licensed under the MIT license
# http://opensource.org/licenses/mit-license.php
# Copyright 2007, Michael Weinrich <testsuite@michael-weinrich.de>
import os, sys
from twisted.internet import gtk2reactor
gtk2reactor.install()
from twisted.internet import reactor
import pygtk
pygtk.require('2.0')
import gtk
from twisted.python import usage
from upntest.UPnTGUI import UPnTGUI
from configobj import ConfigObj
class Options(usage.Options):
optParameters = [['configfile', 'c', '', 'path to configfile'],
]
def main(options):
# get settings or options
def setConfigFile(filename):
def findConfigDir():
try:
configDir = os.path.expanduser('~')
except:
configDir = os.getcwd()
return configDir
if filename is '':
filename = os.path.join( findConfigDir(), '.upntest')
return filename
config = ConfigObj( setConfigFile( options['configfile']))
u = UPnTGUI(config)
if __name__ == '__main__':
options = Options()
try:
options.parseOptions()
except usage.UsageError, errortext:
print '%s: %s' % (sys.argv[0], errortext)
print '%s: Try --help for usage details.' % (sys.argv[0])
sys.exit(1)
reactor.callWhenRunning(main, options)
reactor.run()
\ No newline at end of file
This diff is collapsed.
# Licensed under the MIT license
# http://opensource.org/licenses/mit-license.php
# Copyright 2007, Michael Weinrich <testsuite@michael-weinrich.de>
from twisted.internet import reactor, task
import gtk
import gobject
from upntest.base import UPnT
import louie
import time
import sys
class UPnTGUI:
UPnT = None
def delete_event(self, widget, event, data=None):
return False
def quitApplication(self, widget, data=None):
self.window.destroy()
def destroy(self, widget, data=None):
print 'Ausmachen...'
reactor.stop()
#print 'Warten auf die Langsamen...'
#time.sleep(5)
#kill reactor if some deferreds are not responding
print 'Lange genug gewartet!'
#gtk.main_quit()
reactor.crash()
print 'Crashed!'
del self.UPnT
print 'Fertsch!'
def updateUpnpDevices(self, ip):
model = self.upnp_devices_treeview.get_model()
iter = model.get_iter_first()
current_parent = None
while iter is not None:
if model.get_value(iter, 1) == ip:
current_parent = iter
break
iter = model.iter_next(iter)
if current_parent == None:
current_parent = model.append(None, [self.device_icon, ip])
else:
children_iter = model.iter_children(current_parent)
result = children_iter is not None
while result:
result = model.remove(children_iter)
host = self.UPnT.known_hosts[ip]
for uuid, device in host._devices.items():
device_iter = model.append(current_parent, [self.device_icon, device.deviceType])
for uuid, service in device._services.items():
model.append(device_iter, [self.service_icon, service.serviceType])
def runControlTest(self, widget, data=None):
print 'muh'
def updateMessageBox(self, message):
self.messageTextBuffer.insert(self.messageTextBuffer.get_end_iter(), message + '\n')
self.refreshUI()
def refreshUI(self):
while gtk.events_pending():
gtk.main_iteration()
#reactor.callLater(1, self.refreshUI)
def __init__(self, config):
# create window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("UPnP Test Suite")
self.window.set_size_request(780, 460)
self.window.set_border_width(0)
self.window.connect("delete_event", self.delete_event)
self.window.connect("destroy", self.destroy)
# create the TreeView using TreeStore
model = gtk.TreeStore(
gtk.gdk.Pixbuf,
str)
self.upnp_devices_treeview = gtk.TreeView(model)
self.upnp_devices_treeview.set_size_request(250, 260)
self.upnp_devices_treeview.set_headers_visible(False)
pixbufrenderer = gtk.CellRendererPixbuf()
textrenderer = gtk.CellRendererText()
textrenderer.set_property('xalign', 0.0)
column = gtk.TreeViewColumn()
column.pack_start(pixbufrenderer, False)
column.pack_start(textrenderer, True)
column.set_attributes(pixbufrenderer, pixbuf=0)
column.set_attributes(textrenderer, text=1)
self.upnp_devices_treeview.append_column(column)
self.device_icon = gtk.gdk.pixbuf_new_from_file_at_size('/home/micxer/development/UPnT/gnome-fs-client.svg', 24, 24)
self.service_icon = gtk.gdk.pixbuf_new_from_file_at_size('/home/micxer/development/UPnT/icon_webservice.gif', 24, 24)
self.hbuttonbox = gtk.HButtonBox()
self.hbuttonbox.set_size_request(510, 30)
self.hbuttonbox
#self.hbuttonbox.set_layout(gtk.BUTTONBOX_START)
self.hbuttonbox.set_spacing(4)
self.button = gtk.Button("Test Control")
self.button.connect_object("clicked", self.runControlTest, None)
self.hbuttonbox.pack_start(self.button)
self.button = gtk.Button(stock=gtk.STOCK_QUIT)
self.button.connect("clicked", self.destroy)
self.hbuttonbox.pack_end(self.button)
# TextView for information about selected device
self.device_info_scrolledwindow = gtk.ScrolledWindow()
self.device_info_scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.device_info_scrolledwindow.set_border_width(1)
self.device_info_scrolledwindow.set_size_request(510, 240)
self.device_info_textview = gtk.TextView()
self.device_info_textview.set_editable(False)
self.messageTextBuffer = self.device_info_textview.get_buffer()
self.device_info_scrolledwindow.add(self.device_info_textview)
# TextView for messages from the suite
self.message_scrolledwindow = gtk.ScrolledWindow()
self.message_scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.message_scrolledwindow.set_border_width(1)
self.message_scrolledwindow.set_size_request(760, 200)
self.message_textview = gtk.TextView()
self.message_textview.set_editable(False)
self.messageTextBuffer = self.message_textview.get_buffer()
self.message_scrolledwindow.add(self.message_textview)
# Boxes fot the upper elements
self.hpane = gtk.HPaned()
self.hpane.handle_size = 0
self.hpane.add1(self.upnp_devices_treeview)
self.vbox = gtk.VBox(False, 1)
self.hpane.add2(self.vbox)
self.vbox.pack_start(self.device_info_scrolledwindow)
self.vbox.pack_start(self.hbuttonbox)
# pack all the stuff together
self.vpane = gtk.VPaned()
self.vpane.handle_size = 0
self.vpane.add1(self.hpane)
self.vpane.add2(self.message_scrolledwindow)
self.window.add(self.vpane)
self.window.show_all()
# we are in GUI mode
config['GUI'] = True
# initialize UPnT
self.UPnT = UPnT(config)
louie.connect(self.updateMessageBox, 'UPnT.infoMessage', louie.Any, weak=False)
louie.connect(self.updateUpnpDevices, 'UPnT.host_discovery_end', louie.Any, weak=False)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment