No subject


Fri Jan 17 03:57:02 UTC 2014


version cleaned up with all of the general and advanced tab features
very soon.

Feedback is appreciated.

Lawrence

--Boundary_(ID_g1da1vp1XCa6mDxO57m1YQ)
Content-type: text/x-python; NAME=nxgui.py
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=nxgui.py

#!/usr/bin/env python
#
import gtk,os,getpass,sys,subprocess,time,gobject,shutil
from xml.dom import minidom, Node

def progress_timeout(tobj):
	data = tobj.so.readline()
	if data != "":
		tobj.statuslabel.set_text(data)
		gtk.main_iteration(gtk.FALSE)		
		print data	
		return True
	else:
		time.sleep(5)
		tobj.statuswindow.grab_remove()
		tobj.statuswindow.hide()
		tobj.window.show_all()

class nxgui:
	DEF_PAD = 5
	CONFIG_DLG_RESPONSE_DELETE = 1
	CONFIG_DLG_RESPONSE_SAVE = 2
	NEW_DLG_RESPONSE_CREATE = 1
	NEW_DLG_RESPONSE_RENAME = 2
	SESSION_TYPES = ["Unix", "Windows", "VNC"]
	UNIX_DESKTOPS = ["KDE","GNOME","CDE","Custom"]
	LINK_SPEEDS = ["Modem", "ISDN", "ASDL", "WAN", "LAN"]
	DISPLAY_RES = ["640x480", "800x600","1024x768","Available Area","Fullscreen","Custom"]
	CACHE_VALUES = ["1 MB","2 MB","4 MB","8 MB","16 MB","32 MB"]
	CACHE_CODES = ["1","2","4","8","16","32"]
	DISK_CACHE_VALUES = ["4 MB","8 MB","16 MB","32 MB","64 MB","128 MB"]
	DISK_CACHE_CODES = ["4","8","16","32","64","128"]
	KEYBOARD_VALUES = ["English","Estonian"]
	KEYBOARD_CODES = ["en","ee"]
        options = {}
	groups = {}
	if os.name == "nt":
		USB_TYPE_FILE = "C:\\python24\\pdaxrom\\misc\\usbd.ftype"
		USB_STORAGE_TYPE_FILE = "C:\\python24\\pdaxrom\\misc\\usbdstorage.conf"
		USB_NETWORK_CONF_FILE ="C:\\python24\\pdaxrom\\misc\\usbdnet.conf"
		CFG_FILENAME = ".\\usbconfig.cfg"
	else:
		USB_TYPE_FILE = "/etc/hotplug/usbd.ftype"
		USB_STORAGE_TYPE_FILE = "/etc/hotplug/usbdstorage.conf"
		USB_NETWORK_CONF_FILE ="/etc/hotplug/usbdnet.conf"
		CACHE_PATH = os.environ['HOME'] + "/.nx/cache/"

	def __init__(self):
		self.timer=0
		self.dirty_flag = False
		self.current_service = ""
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
	        self.window.set_title("NX GUI")
	        self.window.set_border_width(5)
		self.window.set_position(gtk.WIN_POS_CENTER)
	        self.window.set_resizable(gtk.FALSE)
	        self.window.connect("delete_event", gtk.main_quit)
	        self.window.connect("destroy", gtk.main_quit)

		MainBox = gtk.VBox(gtk.FALSE, self.DEF_PAD)
		self.window.add(MainBox)
		vbox = MainBox

        # Login
                
                hbox = gtk.HBox(gtk.FALSE, 5)
                vbox.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
                
                label = gtk.Label("Login:")
                hbox.pack_start(label, gtk.FALSE, gtk.FALSE, 5)
                self.loginlabel = label
		self.user = gtk.Entry(0)
                self.user.set_size_request(250,22)
                hbox.pack_end(self.user, gtk.FALSE, gtk.FALSE, 5)
                                 
                hbox = gtk.HBox(gtk.FALSE, 5)
                vbox.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)

                label = gtk.Label("Password:  ")
                hbox.pack_start(label, gtk.FALSE, gtk.FALSE, 5)
                self.passw = gtk.Entry(0)
		self.passw.set_visibility(gtk.FALSE)
                self.passw.set_size_request(250,22)
                hbox.pack_end(self.passw, gtk.FALSE, gtk.FALSE, 5)

                hbox = gtk.HBox(gtk.FALSE, 5)
                vbox.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
                label = gtk.Label("Service:  ")
                hbox.pack_start(label, gtk.FALSE, gtk.FALSE, 5)
		self.service_menu = gtk.combo_box_entry_new_text()
		l = os.listdir("./config")
		self.services = []
		for service in l:
			self.services.append(service)
			self.service_menu.append_text(service)
		print "services: " , self.service_menu.get_model().iter_n_children(None)
	        self.service_menu.connect('changed', self.change_service)
	        self.service_menu.child.connect('focus-out-event', self.focus_out_service)
		self.service_menu.set_size_request(250,30)
                hbox.pack_end(self.service_menu, gtk.FALSE, gtk.FALSE, 5)

	        bbox = gtk.HButtonBox ()
	        vbox.pack_start(bbox, gtk.FALSE, gtk.FALSE, 0)
	        bbox.set_layout(gtk.BUTTONBOX_END)
	        configure_button = gtk.Button("Configure...")
	        configure_button.connect("clicked", self.configure)
	        bbox.add(configure_button)
	        close_button = gtk.Button("Close")
	        close_button.connect("clicked", gtk.main_quit)
	        bbox.add(close_button)
	        login_button = gtk.Button("Login")
	        login_button.connect("clicked", self.run)
	        bbox.add(login_button)

                self.window.show_all();
		
	def load_combo(self, combo, alist):
		for t in alist:
			combo.append_text(t)

	def change_service(self, combobox):
		print "service change:", combobox.get_active()
		print combobox.child.get_text()
		if (combobox.get_active() > -1):
			print "changing service"
			self.current_service = self.services[combobox.get_active()]
		
		return True

	def do_dirty(self, widget=None):
		if (self.dirty_flag == False):
			self.dirty_flag = True
			self.save_button.set_sensitive(gtk.TRUE)
			
	def clear_dirty(self):
		if (self.dirty_flag == True):
			self.dirty_flag = False
			self.save_button.set_sensitive(gtk.FALSE)
			

	def focus_out_service(self, comboentry, event):
		print "lost focus:", comboentry.get_text()
		# select proper entry if in list.
		index = self.combo_select(self.service_menu, self.services, comboentry.get_text())
		print "new index: ", index
		# if this is a new entry, handle it
		if (index < 0):
			index =self.combo_new_entry(self.service_menu, self.services,  comboentry.get_text())
			if (index < 0):
				self.combo_select(self.service_menu, self.services, self.current_service)
			else:
				self.service_menu.set_active(index)
		return False

	def combo_select(self, combobox, reflist, value):
		try:
			i = reflist.index( value )
			combobox.set_active(i)
		except ValueError:
			i = -1
		return i
			
	def combo_new_entry(self, combobox, reflist, value):
		new_dlg = gtk.Dialog("NX - " + value, self.window,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,("Create", self.NEW_DLG_RESPONSE_CREATE, "Rename",self.NEW_DLG_RESPONSE_RENAME, gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))
		vb = new_dlg.vbox
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                label = gtk.Label("You have changed the service name.  What would you like to do?")
                hbox.pack_start(label, gtk.FALSE, gtk.FALSE, 5)
		label.show()
		resp = new_dlg.run()
		new_dlg.destroy()
		if (resp == self.NEW_DLG_RESPONSE_CREATE):
			# load the active file and save the copy
			if (self.current_service != ""):
				self.load_prefs()
				self.save_prefs(value)
			reflist.append(value)
			combobox.append_text(value)
			self.configure()
			return len(reflist)-1
		elif (resp == self.NEW_DLG_RESPONSE_RENAME):
			os.rename('./config/' + self.current_service, './config/' + value)
			index = reflist.index(self.current_service)
			combobox.remove_text(index)
			reflist.remove(self.current_service)
			combobox.insert_text(index, value)
			reflist.insert(index, value)
			return index
		return -1

	def configure(self, widget=None):
	# Configuration
		self.config_dlg = gtk.Dialog("NX -" + self.current_service, self.window,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT)
		self.config_dlg.connect("response", self.config_dlg_do_response)
		MainBox = self.config_dlg.vbox
        # Notebook
        
                self.notebook = gtk.Notebook()
                self.notebook.set_tab_pos(gtk.POS_TOP)
                self.config_dlg.vbox.pack_start(self.notebook, gtk.TRUE, gtk.TRUE, 5) 
		self.notebook.show()
		
	# General
          
		# General
		self.generalframe = gtk.Frame()
                label = gtk.Label("General")
                self.notebook.append_page(self.generalframe, label)
                generalbox = gtk.VBox(gtk.FALSE, 5)
                self.generalframe.add(generalbox)  
		self.generalframe.show()
		generalbox.show()
		# Server
                contentframe = gtk.Frame("Server")
                contentframe.set_border_width(4)
                generalbox.pack_start(contentframe, gtk.FALSE, gtk.FALSE, 5)
		contentframe.show()
                vb = gtk.VBox(gtk.FALSE, 8)
                vb.set_border_width(6)
                contentframe.add(vb)
		vb.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                label = gtk.Label("host:")
                hbox.pack_start(label, gtk.FALSE, gtk.FALSE, 5)
		label.show()
                self.host = gtk.Entry(0)
                self.host.set_size_request(150,22)
	        self.host.connect('changed', self.do_dirty)
                hbox.pack_start(self.host, gtk.FALSE, gtk.FALSE, 5)
		self.host.show()
		label = gtk.Label("port:")
                hbox.pack_start(label, gtk.FALSE, gtk.FALSE, 5)
		label.show()
                self.port = gtk.Entry(0)
                self.port.set_size_request(40,22)
	        self.port.connect('changed', self.do_dirty)
                hbox.pack_start(self.port, gtk.FALSE, gtk.FALSE, 5)
		self.port.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.remember = gtk.CheckButton("Remember my password")
	        self.remember.connect('toggled', self.do_dirty)
		hbox.pack_start(self.remember, gtk.FALSE, gtk.FALSE, 5)
		self.remember.show()
		# Desktop
                contentframe = gtk.Frame("Desktop")
                contentframe.set_border_width(4)
                generalbox.pack_start(contentframe, gtk.FALSE, gtk.FALSE, 5)
		contentframe.show()
                vb = gtk.VBox(gtk.FALSE, 8)
                vb.set_border_width(6)
                contentframe.add(vb)
		vb.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.session = gtk.combo_box_new_text()
                self.load_combo(self.session, self.SESSION_TYPES)
	        self.session.connect('changed', self.change_config_session)
                hbox.pack_start(self.session, gtk.FALSE, gtk.FALSE, 5)
		self.session.show()
                self.desktop = gtk.combo_box_new_text()
	        self.desktop.connect('changed', self.change_config_desktop)
                hbox.pack_start(self.desktop, gtk.FALSE, gtk.FALSE, 5)
		self.desktop.show()
		self.settings_button = gtk.Button("Settings...")
	        self.settings_button.connect("clicked", self.settings_unix)		
                hbox.pack_start(self.settings_button, gtk.FALSE, gtk.FALSE, 5)
		self.settings_button.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                label = gtk.Label("Link speed:")
                hbox.pack_start(label, gtk.FALSE, gtk.FALSE, 5)
		label.show()
                self.link_speed = gtk.combo_box_new_text()
                self.load_combo(self.link_speed, self.LINK_SPEEDS)
	        self.link_speed.connect('changed', self.do_dirty)
                hbox.pack_start(self.link_speed, gtk.FALSE, gtk.FALSE, 5)
		self.link_speed.show()		
		# Display
                contentframe = gtk.Frame("Display")
                contentframe.set_border_width(4)
                generalbox.pack_start(contentframe, gtk.FALSE, gtk.FALSE, 5)
		contentframe.show()
                vb = gtk.VBox(gtk.FALSE, 8)
                vb.set_border_width(6)
                contentframe.add(vb)
		vb.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.resolution = gtk.combo_box_new_text()
                self.load_combo(self.resolution, self.DISPLAY_RES)
	        self.resolution.connect('changed', self.change_config_resolution)
                hbox.pack_start(self.resolution, gtk.FALSE, gtk.FALSE, 5)
		self.resolution.show()		
                label = gtk.Label("W")
                hbox.pack_start(label, gtk.FALSE, gtk.FALSE, 5)
		label.show()
                self.resolution_width = gtk.SpinButton()
		self.resolution_width.set_numeric(gtk.TRUE)
		self.resolution_width.set_range(100,9999)
		self.resolution_width.set_increments(1,50)
                self.resolution_width.set_value(800)
	        self.resolution_width.connect('changed', self.do_dirty)
                hbox.pack_start(self.resolution_width, gtk.FALSE, gtk.FALSE, 5)
		self.resolution_width.show()		
                label = gtk.Label("H")
                hbox.pack_start(label, gtk.FALSE, gtk.FALSE, 5)
		label.show()
                self.resolution_height = gtk.SpinButton()
		self.resolution_height.set_numeric(gtk.TRUE)
		self.resolution_height.set_range(100,9999)
		self.resolution_height.set_increments(1,50)
                self.resolution_height.set_value(600)
	        self.resolution_height.connect('changed', self.do_dirty)
                hbox.pack_start(self.resolution_height, gtk.FALSE, gtk.FALSE, 5)
		self.resolution_height.show()		
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.encoding_default = gtk.RadioButton(label='Use default image encoding')
	        self.encoding_default.connect('toggled', self.toggle_config_encoding)
		hbox.pack_start(self.encoding_default, gtk.FALSE, gtk.FALSE, 5)
		self.encoding_default.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.encoding_custom = gtk.RadioButton(self.encoding_default, 'Use custom settings')
                hbox.pack_start(self.encoding_custom, gtk.FALSE, gtk.FALSE, 5)
		self.encoding_custom.show()
		self.custom_button = gtk.Button("Modify...")
                hbox.pack_start(self.custom_button, gtk.FALSE, gtk.FALSE, 5)
		self.custom_button.show()
		
          # Advanced 
          
                self.advancedframe = gtk.Frame()
                label = gtk.Label("Advanced")
                self.notebook.append_page(self.advancedframe, label)
		self.advancedframe.show()
                advancedbox = gtk.VBox(gtk.FALSE, 5)
                self.advancedframe.add(advancedbox)  
                advancedbox.show()
		# Network
                contentframe = gtk.Frame("Network")
                contentframe.set_border_width(4)
                advancedbox.pack_start(contentframe, gtk.FALSE, gtk.FALSE, 5)
		contentframe.show()
                vb = gtk.VBox(gtk.FALSE, 8)
                vb.set_border_width(6)
                contentframe.add(vb)
		vb.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.tcp = gtk.CheckButton("Disable no-delay for tcp connections")
	        self.tcp.connect('toggled', self.do_dirty)
		hbox.pack_start(self.tcp, gtk.FALSE, gtk.FALSE, 5)
		self.tcp.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.zlib = gtk.CheckButton("Disable ZLIB stream compression")
	        self.zlib.connect('toggled', self.do_dirty)
		hbox.pack_start(self.zlib, gtk.FALSE, gtk.FALSE, 5)
		self.zlib.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.ssl = gtk.CheckButton("Enable SSL encryption of all traffic")
	        self.ssl.connect('toggled', self.do_dirty)
		hbox.pack_start(self.ssl, gtk.FALSE, gtk.FALSE, 5)
		self.ssl.show()
		# Cache
                contentframe = gtk.Frame("Cache")
                contentframe.set_border_width(4)
                advancedbox.pack_start(contentframe, gtk.FALSE, gtk.FALSE, 5)
		contentframe.show()
                vb = gtk.VBox(gtk.FALSE, 8)
                vb.set_border_width(6)
                contentframe.add(vb)
		vb.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                label = gtk.Label("In memory")
                hbox.pack_start(label, gtk.FALSE, gtk.FALSE, 5)
		label.show()
                self.cache = gtk.combo_box_new_text()
                self.load_combo(self.cache, self.CACHE_VALUES)
	        self.cache.connect('changed', self.do_dirty)
                hbox.pack_start(self.cache, gtk.FALSE, gtk.FALSE, 5)
		self.cache.show()		
                label = gtk.Label("On disk")
                self.disk_cache = gtk.combo_box_new_text()
                self.load_combo(self.disk_cache, self.DISK_CACHE_VALUES)
	        self.disk_cache.connect('changed', self.do_dirty)
                hbox.pack_end(self.disk_cache, gtk.FALSE, gtk.FALSE, 5)
                hbox.pack_end(label, gtk.FALSE, gtk.FALSE, 5)
		label.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
		self.disk_cache.show()		
		self.cache_button = gtk.Button("Clean all cache files")
	        self.cache_button.connect("clicked", self.clicked_config_cache)
                hbox.pack_end(self.cache_button, gtk.FALSE, gtk.FALSE, 5)
		self.cache_button.show()
		# Keyboard
                contentframe = gtk.Frame("Keyboard")
                contentframe.set_border_width(4)
                advancedbox.pack_start(contentframe, gtk.FALSE, gtk.FALSE, 5)
		contentframe.show()
                vb = gtk.VBox(gtk.FALSE, 8)
                vb.set_border_width(6)
                contentframe.add(vb)
		vb.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.keyboard_current = gtk.RadioButton(label='Keep current keyboard settings')
	        self.keyboard_current.connect('toggled', self.toggle_config_keyboard)
		hbox.pack_start(self.keyboard_current, gtk.FALSE, gtk.FALSE, 5)
		self.keyboard_current.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.keyboard_other = gtk.RadioButton(self.keyboard_current, 'Use other layout')
                hbox.pack_start(self.keyboard_other, gtk.FALSE, gtk.FALSE, 5)
		self.keyboard_other.show()
                self.keyboards = gtk.combo_box_new_text()
                self.load_combo(self.keyboards, self.KEYBOARD_VALUES)
	        self.keyboards.connect('changed', self.do_dirty)
                hbox.pack_start(self.keyboards, gtk.FALSE, gtk.FALSE, 5)
		self.keyboards.show()		
		
	# Services
          
                self.logframe = gtk.Frame()
                label = gtk.Label("Services")
                self.notebook.append_page(self.logframe, label)
		self.logframe.show()
                logbox = gtk.VBox(gtk.FALSE, 5)
                self.logframe.add(logbox)  
		logbox.show()
		
		
	# Buttons

		self.config_dlg.add_button("Delete", self.CONFIG_DLG_RESPONSE_DELETE)
		self.save_button = self.config_dlg.add_button("Save",self.CONFIG_DLG_RESPONSE_SAVE)
		self.save_button.set_state(gtk.STATE_INSENSITIVE)
		self.config_dlg.add_button(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
		self.config_dlg.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)	
		self.load_prefs()
		self.config_dlg_load()
		self.config_dlg.show()

	def change_config_resolution(self, combobox):
		self.do_dirty()
		res = self.DISPLAY_RES[combobox.get_active()]
		if (res == 'Custom'):
			self.resolution_width.set_sensitive(gtk.TRUE)
			self.resolution_height.set_sensitive(gtk.TRUE)
		else:
			self.resolution_width.set_sensitive(gtk.FALSE)
			self.resolution_height.set_sensitive(gtk.FALSE)
		
	def change_config_session(self, combobox):
		self.do_dirty()
		ses = ""
		self.desktop.get_model().clear()
		if (combobox.get_active() > -1):
			ses = self.SESSION_TYPES[combobox.get_active()]
		if (ses == 'Unix'):
			self.load_combo(self.desktop, self.UNIX_DESKTOPS)
			self.desktop.set_sensitive(True)
		elif (ses == "Windows"):
			self.desktop.append_text("RDP")
			self.desktop.set_sensitive(False)
		elif (ses == "VNC"):
			self.desktop.append_text("RFB")
			self.desktop.set_sensitive(False)
		self.desktop.set_active(0)
		
	def change_config_desktop(self, combobox):
		self.do_dirty()
		self.settings_button.set_sensitive(True)
		ses = self.SESSION_TYPES[self.session.get_active()]
		if (ses == 'Unix'):
			dt = self.UNIX_DESKTOPS[combobox.get_active()]
			if (dt != 'Custom'):
				self.settings_button.set_sensitive(gtk.FALSE)
				self.resolution.set_sensitive(gtk.TRUE)
				self.change_config_resolution(self.resolution)
			else:
				self.resolution.set_sensitive(gtk.FALSE)
				self.resolution_width.set_sensitive(gtk.FALSE)
				self.resolution_height.set_sensitive(gtk.FALSE)
				
	def toggle_config_encoding(self, radio):
		self.do_dirty()
		self.custom_button.set_sensitive(self.encoding_custom.get_active())		
				
	def clicked_config_cache(self, butn):
		cache_msg_dlg = gtk.MessageDialog(self.config_dlg, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "Do you really want to clean all cache files");
		resp = cache_msg_dlg.run()
		if (resp == gtk.RESPONSE_YES):
			shutil.rmtree(self.CACHE_PATH)
			cache_confirm_msg_dlg = gtk.MessageDialog(self.config_dlg, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "All the caches in " + self.CACHE_PATH + " are cleared.");
			cache_confirm_msg_dlg.run()
			cache_confirm_msg_dlg.destroy()
		cache_msg_dlg.destroy()

	def toggle_config_keyboard(self, radio):
		self.do_dirty()
		self.keyboards.set_sensitive(self.keyboard_other.get_active())		


	def config_dlg_do_response(self, dialog, response_id):
		print "response: ", response_id
		if (response_id == gtk.RESPONSE_ACCEPT):
			self.config_dlg_store()
			self.save_prefs()
			self.config_dlg.destroy()
		elif (response_id == self.CONFIG_DLG_RESPONSE_SAVE):
			self.config_dlg_store()
			self.save_prefs()
			self.clear_dirty()
		elif (response_id == gtk.RESPONSE_REJECT):
			self.config_dlg.destroy()
		elif (response_id == self.CONFIG_DLG_RESPONSE_DELETE):
			os.remove('./config/'+ self.current_service)
			i = self.services.index(self.current_service)
			self.services.remove(self.current_service)
			self.service_menu.remove_text(i)
			self.config_dlg.destroy()
			

	def config_dlg_load(self):
	# Advanced
		if (self.get_option("Advanced", "Disable TCP no-delay") == "true"):
			self.tcp.set_active(True)
		else:
			self.tcp.set_active(False)
		if (self.get_option("Advanced", "Disable ZLIB stream compression") == "true"):
			self.zlib.set_active(True)
		else:
			self.zlib.set_active(False)
		if (self.get_option("Advanced", "Enable SSL encryption") == "true"):
			self.ssl.set_active(True)
		else:
			self.ssl.set_active(False)
		if (self.get_option("Advanced", "Cache size") != ''):
		   cache = self.get_option("Advanced", "Cache size") 
		   i = self.CACHE_CODES.index(cache)
		   if (i > -1):
			self.cache.set_active(i)
		if (self.get_option("Advanced", "Cache size on disk") != ''):
		   cache = self.get_option("Advanced", "Cache size on disk") 
		   i = self.DISK_CACHE_CODES.index(cache)
		   if (i > -1):
			self.disk_cache.set_active(i)
		if (self.get_option("Advanced", "Current keyboard") == "false"):
			self.keyboard_other.set_active(gtk.TRUE)
		else:
			self.keyboard_current.set_active(gtk.TRUE)
			self.toggle_config_keyboard(self.keyboard_current)
		if (self.get_option("Advanced", "Custom keyboard layout") != ''):
		   layout = self.get_option("Advanced", "Custom keyboard layout") 
		   i = self.KEYBOARD_CODES.index(layout)
		   if (i > -1):
			self.keyboards.set_active(i)
			
	# General
		self.host.set_text(self.get_option("General", "Server host"))
		self.port.set_text(self.get_option("General", "Server port"))
		if (self.get_option("General", "Remember password") == "true"):
			self.remember.set_active(True)
		else:
			self.remember.set_active(False)
		ses = self.get_option("General", "Session")
		dt = self.get_option("General", "Desktop")
		self.combo_select(self.session, self.SESSION_TYPES, ses)
		if (ses == 'Unix'):
			self.combo_select(self.desktop, self.UNIX_DESKTOPS, dt)
		self.combo_select(self.link_speed, self.LINK_SPEEDS, self.get_option("General", "Link speed"))
		self.combo_select(self.resolution, self.DISPLAY_RES, self.get_option("General", "Resolution"))
		if (self.get_option("General","Resolution width") != ''):
			self.resolution_width.set_value(int(self.get_option("General","Resolution width")))
		if (self.get_option("General","Resolution height") != ''):
			self.resolution_height.set_value(int(self.get_option("General","Resolution height")))
		if (self.get_option("General", "Use default image encoding") == "1"):
			self.encoding_custom.set_active(gtk.TRUE)
		else:
			self.encoding_default.set_active(gtk.TRUE)
			self.toggle_config_encoding(self.encoding_default)
		self.clear_dirty()

	def config_dlg_store(self):
	# Advanced
		if (self.tcp.get_active()):
			cvalue = "true"
		else:
			cvalue = "false"
		self.set_option("Advanced", "Disable TCP no-delay", cvalue)
		if (self.zlib.get_active()):
			cvalue = "true"
		else:
			cvalue = "false"
		self.set_option("Advanced", "Disable ZLIB stream compression", cvalue)
		if (self.ssl.get_active()):
			cvalue = "true"
		else:
			cvalue = "false"
		self.set_option("Advanced", "Enable SSL encryption", cvalue)
		if (self.cache.get_active() > -1):
			self.set_option("Advanced", "Cache size", self.CACHE_CODES[self.cache.get_active()])
		else:
			self.set_option("Advanced", "Cache size", '')
		if (self.disk_cache.get_active() > -1):
			self.set_option("Advanced", "Cache size on disk", self.DISK_CACHE_CODES[self.cache.get_active()])
		else:
			self.set_option("Advanced", "Cache size on disk", '')
		if (self.keyboard_current.get_active() == True):
			self.set_option("Advanced","Current keyboard","true")
		else:
			self.set_option("Advanced","Current keyboard","false")
		if (self.keyboards.get_active() > -1):
			self.set_option("Advanced", "Custom keyboard layout", self.KEYBOARD_CODES[self.keyboards.get_active()])
		else:
			self.set_option("Advanced", "Custom keyboard layout", '')

	# Login
		self.set_option("Login", "User", self.user.get_text())
		self.set_option("Login", "ClearPassword", self.passw.get_text())
	# General
		self.set_option("General", "Server host", self.host.get_text())
		self.set_option("General", "Server port", self.port.get_text())
		
		if (self.remember.get_active()):
			remembervalue = "true"
		else:
			remembervalue = "false"
		self.set_option("General", "Remember password", remembervalue)
		if (self.session.get_active() > -1):
			ses = self.SESSION_TYPES[self.session.get_active()]
			self.set_option("General", "Session", ses)
			if (ses == 'Unix'):
				self.set_option("General", "Desktop", self.UNIX_DESKTOPS[self.desktop.get_active()])
			elif (ses == 'Windows'):
				self.set_option("General", "Desktop", "RDP")
			elif (ses == 'VNC'):
				self.set_option("General", "Desktop", "RFB")
		else:
			self.set_option("General", "Session", '')
			self.set_option("General", "Desktop", '')
		if (self.link_speed.get_active() > -1):
			self.set_option("General", "Link speed", self.LINK_SPEEDS[self.link_speed.get_active()])
		else:
			self.set_option("General", "Link speed", '')
		if (self.resolution.get_active() > -1):
			self.set_option("General", "Resolution", self.DISPLAY_RES[self.resolution.get_active()])
		else:
			self.set_option("General", "Resolution", '')
		self.set_option("General","Resolution width", str(self.resolution_width.get_value_as_int()))	
		self.set_option("General","Resolution height", str(self.resolution_height.get_value_as_int()))	
		if (self.encoding_custom.get_active() == True):
			self.set_option("General","Use default image encoding","1")
		else:
			self.set_option("General","Use default image encoding","0")
	
	def settings_unix(self, widget=None):
	# Settings
		self.settings_dlg = gtk.Dialog("Custom - Settings", self.config_dlg,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK,gtk.RESPONSE_OK,gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL))
		self.settings_dlg.connect("response", self.settings_unix_dlg_do_response)
		MainBox = self.settings_dlg.vbox
                contentframe = gtk.Frame("Application")
                contentframe.set_border_width(4)
                MainBox.pack_start(contentframe, gtk.FALSE, gtk.FALSE, 5)
		contentframe.show()
                vb = gtk.VBox(gtk.FALSE, 8)
                vb.set_border_width(6)
                contentframe.add(vb)
		vb.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.app_console = gtk.RadioButton(label='Run console')
		hbox.pack_start(self.app_console, gtk.FALSE, gtk.FALSE, 5)
		self.app_console.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.app_default = gtk.RadioButton(self.app_console, 'Run default X client script on server')
                hbox.pack_start(self.app_default, gtk.FALSE, gtk.FALSE, 5)
	        self.app_default.connect('toggled', self.toggle_settings_unix_app)
		self.app_default.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.app_command = gtk.RadioButton(self.app_console, 'Run the following command')
	        self.app_command.connect('toggled', self.toggle_settings_unix_app)
                hbox.pack_start(self.app_command, gtk.FALSE, gtk.FALSE, 5)
		self.app_command.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.app_command_value = gtk.Entry(0)
                self.app_command_value.set_size_request(200,22)
                hbox.pack_start(self.app_command_value, gtk.FALSE, gtk.FALSE, 20)
		self.app_command_value.show()
                contentframe = gtk.Frame("Options")
                contentframe.set_border_width(4)
                MainBox.pack_start(contentframe, gtk.FALSE, gtk.FALSE, 5)
		contentframe.show()
                vb = gtk.VBox(gtk.FALSE, 8)
                vb.set_border_width(6)
                contentframe.add(vb)
		vb.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.options_float = gtk.RadioButton(label='Floating window')
		hbox.pack_start(self.options_float, gtk.FALSE, gtk.FALSE, 5)
		self.options_float.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.options_taint = gtk.CheckButton("Disable taint of X replies")
		hbox.pack_start(self.options_taint, gtk.FALSE, gtk.FALSE, 20)
		self.options_taint.show()
                hbox = gtk.HBox(gtk.FALSE, 5)
                vb.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
		hbox.show()
                self.options_new = gtk.RadioButton(self.options_float, 'New virtual desktop')
                hbox.pack_start(self.options_new, gtk.FALSE, gtk.FALSE, 5)
	        self.options_new.connect('toggled', self.toggle_settings_unix_options)
		self.options_new.show()

		self.settings_unix_dlg_load()
		self.settings_dlg.show()

	def toggle_settings_unix_app(self, radio):
		self.app_command_value.set_sensitive(self.app_command.get_active())

	def toggle_settings_unix_options(self, radio):
		self.options_taint.set_sensitive(self.options_float.get_active())
		
	def settings_unix_dlg_do_response(self, dialog, response_id):
		if (response_id == gtk.RESPONSE_OK):
			print "storing settings"
			self.settings_unix_dlg_store()
			self.do_dirty()
		self.settings_dlg.destroy()
			
	def settings_unix_dlg_load(self):
		if (self.get_option("General", "Only console") == "true"):
			self.app_console.set_active(gtk.TRUE)
		elif (self.get_option("General", "Run default script") == "true"):
			self.app_default.set_active(gtk.TRUE)
		else:
			self.app_command.set_active(gtk.TRUE)
		self.toggle_settings_unix_app(self.app_console)
		self.app_command_value.set_text(self.get_option("General", "Command line"))
		if (self.get_option("General", "Virtual desktop") == "true"):
			self.options_new.set_active(gtk.TRUE)
		if (self.get_option("General", "Use taint") == "true"):
			self.options_taint.set_active(gtk.TRUE)
		

	def settings_unix_dlg_store(self):
		if (self.app_console.get_active() == True):
			self.set_option("General","Only console","true")
		else:
			self.set_option("General","Only console","false")
		if (self.app_default.get_active() == True):
			self.set_option("General","Run default script","true")
		else:
			self.set_option("General","Run default script","false")
		self.set_option("General", "Command line", self.app_command_value.get_text())
		if (self.options_new.get_active() == True):
			self.set_option("General","Virtual desktop","true")
		else:
			self.set_option("General","Virtual desktop","false")
		if (self.options_taint.get_active() == True):
			self.set_option("General","Use taint","true")
		else:
			self.set_option("General","Use taint","false")
		
	
        def run(self, widget):
	# Status
		self.statuswindow = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.statuswindow.set_transient_for(self.window)
	        self.statuswindow.set_title("NX GUI Status")
	        self.statuswindow.set_border_width(5)
		self.statuswindow.set_position(gtk.WIN_POS_CENTER)
	        self.statuswindow.set_resizable(gtk.FALSE)
		MainBox = gtk.VBox(gtk.FALSE, self.DEF_PAD)
		self.statuswindow.add(MainBox)
                hbox = gtk.HBox(gtk.FALSE, 5)
                MainBox.pack_start(hbox, gtk.FALSE, gtk.FALSE, 5)
                self.statuslabel = gtk.Label("Status                                           ")
                hbox.pack_start(self.statuslabel, gtk.FALSE, gtk.FALSE, 5)
	        bbox = gtk.HButtonBox ()
	        MainBox.pack_start(bbox, gtk.FALSE, gtk.FALSE, 0)
	        bbox.set_layout(gtk.BUTTONBOX_END)

	        detailsbutton = gtk.Button("details")
		detailsbutton.set_state(gtk.STATE_INSENSITIVE)
		bbox.add(detailsbutton)
	        cancel_button = gtk.Button("Cancel",gtk.STOCK_CANCEL)
