Commit f31dee90 authored by Julien Veyssier's avatar Julien Veyssier

new application qcineoob

parent 320a477b
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
# Copyright(C) 2010-2011 Romain Bignon
#
# 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.applications.qcineoob import QCineoob
if __name__ == '__main__':
QCineoob.run()
from .qcineoob import QCineoob
__all__ = ['QCineoob']
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Romain Bignon
#
# 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 PyQt4.QtCore import SIGNAL
from weboob.capabilities.cinema import ICapCinema
from weboob.tools.application.qt import QtMainWindow, QtDo
from weboob.tools.application.qt.backendcfg import BackendCfg
from weboob.applications.qcineoob.ui.main_window_ui import Ui_MainWindow
from .minimovie import MiniMovie
from .miniperson import MiniPerson
from .movie import Movie
from .person import Person
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.minimovies = []
self.minipersons = []
self.current_movie_widget = None
self.current_person_widget = None
self.history = {'last_action':None,'action_list':[]}
self.connect(self.ui.backButton, SIGNAL("clicked()"), self.doBack)
self.ui.backButton.setDisabled(True)
self.connect(self.ui.searchEdit, SIGNAL("returnPressed()"), self.search)
self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig)
self.loadBackendsList()
if self.ui.backendEdit.count() == 0:
self.backendsConfig()
def backendsConfig(self):
bckndcfg = BackendCfg(self.weboob, (ICapCinema,), self)
if bckndcfg.run():
self.loadBackendsList()
def loadBackendsList(self):
self.ui.backendEdit.clear()
for i, backend in enumerate(self.weboob.iter_backends()):
if i == 0:
self.ui.backendEdit.addItem('All backends', '')
self.ui.backendEdit.addItem(backend.name, backend.name)
if backend.name == self.config.get('settings', 'backend'):
self.ui.backendEdit.setCurrentIndex(i+1)
if self.ui.backendEdit.count() == 0:
self.ui.searchEdit.setEnabled(False)
else:
self.ui.searchEdit.setEnabled(True)
def doAction(self, fun, args):
if self.history['last_action'] != None:
self.history['action_list'].append(self.history['last_action'])
self.ui.backButton.setDisabled(False)
self.history['last_action'] = {'function':fun,'args':args}
return fun(*args)
def doBack(self):
if len(self.history['action_list']) > 0:
todo = self.history['action_list'].pop()
self.history['last_action'] = todo
if len(self.history['action_list']) == 0:
self.ui.backButton.setDisabled(True)
return todo['function'](*todo['args'])
def search(self):
tosearch = self.ui.typeCombo.currentText()
if tosearch == 'person':
self.searchPerson()
elif tosearch == 'movie':
self.searchMovie()
def searchMovie(self):
pattern = unicode(self.ui.searchEdit.text())
if not pattern:
return
self.doAction(self.searchMovieAction,[pattern])
def searchMovieAction(self,pattern):
self.ui.stackedWidget.setCurrentWidget(self.ui.movie_list_page)
for minimovie in self.minimovies:
self.ui.movie_list_page.layout().removeWidget(minimovie)
minimovie.hide()
minimovie.deleteLater()
self.minimovies = []
self.ui.searchEdit.setEnabled(False)
backend_name = str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString())
self.process = QtDo(self.weboob, self.addMovie)
self.process.do('iter_movies', pattern, backends=backend_name)
def addMovie(self, backend, movie):
if not backend:
self.ui.searchEdit.setEnabled(True)
self.process = None
return
minimovie = MiniMovie(self.weboob, backend, movie, self)
self.ui.scrollAreaContent.layout().addWidget(minimovie)
self.minimovies.append(minimovie)
def displayMovie(self, movie):
self.ui.stackedWidget.setCurrentWidget(self.ui.movie_info_page)
if self.current_movie_widget != None:
self.ui.movie_info_page.layout().removeWidget(self.current_movie_widget)
self.current_movie_widget.hide()
self.current_movie_widget.deleteLater()
wmovie = Movie(movie,self)
self.ui.movie_info_page.layout().addWidget(wmovie)
self.current_movie_widget = wmovie
def searchPerson(self):
pattern = unicode(self.ui.searchEdit.text())
if not pattern:
return
self.doAction(self.searchPersonAction,[pattern])
def searchPersonAction(self,pattern):
self.ui.stackedWidget.setCurrentWidget(self.ui.person_list_page)
for miniperson in self.minipersons:
self.ui.person_list_page.layout().removeWidget(miniperson)
miniperson.hide()
miniperson.deleteLater()
self.minipersons = []
self.ui.searchEdit.setEnabled(False)
backend_name = str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString())
self.process = QtDo(self.weboob, self.addPerson)
self.process.do('iter_persons', pattern, backends=backend_name)
def addPerson(self, backend, person):
if not backend:
self.ui.searchEdit.setEnabled(True)
self.process = None
return
miniperson = MiniPerson(self.weboob, backend, person, self)
self.ui.scrollAreaContent_2.layout().addWidget(miniperson)
self.minipersons.append(miniperson)
def displayPerson(self, person):
self.ui.stackedWidget.setCurrentWidget(self.ui.person_info_page)
if self.current_person_widget != None:
self.ui.person_info_page.layout().removeWidget(self.current_person_widget)
self.current_person_widget.hide()
self.current_person_widget.deleteLater()
wperson = Person(person,self)
self.ui.person_info_page.layout().addWidget(wperson)
self.current_person_widget = wperson
def closeEvent(self, ev):
self.config.set('settings', 'backend', str(self.ui.backendEdit.itemData(self.ui.backendEdit.currentIndex()).toString()))
self.config.save()
ev.accept()
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Romain Bignon
#
# 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 PyQt4.QtGui import QFrame, QImage, QPixmap
from weboob.tools.application.qt import QtDo
from weboob.applications.qcineoob.ui.minimovie_ui import Ui_MiniMovie
class MiniMovie(QFrame):
def __init__(self, weboob, backend, movie, parent=None):
QFrame.__init__(self, parent)
self.parent = parent
self.ui = Ui_MiniMovie()
self.ui.setupUi(self)
self.weboob = weboob
self.backend = backend
self.movie = movie
self.ui.titleLabel.setText(movie.original_title)
self.ui.backendLabel.setText(backend.name)
#self.process_thumbnail = QtDo(self.weboob, self.gotThumbnail)
#self.process_thumbnail.do('fillobj', self.movie, ['thumbnail_url'], backends=backend)
def gotThumbnail(self, backend, movie):
if not backend:
return
if movie.thumbnail_url:
img = QImage.fromData(movie.thumbnail.data)
self.ui.imageLabel.setPixmap(QPixmap.fromImage(img))
def enterEvent(self, event):
self.setFrameShadow(self.Sunken)
QFrame.enterEvent(self, event)
def leaveEvent(self, event):
self.setFrameShadow(self.Raised)
QFrame.leaveEvent(self, event)
def mousePressEvent(self, event):
QFrame.mousePressEvent(self, event)
movie = self.backend.get_movie(self.movie.id)
if movie:
self.parent.doAction(self.parent.displayMovie,[movie])
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Romain Bignon
#
# 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 PyQt4.QtGui import QFrame, QImage, QPixmap
from weboob.tools.application.qt import QtDo
from weboob.applications.qcineoob.ui.miniperson_ui import Ui_MiniPerson
class MiniPerson(QFrame):
def __init__(self, weboob, backend, person, parent=None):
QFrame.__init__(self, parent)
self.parent = parent
self.ui = Ui_MiniPerson()
self.ui.setupUi(self)
self.weboob = weboob
self.backend = backend
self.person = person
self.ui.nameLabel.setText(person.name)
#self.ui.birthdateLabel.setText(person.birth_date)
self.ui.backendLabel.setText(backend.name)
#self.process_thumbnail = QtDo(self.weboob, self.gotThumbnail)
#self.process_thumbnail.do('fillobj', self.person, ['thumbnail_url'], backends=backend)
def gotThumbnail(self, backend, person):
if not backend:
return
if person.thumbnail_url:
img = QImage.fromData(person.thumbnail.data)
self.ui.imageLabel.setPixmap(QPixmap.fromImage(img))
def enterEvent(self, event):
self.setFrameShadow(self.Sunken)
QFrame.enterEvent(self, event)
def leaveEvent(self, event):
self.setFrameShadow(self.Raised)
QFrame.leaveEvent(self, event)
def mousePressEvent(self, event):
QFrame.mousePressEvent(self, event)
person = self.backend.get_person(self.person.id)
if person:
self.parent.doAction(self.parent.displayPerson,[person])
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Romain Bignon
#
# 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 PyQt4.QtCore import QUrl
from PyQt4.QtGui import QFrame
from PyQt4.phonon import Phonon
from weboob.applications.qcineoob.ui.movie_ui import Ui_Movie
class Movie(QFrame):
def __init__(self, movie, parent=None):
QFrame.__init__(self, parent)
self.parent = parent
self.ui = Ui_Movie()
self.ui.setupUi(self)
self.movie = movie
self.ui.titleLabel.setText(movie.original_title)
self.ui.durationLabel.setText(unicode(movie.duration))
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Romain Bignon
#
# 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 PyQt4.QtCore import QUrl
from PyQt4.QtGui import QFrame
from PyQt4.phonon import Phonon
from weboob.applications.qcineoob.ui.person_ui import Ui_Person
class Person(QFrame):
def __init__(self, person, parent=None):
QFrame.__init__(self, parent)
self.parent = parent
self.ui = Ui_Person()
self.ui.setupUi(self)
self.person = person
self.ui.nameLabel.setText(person.name)
self.ui.birthdateLabel.setText(person.birth_date.isoformat())
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Romain Bignon
#
# 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.cinema import ICapCinema
from weboob.tools.application.qt import QtApplication
from .main_window import MainWindow
class QCineoob(QtApplication):
APPNAME = 'qcineoob'
VERSION = '0.f'
COPYRIGHT = 'Copyright(C) 2010-2011 Romain Bignon'
DESCRIPTION = "Qt application allowing to search movies etc..."
SHORT_DESCRIPTION = "search movies"
CAPS = ICapCinema
CONFIG = {'settings': {'nsfw': 1,
'sfw': 1,
'sortby': 0,
'backend': ''
}
}
def main(self, argv):
self.load_backends(ICapCinema)
self.load_config()
self.main_window = MainWindow(self.config, self.weboob)
self.main_window.show()
return self.weboob.loop()
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)
<?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>582</width>
<height>463</height>
</rect>
</property>
<property name="windowTitle">
<string>QCineoob</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Search: </string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="searchEdit"/>
</item>
<item>
<widget class="QComboBox" name="typeCombo">
<item>
<property name="text">
<string>movie</string>
</property>
</item>
<item>
<property name="text">
<string>person</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QComboBox" name="backendEdit"/>
</item>
<item>
<widget class="QPushButton" name="backButton">
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>back</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<widget class="QWidget" name="movie_list_page">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaContent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>542</width>
<height>313</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="movie_info_page">
<layout class="QVBoxLayout" name="movieInfoLayout"/>
</widget>
<widget class="QWidget" name="person_list_page">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QScrollArea" name="scrollArea_2">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaContent_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>78</width>
<height>16</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="person_info_page">
<layout class="QVBoxLayout" name="verticalLayout_7"/>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>582</width>
<height>23</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<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="actionBackends"/>
</widget>
<action name="actionBackends">
<property name="text">
<string>Backends</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MiniMovie</class>
<widget class="QFrame" name="MiniMovie">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>464</width>
<height>132</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="imageLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">