[qcookboob] integration of 'kreml export' functionality

This commit is contained in:
Julien Veyssier 2013-03-24 18:42:39 +01:00 committed by Florent
commit 7a63b28181
2 changed files with 35 additions and 3 deletions

View file

@ -17,10 +17,10 @@
# 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 urllib
import urllib, sys, codecs
from PyQt4.QtCore import Qt
from PyQt4.QtGui import QFrame, QImage, QPixmap
from PyQt4.QtCore import Qt, SIGNAL
from PyQt4.QtGui import QFrame, QImage, QPixmap, QFileDialog
from weboob.applications.qcookboob.ui.recipe_ui import Ui_Recipe
from weboob.capabilities.base import empty
@ -33,6 +33,8 @@ class Recipe(QFrame):
self.ui = Ui_Recipe()
self.ui.setupUi(self)
self.connect(self.ui.exportButton, SIGNAL("clicked()"), self.export)
self.recipe = recipe
self.backend = backend
self.gotThumbnail()
@ -79,3 +81,26 @@ class Recipe(QFrame):
data = urllib.urlopen(self.recipe.picture_url).read()
img = QImage.fromData(data)
self.ui.imageLabel.setPixmap(QPixmap.fromImage(img).scaledToWidth(250,Qt.SmoothTransformation))
def export(self):
fileDial = QFileDialog(self, 'Export "%s" recipe' %
self.recipe.title, '%s.kreml' % self.recipe.title.replace('/',','), 'Krecipe file (*.kreml);;all files (*)')
fileDial.setAcceptMode(QFileDialog.AcceptSave)
fileDial.setLabelText(QFileDialog.Accept, 'Export recipe')
fileDial.setLabelText(QFileDialog.FileName, 'Recipe file name')
ok = (fileDial.exec_() == 1)
if not ok:
return
result = fileDial.selectedFiles()
if len(result) > 0:
dest = unicode(result[0])
if not dest.endswith('.kreml'):
dest += '.kreml'
data = self.recipe.toKrecipesXml(author=self.backend.name)
try:
with codecs.open(dest, 'w', 'utf-8') as f:
f.write(data)
except IOError, e:
print >>sys.stderr, 'Unable to write Krecipe file in "%s": %s' % (dest, e)
return 1
return

View file

@ -72,6 +72,13 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="exportButton">
<property name="text">
<string>Export to KRecipesML file</string>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="idFrame">
<property name="maximumSize">