Skip to content

Commit

Permalink
fix tableview presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzy69 committed May 10, 2017
1 parent 909e648 commit c0b8654
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions application/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def __init__(self, parent=None):
self.timerPulse = QTimer(self)
self.timerPulse.timeout.connect(self.pulse)
self.timerPulse.start(1000)
self._boldFont = QFont()
self._boldFont.setBold(True)

def centerWindow(self):
fg = self.frameGeometry()
Expand Down Expand Up @@ -104,14 +106,22 @@ def importUrls(self):
if filePath:
text = readTextFile(filePath)
for url in text.strip().splitlines():
self.sitesModel.appendRow([QStandardItem(url), QStandardItem(""),QStandardItem("")])
rankCell = QStandardItem("")
rankCell.setTextAlignment(Qt.AlignCenter)
self.sitesModel.appendRow([QStandardItem(url), rankCell,QStandardItem("")])

def sitesTableView_doubleClicked(self, modelIndex):
model = self.sitesModel
row = modelIndex.row()
url = model.data(model.index(row, 0))
webbrowser.open(url)

def resetTable(self):
model = self.sitesModel
for i in range(model.rowCount()):
model.setData(model.index(i, 1), "")
model.setData(model.index(i, 2), "")

def clearTable(self):
self.tableRemoveAllRows(self.sitesModel)

Expand All @@ -121,22 +131,24 @@ def tableRemoveAllRows(self, model):

def pulse(self):
self.labelActiveThreads.setText("Active threads: {}".format(MyThread.activeCount))
# if MyThread.activeCount == 0:
# if not self.sitesTableView.isSortingEnabled():
# self.sitesTableView.setSortingEnabled(True)
# if not self.startButton.isEnabled():
# self.startButton.setEnabled(True)
# if self.stopButton.isEnabled():
# self.stopButton.setEnabled(False)
if MyThread.activeCount == 0:
# if not self.sitesTableView.isSortingEnabled():
# self.sitesTableView.setSortingEnabled(True)
if not self.startButton.isEnabled():
self.startButton.setEnabled(True)
if self.stopButton.isEnabled():
self.stopButton.setEnabled(False)
# else:
# if self.sitesTableView.isSortingEnabled():
# self.sitesTableView.setSortingEnabled(False)

@pyqtSlot()
def start(self):
self.resetTable()
model = self.sitesModel
queues = split_list(range(self.sitesModel.rowCount()), self.threadsSpin.value())
self._progressTotal = self.sitesModel.rowCount()
self._progressDone = 0
self._threads = []
self._workers = []
for i, rows in enumerate(queues):
Expand Down Expand Up @@ -170,14 +182,15 @@ def onStatus(self, tuple_):

@pyqtSlot(object)
def onResult(self, result):
self.sitesModel.item(result["row"], 1).setFont(self._boldFont)
if result["status"]:
self.sitesModel.setData(self.sitesModel.index(result["row"], 1), result["rank"])
self.sitesModel.item(result["row"], 1).setBackground(Qt.green)
self.sitesModel.item(result["row"], 1).setForeground(Qt.green)
elif result["status"] is None:
self.sitesModel.setData(self.sitesModel.index(result["row"], 1), "No data")
else:
self.sitesModel.setData(self.sitesModel.index(result["row"], 1), "Fail")
self.sitesModel.item(result["row"], 1).setBackground(Qt.red)
self.sitesModel.item(result["row"], 1).setForeground(Qt.red)
self._progressDone += 1
self.progressBar.setValue(int(float(self._progressDone) / self._progressTotal * 100))

Expand Down

0 comments on commit c0b8654

Please sign in to comment.