借助rdesktop,本人将rdesktop打包到程序所在目录的 bin下。
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'mstsc-linux.ui'
#
# Created: Wed Sep 11 13:07:40 2013
# by: PyQt4 UI code generator 4.8.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(344, 344)
self.host_lable = QtGui.QLabel(Dialog)
self.host_lable.setGeometry(QtCore.QRect(20, 20, 101, 17))
self.host_lable.setLayoutDirection(QtCore.Qt.RightToLeft)
self.host_lable.setObjectName(_fromUtf8("host_lable"))
self.host_comboBox = QtGui.QComboBox(Dialog)
self.host_comboBox.setGeometry(QtCore.QRect(150, 10, 181, 29))
self.host_comboBox.setMaximumSize(QtCore.QSize(181, 29))
self.host_comboBox.setEditable(True)
self.host_comboBox.setObjectName(_fromUtf8("host_comboBox"))
self.name_lable = QtGui.QLabel(Dialog)
self.name_lable.setGeometry(QtCore.QRect(10, 60, 111, 20))
self.name_lable.setLayoutDirection(QtCore.Qt.RightToLeft)
self.name_lable.setObjectName(_fromUtf8("name_lable"))
self.name_lineedit = QtGui.QLineEdit(Dialog)
self.name_lineedit.setGeometry(QtCore.QRect(150, 50, 181, 25))
self.name_lineedit.setObjectName(_fromUtf8("name_lineedit"))
self.passwd_label = QtGui.QLabel(Dialog)
self.passwd_label.setGeometry(QtCore.QRect(10, 100, 111, 20))
self.passwd_label.setLayoutDirection(QtCore.Qt.RightToLeft)
self.passwd_label.setObjectName(_fromUtf8("passwd_label"))
self.passwd_lineedit = QtGui.QLineEdit(Dialog)
self.passwd_lineedit.setGeometry(QtCore.QRect(150, 100, 181, 25))
self.passwd_lineedit.setEchoMode(QtGui.QLineEdit.Password)
self.passwd_lineedit.setObjectName(_fromUtf8("passwd_lineedit"))
self.groupBox = QtGui.QGroupBox(Dialog)
self.groupBox.setGeometry(QtCore.QRect(10, 220, 181, 121))
self.groupBox.setObjectName(_fromUtf8("groupBox"))
self.clipboard_checkbox = QtGui.QCheckBox(self.groupBox)
self.clipboard_checkbox.setGeometry(QtCore.QRect(10, 30, 141, 22))
self.clipboard_checkbox.setObjectName(_fromUtf8("clipboard_checkbox"))
self.fullscreen_checkbox = QtGui.QCheckBox(self.groupBox)
self.fullscreen_checkbox.setGeometry(QtCore.QRect(10, 60, 151, 22))
self.fullscreen_checkbox.setObjectName(_fromUtf8("fullscreen_checkbox"))
self.localsound_checkbox = QtGui.QCheckBox(self.groupBox)
self.localsound_checkbox.setGeometry(QtCore.QRect(10, 90, 151, 22))
self.localsound_checkbox.setObjectName(_fromUtf8("localsound_checkbox"))
self.sharedir_label = QtGui.QLabel(Dialog)
self.sharedir_label.setGeometry(QtCore.QRect(10, 150, 111, 17))
self.sharedir_label.setLayoutDirection(QtCore.Qt.RightToLeft)
self.sharedir_label.setObjectName(_fromUtf8("sharedir_label"))
self.sharedir_lineedit = QtGui.QLineEdit(Dialog)
self.sharedir_lineedit.setGeometry(QtCore.QRect(150, 140, 131, 25))
self.sharedir_lineedit.setReadOnly(True)
self.sharedir_lineedit.setObjectName(_fromUtf8("sharedir_lineedit"))
self.selectdir_button = QtGui.QPushButton(Dialog)
self.selectdir_button.setGeometry(QtCore.QRect(290, 140, 31, 27))
self.selectdir_button.setObjectName(_fromUtf8("selectdir_button"))
self.color_label = QtGui.QLabel(Dialog)
self.color_label.setGeometry(QtCore.QRect(10, 190, 111, 17))
self.color_label.setLayoutDirection(QtCore.Qt.RightToLeft)
self.color_label.setObjectName(_fromUtf8("color_label"))
self.color__comboBox = QtGui.QComboBox(Dialog)
self.color__comboBox.setGeometry(QtCore.QRect(150, 180, 181, 29))
self.color__comboBox.setObjectName(_fromUtf8("color__comboBox"))
self.ok_button = QtGui.QPushButton(Dialog)
self.ok_button.setGeometry(QtCore.QRect(220, 250, 88, 27))
self.ok_button.setObjectName(_fromUtf8("ok_button"))
self.cancel_button = QtGui.QPushButton(Dialog)
self.cancel_button.setGeometry(QtCore.QRect(220, 290, 88, 27))
self.cancel_button.setObjectName(_fromUtf8("cancel_button"))
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
self.host_lable.setText(QtGui.QApplication.translate("Dialog", "Host", None, QtGui.QApplication.UnicodeUTF8))
self.name_lable.setText(QtGui.QApplication.translate("Dialog", "UserName", None, QtGui.QApplication.UnicodeUTF8))
self.passwd_label.setText(QtGui.QApplication.translate("Dialog", "Password", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox.setTitle(QtGui.QApplication.translate("Dialog", "Other", None, QtGui.QApplication.UnicodeUTF8))
self.clipboard_checkbox.setText(QtGui.QApplication.translate("Dialog", "Enable Clipboard", None, QtGui.QApplication.UnicodeUTF8))
self.fullscreen_checkbox.setText(QtGui.QApplication.translate("Dialog", "Enable Full Screen", None, QtGui.QApplication.UnicodeUTF8))
self.localsound_checkbox.setText(QtGui.QApplication.translate("Dialog", "Enable Local Sound", None, QtGui.QApplication.UnicodeUTF8))
self.sharedir_label.setText(QtGui.QApplication.translate("Dialog", "Share Directory", None, QtGui.QApplication.UnicodeUTF8))
self.selectdir_button.setText(QtGui.QApplication.translate("Dialog", "...", None, QtGui.QApplication.UnicodeUTF8))
self.color_label.setText(QtGui.QApplication.translate("Dialog", "Color Setting", None, QtGui.QApplication.UnicodeUTF8))
self.ok_button.setText(QtGui.QApplication.translate("Dialog", "Ok", None, QtGui.QApplication.UnicodeUTF8))
self.cancel_button.setText(QtGui.QApplication.translate("Dialog", "Cancel", None, QtGui.QApplication.UnicodeUTF8))
#!/bin/env python
# -*- coding: utf-8 -*-
from PyQt4 import QtCore,QtGui
import sys,os,socket,time,datetime,shutil,atexit ,platform,os,sys
from mstsc_ui import Ui_Dialog
class Ui(QtGui.QDialog):
def __init__(self, parent=None):
'''
@summary: Construction
'''
self.configSep = '||'
self.configFile = self.getCurrentWorkPath() + os.sep + 'history.log'
self.confInfo = []
super(Ui, self).__init__(parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
self.registHandle()
self.initBaseCtrl()
self.loadConfig()
self.setEnvirment()
def initBaseCtrl(self):
self.ui.color__comboBox.addItem("8")
self.ui.color__comboBox.addItem("16")
self.ui.color__comboBox.addItem("32")
def loadConfig(self):
self.confInfo = self.readCOnfig(self.configFile)
#init
for one in self.confInfo:
oneSplit = one.split(self.configSep)
if len(oneSplit) <= 0:
continue
host = oneSplit[0]
self.ui.host_comboBox.addItem(host)
if len(self.confInfo) > 0:
self.ui.host_comboBox.currentIndex = 0
def setEnvirment(self):
path=os.environ["PATH"]
path = path + ":" + self.getCurrentWorkPath() + os.sep + 'bin'
os.environ["PATH"] = path
return
def registHandle(self):
'''
@summary: regist event
'''
QtCore.QObject.connect(self.ui.selectdir_button, QtCore.SIGNAL("clicked ()"), self.selectDir)
QtCore.QObject.connect(self.ui.ok_button, QtCore.SIGNAL("clicked ()"), self.Do)
QtCore.QObject.connect(self.ui.cancel_button, QtCore.SIGNAL("clicked ()"), self.Cancel)
QtCore.QObject.connect(self.ui.host_comboBox, QtCore.SIGNAL("currentIndexChanged (QString)"), self.hostChanged)
QtCore.QObject.connect(self.ui.color__comboBox, QtCore.SIGNAL("currentIndexChanged (int)"), self.colorChanged)
return
def readCOnfig(self,logfile):
fileConcept = []
if not os.path.exists(logfile):
return fileConcept
file_handler = open(logfile,'r')
while True:
line = file_handler.readline()
if not line :
break
fileConcept.append(line)
file_handler.close()
return fileConcept
def Do(self):
print 'do'
host = unicode(self.ui.host_comboBox.currentText())
name = unicode(self.ui.name_lineedit.text())
passwd = unicode(self.ui.passwd_lineedit.text())
sharedir = unicode(self.ui.sharedir_lineedit.text())
color = unicode(self.ui.color__comboBox.currentText())
enableClipboard = str(self.ui.clipboard_checkbox.isChecked())
enableFullscreen = str(self.ui.fullscreen_checkbox.isChecked())
enableLocalsound = str(self.ui.localsound_checkbox.isChecked())
#run mstsc connect server
commandLine = self.getCurrentWorkPath() + os.sep + 'bin' + os.sep + 'rdesktop'
paramString = ' -u ' + name + ' -p ' + passwd + ' -a ' + color + ' ' + host
if sharedir and sharedir != "":
paramString = paramString + ' -r disk:Share=' + sharedir
if enableClipboard == "True":
paramString = paramString + ' -r clipboard:PRIMARYCLIPBOARD'
if enableFullscreen == "True":
paramString = paramString + ' -f '
if enableLocalsound == "True":
paramString = paramString + ' -r sound:local'
print commandLine + paramString
os.system(commandLine + paramString)
#save Current link info
writeString = host + self.configSep + name + self.configSep + passwd + self.configSep + sharedir + self.configSep + color + self.configSep
writeString = writeString + enableClipboard + self.configSep + enableFullscreen + self.configSep + enableLocalsound
writeString = writeString + "\n"
#
if not os.path.isfile(self.configFile):
file_handler=open(self.configFile,'w')
file_handler.write(writeString + "\n")
self.confInfo.append(writeString)
file_handler.close()
return
else:
writeFlag = False
#文件重写
file_handler=open(self.configFile,'w')
for index in reversed(range(len(self.confInfo))):
oneLine = self.confInfo[index]
if not oneLine:
continue
msgSplit = oneLine.split(self.configSep)
if len(msgSplit)<= 0:
continue
hostTemp = msgSplit[0]
if hostTemp == host and not writeFlag:
file_handler.write(writeString )
writeFlag = True
del self.confInfo[index]
self.confInfo.insert(index,writeString)
continue
file_handler.write(oneLine)
if not writeFlag:
file_handler.write(writeString )
file_handler.close()
return
def Cancel(self):
return
def selectDir(self):
print "selectDir"
#
selectdir = QtGui.QFileDialog.getExistingDirectory(self, "Select Directory", self.getCurrentWorkPath(),QtGui.QFileDialog.ShowDirsOnly | QtGui.QFileDialog.DontResolveSymlinks)
self.ui.sharedir_lineedit.setText(selectdir)
return
def hostChanged(self,cText):
print "hostChanged"
#1 检查数据,是否存在历史数据
existFlag = None
for one in self.confInfo:
if not one :
continue
oneSplit = one.split(self.configSep)
if len(oneSplit) <= 0:
continue
if cText == oneSplit[0]:
existFlag = one
break
if existFlag:
oneSplit = existFlag.split(self.configSep)
self.ui.name_lineedit.setText(oneSplit[1])
self.ui.passwd_lineedit.setText(oneSplit[2])
self.ui.sharedir_lineedit.setText(oneSplit[3])
colorValue = oneSplit[4]
index = self.ui.color__comboBox.findText(colorValue)
self.ui.color__comboBox.currentIndex = index
enableClipboard = oneSplit[5]
enableClipboard = enableClipboard.rstrip()
enableClipboard = enableClipboard.lstrip()
if enableClipboard == "True":
self.ui.clipboard_checkbox.setChecked(True)
else:
self.ui.clipboard_checkbox.setChecked(False)
enableFullscreen = oneSplit[6]
enableFullscreen = enableFullscreen.rstrip()
enableFullscreen = enableFullscreen.lstrip()
if enableFullscreen == "True":
self.ui.fullscreen_checkbox.setChecked(True)
else:
self.ui.fullscreen_checkbox.setChecked(False)
enableLocalsound = oneSplit[7]
enableLocalsound = enableLocalsound.rstrip()
enableLocalsound = enableLocalsound.lstrip()
if enableLocalsound == "True":
self.ui.localsound_checkbox.setChecked(True)
else:
self.ui.localsound_checkbox.setChecked(False)
#2 如果有,则根据历史数据初始化后续控件
return
def colorChanged(self,sIndex):
print "colorChanged"
return
def getCurrentWorkPath(self):
encodeing = sys.stdin.encoding
currentPath = None
if encodeing:
currentPath = unicode(os.getcwd(), sys.stdin.encoding)
else:
currentPath = os.getcwd()
return currentPath
def main():
accountName = QtCore.QString("AFDAS")
app = QtGui.QApplication(sys.argv)
window = Ui()
window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()