#	        cancel_button.connect("clicked", gtk.main_quit)
	        bbox.add(cancel_button)

	        cancel_button.set_flags(gtk.CAN_DEFAULT)
	        cancel_button.grab_default()
		self.window.hide()
		self.statuswindow.show_all()
		self.statuswindow.grab_add()
		gtk.main_iteration(gtk.FALSE)
		cmd = ["./nxrun"]
		if self.current_service != "":
			cmd.append("./config/" + self.current_service)
		cmd.append("-u")
		cmd.append(self.user.get_text())
		cmd.append("-p")
		cmd.append(self.passw.get_text())
		print cmd
		p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
                self.so = p.stdout
		if (self.timer):
			gobject.source_remove(self.timer)
			self.timer = 0
		self.timer = gobject.timeout_add(100, progress_timeout, self)		
		

	def load_prefs(self):
		print "./config/" + self.current_service
		if os.path.isfile("./config/" + self.current_service):
			self.options = {}				
			try:
				xmldoc = minidom.parse("./config/" + self.current_service)
			except:
				return False
			else:
				print "loading..."
				tags = xmldoc.getElementsByTagName("group");
				for tag in tags:	
					print "group: " + tag.getAttribute("name")
					options = tag.getElementsByTagName("option")
					for option in options:
						self.set_option(tag.getAttribute("name"), option.getAttribute("key"), option.getAttribute("value"))
						
				return True
		else:
			return False

	def save_prefs(self,service=None):
	# Root
		conf_tree = minidom.Document()
		root_node = conf_tree.createElement("NXClientSettings")
		root_node.setAttribute("application", "nxclient")
		root_node.setAttribute("version", "1.4.0")
		self.groups = {}
	# options
		k = self.options.keys()
		for key in k:
			self.save_groupoption(conf_tree, root_node,key[0], key[1], self.options[key])
	# Save
		if (service == None):
			service = self.current_service
		conf_tree.appendChild(root_node)
		FD = open("./config/" + service, "w")
		FD.write(conf_tree.toprettyxml())
		FD.close()
		

	def save_groupoption(self, tree, root, name, key, value):
		# First check if the group exists
		if self.groups.has_key(name):
			group_node = self.groups[name]
		else:
		# if not create it
			group_node = self.save_group(tree, root, name)
			self.groups[name] = group_node
		# create the option
		self.save_option(tree, group_node, key, value)
		
	def save_group(self, tree, root, name):
		node = tree.createElement("group")
		node.setAttribute("name", name)
		root.appendChild(node)
		return node
		
	
	def save_option(self, tree, node, key, value):
		option_node = tree.createElement("option")
		option_node.setAttribute("key", key)
		option_node.setAttribute("value", value)
		node.appendChild(option_node)

	def get_option(self, group, key):
		if self.options.has_key((group, key)):
			return self.options[(group, key)]
		else:
			return ""
		
	def set_option(self, group, key, value):
		option = group + ":" + key
		self.options[(group,key)] = value
	
		
	def main(self):
		gtk.main()

if __name__ == "__main__":
	nxgui = nxgui()
	nxgui.main()
	

--Boundary_(ID_g1da1vp1XCa6mDxO57m1YQ)--



More information about the FreeNX-kNX mailing list