Skip to content

Instantly share code, notes, and snippets.

@fereria fereria/main.py
Created Oct 6, 2015

Embed
What would you like to do?
TaskTest
# -*- coding: utf-8 -*-
from PySide import QtCore, QtGui
import sys
import requests
import json
import toolUI
class taskUI(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.ui = toolUI.Ui_Form()
self.ui.setupUi(self)
self.setWindowTitle(u"TaskTool")
self.access = Access()
self.setStatusBox()
self.model = QtGui.QStandardItemModel()
self.ui.taskListView.setModel(self.model)
self.ui.addBtn.clicked.connect(self.addTask)
self.updateTaskList()
def setStatusBox(self):
self.ui.statusBox.clear()
for i in self.access.getStatus():
self.ui.statusBox.addItem(i)
def updateTaskList(self):
taskList = self.access.getTask()
self.model.clear()
for task in taskList:
column = []
columnViewList = ['status','task_name']
for i in columnViewList:
column.append(QtGui.QStandardItem(task[i]))
self.model.appendRow(column)
def addTask(self):
comment = self.ui.taskComment.toPlainText()
status = self.ui.statusBox.currentText()
self.access.setTask(status,comment)
self.ui.taskComment.setText("")
self.updateTaskList()
self.setStatusBox()
class Access(object):
url = "http://localhost:8000/api/"
def getTask(self):
response = self.request('get','','get')
if response is None:
return []
else:
return response
def setTask(self,status,comment):
param = {}
param["status"] = status
param["task_name"] = comment
self.request("set",param,'get')
def getStatus(self):
return self.request('task_info',{'info_type':'status'},'get')
def request(self, apicmd, param, request_type="get"):
url = self.url + apicmd
try:
if request_type == "get":
r = requests.get(url,params=param)
else:
r = requests.post(url,data=param)
if r.status_code == 200 or \
r.status_code == 201:
return self.toJson(r.content)
else:
return []
except requests.ConnectionError:
return None
def toJson(self, value):
return json.loads(value)
def main():
app = QtGui.QApplication(sys.argv)
QtCore.QTextCodec.setCodecForCStrings(QtCore.QTextCodec.codecForLocale())
win = taskUI()
win.show()
sys.exit(app.exec_())
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.