From dcb2375fd1a4bf4a961de9f25485cb228a8d818b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Schreiner?= Date: Tue, 1 Feb 2011 13:59:46 +0100 Subject: [PATCH] New application qwebcontentedit Status: ugly GUI, editing and saving a page mostly working, preview support in progress --- scripts/qwebcontentedit | 25 ++++ setup.py | 5 +- .../applications/qwebcontentedit/__init__.py | 3 + .../qwebcontentedit/main_window.py | 79 +++++++++++ .../qwebcontentedit/qwebcontentedit.py | 36 +++++ .../applications/qwebcontentedit/ui/Makefile | 13 ++ .../qwebcontentedit/ui/__init__.py | 0 .../qwebcontentedit/ui/main_window.ui | 126 ++++++++++++++++++ 8 files changed, 286 insertions(+), 1 deletion(-) create mode 100755 scripts/qwebcontentedit create mode 100644 weboob/applications/qwebcontentedit/__init__.py create mode 100644 weboob/applications/qwebcontentedit/main_window.py create mode 100644 weboob/applications/qwebcontentedit/qwebcontentedit.py create mode 100644 weboob/applications/qwebcontentedit/ui/Makefile create mode 100644 weboob/applications/qwebcontentedit/ui/__init__.py create mode 100644 weboob/applications/qwebcontentedit/ui/main_window.ui diff --git a/scripts/qwebcontentedit b/scripts/qwebcontentedit new file mode 100755 index 00000000..654f47cf --- /dev/null +++ b/scripts/qwebcontentedit @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai + +# Copyright(C) 2010 Romain Bignon +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +from weboob.applications.qwebcontentedit import QWebContentEdit + + +if __name__ == '__main__': + QWebContentEdit.run() diff --git a/setup.py b/setup.py index 66f246c6..7e87e6fe 100755 --- a/setup.py +++ b/setup.py @@ -46,6 +46,7 @@ def build_qt(): os.system('make -C weboob/applications/qboobmsg/ui') os.system('make -C weboob/applications/qhavesex/ui') os.system('make -C weboob/applications/qvideoob/ui') + os.system('make -C weboob/applications/qwebcontentedit/ui') os.system('make -C weboob/tools/application/qt') class Options: @@ -95,7 +96,7 @@ scripts = set(os.listdir('scripts')) packages = set(find_packages()) hildon_scripts = set(('masstransit',)) -qt_scripts = set(('qboobmsg', 'qhavesex', 'qvideoob', 'weboob-config-qt')) +qt_scripts = set(('qboobmsg', 'qhavesex', 'qvideoob', 'weboob-config-qt', 'qwebcontentedit')) if not options.hildon: scripts = scripts - hildon_scripts @@ -116,6 +117,8 @@ qt_packages = set(( 'weboob.applications.qvideoob.ui', 'weboob.applications.qweboobcfg', 'weboob.applications.qweboobcfg.ui', + 'weboob.applications.qwebcontentedit', + 'weboob.applications.qwebcontentedit.ui' )) if not options.hildon: diff --git a/weboob/applications/qwebcontentedit/__init__.py b/weboob/applications/qwebcontentedit/__init__.py new file mode 100644 index 00000000..faa7196f --- /dev/null +++ b/weboob/applications/qwebcontentedit/__init__.py @@ -0,0 +1,3 @@ +from .qwebcontentedit import QWebContentEdit + +__all__ = ['QWebContentEdit'] \ No newline at end of file diff --git a/weboob/applications/qwebcontentedit/main_window.py b/weboob/applications/qwebcontentedit/main_window.py new file mode 100644 index 00000000..233c1ab9 --- /dev/null +++ b/weboob/applications/qwebcontentedit/main_window.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2011 Clément Schreiner +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +from PyQt4.QtCore import SIGNAL + + +from weboob.tools.application.qt import QtMainWindow, QtDo + +from .ui.main_window_ui import Ui_MainWindow + +class MainWindow(QtMainWindow): + def __init__(self, config, weboob, parent=None): + QtMainWindow.__init__(self, parent) + self.ui = Ui_MainWindow() + self.ui.setupUi(self) + + self.config = config + self.weboob = weboob + + self.connect(self.ui.idEdit, SIGNAL("returnPressed()"), self.loadPage) + self.connect(self.ui.loadButton, SIGNAL("clicked()"), self.loadPage) + self.connect(self.ui.tabWidget, SIGNAL("currentChanged(int)"), +self._currentTabChanged) + self.connect(self.ui.saveButton, SIGNAL("clicked()"), self.savePage) + + def _currentTabChanged(self): + if self.ui.tabWidget.currentIndex() == 1: + self.showPreview() + return + + def loadPage(self): + id = unicode(self.ui.idEdit.text()) + if not id: + return + + for backend in self.weboob.iter_backends(): + self.content = backend.get_content(id) + if self.content: + self.ui.contentEdit.setPlainText(self.content.content) + self.backend = backend + return + + + def savePage(self): + if not hasattr(self, "backend"): + return + new_content = unicode(self.ui.contentEdit.toPlainText()) + if new_content != self.content.content: + self.content.content = new_content + message = unicode(self.ui.descriptionEdit.text()) + self.process = QtDo(self.weboob, self._savePage_cb, self._savePage_eb) + self.process.do('push_content', self.content, message, backends=self.backend) + + def _savePage_cb(self, backend, data): + if not backend: + return + self.ui.descriptionEdit.clear() + + def _savePage_eb(self, backend, error, backtrace): + print error + print backtrace + + def showPreview(self): + self.ui.previewEdit.setHtml(self.backend.preview_content(self.content)) + return diff --git a/weboob/applications/qwebcontentedit/qwebcontentedit.py b/weboob/applications/qwebcontentedit/qwebcontentedit.py new file mode 100644 index 00000000..b8e93273 --- /dev/null +++ b/weboob/applications/qwebcontentedit/qwebcontentedit.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2011 Clément Schreiner +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +from weboob.tools.application.qt import QtApplication +from weboob.capabilities.content import ICapContent + +from .main_window import MainWindow + +class QWebContentEdit(QtApplication): + APPNAME = 'qwebcontentedit' + VERSION = '0.6' + COPYRIGHT = 'Copyright(C) 2011 Clément Schreiner' + DESCRIPTION = "Qt application for managing content on supported websites" + CAPS = ICapContent + + def main(self, argv): + self.load_backends(ICapContent, storage=self.create_storage()) + self.main_window = MainWindow(self.config, self.weboob) + self.main_window.show() + return self.weboob.loop() + + diff --git a/weboob/applications/qwebcontentedit/ui/Makefile b/weboob/applications/qwebcontentedit/ui/Makefile new file mode 100644 index 00000000..f0db5154 --- /dev/null +++ b/weboob/applications/qwebcontentedit/ui/Makefile @@ -0,0 +1,13 @@ +UI_FILES = $(wildcard *.ui) +UI_PY_FILES = $(UI_FILES:%.ui=%_ui.py) +PYUIC = pyuic4 + +all: $(UI_PY_FILES) + +%_ui.py: %.ui + $(PYUIC) -o $@ $^ + +clean: + rm -f *.pyc + rm -f $(UI_PY_FILES) + diff --git a/weboob/applications/qwebcontentedit/ui/__init__.py b/weboob/applications/qwebcontentedit/ui/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/weboob/applications/qwebcontentedit/ui/main_window.ui b/weboob/applications/qwebcontentedit/ui/main_window.ui new file mode 100644 index 00000000..da420a47 --- /dev/null +++ b/weboob/applications/qwebcontentedit/ui/main_window.ui @@ -0,0 +1,126 @@ + + + MainWindow + + + + 0 + 0 + 469 + 521 + + + + MainWindow + + + + + + + + + + + + Load + + + + + + + + + 1 + + + + Edit + + + + + + + + + + Preview + + + + + + true + + + + + + + + + + + + + Edit description + + + + + + + Save + + + + + + + + + + + 0 + 0 + 469 + 21 + + + + + File + + + + + + + + + Exit + + + + + + + actionExit + triggered() + MainWindow + close() + + + -1 + -1 + + + 343 + 306 + + + + +