Commit 302ee77f authored by ntome's avatar ntome Committed by Romain Bignon

add qgalleroob qt app

QGalleroob allows to search galleries and images and browse collections
of those.
parent 75502ac5
core := weboob/tools/application/qt5
applications := qboobmsg qhavedate qwebcontentedit qflatboob qcineoob qcookboob qhandjoob qbooblyrics
applications := qboobmsg qhavedate qwebcontentedit qflatboob qcineoob qcookboob qhandjoob qbooblyrics qgalleroob
ifeq ($(WIN32),)
applications += qvideoob
endif
......
[Desktop Entry]
Name=QGalleroob
Comment=Search for galleries and images on many websites, and get info about them
Exec=qgalleroob
Icon=qgalleroob
Terminal=false
Type=Application
StartupNotify=true
Categories=Graphics;Viewer;Qt;
Keywords=image;gallery;view;
......@@ -66,6 +66,7 @@ def install_weboob():
hildon_scripts = set(('masstransit',))
qt_scripts = set(('qboobmsg',
'qhavedate',
'qgalleroob',
'qvideoob',
'weboob-config-qt',
'qwebcontentedit',
......@@ -105,7 +106,9 @@ def install_weboob():
'weboob.applications.qwebcontentedit',
'weboob.applications.qwebcontentedit.ui'
'weboob.applications.qflatboob',
'weboob.applications.qflatboob.ui'
'weboob.applications.qflatboob.ui',
'weboob.applications.qgalleroob',
'weboob.applications.qgalleroob.ui',
))
if not options.hildon:
......
from .qgalleroob import QGalleroob
__all__ = ['QGalleroob']
# -*- coding: utf-8 -*-
# Copyright(C) 2016 Vincent A
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
import os
from PyQt5.QtCore import QModelIndex, pyqtSlot as Slot
from weboob.tools.application.qt5 import QtMainWindow
from weboob.tools.application.qt5.backendcfg import BackendCfg
from weboob.tools.application.qt5.models import BackendListModel, ResultModel, FilterTypeModel
from weboob.capabilities.collection import BaseCollection, CapCollection
from weboob.capabilities.gallery import CapGallery, BaseGallery
from weboob.capabilities.image import CapImage, BaseImage
from .ui.mainwindow_ui import Ui_MainWindow
from .viewer import Viewer
def size_format(n):
UNITS = [
(1 << 40, 'TiB'),
(1 << 30, 'GiB'),
(1 << 20, 'MiB'),
(1 << 10, 'KiB'),
(0, 'B')
]
for f, u in UNITS:
if n > f:
return '%.2f %s' % (n / float(f), u)
class MainWindow(QtMainWindow):
def __init__(self, config, storage, weboob, parent=None):
super(MainWindow, self).__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.mdl = ResultModel(weboob)
self.mdl.setColumnFields([['name', 'title'],['url']])
self.proxy_mdl = FilterTypeModel()
self.proxy_mdl.setAcceptedTypes([BaseCollection])
self.proxy_mdl.setSourceModel(self.mdl)
self.ui.collectionTree.setModel(self.proxy_mdl)
self.ui.collectionTree.selectionModel().currentChanged.connect(self.showCollection)
self.config = config
self.storage = storage
self.weboob = weboob
self.ui.browseButton.clicked.connect(self.startBrowse)
self.ui.searchEdit.returnPressed.connect(self.startSearch)
self.ui.searchButton.clicked.connect(self.startSearch)
self.ui.galleryList.setModel(self.mdl)
self.ui.galleryList.selectionModel().currentChanged.connect(self.showGallery)
self.ui.galleryList.hide()
self.ui.imageList.setModel(self.mdl)
self.ui.imageList.selectionModel().currentChanged.connect(self.showImageInfo)
self.ui.imageList.activated.connect(self.openImage)
# backendEdit choice
self.fillBackends()
self.ui.backendEdit.currentIndexChanged.connect(self.changeBackend)
if self.weboob.count_backends() == 0:
self.backendsConfig()
self.ui.actionBackends.triggered.connect(self.backendsConfig)
self.lastSaveDir = os.path.expanduser('~')
@Slot()
def backendsConfig(self):
cfg = BackendCfg(self.weboob, (CapImage,), self)
if cfg.run():
self.fillBackends()
def fillBackends(self):
model = BackendListModel(self.weboob)
model.addBackends(CapGallery, entry_title=True)
model.addBackends(CapImage, entry_title=True)
self.ui.backendEdit.setModel(model)
def selectedBackend(self):
cap = self.ui.backendEdit.currentData(BackendListModel.RoleCapability)
backend = self.ui.backendEdit.currentData(BackendListModel.RoleBackendName)
return cap, backend
def _collectionBackends(self):
cap, backend = self.selectedBackend()
if backend is not None:
return [backend]
backends = self.weboob.iter_backends(caps=cap)
return [b for b in backends if b.has_caps(CapCollection)]
@Slot()
def changeBackend(self):
cap, backend = self.selectedBackend()
if cap is CapImage:
res_class = BaseImage
else:
res_class = BaseGallery
self.mdl.setResourceClasses([res_class])
@Slot(QModelIndex)
def showCollection(self, qidx):
cap, _ = self.selectedBackend()
qidx = self.proxy_mdl.mapToSource(qidx)
qidx = qidx.sibling(qidx.row(), 0)
if cap is CapImage:
self.ui.galleryList.hide()
self.ui.imageList.setRootIndex(qidx)
self.ui.imageList.setEnabled(True)
self.ui.imageList.show()
else:
self.ui.galleryList.show()
self.ui.galleryList.setRootIndex(qidx)
self.ui.galleryList.setEnabled(True)
@Slot(QModelIndex)
def showGallery(self, qidx):
self.ui.imageList.setEnabled(True)
self.ui.imageList.show()
qidx = qidx.sibling(qidx.row(), 0)
self.ui.imageList.setRootIndex(qidx)
def showNoneItem(self):
self.ui.labelTitle.setText('-')
self.ui.labelDescription.setText('-')
self.ui.labelAuthor.setText('-')
self.ui.labelDate.setText('-')
self.ui.labelLink.setText('-')
self.ui.labelSize.setText('-')
self.ui.labelRating.setText('-')
@Slot(QModelIndex)
def showImageInfo(self, qidx):
image = qidx.data(self.mdl.RoleObject)
if image is None:
self.showNoneItem()
return
self.ui.labelTitle.setText(image.title or '')
self.ui.labelDescription.setText(image.description or '')
self.ui.labelAuthor.setText(image.author or '')
if image.size:
self.ui.labelSize.setText(size_format(image.size) or '')
else:
self.ui.labelSize.setText('-')
if image.url:
self.ui.labelLink.setText('<a href="%s">Link</a>' % image.url)
else:
self.ui.labelLink.setText('')
@Slot(QModelIndex)
def openImage(self, qidx):
viewer = Viewer(self.weboob, self)
viewer.setData(self.mdl, qidx)
viewer.show()
@Slot()
def startSearch(self):
pattern = self.ui.searchEdit.text()
if not pattern:
return
self.mdl.clear()
cap, backend = self.selectedBackend()
if cap is CapImage:
self.ui.galleryList.hide()
self.ui.imageList.setRootIndex(QModelIndex())
self.mdl.addRootDo('search_image', pattern, backends=backend)
self.ui.imageList.setEnabled(True)
self.ui.imageList.show()
elif cap is CapGallery:
self.ui.imageList.hide()
self.ui.galleryList.setRootIndex(QModelIndex())
self.mdl.addRootDo('search_galleries', pattern, backends=backend)
self.ui.galleryList.setEnabled(True)
self.ui.galleryList.show()
@Slot()
def startBrowse(self):
self.ui.collectionTree.setEnabled(True)
self.ui.galleryList.setEnabled(False)
self.ui.imageList.setEnabled(False)
self.mdl.clear()
cap, backend = self.selectedBackend()
if cap is CapImage:
self.ui.galleryList.hide()
res_class = BaseImage
else:
self.ui.galleryList.show()
res_class = BaseGallery
self.mdl.setResourceClasses([res_class])
backends = self._collectionBackends()
self.mdl.addRootDo('iter_resources', [res_class], [], backends=backends)
# -*- coding: utf-8 -*-
# Copyright(C) 2016 Vincent A
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.capabilities.gallery import CapGallery
from weboob.capabilities.image import CapImage
from weboob.tools.application.qt5 import QtApplication
from weboob.tools.config.yamlconfig import YamlConfig
from .main_window import MainWindow
class QGalleroob(QtApplication):
APPNAME = 'qgalleroob'
VERSION = '1.1'
COPYRIGHT = u'Copyright(C) 2016 Vincent A'
DESCRIPTION = "Qt application to view image galleries."
SHORT_DESCRIPTION = "search for images"
#~ CONFIG = {'queries': {}}
#~ STORAGE = {'bookmarks': [], 'read': [], 'notes': {}}
def main(self, argv):
self.load_backends(CapGallery)
self.load_backends(CapImage)
self.create_storage()
self.load_config(klass=YamlConfig)
main_window = MainWindow(self.config, self.storage, self.weboob)
main_window.show()
return self.weboob.loop()
UI_FILES = $(wildcard *.ui)
UI_PY_FILES = $(UI_FILES:%.ui=%_ui.py)
PYUIC = pyuic5
all: $(UI_PY_FILES)
%_ui.py: %.ui
$(PYUIC) -o $@ $^
clean:
rm -f *.pyc
rm -f $(UI_PY_FILES)
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Viewer</class>
<widget class="QMainWindow" name="Viewer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>QGalleroob viewer</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>780</width>
<height>503</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="view">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="firstButton">
<property name="text">
<string>|&lt;</string>
</property>
<property name="icon">
<iconset theme="go-first"/>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="prevButton">
<property name="text">
<string>&lt;</string>
</property>
<property name="icon">
<iconset theme="go-previous"/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="posLabel">
<property name="text">
<string>1/N</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="nextButton">
<property name="text">
<string>&gt;</string>
</property>
<property name="icon">
<iconset theme="go-next"/>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="lastButton">
<property name="text">
<string>&gt;|</string>
</property>
<property name="icon">
<iconset theme="go-last"/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionZoomIn"/>
<addaction name="actionZoomOut"/>
<addaction name="actionFullSize"/>
<addaction name="actionFitWindow"/>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>19</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionSaveImage"/>
<addaction name="actionClose"/>
</widget>
<addaction name="menuFile"/>
</widget>
<action name="actionClose">
<property name="text">
<string>Close</string>
</property>
</action>
<action name="actionSaveImage">
<property name="icon">
<iconset theme="document-save"/>
</property>
<property name="text">
<string>Save image...</string>
</property>
</action>
<action name="actionFullSize">
<property name="icon">
<iconset theme="zoom-original"/>
</property>
<property name="text">
<string>Original size</string>
</property>
<property name="shortcut">
<string>G</string>
</property>
</action>
<action name="actionFitWindow">
<property name="icon">
<iconset theme="zoom-fit-best"/>
</property>
<property name="text">
<string>Fit to window</string>
</property>
<property name="shortcut">
<string>F</string>
</property>
</action>
<action name="actionZoomOut">
<property name="icon">
<iconset theme="zoom-out"/>
</property>
<property name="text">
<string>Zoom out</string>
</property>
<property name="shortcut">
<string>-</string>
</property>
</action>
<action name="actionZoomIn">
<property name="icon">
<iconset theme="zoom-in"/>
</property>
<property name="text">
<string>Zoom in</string>
</property>
<property name="shortcut">
<string>+</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>
# -*- coding: utf-8 -*-
# Copyright(C) 2016 Vincent A
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
import os
import re
from PyQt5.QtWidgets import QFileDialog, QMessageBox
from PyQt5.QtGui import QPixmap, QImage, QKeySequence
from PyQt5.QtCore import Qt, pyqtSlot as Slot
from weboob.tools.application.qt5 import QtMainWindow, QtDo
from weboob.tools.application.qt5.models import ResultModel
from weboob.capabilities.base import NotLoaded
from .ui.viewer_ui import Ui_Viewer
ZOOM_FACTOR, ZOOM_FIT = range(2)
class Viewer(QtMainWindow):
def __init__(self, weboob, parent=None):
super(Viewer, self).__init__(parent)
self.ui = Ui_Viewer()
self.ui.setupUi(self)
self.ui.prevButton.clicked.connect(self.prev)
self.ui.nextButton.clicked.connect(self.next)
self.ui.firstButton.clicked.connect(self.first)
self.ui.lastButton.clicked.connect(self.last)
self.ui.actionZoomIn.triggered.connect(self.zoomIn)
self.ui.actionZoomOut.triggered.connect(self.zoomOut)
self.ui.actionFullSize.triggered.connect(self.zoomFullSize)
self.ui.actionFitWindow.triggered.connect(self.zoomFit)
self.ui.actionSaveImage.setShortcut(QKeySequence.Save)
self.ui.actionSaveImage.triggered.connect(self.saveImage)
self.ui.actionClose.setShortcut(QKeySequence.Close)
self.ui.actionClose.triggered.connect(self.close)
self.model = None
self.current = None
self.total = 0
self.zoomFactor = 1
self.zoomMode = ZOOM_FACTOR
self.weboob = weboob
def setData(self, model, qidx):
self.model = model
self.current = qidx
self.model.rowsInserted.connect(self.updatePos)
self.model.rowsRemoved.connect(self.updatePos)
self.model.rowsInserted.connect(self.updateNavButtons)
self.model.rowsRemoved.connect(self.updateNavButtons)
self.updateImage()
def updateNavButtons(self):
prev = self.current.row() > 0
self.ui.prevButton.setEnabled(prev)
self.ui.firstButton.setEnabled(prev)
next = self.current.row() < self.total - 1
self.ui.nextButton.setEnabled(next)
self.ui.lastButton.setEnabled(next)
def updatePos(self):
self.total = self.model.rowCount(self.current.parent())
self.ui.posLabel.setText('%d / %d' % (self.current.row() + 1, self.total))
def _gotData(self, obj, qidx):
if self.current == qidx:
self.pixmap = QPixmap(QImage.fromData(obj.data))
self._rebuildImage()
def updateImage(self):
self.updatePos()
self.updateNavButtons()
obj = self.current.data(ResultModel.RoleObject)
pixmap = QPixmap()
if obj.data is NotLoaded:
qidx = self.current
process = QtDo(self.weboob, lambda r: self._gotData(r, qidx))
process.do('fillobj', obj, ['data'])
elif obj.data:
pixmap = QPixmap(QImage.fromData(obj.data))
self.pixmap = pixmap
self._rebuildImage()
@Slot()
def next(self):
new = self.current.sibling(self.current.row() + 1, 0)
if not new.isValid():
return
self.current = new
self.updateImage()
@Slot()
def prev(self):
if self.current.row() == 0:
return
self.current = self.current.sibling(self.current.row() - 1, 0)
self.updateImage()
@Slot()
def first(self):
self.current = self.current.sibling(0, 0)
self.updateImage()
@Slot()
def last(self):
self.current = self.current.sibling(self.total - 1, 0)
self.updateImage()
@Slot()
def zoomIn(self):
self.zoomFactor *= 1.25
self.zoomMode = ZOOM_FACTOR
self._rebuildImage()
@Slot()
def zoomOut(self):
self.zoomFactor *= 0.75
self.zoomMode = ZOOM_FACTOR
self._rebuildImage()
@Slot()
def zoomFullSize(self):
self.zoomFactor = 1
self.zoomMode = ZOOM_FACTOR
self._rebuildImage()
@Slot()
def zoomFit(self):
self.zoomMode = ZOOM_FIT
self._rebuildImage()