def add_movie_db(self, close): if len(self.am_original_title.get_text()) or len(self.am_title.get_text()): self.db.add_movie(self) # lets move poster from tmp to posters dir tmp_dest = os.path.join(self.griffith_dir, "posters") if self.windows: temp_dir = "C:\\windows\\temp\\" else: temp_dir = "/tmp/" pic = string.replace(self.am_picture_name.get_text()+".jpg",temp_dir,"") if len(self.am_picture_name.get_text()): if os.path.isfile(os.path.join(temp_dir, pic)): shutil.move(os.path.join(temp_dir, pic), tmp_dest) if int(self.am_number.get_text()) >= 2: insert_after = self.treemodel.get_iter(int(self.am_number.get_text())-2) else: insert_after = None myiter = self.treemodel.insert_after(None, insert_after) if len(self.am_picture_name.get_text()): image_path = os.path.join(tmp_dest, pic) #lets make the thumbnail and medium image from poster for future use gutils.make_thumbnail(self, image_path) gutils.make_medium_image(self, image_path) else: image_path = os.path.join(self.locations['images'], "default.png") handler = self.Image.set_from_file(image_path) pixbuf = self.Image.get_pixbuf() self.treemodel.set_value(myiter, 1, \ '%004d' % int(self.am_number.get_text())) self.treemodel.set_value(myiter, 2, pixbuf.scale_simple(30,40,3)) self.treemodel.set_value(myiter, \ 3, str(self.am_original_title.get_text())) self.treemodel.set_value(myiter, 4, str(self.am_title.get_text())) self.treemodel.set_value(myiter, 5, str(self.am_director.get_text())) #update statusbar self.total += 1 self.total_filter = self.total self.count_statusbar() #select new entry from main treelist treeselection = self.main_treeview.get_selection() treeselection.select_iter(myiter) self.main_treeview.set_cursor(int(self.am_number.get_text())-1) self.treeview_clicked() next_number=gutils.find_next_available(self) initialize_add_dialog(self) self.am_number.set_text(str(next_number)) if close: self.hide_add_movie() else: gutils.error(self.w_results, \ _("You should fill the original title\nor the movie title."))
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 change_poster(self): """ changes movie poster image to a custom one showing a file chooser dialog to select it """ import shutil picture = self.e_picture m_id = self.get_maintree_selection() filename = gutils.file_chooser(_("Select image"), action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK), name="", folder=self.locations['desktop'], picture=True) if filename[0]: try: picture.set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(filename[0]).scale_simple(100, 140, gtk.gdk.INTERP_BILINEAR)) file_to_copy = os.path.basename(filename[0]) shutil.copyfile(filename[0],'%s/posters/%s.jpg' % (self.griffith_dir, os.path.splitext(file_to_copy)[0])) gutils.make_thumbnail(self, '%s.jpg' % os.path.splitext(file_to_copy)[0]) gutils.make_medium_image(self, '%s.jpg' % os.path.splitext(file_to_copy)[0]) update.update_image(self, os.path.splitext(file_to_copy)[0], m_id[0]) update_tree_thumbnail(self, '%s/posters/t_%s.jpg' % (self.griffith_dir, os.path.splitext(file_to_copy)[0])) except: gutils.error(self, _("Image not valid."), self.main_window)
def clone_movie(self): treeselection = self.widgets['treeview'].get_selection() (tmp_model, tmp_iter) = treeselection.get_selected() if tmp_iter is None: return False number = tmp_model.get_value(tmp_iter, 0) movie = self.db.Movie.get_by(number=number) if movie is None: return False next_number = gutils.find_next_available(self.db) if movie.image is not None: new_image = str(movie.image) + '_' + str(next_number) else: new_image = None # integer problem workaround if int(movie.seen)==1: seen = True else: seen = False new_movie = self.db.Movie() new_movie.cast = movie.cast new_movie.classification = movie.classification new_movie.vcodec_id = movie.vcodec_id new_movie.collection_id = movie.collection_id new_movie.volume_id = movie.volume_id new_movie.color = movie.color new_movie.cond = movie.cond new_movie.country = movie.country new_movie.director = movie.director new_movie.genre = movie.genre new_movie.image = new_image new_movie.site = movie.site new_movie.loaned = movie.loaned new_movie.layers = movie.layers new_movie.medium_id = movie.medium_id new_movie.number = next_number new_movie.media_num = movie.media_num new_movie.notes = movie.notes new_movie.o_title = movie.o_title new_movie.plot = movie.plot new_movie.rating = movie.rating new_movie.region = movie.region new_movie.runtime = movie.runtime new_movie.seen = seen new_movie.o_site = movie.o_site new_movie.studio = movie.studio new_movie.title = movie.title new_movie.trailer = movie.trailer new_movie.year = movie.year new_movie.tags = movie.tags new_movie.languages = movie.languages new_movie.loans = movie.loans # save new_movie.save() new_movie.flush() # WARNING: loan problems (don't copy volume/collection data until resolved) tmp_dest = self.locations['posters'] if movie.image is not None: image_path = os.path.join(tmp_dest, str(movie.image)+".jpg") clone_path = os.path.join(tmp_dest, new_image+".jpg") # clone image # catch IOError otherwise you would not see the cloned entry in # the list before the next start of griffith or another refresh # of the list try: shutil.copyfile(image_path, clone_path) image_path = clone_path gutils.make_thumbnail(self, "%s.jpg" % new_image) gutils.make_medium_image(self, "%s.jpg" % new_image) except IOError: image_path = os.path.join(self.locations['images'], "default.png") else: image_path = os.path.join(self.locations['images'], "default.png") handler = self.Image.set_from_file(image_path) # change_filter calls populate_treeview which updates the status bar quick_filter.change_filter(self)
def add_movie_db(self, close): details = get_details(self) if not details['o_title'] and not details['title']: gutils.error(self.widgets['results']['window'], _("You should fill the original title\nor the movie title."), parent=self.widgets['add']['window']) return False if details['o_title']: tmp_movie = self.db.Movie.get_by(o_title=details['o_title']) if tmp_movie is not None: response = gutils.question(self, msg=_('Movie with that title already exists, are you sure you want to add?'), cancel=0, parent=self.widgets['add']['window']) if response == gtk.RESPONSE_NO: return False if details['title']: tmp_movie = self.db.Movie.get_by(title=details['title']) if tmp_movie is not None: response = gutils.question(self, msg=_('Movie with that title already exists, are you sure you want to add?'), cancel=0, parent=self.widgets['add']['window']) if response == gtk.RESPONSE_NO: return False movie = self.db.Movie() if not movie.add_to_db(details): return False # lets move poster from tmp to posters dir tmp_dest = self.locations['posters'] image_path = '' if details['image']: tmp_image_path = os.path.join(self.locations['temp'], "poster_%s.jpg" % details['image']) if os.path.isfile(tmp_image_path): image_path = os.path.join(tmp_dest, "%s.jpg" % details['image']) shutil.move(tmp_image_path, 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']) rows = len(self.treemodel) if rows>0: insert_after = self.treemodel.get_iter(rows-1) # last else: insert_after = None myiter = self.treemodel.insert_after(None, insert_after) if not os.path.isfile(image_path): image_path = os.path.join(self.locations['images'], 'default.png') handler = self.Image.set_from_file(image_path) pixbuf = self.Image.get_pixbuf() self.treemodel.set_value(myiter, 0, '%004d' % details['number']) self.treemodel.set_value(myiter, 1, pixbuf.scale_simple(30,40,3)) self.treemodel.set_value(myiter, 2, details['o_title']) self.treemodel.set_value(myiter, 3, details['title']) self.treemodel.set_value(myiter, 4, details['director']) self.treemodel.set_value(myiter, 5, details['genre']) self.treemodel.set_value(myiter, 6, details['seen']) if details['year'] is None: self.treemodel.set_value(myiter, 7, '') else: self.treemodel.set_value(myiter, 7, details['year']) if details['runtime'] is None: self.treemodel.set_value(myiter, 8, '') else: self.treemodel.set_value(myiter, 8, '%003d' % int(details['runtime']) + _(' min')) #update statusbar self.total += 1 self.count_statusbar() #select new entry from main treelist self.widgets['treeview'].get_selection().select_iter(myiter) self.treeview_clicked() clear(self) if close: self.hide_add_window()
def set_details(self, item=None):#{{{ from loan import get_loan_info, get_loan_history if item is None: item = {} if item.has_key('movie_id') and item['movie_id']: self._movie_id = item['movie_id'] else: self._movie_id = None w = self.widgets['movie'] if item.has_key('number') and item['number']: w['number'].set_text(str(int(item['number']))) else: w['number'].set_text('') if item.has_key('title') and item['title']: w['title'].set_markup("<b><span size='large'>%s</span></b>" % gutils.html_encode(item['title'])) else: w['title'].set_text('') if item.has_key('o_title') and item['o_title']: w['o_title'].set_markup("<span size='medium'><i>%s</i></span>" % gutils.html_encode(item['o_title'])) else: w['o_title'].set_text('') if item.has_key('director') and item['director']: w['director'].set_markup("<i>%s</i>" % gutils.html_encode(item['director'])) else: w['director'].set_text('') if item.has_key('plot') and item['plot']: w['plot'].set_text(str(item['plot'])) else: w['plot'].set_text('') if item.has_key('year') and item['year']: w['year'].set_text(str(item['year'])) else: w['year'].set_text('') if item.has_key('runtime') and item['runtime']: w['runtime'].set_text(str(int(item['runtime']))) else: w['runtime'].set_text('x') if item.has_key('cast') and item['cast']: w['cast'].set_text(str(item['cast'])) else: w['cast'].set_text('') if item.has_key('country') and item['country']: w['country'].set_markup("<i>%s</i>" % gutils.html_encode(item['country'])) else: w['country'].set_text('') if item.has_key('genre') and item['genre']: w['genre'].set_markup("<i>%s</i>" % gutils.html_encode(item['genre'])) else: w['genre'].set_text('') if item.has_key('cond') and item['cond']: if str(item['cond']) in [ str(i) for i in range(len(self._conditions)) ]: w['condition'].set_markup("<i>%s</i>" % self._conditions[item['cond']]) else: w['condition'].set_text('') self.debug.show("Wrong value in 'condition' field (movie_id=%s, cond=%s)" % (item['movie_id'], item['cond'])) else: w['condition'].set_text('') if item.has_key('region') and item['region']: if str(item['region']) in [ str(i) for i in range(len(self._regions)) ]: w['region'].set_markup("<i>%s</i>" % gutils.html_encode(item['region'])) if int(item['region']) < 9: self.widgets['tooltips'].set_tip(w['region'], self._regions[int(item['region'])]) else: self.debug.show("Wrong value in 'region' field (movie_id=%s, region=%s)" % (item['movie_id'], item['region'])) w['region'].set_text('') self.widgets['tooltips'].set_tip(w['region'], self._regions[0]) # N/A else: w['region'].set_text('') self.widgets['tooltips'].set_tip(w['region'], self._regions[0]) # N/A if item.has_key('layers') and item['layers']: if str(item['layers']) in [ str(i) for i in range(len(self._layers)) ]: w['layers'].set_markup("<i>%s</i>" % self._layers[item['layers']]) else: self.debug.show("Wrong value in 'layers' field (movie_id=%s, layers=%s)" % (item['movie_id'], item['layers'])) w['layers'].set_text('') else: w['layers'].set_text('') if item.has_key('color') and item['color']: if str(item['color']) in [ str(i) for i in range(len(self._colors)) ]: w['color'].set_markup("<i>%s</i>" % self._colors[item['color']]) else: self.debug.show("Wrong value in 'color' field (movie_id=%s, color=%s)" % (item['movie_id'], item['color'])) w['color'].set_markup('') else: w['color'].set_markup('') if item.has_key('classification') and item['classification']: w['classification'].set_markup("<i>%s</i>" % gutils.html_encode(item['classification'])) else: w['classification'].set_text('') if item.has_key('studio') and item['studio']: w['studio'].set_markup("<i>%s</i>" % gutils.html_encode(item['studio'])) else: w['studio'].set_text('') if item.has_key('o_site') and item['o_site']: self._o_site_url = str(item['o_site']) w['go_o_site_button'].set_sensitive(True) else: self._o_site_url = None w['go_o_site_button'].set_sensitive(False) if item.has_key('site') and item['site']: self._site_url = str(item['site']) w['go_site_button'].set_sensitive(True) else: self._site_url = None w['go_site_button'].set_sensitive(False) if item.has_key('trailer') and item['trailer']: self._trailer_url = str(item.trailer) w['go_trailer_button'].set_sensitive(True) else: self._trailer_url = None w['go_trailer_button'].set_sensitive(False) if item.has_key('seen') and item['seen'] == True: w['seen_icon'].set_from_file(os.path.join(self.locations['images'], 'seen.png')) else: w['seen_icon'].set_from_file(os.path.join(self.locations['images'], 'unseen.png')) if item.has_key('notes') and item['notes']: w['notes'].set_text(str(item.notes)) else: w['notes'].set_text('') tmp = '' if item.has_key('media_num') and item['media_num']: tmp = str(item.media_num) else: tmp = '0' if item.has_key('medium_id') and item['medium_id']: if item.medium is not None: tmp += ' x ' + item.medium.name else: pass w['medium'].set_markup("<i>%s</i>" % gutils.html_encode(tmp)) if item.has_key('vcodec_id'): if item.vcodec is not None: w['vcodec'].set_markup("<i>%s</i>" % gutils.html_encode(item.vcodec.name)) else: w['vcodec'].set_text('') else: w['vcodec'].set_text('') # poster if item.has_key('image') and item['image']: tmp_dest = self.locations['posters'] tmp_img = os.path.join(tmp_dest, "m_%s.jpg"%item['image']) tmp_img2 = os.path.join(tmp_dest, "%s.jpg"%item['image']) if os.path.isfile(tmp_img2): image_path = tmp_img self.widgets['add']['delete_poster'].set_sensitive(True) self.widgets['menu']['delete_poster'].set_sensitive(True) w['picture_button'].set_sensitive(True) else: image_path = os.path.join(self.locations['images'], 'default.png') self.widgets['add']['delete_poster'].set_sensitive(False) self.widgets['menu']['delete_poster'].set_sensitive(False) w['picture_button'].set_sensitive(False) # lets see if we have a scaled down medium image already created if not os.path.isfile(image_path): # if not, lets make one for future use :D original_image = os.path.join(tmp_dest, "%s.jpg"%item.image) if os.path.isfile(original_image): gutils.make_medium_image(self, "%s.jpg"%item.image) else: image_path = os.path.join(self.locations['images'], 'default.png') w['picture_button'].set_sensitive(False) w['picture'].set_from_file(image_path) # ratig rimage = int(self.config.get('rating_image', 0)) if rimage: prefix = '' else: prefix = 'meter' if item.has_key('rating') and item['rating']: rating_file = "%s/%s0%d.png" % (self.locations['images'], prefix, item['rating']) else: rating_file = "%s/%s0%d.png" % (self.locations['images'], prefix, 0) handler = w['image_rating'].set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(rating_file)) gutils.garbage(handler) # check loan status and adjust buttons and history box if item.has_key('loaned') and item['loaned'] == True: self.widgets['popups']['loan'].set_sensitive(False) self.widgets['popups']['email'].set_sensitive(True) self.widgets['popups']['return'].set_sensitive(True) self.widgets['menu']['loan'].set_sensitive(False) self.widgets['menu']['email'].set_sensitive(True) self.widgets['menu']['return'].set_sensitive(True) w['loan_button'].set_sensitive(False) w['email_reminder_button'].set_sensitive(True) w['return_button'].set_sensitive(True) data_loan = get_loan_info(self.db, collection_id=item['collection_id'], volume_id=item['volume_id'], movie_id=item['movie_id']) if data_loan is None: item.loaned = False else: data_person = self.db.Person.get_by(person_id=data_loan.person.person_id) self.person_name = str(data_person.name) self.person_email = str(data_person.email) self.loan_date = str(data_loan.date) w['loan_info'].set_use_markup(False) w['loan_info'].set_label(_("This movie has been loaned to ") + self.person_name + _(" on ") + self.loan_date[:10]) if item.has_key('loaned') and item['loaned'] != True: # "loaned" status can be changed above, so don't use "else:" in this line self.widgets['popups']['loan'].set_sensitive(True) self.widgets['popups']['email'].set_sensitive(False) self.widgets['popups']['return'].set_sensitive(False) self.widgets['menu']['loan'].set_sensitive(True) self.widgets['menu']['email'].set_sensitive(False) self.widgets['menu']['return'].set_sensitive(False) w['return_button'].set_sensitive(False) w['email_reminder_button'].set_sensitive(False) w['loan_button'].set_sensitive(True) w['loan_info'].set_markup("<b>%s</b>" % _("Movie not loaned")) # loan history self.loans_treemodel.clear() if item.has_key('collection_id') or item.has_key('volume_id') or item.has_key('movie_id'): loans = get_loan_history(self.db, collection_id=item['collection_id'], volume_id=item['volume_id'], movie_id=item['movie_id']) for loan in loans: myiter = self.loans_treemodel.append(None) self.loans_treemodel.set_value(myiter, 0,'%s' % str(loan.date)[:10]) if loan.return_date and loan.return_date != '': self.loans_treemodel.set_value(myiter, 1, str(loan.return_date)[:10]) else: self.loans_treemodel.set_value(myiter, 1, "---") person = self.db.Person.get_by(person_id=loan.person.person_id) self.loans_treemodel.set_value(myiter, 2, person.name) # volumes/collections if item.has_key('volume_id') and item['volume_id']>0: if item.has_key('volume') and item['volume']: w['volume'].set_markup("<b>%s</b>" % gutils.html_encode(item['volume'].name)) w['show_volume_button'].set_sensitive(True) else: w['volume'].set_text('') w['show_volume_button'].set_sensitive(False) else: w['volume'].set_text('') w['show_volume_button'].set_sensitive(False) if item.has_key('collection_id') and item['collection_id']>0: if item.has_key('collection') and item['collection']: w['collection'].set_markup("<b>%s</b>" % gutils.html_encode(item['collection'].name)) w['show_collection_button'].set_sensitive(True) else: w['collection'].set_text('') w['show_collection_button'].set_sensitive(False) else: w['collection'].set_text('') w['show_collection_button'].set_sensitive(False) # languages for i in w['audio_vbox'].get_children(): i.destroy() for i in w['subtitle_vbox'].get_children(): i.destroy() if item.has_key('languages') and len(item['languages'])>0: for i in item['languages']: if i.type == 3: # subtitles if i.subformat: tmp = "%s - %s" % (i.language.name, i.subformat.name) else: tmp = "%s" % i.language.name w['subtitle_vbox'].pack_start(gtk.Label(tmp)) else: language = i.language.name if i.type is not None and len(self._lang_types[i.type])>0: language += " <i>%s</i>" % self._lang_types[i.type] tmp = '' if i.achannel: tmp = i.achannel.name if i.acodec: if len(tmp)>0: tmp += ", %s" % i.acodec.name else: tmp = i.acodec.name if len(tmp)>0: tmp = "%s (%s)" % (language, tmp) else: tmp = language widget = gtk.Label(tmp) widget.set_use_markup(True) w['audio_vbox'].pack_start(widget) w['audio_vbox'].show_all() w['subtitle_vbox'].show_all() #tags if item.has_key('tags'): tmp = '' for tag in item['tags']: tmp += "%s, " % tag.name tmp = tmp[:-2] # cut last comma w['tags'].set_text(tmp)
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."))
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")) 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:
def clone_movie(self): treeselection = self.widgets['treeview'].get_selection() (tmp_model, tmp_iter) = treeselection.get_selected() if tmp_iter is None: return False number = tmp_model.get_value(tmp_iter, 0) movie = self.db.Movie.get_by(number=number) if movie is None: return False next_number = gutils.find_next_available(self.db) new_image = str(movie.image) + '_' + str(next_number) # integer problem workaround if int(movie.seen)==1: seen = True else: seen = False new_movie = self.db.Movie() new_movie.cast = movie.cast new_movie.classification = movie.classification new_movie.color = movie.color new_movie.cond = movie.cond new_movie.country = movie.country new_movie.director = movie.director new_movie.genre = movie.genre new_movie.image = new_image new_movie.site = movie.site new_movie.layers = movie.layers new_movie.medium_id = movie.medium_id new_movie.number = next_number new_movie.media_num = movie.media_num new_movie.notes = movie.notes new_movie.o_title = movie.o_title new_movie.plot = movie.plot new_movie.rating = movie.rating new_movie.region = movie.region new_movie.runtime = movie.runtime new_movie.seen = seen new_movie.o_site = movie.o_site new_movie.studio = movie.studio new_movie.title = movie.title new_movie.trailer = movie.trailer new_movie.year = movie.year new_movie.tags = movie.tags new_movie.languages = movie.languages # save new_movie.save() new_movie.flush() # WARNING: loan problems (don't copy volume/collection data until resolved) tmp_dest = self.locations['posters'] if movie.image is not None: image_path = os.path.join(tmp_dest, str(movie.image)+".jpg") clone_path = os.path.join(tmp_dest, new_image+".jpg") # clone image shutil.copyfile(image_path, clone_path) image_path = clone_path gutils.make_thumbnail(self, "%s.jpg" % new_image) gutils.make_medium_image(self, "%s.jpg" % new_image) else: image_path = os.path.join(self.locations['images'], "default.png") handler = self.Image.set_from_file(image_path) #update statusbar self.total = self.total + 1 self.count_statusbar() self.populate_treeview() #self.widgets['treeview'].set_cursor(next_number-1) self.go_last() self.treeview_clicked()
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")) 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"])
def set_details(self, item=None): # {{{ from loan import get_loan_info, get_loan_history if item is None: item = {} if item.has_key("movie_id") and item["movie_id"]: self._movie_id = item["movie_id"] else: self._movie_id = None w = self.widgets["movie"] if item.has_key("number") and item["number"]: w["number"].set_text(str(int(item["number"]))) else: w["number"].set_text("") if item.has_key("title") and item["title"]: w["title"].set_markup("<b><span size='large'>%s</span></b>" % gutils.html_encode(item["title"])) else: w["title"].set_text("") if item.has_key("o_title") and item["o_title"]: w["o_title"].set_markup("<span size='medium'><i>%s</i></span>" % gutils.html_encode(item["o_title"])) else: w["o_title"].set_text("") if item.has_key("director") and item["director"]: w["director"].set_markup("<i>%s</i>" % gutils.html_encode(item["director"])) else: w["director"].set_text("") if item.has_key("plot") and item["plot"]: w["plot"].set_text(str(item["plot"])) else: w["plot"].set_text("") if item.has_key("year") and item["year"]: w["year"].set_text(str(item["year"])) else: w["year"].set_text("") if item.has_key("runtime") and item["runtime"]: w["runtime"].set_text(str(int(item["runtime"]))) else: w["runtime"].set_text("x") if item.has_key("cast") and item["cast"]: w["cast"].set_text(str(item["cast"])) else: w["cast"].set_text("") if item.has_key("country") and item["country"]: w["country"].set_markup("<i>%s</i>" % gutils.html_encode(item["country"])) else: w["country"].set_text("") if item.has_key("genre") and item["genre"]: w["genre"].set_markup("<i>%s</i>" % gutils.html_encode(item["genre"])) else: w["genre"].set_text("") if item.has_key("cond") and item["cond"]: if str(item["cond"]) in [str(i) for i in range(len(self._conditions))]: w["condition"].set_markup("<i>%s</i>" % self._conditions[item["cond"]]) else: w["condition"].set_text("") self.debug.show( "Wrong value in 'condition' field (movie_id=%s, cond=%s)" % (item["movie_id"], item["cond"]) ) else: w["condition"].set_text("") if item.has_key("region") and item["region"]: if str(item["region"]) in [str(i) for i in range(len(self._regions))]: w["region"].set_markup("<i>%s</i>" % gutils.html_encode(item["region"])) if int(item["region"]) < 9: self.widgets["tooltips"].set_tip(w["region"], self._regions[int(item["region"])]) else: self.debug.show( "Wrong value in 'region' field (movie_id=%s, region=%s)" % (item["movie_id"], item["region"]) ) w["region"].set_text("") self.widgets["tooltips"].set_tip(w["region"], self._regions[0]) # N/A else: w["region"].set_text("") self.widgets["tooltips"].set_tip(w["region"], self._regions[0]) # N/A if item.has_key("layers") and item["layers"]: if str(item["layers"]) in [str(i) for i in range(len(self._layers))]: w["layers"].set_markup("<i>%s</i>" % self._layers[item["layers"]]) else: self.debug.show( "Wrong value in 'layers' field (movie_id=%s, layers=%s)" % (item["movie_id"], item["layers"]) ) w["layers"].set_text("") else: w["layers"].set_text("") if item.has_key("color") and item["color"]: if str(item["color"]) in [str(i) for i in range(len(self._colors))]: w["color"].set_markup("<i>%s</i>" % self._colors[item["color"]]) else: self.debug.show("Wrong value in 'color' field (movie_id=%s, color=%s)" % (item["movie_id"], item["color"])) w["color"].set_markup("") else: w["color"].set_markup("") if item.has_key("classification") and item["classification"]: w["classification"].set_markup("<i>%s</i>" % gutils.html_encode(item["classification"])) else: w["classification"].set_text("") if item.has_key("studio") and item["studio"]: w["studio"].set_markup("<i>%s</i>" % gutils.html_encode(item["studio"])) else: w["studio"].set_text("") if item.has_key("o_site") and item["o_site"]: self._o_site_url = str(item["o_site"]) w["go_o_site_button"].set_sensitive(True) else: self._o_site_url = None w["go_o_site_button"].set_sensitive(False) if item.has_key("site") and item["site"]: self._site_url = str(item["site"]) w["go_site_button"].set_sensitive(True) else: self._site_url = None w["go_site_button"].set_sensitive(False) if item.has_key("trailer") and item["trailer"]: self._trailer_url = str(item.trailer) w["go_trailer_button"].set_sensitive(True) else: self._trailer_url = None w["go_trailer_button"].set_sensitive(False) if item.has_key("seen") and item["seen"] == True: w["seen_icon"].set_from_file(os.path.join(self.locations["images"], "seen.png")) else: w["seen_icon"].set_from_file(os.path.join(self.locations["images"], "unseen.png")) if item.has_key("notes") and item["notes"]: w["notes"].set_text(str(item.notes)) else: w["notes"].set_text("") tmp = "" if item.has_key("media_num") and item["media_num"]: tmp = str(item.media_num) else: tmp = "0" if item.has_key("medium_id") and item["medium_id"]: if item.medium is not None: tmp += " x " + item.medium.name else: pass w["medium"].set_markup("<i>%s</i>" % gutils.html_encode(tmp)) if item.has_key("vcodec_id"): if item.vcodec is not None: w["vcodec"].set_markup("<i>%s</i>" % gutils.html_encode(item.vcodec.name)) else: w["vcodec"].set_text("") else: w["vcodec"].set_text("") # poster if item.has_key("image") and item["image"]: tmp_dest = self.locations["posters"] tmp_img = os.path.join(tmp_dest, "m_%s.jpg" % item["image"]) tmp_img2 = os.path.join(tmp_dest, "%s.jpg" % item["image"]) if os.path.isfile(tmp_img2): image_path = tmp_img self.widgets["add"]["delete_poster"].set_sensitive(True) self.widgets["menu"]["delete_poster"].set_sensitive(True) w["picture_button"].set_sensitive(True) else: image_path = os.path.join(self.locations["images"], "default.png") self.widgets["add"]["delete_poster"].set_sensitive(False) self.widgets["menu"]["delete_poster"].set_sensitive(False) w["picture_button"].set_sensitive(False) # lets see if we have a scaled down medium image already created if not os.path.isfile(image_path): # if not, lets make one for future use :D original_image = os.path.join(tmp_dest, "%s.jpg" % item.image) if os.path.isfile(original_image): gutils.make_medium_image(self, "%s.jpg" % item.image) else: image_path = os.path.join(self.locations["images"], "default.png") w["picture_button"].set_sensitive(False) w["picture"].set_from_file(image_path) # ratig rimage = int(self.config.get("rating_image", 0)) if rimage: prefix = "" else: prefix = "meter" if item.has_key("rating") and item["rating"]: rating_file = "%s/%s0%d.png" % (self.locations["images"], prefix, item["rating"]) else: rating_file = "%s/%s0%d.png" % (self.locations["images"], prefix, 0) handler = w["image_rating"].set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(rating_file)) gutils.garbage(handler) # check loan status and adjust buttons and history box if item.has_key("loaned") and item["loaned"] == True: self.widgets["popups"]["loan"].set_sensitive(False) self.widgets["popups"]["email"].set_sensitive(True) self.widgets["popups"]["return"].set_sensitive(True) self.widgets["menu"]["loan"].set_sensitive(False) self.widgets["menu"]["email"].set_sensitive(True) self.widgets["menu"]["return"].set_sensitive(True) w["loan_button"].set_sensitive(False) w["email_reminder_button"].set_sensitive(True) w["return_button"].set_sensitive(True) data_loan = get_loan_info( self.db, collection_id=item["collection_id"], volume_id=item["volume_id"], movie_id=item["movie_id"] ) if data_loan is None: item.loaned = False else: data_person = self.db.Person.get_by(person_id=data_loan.person.person_id) self.person_name = str(data_person.name) self.person_email = str(data_person.email) self.loan_date = str(data_loan.date) w["loan_info"].set_use_markup(False) w["loan_info"].set_label( _("This movie has been loaned to ") + self.person_name + _(" on ") + self.loan_date[:10] ) if ( item.has_key("loaned") and item["loaned"] != True ): # "loaned" status can be changed above, so don't use "else:" in this line self.widgets["popups"]["loan"].set_sensitive(True) self.widgets["popups"]["email"].set_sensitive(False) self.widgets["popups"]["return"].set_sensitive(False) self.widgets["menu"]["loan"].set_sensitive(True) self.widgets["menu"]["email"].set_sensitive(False) self.widgets["menu"]["return"].set_sensitive(False) w["return_button"].set_sensitive(False) w["email_reminder_button"].set_sensitive(False) w["loan_button"].set_sensitive(True) w["loan_info"].set_markup("<b>%s</b>" % _("Movie not loaned")) # loan history self.loans_treemodel.clear() if item.has_key("collection_id") or item.has_key("volume_id") or item.has_key("movie_id"): loans = get_loan_history( self.db, collection_id=item["collection_id"], volume_id=item["volume_id"], movie_id=item["movie_id"] ) for loan in loans: myiter = self.loans_treemodel.append(None) self.loans_treemodel.set_value(myiter, 0, "%s" % str(loan.date)[:10]) if loan.return_date and loan.return_date != "": self.loans_treemodel.set_value(myiter, 1, str(loan.return_date)[:10]) else: self.loans_treemodel.set_value(myiter, 1, "---") person = self.db.Person.get_by(person_id=loan.person.person_id) self.loans_treemodel.set_value(myiter, 2, person.name) # volumes/collections if item.has_key("volume_id") and item["volume_id"] > 0: if item.has_key("volume") and item["volume"]: w["volume"].set_markup("<b>%s</b>" % gutils.html_encode(item["volume"].name)) w["show_volume_button"].set_sensitive(True) else: w["volume"].set_text("") w["show_volume_button"].set_sensitive(False) else: w["volume"].set_text("") w["show_volume_button"].set_sensitive(False) if item.has_key("collection_id") and item["collection_id"] > 0: if item.has_key("collection") and item["collection"]: w["collection"].set_markup("<b>%s</b>" % gutils.html_encode(item["collection"].name)) w["show_collection_button"].set_sensitive(True) else: w["collection"].set_text("") w["show_collection_button"].set_sensitive(False) else: w["collection"].set_text("") w["show_collection_button"].set_sensitive(False) # languages for i in w["audio_vbox"].get_children(): i.destroy() for i in w["subtitle_vbox"].get_children(): i.destroy() if item.has_key("languages") and len(item["languages"]) > 0: for i in item["languages"]: if i.type == 3: # subtitles if i.subformat: tmp = "%s - %s" % (i.language.name, i.subformat.name) else: tmp = "%s" % i.language.name w["subtitle_vbox"].pack_start(gtk.Label(tmp)) else: language = i.language.name if i.type is not None and len(self._lang_types[i.type]) > 0: language += " <i>%s</i>" % self._lang_types[i.type] tmp = "" if i.achannel: tmp = i.achannel.name if i.acodec: if len(tmp) > 0: tmp += ", %s" % i.acodec.name else: tmp = i.acodec.name if len(tmp) > 0: tmp = "%s (%s)" % (language, tmp) else: tmp = language widget = gtk.Label(tmp) widget.set_use_markup(True) w["audio_vbox"].pack_start(widget) w["audio_vbox"].show_all() w["subtitle_vbox"].show_all() # tags if item.has_key("tags"): tmp = "" for tag in item["tags"]: tmp += "%s, " % tag.name tmp = tmp[:-2] # cut last comma w["tags"].set_text(tmp)
def treeview_clicked(self): try: tmp = self.initialized # if Griffith is not initialized, return false except: return if self.total: self.clear_details() treeselection = self.main_treeview.get_selection() (tmp_model, tmp_iter) = treeselection.get_selected() id = tmp_model.get_value(tmp_iter,1) row = self.db.select_movie_by_num(id)[0] plot_buffer = self.e_plot.get_buffer() obs_buffer = self.e_obs.get_buffer() with_buffer = self.e_with.get_buffer() with_iter = with_buffer.get_start_iter() self.e_movie_id.set_text(str(row['id'])) self.e_number.set_text(str(row['number'])) self.e_original_title.set_text(str(row['original_title'])) self.e_title.set_text(str(row['title'])) self.e_director.set_text(str(row['director'])) plot_buffer.set_text(str(row['plot'])) self.e_discs.set_value(int(row['num_media'])) if str(row['year']) != "0": self.e_year.set_text(str(row['year'])) if str(row['runtime']) != "0": self.e_runtime.set_text(str(row['runtime'])) with_buffer.set_text(str(row['actors'])) self.e_country.set_text(str(row['country'])) self.e_genre.set_text(str(row['genre'])) if row['condition'] != "": self.e_condition.set_active(int(row['condition'])) if row['region'] != "": self.e_region.set_active(int(row['region'])) if row['layers'] != "": self.e_layers.set_active(int(row['layers'])) if row['color'] != "": self.e_color.set_active(int(row['color'])) self.e_classification.set_text(str(row['classification'])) self.e_studio.set_text(str(row['studio'])) self.e_site.set_text(str(row['site'])) self.e_imdb.set_text(str(row['imdb'])) if row['seen']: self.e_seen.set_active(True) else: self.e_seen.set_active(False) if row['rating']: self.image_rating.show() self.rating_slider.set_value(int(row['rating'])) else: self.image_rating.hide() self.e_trailer.set_text(str(row['trailer'])) if row['obs']<>None: obs_buffer.set_text(str(row['obs'])) self.e_media.set_active(int(row['media'])) # check loan status and adjust buttons and history box if row['loaned']: self.popup_loan.set_sensitive(False) self.popup_email.set_sensitive(True) self.popup_return.set_sensitive(True) self.loan_button.set_sensitive(False) self.b_email_reminder.set_sensitive(True) self.return_button.set_sensitive(True) else: self.popup_loan.set_sensitive(True) self.popup_email.set_sensitive(False) self.popup_return.set_sensitive(False) self.return_button.set_sensitive(False) self.b_email_reminder.set_sensitive(False) self.loan_button.set_sensitive(True) # poster tmp_dest = os.path.join(self.griffith_dir, "posters") tmp_img = os.path.join(tmp_dest, "m_%s.jpg"%row['image']) tmp_img2 = os.path.join(tmp_dest, "%s.jpg"%row['image']) if len(row['image']) and os.path.isfile(tmp_img2): image_path = tmp_img self.delete_poster.set_sensitive(True) self.zoom_poster.set_sensitive(True) else: image_path = os.path.join(self.locations['images'], "default.png") self.delete_poster.set_sensitive(False) self.zoom_poster.set_sensitive(False) # lets see if we have a scaled down medium image already created if os.path.isfile(image_path): pass else: # if not, lets make one for future use :D original_image = os.path.join(tmp_dest, "%s.jpg"%row['image']) if os.path.isfile(original_image): gutils.make_medium_image(self, "%s.jpg"%row['image']) else: self.Image.set_from_file(os.path.join(self.locations['images'], "default.png")) pixbuf = self.Image.get_pixbuf() handler = self.e_picture.set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(image_path)) if row['loaned']: if row['collection_id'] > 0 and self.db.is_collection_loaned(row['collection_id']) == 1: data_loan = self.db.get_loan_info(collection_id=row['collection_id']) elif row['volume_id'] > 0 and self.db.is_volume_loaned(row['volume_id']) == 1: data_loan = self.db.get_loan_info(volume_id=row['volume_id']) else: data_loan = self.db.get_loan_info(movie_id=row['number']) data_person = self.db.select_person_by_id(data_loan[0]['person_id']) self.person_name = data_person[0]['name'] self.person_email = data_person[0]['email'] self.loan_date = str(data_loan[0]['date']) self.loan_info.set_label(self._("This movie has been loaned to ") + self.person_name + self._(" on ") + self.loan_date[:10]) else: self.loan_info.set_label(self._("Movie not loaned")) #loan history self.loans_treemodel.clear() loans = self.db.get_loan_history(collection_id=row['collection_id'], volume_id=row['volume_id'], movie_id=row['number']) for loan_row in loans: myiter = self.loans_treemodel.append(None) self.loans_treemodel.set_value(myiter, 0,'%s' % str(loan_row['date'])[:10]) if loan_row['return_date'] != '': self.loans_treemodel.set_value(myiter, 1, str(loan_row['return_date'])[:10]) else: self.loans_treemodel.set_value(myiter, 1, "---") person = self.db.select_person_by_id(loan_row['person_id']) self.loans_treemodel.set_value(myiter, 2, person[0]['name']) #volumes/collections i = gutils.findKey(row['volume_id'], self.volume_combo_ids) self.e_volume_combo.set_active(i) i = gutils.findKey(row['collection_id'], self.collection_combo_ids) self.e_collection_combo.set_active(i) self.e_volume_id.set_text(str(row['volume_id'])) self.e_collection_id.set_text(str(row['collection_id'])) self.e_volume_id.hide() self.e_collection_id.hide() #languages languages = self.db.get_all_data("movie_lang", where="movie_id='%s'" % row['id']) self.e_languages = [] # language widgets if len(languages) > 0: from initialize import create_language_hbox for i in languages: create_language_hbox(self, widget=self.e_lang_vbox, tab=self.e_languages, default=i['lang_id'], type=i['type']) #tags for tag in self.db.get_all_data("movie_tag", where="movie_id='%s'" % row['id'], what="tag_id"): i = gutils.findKey(tag['tag_id'], self.tags_ids) self.e_tags[i].set_active(True)