Code cleaning. Comments, methods renaming and other cosmetic changes.
- added doc strings to every method - showPreview -> loadPreview (for consistency) - _loadPage_cb -> _loadedPage (same for savePage) - _loadPage_eb -> _errorLoadPage (same for savePage) - try to limit lines to 79 columns
This commit is contained in:
parent
4b8e2937be
commit
07c7b7b1be
1 changed files with 61 additions and 20 deletions
|
|
@ -40,13 +40,24 @@ class MainWindow(QtMainWindow):
|
||||||
self.weboob = weboob
|
self.weboob = weboob
|
||||||
self.backend = None
|
self.backend = None
|
||||||
|
|
||||||
self.connect(self.ui.idEdit, SIGNAL("returnPressed()"), self.loadPage)
|
self.connect(self.ui.idEdit,
|
||||||
self.connect(self.ui.loadButton, SIGNAL("clicked()"), self.loadPage)
|
SIGNAL("returnPressed()"),
|
||||||
self.connect(self.ui.tabWidget, SIGNAL("currentChanged(int)"),
|
self.loadPage)
|
||||||
self._currentTabChanged)
|
self.connect(self.ui.loadButton,
|
||||||
self.connect(self.ui.saveButton, SIGNAL("clicked()"), self.savePage)
|
SIGNAL("clicked()"),
|
||||||
self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig)
|
self.loadPage)
|
||||||
self.connect(self.ui.contentEdit, SIGNAL("textChanged()"), self._textChanged)
|
self.connect(self.ui.tabWidget,
|
||||||
|
SIGNAL("currentChanged(int)"),
|
||||||
|
self._currentTabChanged)
|
||||||
|
self.connect(self.ui.saveButton,
|
||||||
|
SIGNAL("clicked()"),
|
||||||
|
self.savePage)
|
||||||
|
self.connect(self.ui.actionBackends,
|
||||||
|
SIGNAL("triggered()"),
|
||||||
|
self.backendsConfig)
|
||||||
|
self.connect(self.ui.contentEdit,
|
||||||
|
SIGNAL("textChanged()"),
|
||||||
|
self._textChanged)
|
||||||
self.connect(self.ui.loadHistoryButton,
|
self.connect(self.ui.loadHistoryButton,
|
||||||
SIGNAL("clicked()"),
|
SIGNAL("clicked()"),
|
||||||
self.loadHistory)
|
self.loadHistory)
|
||||||
|
|
@ -57,40 +68,51 @@ class MainWindow(QtMainWindow):
|
||||||
self.loadBackends()
|
self.loadBackends()
|
||||||
|
|
||||||
def backendsConfig(self):
|
def backendsConfig(self):
|
||||||
|
""" Opens backends configuration dialog when 'Backends' is clicked """
|
||||||
bckndcfg = BackendCfg(self.weboob, (ICapContent,), self)
|
bckndcfg = BackendCfg(self.weboob, (ICapContent,), self)
|
||||||
if bckndcfg.run():
|
if bckndcfg.run():
|
||||||
self.loadBackends()
|
self.loadBackends()
|
||||||
|
|
||||||
def loadBackends(self):
|
def loadBackends(self):
|
||||||
|
""" Fills the backends comboBox with available backends """
|
||||||
self.ui.backendBox.clear()
|
self.ui.backendBox.clear()
|
||||||
for backend in self.weboob.iter_backends():
|
for backend in self.weboob.iter_backends():
|
||||||
self.ui.backendBox.insertItem(0, backend.name)
|
self.ui.backendBox.insertItem(0, backend.name)
|
||||||
|
|
||||||
def _currentTabChanged(self):
|
def _currentTabChanged(self):
|
||||||
|
""" Loads history or preview when the corresponding tabs are shown """
|
||||||
if self.ui.tabWidget.currentIndex() == 1:
|
if self.ui.tabWidget.currentIndex() == 1:
|
||||||
if self.backend is not None:
|
if self.backend is not None:
|
||||||
self.showPreview()
|
self.loadPreview()
|
||||||
elif self.ui.tabWidget.currentIndex() == 2:
|
elif self.ui.tabWidget.currentIndex() == 2:
|
||||||
if self.backend is not None:
|
if self.backend is not None:
|
||||||
self.loadHistory()
|
self.loadHistory()
|
||||||
|
|
||||||
def _textChanged(self):
|
def _textChanged(self):
|
||||||
|
""" The text in the content QPlainTextEdit has changed """
|
||||||
if self.backend:
|
if self.backend:
|
||||||
self.ui.saveButton.setEnabled(True)
|
self.ui.saveButton.setEnabled(True)
|
||||||
self.ui.saveButton.setText('Save')
|
self.ui.saveButton.setText('Save')
|
||||||
|
|
||||||
def loadPage(self):
|
def loadPage(self):
|
||||||
|
""" Loads a page's source into the 'content' QPlainTextEdit """
|
||||||
_id = unicode(self.ui.idEdit.text())
|
_id = unicode(self.ui.idEdit.text())
|
||||||
if not _id:
|
if not _id:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.ui.loadButton.setEnabled(False)
|
self.ui.loadButton.setEnabled(False)
|
||||||
self.ui.loadButton.setText('Loading...')
|
self.ui.loadButton.setText('Loading...')
|
||||||
|
|
||||||
backend = str(self.ui.backendBox.currentText())
|
backend = str(self.ui.backendBox.currentText())
|
||||||
self.process = QtDo(self.weboob, self._loadPage_cb, self._loadPage_eb)
|
self.process = QtDo(self.weboob,
|
||||||
|
self._loadedPage,
|
||||||
|
self._errorLoadPage)
|
||||||
self.process.do('get_content', _id, backends=(backend,))
|
self.process.do('get_content', _id, backends=(backend,))
|
||||||
|
|
||||||
def _loadPage_cb(self, backend, data):
|
def _loadedPage(self, backend, data):
|
||||||
|
""" Callback for loadPage """
|
||||||
if not backend:
|
if not backend:
|
||||||
|
# Loading is finished
|
||||||
self.process = None
|
self.process = None
|
||||||
if self.backend:
|
if self.backend:
|
||||||
self.ui.contentEdit.setReadOnly(False)
|
self.ui.contentEdit.setReadOnly(False)
|
||||||
|
|
@ -102,16 +124,19 @@ class MainWindow(QtMainWindow):
|
||||||
self.backend = None
|
self.backend = None
|
||||||
QMessageBox.critical(self, self.tr('Unable to open page'),
|
QMessageBox.critical(self, self.tr('Unable to open page'),
|
||||||
'Unable to open page "%s" on %s: it does not exist.'
|
'Unable to open page "%s" on %s: it does not exist.'
|
||||||
% (self.ui.idEdit.text(), self.ui.backendBox.currentText()),
|
% (self.ui.idEdit.text(),
|
||||||
|
self.ui.backendBox.currentText()),
|
||||||
QMessageBox.Ok)
|
QMessageBox.Ok)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.content = data
|
self.content = data
|
||||||
self.ui.contentEdit.setPlainText(self.content.content)
|
self.ui.contentEdit.setPlainText(self.content.content)
|
||||||
self.setWindowTitle("QWebcontentedit - %s@%s" %(self.content.id, backend.name))
|
self.setWindowTitle("QWebcontentedit - %s@%s" %(self.content.id,
|
||||||
|
backend.name))
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
|
|
||||||
def _loadPage_eb(self, backend, error, backtrace):
|
def _errorLoadPage(self, backend, error, backtrace):
|
||||||
|
""" Error callback for loadPage """
|
||||||
content = unicode(self.tr('Unable to load page:\n%s\n')) % to_unicode(error)
|
content = unicode(self.tr('Unable to load page:\n%s\n')) % to_unicode(error)
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level == logging.DEBUG:
|
||||||
content += '\n%s\n' % to_unicode(backtrace)
|
content += '\n%s\n' % to_unicode(backtrace)
|
||||||
|
|
@ -121,6 +146,7 @@ class MainWindow(QtMainWindow):
|
||||||
self.ui.saveButton.setText("Load")
|
self.ui.saveButton.setText("Load")
|
||||||
|
|
||||||
def savePage(self):
|
def savePage(self):
|
||||||
|
""" Saves the current page to the remote site """
|
||||||
if self.backend is None:
|
if self.backend is None:
|
||||||
return
|
return
|
||||||
new_content = unicode(self.ui.contentEdit.toPlainText())
|
new_content = unicode(self.ui.contentEdit.toPlainText())
|
||||||
|
|
@ -131,18 +157,27 @@ class MainWindow(QtMainWindow):
|
||||||
self.ui.contentEdit.setReadOnly(True)
|
self.ui.contentEdit.setReadOnly(True)
|
||||||
self.content.content = new_content
|
self.content.content = new_content
|
||||||
message = unicode(self.ui.descriptionEdit.text())
|
message = unicode(self.ui.descriptionEdit.text())
|
||||||
self.process = QtDo(self.weboob, self._savePage_cb, self._savePage_eb)
|
self.process = QtDo(self.weboob,
|
||||||
self.process.do('push_content', self.content, message, minor=minor, backends=self.backend)
|
self._savedPage,
|
||||||
|
self._errorSavePage)
|
||||||
|
self.process.do('push_content',
|
||||||
|
self.content,
|
||||||
|
message,
|
||||||
|
minor=minor,
|
||||||
|
backends=self.backend)
|
||||||
|
|
||||||
def _savePage_cb(self, backend, data):
|
def _savedPage(self, backend, data):
|
||||||
|
""" Callback for savePage's QtDo """
|
||||||
if not backend:
|
if not backend:
|
||||||
|
# saving has finished
|
||||||
self.process = None
|
self.process = None
|
||||||
self.ui.saveButton.setText('Saved')
|
self.ui.saveButton.setText('Saved')
|
||||||
self.ui.contentEdit.setReadOnly(False)
|
self.ui.contentEdit.setReadOnly(False)
|
||||||
return
|
return
|
||||||
self.ui.descriptionEdit.clear()
|
self.ui.descriptionEdit.clear()
|
||||||
|
|
||||||
def _savePage_eb(self, backend, error, backtrace):
|
def _errorSavePage(self, backend, error, backtrace):
|
||||||
|
""" """
|
||||||
content = unicode(self.tr('Unable to save page:\n%s\n')) % to_unicode(error)
|
content = unicode(self.tr('Unable to save page:\n%s\n')) % to_unicode(error)
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level == logging.DEBUG:
|
||||||
content += '\n%s\n' % to_unicode(backtrace)
|
content += '\n%s\n' % to_unicode(backtrace)
|
||||||
|
|
@ -150,7 +185,8 @@ class MainWindow(QtMainWindow):
|
||||||
content, QMessageBox.Ok)
|
content, QMessageBox.Ok)
|
||||||
self.ui.saveButton.setEnabled(True)
|
self.ui.saveButton.setEnabled(True)
|
||||||
|
|
||||||
def showPreview(self):
|
def loadPreview(self):
|
||||||
|
""" Loads the current page's preview into the preview QTextEdit """
|
||||||
tmp_content = deepcopy(self.content)
|
tmp_content = deepcopy(self.content)
|
||||||
tmp_content.content = unicode(self.ui.contentEdit.toPlainText())
|
tmp_content.content = unicode(self.ui.contentEdit.toPlainText())
|
||||||
self.ui.previewEdit.setHtml(self.backend.get_content_preview(tmp_content))
|
self.ui.previewEdit.setHtml(self.backend.get_content_preview(tmp_content))
|
||||||
|
|
@ -162,10 +198,14 @@ class MainWindow(QtMainWindow):
|
||||||
|
|
||||||
self.ui.loadHistoryButton.setEnabled(False)
|
self.ui.loadHistoryButton.setEnabled(False)
|
||||||
self.ui.loadHistoryButton.setText("Loading...")
|
self.ui.loadHistoryButton.setText("Loading...")
|
||||||
|
|
||||||
self.ui.historyTable.clear()
|
self.ui.historyTable.clear()
|
||||||
self.ui.historyTable.setRowCount(0)
|
self.ui.historyTable.setRowCount(0)
|
||||||
|
|
||||||
self.ui.historyTable.setHorizontalHeaderLabels(["Revision", "Time", "Author", "Summary"])
|
self.ui.historyTable.setHorizontalHeaderLabels(["Revision",
|
||||||
|
"Time",
|
||||||
|
"Author",
|
||||||
|
"Summary"])
|
||||||
self.ui.historyTable.setColumnWidth(3, 1000)
|
self.ui.historyTable.setColumnWidth(3, 1000)
|
||||||
|
|
||||||
self.process = QtDo(self.weboob, self._gotRevision)
|
self.process = QtDo(self.weboob, self._gotRevision)
|
||||||
|
|
@ -177,6 +217,7 @@ class MainWindow(QtMainWindow):
|
||||||
def _gotRevision(self, backend, revision):
|
def _gotRevision(self, backend, revision):
|
||||||
""" Callback for loadHistory's QtDo """
|
""" Callback for loadHistory's QtDo """
|
||||||
if not backend:
|
if not backend:
|
||||||
|
# The last revision has been processed
|
||||||
self.process = None
|
self.process = None
|
||||||
self.ui.loadHistoryButton.setEnabled(True)
|
self.ui.loadHistoryButton.setEnabled(True)
|
||||||
self.ui.loadHistoryButton.setText("Reload")
|
self.ui.loadHistoryButton.setText("Reload")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue