Index: cases/testmodel.py
===================================================================
--- cases/testmodel.py	(revision 397754)
+++ cases/testmodel.py	(working copy)
@@ -55,12 +55,14 @@
 
     def _request_deal(self, message, packet):
         global g_runing_status
+        #print "request:\n %s\n:"%message
         if self.request_callback != None:
             info = g_runing_status.get_status()
             self.request_callback(info, message, packet)
 
     def _response_deal(self, message, packet):
         global g_runing_status
+        #print "response:\n %s\n:"%message
         if self.response_callback != None:
             info = g_runing_status.get_status()
             self.response_callback(info, message, packet)
Index: testrunner/rpctestrunner.py
===================================================================
--- testrunner/rpctestrunner.py	(revision 397754)
+++ testrunner/rpctestrunner.py	(working copy)
@@ -31,7 +31,8 @@
 from RPC.connect.rpc import rpc_set_timeout
 from RPC.connect.rpc import rpc_register_request_callback, rpc_register_response_callback,rpc_register_notify_callback
 from RPC.dh.dh_json import get_json_value, json_loads, get_json_value_with_default_value
-from cases.testmodel import TestModel,get_case_dict
+from cases.testmodel import TestModel,get_case_dict, g_tm
+
 import logging
 from collections import OrderedDict
 
@@ -60,6 +61,12 @@
 		self.logger = logger
 		self.logger.info('logger runner say something...') 
 
+	def set_login_params(self, host, port, username, password):
+		self.host = host
+		self.port = port
+		self.password = password
+		self.username = username
+
 	def login(self, host, port, username, password):
 		self.host = host
 		self.port = port
@@ -69,17 +76,17 @@
 		self.login_thread.start()
 
 		"""
-		rpc_register_request_callback(self.request_callback) 
-		rpc_register_response_callback(self.response_callback) 
-		rpc_register_notify_callback(self.notify_callback) 
+		rpc_register_request_callback(self.request_callback)
+		rpc_register_response_callback(self.response_callback)
+		rpc_register_notify_callback(self.notify_callback)
 		"""
 	def login_direct(self, host, port, username, password):
 		return rpc_connect_to_sut(host, int(port), username, password)  
 
 	def logout(self):
 		"""
-		rpc_register_request_callback(None) 
-		rpc_register_response_callback(None) 
+		rpc_register_request_callback(None)
+		rpc_register_response_callback(None)
 		rpc_register_notify_callback(None) 
 		"""
 		rpc_disconnect_from_sut()
@@ -197,7 +204,7 @@
 
 	def login(self, runner):
 		try:
-			self.login_status = rpc_connect_to_sut(runner.host, int(runner.port), runner.username, runner.password)  
+			self.login_status = rpc_connect_to_sut(runner.host, int(runner.port), runner.username, runner.password) 
 		except Exception, e:
 			self.logger.error("Login Failed")
 			return e._get_message()
@@ -221,6 +228,7 @@
 		logger = logging.getLogger('ui_Mode.SendThread')  #main.mod
 		self.logger = logger
 		self.logger.info('logger LoginThread say something...') 
+		self.login_status = "Connect Fail"
 
 	def add_task(self, request_dict):
 		self.task_list.append(request_dict)
@@ -261,6 +269,10 @@
 				case_compt = compt_dict.get(str(k))
 				cpt_obj = case_compt["obj"]
 				cpt_method_list = case_compt["methodlist"]
+				
+				if self.proc_login() != "Success":
+					return
+				print "rpc_connect_to_sut start"
 				for method in v:
 					if method in cpt_method_list:
 						steps = cpt_obj.getsteps(method) ##
@@ -269,16 +281,12 @@
 						success = True
 						for step in range(steps):
 							stepinfo = cpt_obj.getstepinfo(method, step)
-							#print "stepinfo mode is:%s \n" % stepinfo["mode"]
-
 							try:
 								result =  cpt_obj.execute(method, step) ##
 							except:
 								result = "System Raise Error!"
-							#num = num+1 
-
+							
 							case_response_dict = OrderedDict()
-							#case_response_dict["num"] = num
 							case_response_dict["method"] = method
 							case_response_dict["step"] = step
 							case_response_dict["mode"] = stepinfo["mode"]
@@ -287,7 +295,7 @@
 
 							if success:
 								num = num+1
-								case_response_dict["num"] = num 
+								case_response_dict["num"] = num
 								self.runner.on_runner_notify_response(case_response_dict)
 							elif stepinfo["mode"] == "C":
 								num = num+1
@@ -296,20 +304,30 @@
 
 							if stepinfo["mode"] == "T" and result !=  "Success":
 								success = False
-
 							if stepinfo["mode"] == "P" and result != "Success":
-								#success = False
 								break
-
 							if result == "Connect Fail":
 								return True
-
 							if self.runner.interval_time > 0:
 								self.proc_runner_interval(self.runner.interval_time)
 							if not self.active:
 								return True
+				rpc_disconnect_from_sut()
+				print "rpc_disconnect_from_sut over"
 		return True
 
+	def proc_login(self):
+		try:
+			self.login_status = rpc_connect_to_sut(self.runner.host, int(self.runner.port), self.runner.username, self.runner.password)  
+		except Exception, e:
+			self.logger.error("Login Failed")
+			return e._get_message()
+		global g_tm
+		g_tm.register_callback()
+		self.logger.debug("login_status :%s"%self.login_status)
+		self.runner.on_handle_login(self.login_status)
+		return self.login_status
+
 	def proc_runner_interval(self, interval_time):
 		while interval_time > 0 :
 			time.sleep(0.1)
@@ -319,7 +337,7 @@
 
 	def stop(self):
 		self.active = False
-		#self.runner.on_handle_message(2)
+		self.runner.on_handle_message(2)
 		self.logger.debug("stop thread")
 
 
Index: ui/UI_Mainwindow.py
===================================================================
--- ui/UI_Mainwindow.py	(revision 397754)
+++ ui/UI_Mainwindow.py	(working copy)
@@ -36,14 +36,13 @@
 		return QtGui.QApplication.translate(context, text, disambig)
 
 class QCheckTreeWidgetItem(QtGui.QTreeWidgetItem):
-	def __init__(self, parent=None , CheckState=QtCore.Qt.Unchecked):
+	def __init__(self, parent=None ,CheckBox = False, CheckState=QtCore.Qt.Unchecked):
 		QtGui.QTreeWidgetItem.__init__(self, parent)
 		#self.setText(0, Text)
-		#if CheckBox:
-		self.setCheckState(0, CheckState)
-		self.LastCheckState = CheckState
+		if CheckBox:
+			self.setCheckState(0, CheckState)
+			self.LastCheckState = CheckState
 
-
 class Base_MainWindow(QtGui.QMainWindow):
 	def __init__(self):
 		QtGui.QMainWindow.__init__(self)
@@ -423,7 +422,7 @@
 		self.trewInterface.setObjectName(_fromUtf8("trewInterface"))
 		#New FatherItem and Insert All Method
 		#item_0 = QtGui.QTreeWidgetItem(self.trewInterface)
-		item_0 = QCheckTreeWidgetItem(self.trewInterface, CheckState = QtCore.Qt.Checked)
+		item_0 = QCheckTreeWidgetItem(self.trewInterface, CheckBox = True, CheckState = QtCore.Qt.Checked)
 
 		item_0.setCheckState(0, QtCore.Qt.Checked)
 		item_0.setText(0, "RPC")
@@ -504,7 +503,8 @@
 		self.trewInterface_2.setAllColumnsShowFocus(False)
 		self.trewInterface_2.setHeaderHidden(True)
 		self.trewInterface_2.setObjectName(_fromUtf8("trewInterface_2"))
-		tree2_item_0 = QtGui.QTreeWidgetItem(self.trewInterface_2)
+		tree2_item_0 = QCheckTreeWidgetItem(self.trewInterface_2)
+		tree2_item_0.setText(0, "RPC")
 		self.tree2_rootitem = tree2_item_0
 		##初始化测试框 RPC树
 		#self.init_allmethod_withouself.tmodule(self.tree2_rootitem)
