Thread: SF.net SVN: fclient:[950] trunk/fclient/fclient/impl/ViewBrowser
Status: Pre-Alpha
Brought to you by:
jurner
From: <jU...@us...> - 2008-08-22 08:04:31
|
Revision: 950 http://fclient.svn.sourceforge.net/fclient/?rev=950&view=rev Author: jUrner Date: 2008-08-22 08:04:41 +0000 (Fri, 22 Aug 2008) Log Message: ----------- impl browser bookmarks. pages cann be bookmarked now ++ bookmark editor Modified Paths: -------------- trunk/fclient/fclient/impl/ViewBrowser/Actions.py trunk/fclient/fclient/impl/ViewBrowser/ViewBrowser.py Modified: trunk/fclient/fclient/impl/ViewBrowser/Actions.py =================================================================== --- trunk/fclient/fclient/impl/ViewBrowser/Actions.py 2008-08-22 08:02:47 UTC (rev 949) +++ trunk/fclient/fclient/impl/ViewBrowser/Actions.py 2008-08-22 08:04:41 UTC (rev 950) @@ -186,7 +186,20 @@ isEnabled=True, trigger=parent.onCloseCurrentSideBar, ) - + + # bookmarks + self.action( + name='ActionEditBookmarks', + text=self.trUtf8('Edit bookmarks..'), + isEnabled=True, + trigger=parent.onEditBookmarks, + ) + self.action( + name='ActionBookmarkPage', + text=self.trUtf8('Bookmark page..'), + isEnabled=True, + trigger=parent.onBookmarkPage, + ) def intertwineBrowserActions(self, browser=None): """intertwines Browser actions with BrowserWidget actions @@ -218,3 +231,16 @@ myPageAction.setUserData((newPageAction, onActionChanged)) myPageAction.connect(newPageAction, QtCore.SIGNAL('changed()'), onActionChanged) newPageAction.connect(myPageAction, QtCore.SIGNAL('triggered()'), newPageAction.trigger) + +#*********************************************************************************** +# +#*********************************************************************************** +class BookmarkAction(QtGui.QAction): + + def __init__(self, parent, text, target): + QtGui.QAction.__init__(self, text, parent) + self.target = target + + + + Modified: trunk/fclient/fclient/impl/ViewBrowser/ViewBrowser.py =================================================================== --- trunk/fclient/fclient/impl/ViewBrowser/ViewBrowser.py 2008-08-22 08:02:47 UTC (rev 949) +++ trunk/fclient/fclient/impl/ViewBrowser/ViewBrowser.py 2008-08-22 08:04:41 UTC (rev 950) @@ -41,7 +41,7 @@ # x. close icon for ActionCloseSideBar # x. peformance of QWebView sucks when it comes to rendering images # x. on some pages images are not be loaded (no network error?!) while ff loads them without any problems -# +# x. icons for bookmarks #******************************************************************************************* #TODO: code # @@ -77,6 +77,8 @@ from . import Settings from .dlgs import DlgPropsBrowserObject +from .dlgs import DlgBookmarks +from .dlgs import DlgBookmarkPage from .Ui_BrowserWidget import Ui_ViewBrowserWidget #***************************************************************************************** @@ -109,6 +111,8 @@ QtGui.QWidget.__init__(self, parent) self.menuSideBars = QtGui.QMenu(self.trUtf8('Side bars')) #TODO: retranslate + self.menuBookmarks = QtGui.QMenu(self.trUtf8('Bookmarks')) #TODO: retranslate + self.connect(self.menuBookmarks, QtCore.SIGNAL('aboutToShow()'), self.onMenuBookmarksAboutToShow) self.setupUi(self) self.isCreated = False @@ -274,6 +278,12 @@ if isinstance(widget, Browser.Browser): return widget + def currentUrl(self): + browser = self.currentBrowser() + if browser is not None: + lastBrowserState = browser.userData() + return lastBrowserState.url + def load(self, url, force=False, browser=None): """loads an url in the current browser. if there is no current browser, a new browser is created @param force: (bool) if True, a new browser is opend if there is no browser available @@ -379,7 +389,10 @@ menu.addAction(self.fcActions['ActionFind']) menu.addAction(self.fcActions['ActionFindNext']) menu.addAction(self.fcActions['ActionFindPrevious']) + menu.addAction(self.fcActions['ActionEditBookmarks']) + menu.addAction(self.fcActions['ActionBookmarkPage']) + menu.addMenu(self.menuBookmarks) menu.addMenu(self.menuSideBars) return menu @@ -417,6 +430,20 @@ ######################################### ## event handlers ######################################### + def onBookmarkPage(self, action): + dlg = DlgBookmarkPage.DlgBookmarkPage(self) + dlg.show() + if dlg.result() == dlg.Accepted: + pass + + def onBookmarkTriggered(self): + action = self.sender() + if self.fcSettings.value('OpenBookmarksInNewTab'): + browser = self.newBrowser(self.trUtf8('Loading')) + self.load(action.target, browser=browser) + else: + self.load(action.target, force=True) + #TODO: actions need some comb over def onBrowserCustomContextMenuRequested(self, pt): browser = self.sender() @@ -604,6 +631,12 @@ self.fcActions['ActionFindNext'].setEnabled(bool(text)) self.fcActions['ActionFindPrevious'].setEnabled(bool(text)) + def onEditBookmarks(self, action): + dlg = DlgBookmarks.DlgBookmarks(self) + dlg.show() + if dlg.result() == dlg.Accepted: + pass + def onFind(self, action): frameFind = self.controlById(self.IdFrameFind) ed = self.controlById(self.IdEdFind) @@ -651,6 +684,27 @@ qUrl = QtCore.QUrl(home) self.load(qUrl, force=True) + #TODO: how to know if we have bookmarks? + def onMenuBookmarksAboutToShow(self): + self.menuBookmarks.clear() + stack = [self.menuBookmarks, ] + try: + for event, params in DlgBookmarks.DlgBookmarks.walkBookmarks(DlgBookmarks.BookmarksFile): + if event == 'beginfolder': + menu = QtGui.QMenu(params['name'], stack[-1]) + stack[-1].addMenu(menu) + stack.append(menu) + elif event == 'endfolder': + stack.pop() + elif event == 'bookmark': + action = Actions.BookmarkAction(stack[-1], params['name'], params['target']) + stack[-1].addAction(action) + self.connect(action, QtCore.SIGNAL('triggered()'), self.onBookmarkTriggered) + except SyntaxError: + pass + except IOError: + pass + def onNavBarReturnPressed(self): text = self.controlById(self.IdEdAddressBar).text() if text.isEmpty(): @@ -683,6 +737,7 @@ if browser is not None and act is browser.pageAction(browser.page().Back): self._adjustBackIsClose() + #TODO: not yet implemented def onSavePage(self, action): # we have to cheat a bit here and reload the page to make shure the page has # all QNetWorkReplies present This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-09-06 08:52:05
|
Revision: 966 http://fclient.svn.sourceforge.net/fclient/?rev=966&view=rev Author: jUrner Date: 2008-09-06 08:52:13 +0000 (Sat, 06 Sep 2008) Log Message: ----------- added functionality to view html source of a page Modified Paths: -------------- trunk/fclient/fclient/impl/ViewBrowser/Actions.py trunk/fclient/fclient/impl/ViewBrowser/ViewBrowser.py Added Paths: ----------- trunk/fclient/fclient/impl/ViewBrowser/dlgs/DlgViewPageSource.py trunk/fclient/fclient/impl/ViewBrowser/dlgs/DlgViewPageSource.ui trunk/fclient/fclient/impl/ViewBrowser/dlgs/Ui_DlgViewPageSource.py Modified: trunk/fclient/fclient/impl/ViewBrowser/Actions.py =================================================================== --- trunk/fclient/fclient/impl/ViewBrowser/Actions.py 2008-09-06 08:51:02 UTC (rev 965) +++ trunk/fclient/fclient/impl/ViewBrowser/Actions.py 2008-09-06 08:52:13 UTC (rev 966) @@ -199,8 +199,24 @@ text=self.trUtf8('Bookmark page..'), isEnabled=True, trigger=parent.onBookmarkPage, - ) + ) + + # others + self.action( + name='ActionViewPageSource', + text=self.trUtf8('View page source..'), + isEnabled=True, + trigger=parent.onViewPageSource, + ) + + self.action( + name='ActionViewFrameSource', + text=self.trUtf8('View frame source..'), + isEnabled=True, + trigger=parent.onViewFrameSource, + ) + def intertwineBrowserActions(self, browser=None): """intertwines Browser actions with BrowserWidget actions @note: call everytime the current browser changes Modified: trunk/fclient/fclient/impl/ViewBrowser/ViewBrowser.py =================================================================== --- trunk/fclient/fclient/impl/ViewBrowser/ViewBrowser.py 2008-09-06 08:51:02 UTC (rev 965) +++ trunk/fclient/fclient/impl/ViewBrowser/ViewBrowser.py 2008-09-06 08:52:13 UTC (rev 966) @@ -79,6 +79,7 @@ from .dlgs import DlgPropsBrowserObject from .dlgs import DlgBookmarks from .dlgs import DlgBookmarkPage +from .dlgs import DlgViewPageSource from .Ui_BrowserWidget import Ui_ViewBrowserWidget #***************************************************************************************** @@ -183,10 +184,13 @@ ## private methods ######################################### def _adjustCurrentBrowserDependendStuff(self): - self.fcActions.intertwineBrowserActions(self.currentBrowser()) + browser = self.currentBrowser() + self.fcActions.intertwineBrowserActions(browser) if self.sideBarLoadDetails.isVisible(): - self.sideBarLoadDetails.setBrowser(self.currentBrowser()) + self.sideBarLoadDetails.setBrowser(browser) + self.fcActions['ActionViewPageSource'].setEnabled(browser is not None) + #NOTE: to reduce flicker set min size to max size def _adjustTabText(self, qString): maxTabText = self.fcSettings.value('MaxTabText') @@ -391,6 +395,7 @@ menu.addAction(self.fcActions['ActionFindPrevious']) menu.addAction(self.fcActions['ActionEditBookmarks']) menu.addAction(self.fcActions['ActionBookmarkPage']) + menu.addAction(self.fcActions['ActionViewPageSource']) menu.addMenu(self.menuBookmarks) menu.addMenu(self.menuSideBars) @@ -472,6 +477,7 @@ menu.addSeparator() menu.addAction(browser.pageAction(page.Copy)) menu.addAction(self.fcActions['ActionObjectProperties']) + menu.addAction(self.fcActions['ActionViewFrameSource']) #TODO: QwebView assumes we can download queries - we can't browser.pageAction(page.DownloadLinkToDisk).setEnabled(config.fcpClient.isConnected()) @@ -789,7 +795,24 @@ # update status info addressBar.setText(lastBrowserState.url.toString()) - + + def onViewFrameSource(self, action): + browser = self.currentBrowser() + if browser is not None: + dlg = DlgViewPageSource.DlgViewPageSource(self, html= browser.page().currentFrame().toHtml()) + dlg.show() + if dlg.result() == dlg.Accepted: + pass + + def onViewPageSource(self, action): + browser = self.currentBrowser() + if browser is not None: + dlg = DlgViewPageSource.DlgViewPageSource(self, html= browser.page().mainFrame().toHtml()) + dlg.show() + if dlg.result() == dlg.Accepted: + pass + + #TODO: enable/disable, but no view gives non feedback on max/min zoom def onZoomIn(self, action): browser = self.currentBrowser() Added: trunk/fclient/fclient/impl/ViewBrowser/dlgs/DlgViewPageSource.py =================================================================== --- trunk/fclient/fclient/impl/ViewBrowser/dlgs/DlgViewPageSource.py (rev 0) +++ trunk/fclient/fclient/impl/ViewBrowser/dlgs/DlgViewPageSource.py 2008-09-06 08:52:13 UTC (rev 966) @@ -0,0 +1,86 @@ + +#********************************************************************************* +#TODO: +# +# x. html syntax highlighter +# +#********************************************************************************* +# some fixes for relative imports +# see --> [http://bugs.python.org/issue1510172] absolute/rellative import not working (works only current dir and below) +# see --> [http://mail.python.org/pipermail/python-ideas/2007-February/000232.html] PEP for executing a module in a +# ...package containing relative imports +from __future__ import absolute_import +if __name__ == '__main__': + import os + __path__ = [os.path.dirname(__file__)] + from ._fix_mexec import fix_mexec + fix_mexec(__name__, __file__) + del fix_mexec + +import os +from PyQt4 import QtCore, QtGui + +from ... import config +from .Ui_DlgViewPageSource import Ui_DlgViewPageSource +#********************************************************************************** +# +#********************************************************************************** +class Settings(config.SettingsBase): + _key_ = 'DlgBrowserViewpageSource' + _settings_ = ( + ('Geometry', 'ByteArray', QtCore.QByteArray()), + ) + +#********************************************************************************** +# +#********************************************************************************** +class HtmlSyntaxHighlighter(QtGui.QSyntaxHighlighter): + + def __init__(self, parent=None): + QtGui.QSyntaxHighlighter.__init__(self, parent) + + + def highlightBlock(self, text): + pass + +#********************************************************************************** +# +#********************************************************************************** +class DlgViewPageSource(QtGui.QDialog, Ui_DlgViewPageSource): + + + IdEd = 'ed' + + def __init__(self, parent=None, html=None): + QtGui.QDialog.__init__(self, parent) + + self.setupUi(self) + + self.fcSettings = Settings(self).restore() + self.restoreGeometry(self.fcSettings.value('Geometry')) + + + ed = self.controlById(self.IdEd) + if html is not None: + ed.setPlainText(html) + self.hilighter = HtmlSyntaxHighlighter(ed.document()) + + def controlById(self, idControl): + return getattr(self, idControl) + + def hideEvent(self, event): + self.fcSettings.setValues(Geometry=self.saveGeometry()) + +#********************************************************************************** +# +#********************************************************************************** +if __name__ == '__main__': + import sys + + app = QtGui.QApplication(sys.argv) + w = DlgViewPageSource(None, html='''<a href="foo">bar</a> + ''' + ) + w.show() + res = app.exec_() + sys.exit(res) Added: trunk/fclient/fclient/impl/ViewBrowser/dlgs/DlgViewPageSource.ui =================================================================== --- trunk/fclient/fclient/impl/ViewBrowser/dlgs/DlgViewPageSource.ui (rev 0) +++ trunk/fclient/fclient/impl/ViewBrowser/dlgs/DlgViewPageSource.ui 2008-09-06 08:52:13 UTC (rev 966) @@ -0,0 +1,73 @@ +<ui version="4.0" > + <class>DlgViewPageSource</class> + <widget class="QDialog" name="DlgViewPageSource" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>461</width> + <height>594</height> + </rect> + </property> + <property name="windowTitle" > + <string>View page source..</string> + </property> + <layout class="QGridLayout" name="gridLayout" > + <item row="0" column="0" > + <widget class="QPlainTextEdit" name="ed" > + <property name="readOnly" > + <bool>true</bool> + </property> + <property name="textInteractionFlags" > + <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QDialogButtonBox" name="buttonBox" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons" > + <set>QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>DlgViewPageSource</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel" > + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel" > + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>DlgViewPageSource</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel" > + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel" > + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> Added: trunk/fclient/fclient/impl/ViewBrowser/dlgs/Ui_DlgViewPageSource.py =================================================================== --- trunk/fclient/fclient/impl/ViewBrowser/dlgs/Ui_DlgViewPageSource.py (rev 0) +++ trunk/fclient/fclient/impl/ViewBrowser/dlgs/Ui_DlgViewPageSource.py 2008-09-06 08:52:13 UTC (rev 966) @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file '/home/me/src/fclient/trunk/fclient/fclient/impl/ViewBrowser/dlgs/DlgViewPageSource.ui' +# +# Created: Sat Sep 6 10:42:58 2008 +# by: PyQt4 UI code generator 4.4.2 +# +# WARNING! All changes made in this file will be lost! + +from PyQt4 import QtCore, QtGui + +class Ui_DlgViewPageSource(object): + def setupUi(self, DlgViewPageSource): + DlgViewPageSource.setObjectName("DlgViewPageSource") + DlgViewPageSource.resize(461,594) + self.gridLayout = QtGui.QGridLayout(DlgViewPageSource) + self.gridLayout.setObjectName("gridLayout") + self.ed = QtGui.QPlainTextEdit(DlgViewPageSource) + self.ed.setReadOnly(True) + self.ed.setTextInteractionFlags(QtCore.Qt.TextSelectableByKeyboard|QtCore.Qt.TextSelectableByMouse) + self.ed.setObjectName("ed") + self.gridLayout.addWidget(self.ed,0,0,1,1) + self.buttonBox = QtGui.QDialogButtonBox(DlgViewPageSource) + self.buttonBox.setOrientation(QtCore.Qt.Horizontal) + self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok) + self.buttonBox.setObjectName("buttonBox") + self.gridLayout.addWidget(self.buttonBox,1,0,1,1) + + self.retranslateUi(DlgViewPageSource) + QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("accepted()"),DlgViewPageSource.accept) + QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("rejected()"),DlgViewPageSource.reject) + QtCore.QMetaObject.connectSlotsByName(DlgViewPageSource) + + def retranslateUi(self, DlgViewPageSource): + DlgViewPageSource.setWindowTitle(QtGui.QApplication.translate("DlgViewPageSource", "View page source..", None, QtGui.QApplication.UnicodeUTF8)) + + +if __name__ == "__main__": + import sys + app = QtGui.QApplication(sys.argv) + DlgViewPageSource = QtGui.QDialog() + ui = Ui_DlgViewPageSource() + ui.setupUi(DlgViewPageSource) + DlgViewPageSource.show() + sys.exit(app.exec_()) + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |