def delete_poster(self): session = self.db.Session() movie = session.query(db.Movie).filter_by(movie_id=self._movie_id).first() if not movie: log.error("Cannot delete unknown movie's poster!") return False if gutils.question(_("Are you sure you want to delete this poster?"), self.widgets['window']): image_path = gutils.get_defaultimage_fname(self) handler = self.widgets['movie']['picture'].set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(image_path)) gutils.garbage(handler) update_tree_thumbnail(self, gutils.get_defaultthumbnail_fname(self)) # update in database delete.delete_poster(self, movie.poster_md5) movie.poster_md5 = None session.add(movie) try: session.commit() except Exception, e: session.rollback() log.error("cannot delete poster: %s" % e) return False self.update_statusbar(_("Image has been updated")) self.widgets['add']['delete_poster'].set_sensitive(False) self.widgets['movie']['picture_button'].set_sensitive(False)
def delete_poster(self, movie_id=None): if movie_id is None: movie_id = self._movie_id session = self.db.Session() movie = session.query(db.Movie).filter_by(movie_id=movie_id).first() if not movie: log.error("Cannot delete unknown movie's poster!") return False if gutils.question(_("Are you sure you want to delete this poster?"), self.widgets["window"]): # update in database delete.delete_poster(self, movie.poster_md5) movie.poster_md5 = None session.add(movie) try: session.commit() except Exception, e: session.rollback() log.error("cannot delete poster: %s" % e) return False if self._movie_id == movie_id: # only if the current selected movie is the same like that one for removing poster image_path = gutils.get_defaultimage_fname(self) handler = self.widgets["movie"]["picture"].set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(image_path)) gutils.garbage(handler) self.widgets["add"]["delete_poster"].set_sensitive(False) self.widgets["movie"]["picture_button"].set_sensitive(False) # always refresh the treeview entry update_tree_thumbnail(self, gutils.get_defaultthumbnail_fname(self)) self.update_statusbar(_("Image has been updated")) return True
def delete_poster(self): movie = self.db.Movie.get_by(movie_id=self._movie_id) if not movie: self.debug.show("Can't delete unknown movie's poster!") return False response = gutils.question(self, _("Are you sure you want to delete this poster?"), 1, self.widgets['window']) if response==-8: image_path = os.path.join(self.locations['images'], 'default.png') handler = self.widgets['movie']['picture'].set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(image_path)) gutils.garbage(handler) update_tree_thumbnail(self, os.path.join(self.locations['images'], 'default_thumbnail.png')) # update in database old_image = movie.image movie.image = None movie.update() movie.flush() self.update_statusbar(_("Image has been updated")) self.widgets['add']['delete_poster'].set_sensitive(False) self.widgets['menu']['delete_poster'].set_sensitive(False) self.widgets['movie']['picture_button'].set_sensitive(False) if old_image: delete.delete_poster(self, old_image) else: pass
def delete_poster(self, movie_id=None): if movie_id is None: movie_id = self._movie_id session = self.db.Session() movie = session.query(db.Movie).filter_by(movie_id=movie_id).first() if not movie: log.error("Cannot delete unknown movie's poster!") return False if gutils.question(_("Are you sure you want to delete this poster?"), self.widgets['window']): # update in database delete.delete_poster(self, movie.poster_md5) movie.poster_md5 = None session.add(movie) try: session.commit() except Exception, e: session.rollback() log.error("cannot delete poster: %s" % e) return False if self._movie_id == movie_id: # only if the current selected movie is the same like that one for removing poster image_path = gutils.get_defaultimage_fname(self) handler = self.widgets['movie']['picture'].set_from_pixbuf( gtk.gdk.pixbuf_new_from_file(image_path)) gutils.garbage(handler) self.widgets['add']['delete_poster'].set_sensitive(False) self.widgets['movie']['picture_button'].set_sensitive(False) # always refresh the treeview entry update_tree_thumbnail(self, gutils.get_defaultthumbnail_fname(self)) self.update_statusbar(_("Image has been updated")) return True
def delete_poster(self): session = self.db.Session() movie = session.query(db.Movie).filter_by(movie_id=self._movie_id).first() if not movie: log.error("Cannot delete unknown movie's poster!") return False response = gutils.question(_("Are you sure you want to delete this poster?"), True, self.widgets["window"]) if response == -8: image_path = os.path.join(self.locations["images"], "default.png") handler = self.widgets["movie"]["picture"].set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(image_path)) gutils.garbage(handler) update_tree_thumbnail(self, os.path.join(self.locations["images"], "default_thumbnail.png")) # update in database delete.delete_poster(self, movie.poster_md5) movie.poster_md5 = None session.add(movie) try: session.commit() except Exception, e: session.rollback() log.error("cannot delete poster: %s" % e) return False self.update_statusbar(_("Image has been updated")) self.widgets["add"]["delete_poster"].set_sensitive(False) self.widgets["menu"]["delete_poster"].set_sensitive(False) self.widgets["movie"]["picture_button"].set_sensitive(False)
def update_movie(self): if self._am_movie_id is not None: movie = self.db.Movie.get_by(movie_id=self._am_movie_id) else: movie = self.db.Movie.get_by(movie_id=self._movie_id) if movie is None: # movie was deleted in the meantime return add_movie_db(self, True) old_image = movie.image details = get_details(self) if movie.update_in_db(details): treeselection = self.widgets['treeview'].get_selection() (tmp_model, tmp_iter) = treeselection.get_selected() if details['image'] and details['image'] != old_image: # TODO: fetch poster from amazon / load from disk image_path = os.path.join(self.locations['temp'], "poster_%s.jpg" % details['image']) if os.path.isfile(image_path): # delete old image import delete delete.delete_poster(self, old_image) new_image_path = os.path.join(self.locations['posters'], "%s.jpg" % details['image']) shutil.move(image_path, new_image_path) #lets make the thumbnail and medium image from poster for future use gutils.make_thumbnail(self, "%s.jpg"%details['image']) gutils.make_medium_image(self, "%s.jpg"%details['image']) # update thumbnail in main list handler = self.Image.set_from_file(new_image_path) pixbuf = self.Image.get_pixbuf() tmp_model.set_value(tmp_iter,1, pixbuf.scale_simple(30,40,3)) # update main treelist tmp_model.set_value(tmp_iter,0,'%004d' % int(movie.number)) tmp_model.set_value(tmp_iter,2, movie.o_title) tmp_model.set_value(tmp_iter,3, movie.title) tmp_model.set_value(tmp_iter,4, movie.director) tmp_model.set_value(tmp_iter,5, movie.genre) tmp_model.set_value(tmp_iter,6, movie.seen) if movie.year is None: tmp_model.set_value(tmp_iter,7, '') else: tmp_model.set_value(tmp_iter,7, movie.year) if movie.runtime is None: tmp_model.set_value(tmp_iter,8, '') else: tmp_model.set_value(tmp_iter,8, '%003d' % int(movie.runtime) + _(' min')) if movie.rating is None: tmp_model.set_value(tmp_iter,9, '') else: tmp_model.set_value(tmp_iter,9, movie.rating) # close add window self.widgets['add']['window'].hide() # refresh self.treeview_clicked() self.update_statusbar(_('Movie information has been updated'))
def delete_poster(self): m_id, m_iter = self.get_maintree_selection() poster = self.db.select_movie_by_num(m_id)[0]['image'] response = gutils.question(self, _("Are you sure you want to delete this poster?"), 1, self.main_window) if response==-8: image_path = self.locations['images'] + "/default.png" handler = self.e_picture.set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(image_path)) gutils.garbage(handler) update_tree_thumbnail(self, self.locations['images'] + "/default_thumbnail.png") m_id = self.get_maintree_selection() update.clear_image(self, m_id[0]) self.delete_poster.set_sensitive(False) self.zoom_poster.set_sensitive(False) delete.delete_poster(self, poster) else: pass
poster = db.Poster(md5sum=poster_md5, data=data) session.add(poster) # update the md5 *after* all other queries (so that UPDATE will not be invoked) movie.poster_md5 = poster_md5 session.add(movie) try: session.commit() except Exception, e: session.rollback() log.error("cannot add poster to database: %s" % e) return False if old_poster_md5: delete.delete_poster(self, old_poster_md5) filename = gutils.get_image_fname(poster_md5, self.db, "s") if filename: update_tree_thumbnail(self, filename) self.widgets["movie"]["picture_button"].set_sensitive(True) self.widgets["add"]["delete_poster"].set_sensitive(True) self.update_statusbar(_("Image has been updated")) return True def delete_poster(self, movie_id=None): if movie_id is None: movie_id = self._movie_id
def get_poster(self, f, result, current_poster): if f == None: treeselection = self.results_treeview.get_selection() (tmp_model, tmp_iter) = treeselection.get_selected() f = int(tmp_model.get_value(tmp_iter, 0)) self.w_results.hide() file_to_copy = tempfile.mktemp(suffix=self.e_number.get_text(), prefix='poster_', \ dir=os.path.join(self.griffith_dir, "posters")) file_to_copy += ".jpg" try: progress = movie.Progress(self.main_window,_("Fetching poster"),_("Wait a moment")) retriever = movie.Retriever(result[f].ImageUrlLarge, self.main_window, progress, file_to_copy) retriever.start() while retriever.isAlive(): progress.pulse() if progress.status: retriever.suspend() while gtk.events_pending(): gtk.main_iteration() progress.close() urlcleanup() except: gutils.warning(self, _("Sorry. A connection error was occurred.")) self.debug.show(file_to_copy) if os.path.isfile(file_to_copy): handler = self.big_poster.set_from_file(file_to_copy) gutils.garbage(handler) try: im = Image.open(file_to_copy) except IOError: self.debug.show("failed to identify %s"%file_to_copy) else: if im.format == "GIF": gutils.warning(self, _("Sorry. This poster image format is not supported.")) os.remove(file_to_copy) return self.poster_window.show() self.poster_window.move(0,0) response = \ gutils.question(self, \ _("Do you want to use this poster instead?"), \ 1, self.main_window) if response == -8: self.debug.show("Using new fetched poster, updating and removing old one from disk.") update.update_image(self, os.path.basename(file_to_copy), self.e_number.get_text()) gutils.make_thumbnail(self, '%s' % os.path.basename(file_to_copy)) gutils.make_medium_image(self, '%s' % os.path.basename(file_to_copy)) update_tree_thumbnail(self, '%s/posters/t_%s' % (self.griffith_dir, \ os.path.basename(file_to_copy))) self.e_picture.set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(os.path.join(self.griffith_dir, "posters/m_%s"%os.path.basename(file_to_copy)))) delete.delete_poster(self, current_poster) else: self.debug.show("Reverting to previous poster and deleting new one from disk.") try: os.remove(file_to_copy) except: self.debug.show("no permission for %s"%file_to_copy) self.poster_window.hide() else: gutils.warning(self, _("Sorry. This movie is listed but have no poster available at Amazon.com."))
gutils.error(self, _("Image not valid."), self.widgets['window']) return False filename = os.path.basename(file_path) new_image = os.path.splitext(filename)[0] if self.db.Movie.get_by(image=new_image) is not None: i = 0 while True: i += 1 if self.db.Movie.get_by(image="%s_%s" % (new_image, i)) is None: new_image = "%s_%s" % (new_image, i) break movie = self.db.Movie.get_by(number=number) old_image = os.path.join(self.locations['posters'], "%s.jpg" % movie.image) delete.delete_poster(self, old_image) movie.image = new_image movie.update() movie.flush() shutil.copyfile(file_path, os.path.join(self.locations['posters'], "%s.jpg" % new_image)) gutils.make_thumbnail(self, '%s.jpg' % new_image) gutils.make_medium_image(self, '%s.jpg' % new_image) update_tree_thumbnail(self, os.path.join(self.locations['posters'], 't_%s.jpg' % new_image)) self.widgets['movie']['picture_button'].set_sensitive(True) self.widgets['add']['delete_poster'].set_sensitive(True) self.widgets['menu']['delete_poster'].set_sensitive(True) self.update_statusbar(_("Image has been updated"))
poster = db.Poster(md5sum=poster_md5, data=data) session.add(poster) # update the md5 *after* all other queries (so that UPDATE will not be invoked) movie.poster_md5 = poster_md5 session.add(movie) try: session.commit() except Exception, e: session.rollback() log.error("cannot add poster to database: %s" % e) return False if old_poster_md5: delete.delete_poster(self, old_poster_md5) filename = gutils.get_image_fname(poster_md5, self.db, 's') if filename: update_tree_thumbnail(self, filename) self.widgets['movie']['picture_button'].set_sensitive(True) self.widgets['add']['delete_poster'].set_sensitive(True) self.update_statusbar(_("Image has been updated")) return True def delete_poster(self, movie_id=None): if movie_id is None: movie_id = self._movie_id