@@ -675,7 +675,6 @@
 		self.twOutput.setTabText(self.twOutput.indexOf(self.tab), _translate("MainWindow", "Notify", None))
 		self.tbwMethod.setSortingEnabled(False)
 		
-		
 		item = self.tbwMethod.verticalHeaderItem(0)
 		item.setText(_translate("MainWindow", "1", None))
 		
@@ -741,7 +740,7 @@
 		self.trewInterface_2.headerItem().setText(0, _translate("MainWindow", "RPC Interface", None))
 		__sortingEnabled = self.trewInterface_2.isSortingEnabled()
 		self.trewInterface_2.setSortingEnabled(False)
-		self.trewInterface_2.topLevelItem(0).setText(0, _translate("MainWindow", "RPC", None))
+		#self.trewInterface_2.topLevelItem(0).setText(0, _translate("MainWindow", "RPC", None))
 		self.trewInterface_2.setSortingEnabled(__sortingEnabled)
 
 		#暂时去除RunAll功能
Index: ui/Ui_RPCTest.py
===================================================================
--- ui/Ui_RPCTest.py	(revision 397889)
+++ ui/Ui_RPCTest.py	(working copy)
@@ -68,6 +68,7 @@
 		self.captureState = False
 		self.login_state = False
 		self.start_state = False
+		self.d_login_state = False
 		self.reportfile = None
 		self.TestRun = None
 		self.method_dict = {}
@@ -128,7 +129,7 @@
 		self.update_config()
 		
 		##测试界面树
-		self.get_test_method(self.rootItem)
+		self.get_test_method(self.rootItem, True)
 		self.set_allitem_selected(self.rootItem)
 		
 		#Debug界面树
@@ -314,17 +315,17 @@
 	def on_intervaltime_changed(self, intervaltime):
 		self.leIntervalTime.setText(intervaltime)
 
-
 	def login_callback(self, login_state):
 		self.logger.debug("%s"%login_state)
 		self.login_status_callback = login_state
 		self.centralwidget.emit(QtCore.SIGNAL(_fromUtf8("login()")))
 
 	def on_login_callback(self):
-		self.remove_loading()
+		#self.remove_loading()
+		
 		self.btnLogon.setEnabled(True)
 		if "Success" == self.login_status_callback:
-			
+			return
 			#设备异常登出后，再次登陆要清空上次测试结果
 			try:
 				self.statusBar.removeWidget(self.status_result)
@@ -333,16 +334,11 @@
 
 			##登陆成功后 设置不可更改
 			self.btnLogon.setText("Logout")
-
 			self.login_state = True
 			self.leIP.setEnabled(False)
 			self.leUsername.setEnabled(False)
 			self.lePassword.setEnabled(False)
 			self.lePort.setEnabled(False)
-			
-			#self.btnLogin.setChecked(False)
-			#self.btnLogin.setEnabled(False)
-			
 			self.lblIP.setEnabled(False)
 			self.lblUsername.setEnabled(False)
 			self.lblPassword.setEnabled(False)
@@ -355,29 +351,26 @@
 			self.status_login.setText('  IP  : '+  self.leIP.text()  + '   On-Line' +'    ')
 			#self.statusBar.addPermanentWidget(self.status_login)
 			self.statusBar.addWidget(self.status_login)
-
 			#登陆成功后，设置回调
 			global g_tm
 			g_tm.register_callback()
+		else:
+			self.on_stop()
+			self.proc_login_filed(self.login_status_callback)
 
-		elif "Address Not Valid" == self.login_status_callback:
+	def proc_login_filed(self, login_result):
+		if "Address Not Valid" == login_result:
 			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "IP Error！！", None))
-			#self.btnLogin.setChecked(False)
-		elif "Connect Fail" == self.login_status_callback:
+		elif "Connect Fail" == login_result:
 			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "Connect Filed！！", None))
-			#self.btnLogin.setChecked(False)
-		elif "Fail" == self.login_status_callback:
+		elif "Fail" == login_result:
 			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "Username or Password Error！！", None))
-			#self.btnLogin.setChecked(False)
-		elif "User Not Valid" == self.login_status_callback:
+		elif "User Not Valid" == login_result:
 			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "User Invalid！！", None))
-			#self.btnLogin.setChecked(False)
-		elif "Password NotValid" == self.login_status_callback:
+		elif "Password NotValid" == login_result:
 			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "Password Error！！", None))
-			#self.btnLogin.setChecked(False)
 		else:
 			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "Device Abnormal！！", None))
-			#self.btnLogin.setChecked(False)
 
 	###回调函数处理
 	def notify_callback(self, message, info, packet):
@@ -433,9 +426,7 @@
 		self.logger.debug("Request Message is:%s"%message)
 		self.request_list.append(out)
 		self.request_list_show = []
-		
 		self.request_dict[str(key)] = message
-
 		#self.response_dict = {}
 		self.request_list_show.append(out)
 		self.centralwidget.emit(QtCore.SIGNAL(_fromUtf8("request()")))
@@ -463,9 +454,7 @@
 			if None != packet and 0 != len(packet):
 				#print "response packet length:%d" % len(packet)
 				self.logger.debug("request packet length:%d"%len(packet))
-
 			out = json.dumps(info, ensure_ascii=True, sort_keys=True, indent = 3)
-
 			self.test_log_dict[str(key)]["Response"] = info
 			log = json.dumps(self.test_log_dict, ensure_ascii=True, sort_keys=True, indent = 3)
 
@@ -494,7 +483,6 @@
 			return
 		out = self.response_list_show.pop()
 		encode_out = unicode(out, 'utf8')
-
 		self.teDetailResponse.setText(out +'\n')
 
 	def runner_callback(self, message_dict):
@@ -510,7 +498,6 @@
 
 		if result == "Connect Fail":
 			self.centralwidget.emit(QtCore.SIGNAL(_fromUtf8("connect_error()")))
-
 		if mode == "T":
 			self.excecuted = self.excecuted + 1
 		elif mode == "P" and result != "Success":
@@ -561,11 +548,9 @@
 
 	def on_runner_thread_callback(self):
 		print "on_runner_thread_callback"
-
 		#if not self.start_state:
 		#	return
 		##用例跑完自动结束
-
 		##设置开始按钮状态
 		self.cbtnRuncur.setEnabled(True)
 		self.cbtnReport.setEnabled(True)
@@ -577,16 +562,13 @@
 		#self.statusBar.removeWidget(self.status_run)
 		##状态栏显示结果
 		self.get_test_result()
-
 		global g_tm
 		g_tm.register_request_callback(None)
 		g_tm.register_response_callback(None)
-
 		## Stop Net Capture
 		if self.captureState and self.default_setting_dict["savecapture"]:
 			self.stop_capture()
 			self.logger.debug("stop_capture")
-
 		self.TestRun.register_runner_response(None)
 		self.TestRun.register_runner_thread_state(None)
 
@@ -597,6 +579,7 @@
 			if reportfile.open(QtCore.QFile.WriteOnly):
 				reportfile.writeData(log)
 				reportfile.close()
+		QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "Run    Over!", None))
 
 
 	def on_cbSchema_index_changed(self, text):
@@ -656,7 +639,7 @@
 			return method_dict
 		except:
 			self.logger.warn("Case load error")
-			QtGui.QMessageBox.warning(self, self.tr("Warning "),_translate("MainWindow", "Case load error！！", None))
+			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "Case load error！！", None))
 			return None
 
 	def applay_test_palne(self, method_dict):
@@ -737,21 +720,10 @@
 		username = self.leUsername.text()
 		password = self.lePassword.text()
 		port = self.lePort.text()
-
-		if not self.check_ip(str(host)):
-			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "IP Invalid！！", None))
+		if not self.login_check(host, port, username, password):
 			return
 
-		if not self.check_port(str(port)):
-			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "Port Invalid！！", None))
-			return
-
-		if username == "":
-			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "User name empty！！", None))
-			return
-
 		self.btnLogon.setEnabled(False)
-
 		self.TestRun = RPCTestRunner()
 		self.TestRun.register_runner_login_state(self.login_callback)
 		##登陆
@@ -765,6 +737,18 @@
 		self.user_config["loginConfig"] = config
 
 
