def chooseFile(self): self.file = QtGui.QFileDialog.getOpenFileName(self, self.trUtf8("选择.xls文件"), ".", self.trUtf8("Image Files(*.xls )")) if self.file==(u'', u''): return; else: i = 1 if self.chooseSheet.count() !=1: self.chooseSheet.clear() self.chooseSheet.addItem(self.trUtf8("请选择")) self.execlnameLineEdit.setText(self.file[0]) sheets =readExcel(self.file[0]).getSheetNames() i =0 while i<len(sheets): self.chooseSheet.addItem(sheets[i]) i=i+1
def run(self): self.errorTipLable2.hide() jsondata = self.scriptTextEdit.toPlainText() url = self.urlLineEdit.text() request_type = self.chooseRadio() headers = self.headersLineEdit.text() if headers: try: headers = json.loads(headers) except: self.errorMessage("Headers不支持该格式") return if not isinstance(headers, dict): self.errorMessage("Headers不支持该格式") return if self.form_type.isChecked(): if not url: self.errorMessage("url不能为空") return elif not jsondata: self.errorMessage("参数不能为空") return else : try: newjsondata = json.loads(jsondata) except: self.errorMessage("参数不支持该格式") return if isinstance(newjsondata, dict): sendapi = sendAPI(url,headers,newjsondata,request_type) result = sendapi.run() self.saveResult(result) elif isinstance(newjsondata, list): sendapi = sendAPI(url,headers,newjsondata,request_type) result = sendapi.run() self.saveResult(result) else: self.errorMessage("参数不支持该格式") elif self.form_excel_type.isChecked(): excel_path = self.execlnameLineEdit.text() sheet_name = self.chooseSheet.currentText() if not self.urlLineEdit.text(): self.errorMessage("url不能为空") elif not self.execlnameLineEdit.text(): self.errorMessage("数据文件不能为空") elif self.chooseSheet.currentText()==u"请选择": self.errorMessage("表格名不能为空") else: read_excel = readExcel(excel_path) data = read_excel.readTable(sheet_name) sendapi = sendAPI(url,headers,data,request_type) result = sendapi.run() self.saveResult(result) elif self.json_excel_type.isChecked(): excel_path = self.execlnameLineEdit.text() sheet_name = self.chooseSheet.currentText() if not self.urlLineEdit.text(): self.errorMessage("url不能为") elif not self.execlnameLineEdit.text(): self.errorMessage("数据文件不能为空") elif self.chooseSheet.currentText()==u"请选择": self.errorMessage("表格名不能为空") else: read_excel = readExcel(excel_path) data = read_excel.readTable(sheet_name) sendapi = sendAPI(url,headers,json.dumps(data),request_type) result = sendapi.run() self.saveResult(result) else: if not url: self.errorMessage("url不能为空") return elif not jsondata: self.errorMessage("参数不能为空") return else : try: newjsondata = json.loads(jsondata) except: self.errorMessage("参数不支持该格式") return if isinstance(newjsondata, dict): sendapi = sendAPI(url,headers,json.dumps(newjsondata),request_type) result = sendapi.run() self.saveResult(result) elif isinstance(newjsondata, list): sendapi = sendAPI(url,headers,json.dumps(newjsondata),request_type) result = sendapi.run() self.saveResult(result) else: self.errorMessage("参数不支持该格式")