Commit 302ee77f authored by hydrargyrum's avatar hydrargyrum Committed by Romain Bignon
Browse files

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)
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>QGalleroob</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>464</width>
<height>472</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QListView" name="galleryList">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="flow">
<enum>QListView::LeftToRight</enum>
</property>
<property name="isWrapping" stdset="0">
<bool>true</bool>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="gridSize">
<size>
<width>256</width>
<height>256</height>
</size>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QListView" name="imageList">
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="flow">
<enum>QListView::LeftToRight</enum>
</property>
<property name="isWrapping" stdset="0">
<bool>true</bool>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="gridSize">
<size>
<width>256</width>
<height>256</height>
</size>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</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>
<widget class="QToolBar" name="ToolBar">
<property name="windowTitle">
<string>ToolBar</string>
</property>
<property name="movable">
<bool>false</bool>
</property>
<property name="floatable">
<bool>false</bool>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionBackends"/>
</widget>
<widget class="QDockWidget" name="dockWidget_2">
<property name="features">
<set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable</set>
</property>
<property name="windowTitle">
<string>Info</string>
</property>
<attribute name="dockWidgetArea">
<number>2</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents_2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Title</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Description</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Author</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="labelAuthor">
<property name="text">
<string>-</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="labelDescription">
<property name="text">
<string>-</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="labelSize">
<property name="text">
<string>-</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QLabel" name="labelLink">
<property name="text">
<string>-</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_7">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Date</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="labelDate">
<property name="text">
<string>-</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<weight>75</weight>