+	def login_check(self, host, port, username, password):
+		if not self.check_ip(str(host)):
+			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "IP Invalid！！", None))
+			return False
+		if not self.check_port(str(port)):
+			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "Port Invalid！！", None))
+			return False
+		if username == "":
+			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "User name empty！！", None))
+			return False
+		return True
+
 	def check_ip(self, ipaddr):
 		num_list = []
 		if isinstance(ipaddr, str) or isinstance(ipaddr, unicode):
@@ -779,6 +763,7 @@
 				return True
 		return False
 
+
 	def check_port(self, port):
 		if isinstance(port, str):
 			try:
@@ -845,19 +830,7 @@
 		#self.statusBar.showMessage('IPA ddress : '+  self.leIP.text()  + '    OFF-Line')
 		self.TestRun = None
 
-	##用户run按钮回调接口
-	def on_start(self):
-		if not self.login_state:
-			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "Please Login First！！", None))
-			return
-		##获取选中的RPC
-		method_dict = self.get_chosed_item()
-		#print "on_start:%s"%method_dict
-		self.logger.debug("on_start :%s"%method_dict)
-		if self.check_case_null(method_dict):
-			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "Please chose case first！！", None))
-			return
-
+	def start_init(self):
 		##清空前一次表单
 		#self.delete_twItem()
 		self.tbwMethod.clearContents()
@@ -877,12 +850,51 @@
 		self.is_debug_mode = False
 		self.start_state = True
 
+		##初始化 请求与响应列表
+		self.request_list = []
+		self.response_list = []
+		self.request_dict = {}
+		self.response_dict = {}
+		self.table_dict = {}
+		self.ret_list = []
+
+		#清空用例颜色
+		self.restore_method_color()
+		self.teNotify.clear()
+
+	##用户run按钮回调接口
+	def on_start(self):
+		"""
+		if not self.login_state:
+			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "Please Login First！！", None))
+			return
+		"""
+		##获取选中的RPC
+		method_dict = self.get_chosed_item()
+		#print "on_start:%s"%method_dict
+		self.logger.debug("on_start :%s"%method_dict)
+		if self.check_case_null(method_dict):
+			QtGui.QMessageBox.warning(self.MainWindow, self.tr("Warning "),_translate("MainWindow", "Please chose case first！！", None))
+			return
+		#初始化
+		self.start_init()
+		#######
+		host = self.leIP.text()
+		port = self.lePort.text()
+		username = self.leUsername.text()
+		password = self.lePassword.text()
+		if not self.login_check(host, port, username, password):
+			return
+
+		self.TestRun = RPCTestRunner()
+		self.TestRun.set_login_params(host, int(port), username, password)
+		self.TestRun.register_runner_login_state(self.login_callback)
 		##测试完成回调
 		self.TestRun.register_runner_response(self.runner_callback)
 		self.TestRun.register_runner_thread_state(self.runner_thread_callback)
 
 		global g_tm
-		g_tm.register_callback()
+		#g_tm.register_callback()
 		g_tm.register_request_callback(self.request_callback)
 		g_tm.register_response_callback(self.response_callback)
 		g_tm.register_notify_callback(self.notify_callback)
@@ -893,30 +905,15 @@
 		except:
 			self.logger.error("statusBar.removeWidget error")
 
-		#清空用例颜色
-		self.restore_method_color()
-		self.teNotify.clear()
 
 		self.default_setting_dict["savelog"] = self.Ui_Setting.setting_dict["savelog"]
 		self.default_setting_dict["logpath"] = self.Ui_Setting.setting_dict["logpath"]
 		## Start Net Capture 
 		if self.default_setting_dict["savecapture"]:
-		#if self.ckbSaveCapture.checkState() == QtCore.Qt.Checked:
-		#	if self.filePath == None:
-		#		return
 			self.start_capture(self.default_setting_dict["capturepath"])
 			self.captureState = True
 		#self.TestRun.register_notify_response(self.runner_callback)
 
-		##初始化 请求与响应列表
-		self.request_list = []
-		self.response_list = []
-
-		self.request_dict = {}
-		self.response_dict = {}
-		self.table_dict = {}
-		self.ret_list = []
-
 		##设置状态栏
 		self.status_result = QtGui.QLabel(self.statusBar)	
 		self.statusBar.insertWidget(1,self.status_result)
@@ -935,19 +932,21 @@
 		intervatime = int(self.default_setting_dict["intervaltime"])
 
 		##保存用户配置
-		config = {}
-		config["timeout"] = timeout
-		config["intervatime"] = int(intervatime)
-		self.user_config["environment Config"] = config
-		python = []
+		en_config = {"timeout":timeout, "intervatime": int(intervatime)}
+		lg_config = {"ipAddress": str(host), "port": int(port),"username": str(username), "password":str(password)}
+		self.svae_user_config(en_config, lg_config)
+
+		self.TestRun.set_interva_time(int(intervatime))
+		self.TestRun.start(method_dict)
+
+	def svae_user_config(self, en_config, lg_config):
+		self.user_config["environment Config"] = en_config
+		self.user_config["loginConfig"] = lg_config
 		python = ["version 2.6", "version 2.7"]
 		self.user_config["python version"] = python
 		stream = file("config/userconfig.yaml", "w")
 		yaml.safe_dump(self.user_config, stream, allow_unicode= True, default_flow_style=False)
 
-		self.TestRun.set_interva_time(int(intervatime))
-		self.TestRun.start(method_dict)
-
 	def check_case_null(self, case_dict):
 		none_case = True
 		for value in case_dict.values():
@@ -955,7 +954,7 @@
 				none_case = False
 		return none_case
 
-	def get_test_method(self, item):
+	def get_test_method(self, item, CheckBox=False):
 		if self.model_dict == None:
 			return
 		font = QtGui.QFont()
@@ -964,18 +963,18 @@
 		font.setWeight(10)
 
 		for keys, value in self.model_dict.items():
-			modelItem = self.insert_child(item, keys)
+			modelItem = self.insert_child(item, keys, CheckBox=CheckBox)
 			modelItem.setFont(0, font)
 			copmt_dict = value["componentdict"]
 			for k, v in copmt_dict.items():
-				componentItem = self.insert_child(modelItem, k)
+				componentItem = self.insert_child(modelItem, k, CheckBox=CheckBox)
 				componentItem.setFont(0, font)
 				methodlist = v["methodlist"]
 				for mth in methodlist:
-					methodItem = self.insert_child(componentItem, mth)
+					methodItem = self.insert_child(componentItem, mth, CheckBox=CheckBox)
 					methodItem.setFont(0, font)
 	
-	##output和Details窗口显示RPC测试输出结果   
+	##output和Details窗口显示RPC测试输出结果
 	def show_result(self, title, response):
 		self.teDetailResponse.setText(title +':'+'\n'+ response +'\n')
 
@@ -1038,7 +1037,7 @@
 		#MainWindow = QtGui.QMainWindow()
 		filed = int(chosed) - int(passed)
 		if excecuted == 0:
-			self.status_result.setText("Total: "+str(allmethod) +'   '+"Selected: "+str(chosed)+'   '+"Passed: "+str(passed)+ '   '+"Filedd: "+str(filed)+'    ')
+			self.status_result.setText("Total: "+str(allmethod) +'   '+"Selected: "+str(chosed)+'   '+"Passed: "+str(passed)+ '   '+"Failed: "+str(filed)+'    ')
 		else:
 			self.status_result.setText("Selected: "+str(chosed)+'   '+"Excecuted: "+str(excecuted)+'   '+"Passed: "+str(passed)+'    ')
 
@@ -1446,12 +1445,16 @@
 
 	##切换Diagnostics和Templetes Debug两个Tab界面回调函数
 	##需将Diagnostics的测试结果清空、环境设置置未False
-	def on__tabWidget_changed(self, tab_index): 
+	def on__tabWidget_changed(self, tab_index):
 		if tab_index == 1:
 			self.statusBar.removeWidget(self.status_result)
 			#self.gbEnvironmentSet.setEnabled(False)
 			self.mathod_item_dict = self.get_all_method_map(self.tree2_rootitem)
+			if self.debug_login() == "Success":
+				self.d_login_state = True
 		elif tab_index == 0:
+			rpc_disconnect_from_sut()
+			self.d_login_state = False
 			pass
 			#self.gbEnvironmentSet.setEnabled(True)
 
@@ -1468,12 +1471,14 @@
 		if mystr1 == self.tree2_rootitem.text(num):
 			self.tree2_method = ''
 			return
-
 		for model in self.model_dict.values():
 			for copt in model["componentdict"].values():
 				if self.tree2_method in copt["methodlist"]:
 					copt_obj = copt["obj"]
 					self.current_component = copt_obj
+					#
+					if not self.d_login_state:
+						return
 					debug_params = copt_obj.getdebugrequest(str(self.tree2_method))
 					self.logger.debug("debug_params is :%s"%debug_params)
 					if debug_params != None:
@@ -1483,6 +1488,21 @@
 						##清空上一次测试结果
 						self.txbResponse.clear()#setPlainText(out)
 
+	def debug_login(self):
+		host = self.leIP.text()
+		port = self.lePort.text()
+		username = self.leUsername.text()
+		password = self.lePassword.text()
+		login_status = "Connect Fail"
+		if not self.login_check(host, port, username, password):
+			return login_status
+		try:
+			login_status = rpc_connect_to_sut(str(host), int(port), str(username), str(password))  
+		except Exception, e:
+			return e._get_message()
+		global g_tm
+		g_tm.register_callback()
+		return login_status
 
 	def on_debug_send_request(self):
 		self.is_debug_mode = True
@@ -1493,7 +1513,6 @@
 		g_tm.register_response_callback(self.response_callback)
 		#rpc_register_response_callback(self.debug_response_callback) ##注册响应消息
 		#g_tm.register_notify_callback(self.notify_callback) ##注册订阅消息
-
 		debug_params = self.txbRequest.toPlainText()
 		self.logger.debug("debug_params is :%s"%debug_params)
 
@@ -1516,7 +1535,6 @@
 		if user_defined_request.has_key("session") and user_defined_request.has_key("params")  and user_defined_request.has_key("method"):
 			self.txbRequest.setText(user_defined_request)
 
-
 	###测试界面功能
 	##界面1
 	def on_listWidgets_clieck(self, listItem):
@@ -1645,8 +1663,10 @@
 
 		child_item.treeWidget().setCurrentItem(child_item)
 		child_item.treeWidget().setFocus()
-		if not self.login_state:
+
+		if not self.d_login_state:
 			return
+		
 		##获取测试列表
 		for model in self.model_dict.values():
 			for copt in model["componentdict"].values():
@@ -1917,7 +1937,7 @@
 		instrtItem = QtGui.QTreeWidgetItem(self.rootItem)
 		instrtItem.setCheckState(0, QtCore.Qt.Checked)
 		instrtItem.setText(0, moduleName) 
-		instrtItem.setTextColor(0, QtGui.QColor(255, 0, 0))
+		instrtItem.setTextColor(0, QtGui.QColor(255, 0, 0))	
 		self.insert_treeitem( self.insert_treeitem(instrtItem,  componentName),  methodName)
 
 
@@ -2024,18 +2044,20 @@
 
 
 	##父item中新增名为name的子item，如果已经存在则返回该子item，否则插入新子item并返回该子item
-	def insert_child(self, item, name, column = 0):
+	def insert_child(self, item, name, column = 0, CheckBox = False):
 		""" TreeItemWidget Insert """
+		#print "insert_child"
 		if name == '':
 			return 
 		childCount = item.childCount()
 		for i in range(childCount):
 			if name == item.child(i).text(column):
 				return item.child(i)
-
 		#itemChild = QtGui.QTreeWidgetItem()
-		itemChild = QCheckTreeWidgetItem(CheckState = QtCore.Qt.Checked)
-
+		if CheckBox:
+			itemChild = QCheckTreeWidgetItem(CheckBox=True, CheckState=QtCore.Qt.Checked)
+		else:
+			itemChild = QCheckTreeWidgetItem()
 		item.addChild(itemChild)
 		self.edit_item(itemChild, name, column)
 		return itemChild
