예제 #1
0
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."))
예제 #2
0
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 populate(self, data):
	self.treemodel.clear()
	for row in data:
		myiter = self.treemodel.append(None)
		self.treemodel.set_value(myiter,1,'%004d' % int(row['number']))

		# check preferences to hide or show columns
		if (self.config.get('view_otitle') == 'True'):
			self.otitle_column.set_visible(True)
		else:
			self.otitle_column.set_visible(False)
		if (self.config.get('view_title') == 'True'):
			self.title_column.set_visible(True)
		else:
			self.title_column.set_visible(False)
		if (self.config.get('view_director') == 'True'):
			self.director_column.set_visible(True)
		else:
			self.director_column.set_visible(False)
		if (self.config.get('view_image') == 'True'):
			self.image_column.set_visible(True)
			tmp_dest = os.path.join(self.griffith_dir, "posters")
			tmp_img = os.path.join(tmp_dest, "t_"+row['image']+".jpg")
			if len(row['image']) and os.path.isfile(tmp_img):
				image_path = tmp_img
			else:
				image_path = self.locations['images'] + "/default_thumbnail.png"
			# lets see if we have a scaled down thumbnail already created
			if os.path.isfile(os.path.join(tmp_dest, "t_"+row['image']+".jpg")):
				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_thumbnail(self, "%s.jpg"%row['image'])
				else:
					self.Image.set_from_file("%s/default_thumbnail.png"%self.locations['images'])
					pixbuf = self.Image.get_pixbuf()
			self.Image.set_from_file(image_path)
			pixbuf = self.Image.get_pixbuf()
			self.treemodel.set_value(myiter, 2, pixbuf)

		else:
			# let's hide image column from main treeview since we don't want it to be visible
			self.image_column.set_visible(False)
		self.treemodel.set_value(myiter,3,str(row['original_title']))
		self.treemodel.set_value(myiter,4,str(row['title']))
		self.treemodel.set_value(myiter,5,str(row['director']))
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
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 populate(self, movies=None, where=None):#{{{
	if self.initialized is False:
		return False
	from sqlalchemy import Select, desc
	
	if movies is None:
		movies = Select([self.db.Movie.c.number,
			self.db.Movie.c.o_title, self.db.Movie.c.title,
			self.db.Movie.c.director, self.db.Movie.c.image,
			self.db.Movie.c.genre, self.db.Movie.c.seen,
			self.db.Movie.c.year, self.db.Movie.c.runtime,
			self.db.Movie.c.rating])

	if isinstance(movies, Select):
		if not where: # because of possible 'seen', 'loaned', 'collection_id' in where
			# seen / loaned
			loaned_only = self.widgets['menu']['loaned_movies'].get_active()
			not_seen_only = self.widgets['menu']['not_seen_movies'].get_active()
			if loaned_only:
				movies.append_whereclause(self.db.Movie.c.loaned==True)
			if not_seen_only:
				movies.append_whereclause(self.db.Movie.c.seen==False)
			# collection
			pos = self.widgets['filter']['collection'].get_active()
			if pos >= 0:
				col_id = self.collection_combo_ids[pos]
				if col_id > 0:
					movies.append_whereclause(self.db.Movie.c.collection_id==col_id)
			# volume
			pos = self.widgets['filter']['volume'].get_active()
			if pos >= 0:
				vol_id = self.volume_combo_ids[pos]
				if vol_id > 0:
					movies.append_whereclause(self.db.Movie.c.volume_id==vol_id)
			# loaned to
			pos = self.widgets['filter']['loanedto'].get_active()
			if pos >= 0:
				per_id = self.loanedto_combo_ids[pos]
				if per_id > 0:
					from sqlalchemy import join, exists, and_
					loan_exists = exists([self.db.Loan.c.movie_id], \
						and_(self.db.Movie.c.movie_id==self.db.Loan.c.movie_id, self.db.Loan.c.person_id==per_id, self.db.Loan.c.return_date==None))
					movies.append_whereclause(loan_exists)
					#loan_join = join(self.db.metadata.tables['movies'], \
					#	self.db.metadata.tables['loans'], \
					#	self.db.metadata.tables['movies'].c.movie_id==self.db.metadata.tables['loans'].c.movie_id)
					#movies = movies.select_from(loan_join)
			# tag
			pos = self.widgets['filter']['tag'].get_active()
			if pos >= 0:
				tag_id = self.bytag_combo_ids[pos]
				if tag_id > 0:
					from sqlalchemy import join, exists, and_
					tag_exists = exists([self.db.MovieTag.c.movie_id], \
						and_(self.db.Movie.c.movie_id==self.db.MovieTag.c.movie_id, self.db.MovieTag.c.tag_id==tag_id))
					movies.append_whereclause(tag_exists)
		
		# select sort column
		sort_column_name = self.config.get('sortby', 'number', section='mainlist')
		sort_reverse = self.config.get('sortby_reverse', False, section='mainlist')
		for i in sort_column_name.split(','):
			if self.db.Movie.c.has_key(i):
				if sort_reverse:
					movies.order_by_clause.append(desc(self.db.Movie.c[i]))
				else:
					movies.order_by_clause.append(self.db.Movie.c[i])
		
		# additional whereclause (volume_id, collection_id, ...)
		if where:
			for i in where:
				if self.db.Movie.c.has_key(i):
					movies.append_whereclause(self.db.Movie.c[i]==where[i])
		movies = movies.execute().fetchall()

	self.total = len(movies)
	# disable refreshing while inserting
	self.widgets['treeview'].freeze_child_notify()
	self.widgets['treeview'].set_model(None)

	# save user sort column
	sort_column_id, order = self.treemodel.get_sort_column_id()

	# new treemodel (faster and prevents some problems)
	self.treemodel = gtk.TreeStore(str, gtk.gdk.Pixbuf, str, str, str, str, bool, str, str, int)

	# check preferences to hide or show columns
	if self.config.get('number', True, 'mainlist') == True:
		self.number_column.set_visible(True)
	else:
		self.number_column.set_visible(False)
	if self.config.get('otitle', True, 'mainlist') == True:
		self.otitle_column.set_visible(True)
	else:
		self.otitle_column.set_visible(False)
	if self.config.get('title', True, 'mainlist') == True:
		self.title_column.set_visible(True)
	else:
		self.title_column.set_visible(False)
	if self.config.get('director', True, 'mainlist') == True:
		self.director_column.set_visible(True)
	else:
		self.director_column.set_visible(False)
	if self.config.get('image', True, 'mainlist') == True:
		self.image_column.set_visible(True)
	else:
		self.image_column.set_visible(False)
	if self.config.get('genre', True, 'mainlist') == True:
		self.genre_column.set_visible(True)
	else:
		self.genre_column.set_visible(False)
	if self.config.get('seen', True, 'mainlist') == True:
		self.seen_column.set_visible(True)
	else:
		self.seen_column.set_visible(False)
	if self.config.get('year', True, 'mainlist') == True:
		self.year_column.set_visible(True)
	else:
		self.year_column.set_visible(False)
	if self.config.get('runtime', True, 'mainlist') == True:
		self.runtime_column.set_visible(True)
	else:
		self.runtime_column.set_visible(False)
	if self.config.get('rating', True, 'mainlist') == True:
		self.rating_column.set_visible(True)
	else:
		self.rating_column.set_visible(False)
		
	for movie in movies:
		myiter = self.treemodel.append(None)
		
		self.treemodel.set_value(myiter,0,'%004d' % int(movie.number))

		if self.config.get('image', True, section='mainlist') == True:
			tmp_dest = self.locations['posters']
			tmp_img = os.path.join(tmp_dest, "t_%s.jpg" % str(movie.image))
			if movie.image and os.path.isfile(tmp_img):
				image_path = tmp_img
			else:
				image_path = os.path.join(self.locations['images'], 'default_thumbnail.png')
			# lets see if we have a scaled down thumbnail already created
			if os.path.isfile(os.path.join(tmp_dest, "t_%s.jpg" % str(movie.image))):
				pass
			else:
				# if not, lets make one for future use :D
				original_image = os.path.join(tmp_dest, "%s.jpg" % movie.image)
				if os.path.isfile(original_image):
					gutils.make_thumbnail(self, "%s.jpg" % movie.image)
				else:
					self.Image.set_from_file("%s/default_thumbnail.png" % self.locations['images'])
					pixbuf = self.Image.get_pixbuf()
			self.Image.set_from_file(image_path)
			pixbuf = self.Image.get_pixbuf()
			self.treemodel.set_value(myiter, 1, pixbuf)
		self.treemodel.set_value(myiter,2,movie.o_title)
		self.treemodel.set_value(myiter,3,movie.title)
		self.treemodel.set_value(myiter,4,movie.director)
		self.treemodel.set_value(myiter,5,movie.genre)
		self.treemodel.set_value(myiter,6,movie.seen)
		if movie.year is not None and isinstance(movie.year, int):
			self.treemodel.set_value(myiter,7,movie.year)
		if movie.runtime is not None and isinstance(movie.runtime, int):
			self.treemodel.set_value(myiter,8, '%003d' % movie.runtime + _(' min'))
		if movie.rating is not None and isinstance(movie.rating, int):
			self.treemodel.set_value(myiter,9,movie.rating)
		
	# restore user sort column
	if sort_column_id is not None:
		self.treemodel.set_sort_column_id(sort_column_id, gtk.SORT_ASCENDING)
	
	# add new treemodel and allow refreshs again
	self.widgets['treeview'].set_model(self.treemodel)
	self.widgets['treeview'].thaw_child_notify()
	self.widgets['treeview'].set_cursor_on_cell(0)
	self.count_statusbar()
def populate(self, movies=None, where=None):#{{{
	if self.initialized is False:
		return False
	from sqlalchemy import Select, desc
	
	if movies is None:
		movies = Select([self.db.Movie.c.number,
			self.db.Movie.c.o_title, self.db.Movie.c.title,
			self.db.Movie.c.director, self.db.Movie.c.image])

	if isinstance(movies, Select):
		if not where: # because of possible 'seen', 'loaned', 'collection_id' in where
			# seen / loaned
			loaned_only = self.widgets['menu']['loaned_movies'].get_active()
			not_seen_only = self.widgets['menu']['not_seen_movies'].get_active()
			if loaned_only:
				movies.append_whereclause(self.db.Movie.c.loaned==True)
			if not_seen_only:
				movies.append_whereclause(self.db.Movie.c.seen==False)
			# collection
			col_id = self.collection_combo_ids[self.widgets['filter']['collection'].get_active()]
			if col_id > 0:
				movies.append_whereclause(self.db.Movie.c.collection_id==col_id)
		
		# select sort column
		sort_column_name = self.config.get('sortby', 'number')
		sort_reverse = self.config.get('sortby_reverse', False)
		for i in sort_column_name.split(','):
			if self.db.Movie.c.has_key(i):
				if sort_reverse:
					movies.order_by_clause.append(desc(self.db.Movie.c[i]))
				else:
					movies.order_by_clause.append(self.db.Movie.c[i])
		
		# additional whereclause (volume_id, collection_id, ...)
		if where:
			for i in where:
				if self.db.Movie.c.has_key(i):
					movies.append_whereclause(self.db.Movie.c[i]==where[i])
		movies = movies.execute().fetchall()

	self.total = len(movies)
	# disable refreshing while inserting
	self.widgets['treeview'].freeze_child_notify()
	self.widgets['treeview'].set_model(None)

	# save user sort column
	sort_column_id, order = self.treemodel.get_sort_column_id()

	# new treemodel (faster and prevents some problems)
	self.treemodel = gtk.TreeStore(str, gtk.gdk.Pixbuf, str, str, str)

	# check preferences to hide or show columns
	if self.config.get('view_number', 'True') == 'True':
		self.number_column.set_visible(True)
	else:
		self.number_column.set_visible(False)
	if self.config.get('view_otitle', 'True') == 'True':
		self.otitle_column.set_visible(True)
	else:
		self.otitle_column.set_visible(False)
	if self.config.get('view_title', 'True') == 'True':
		self.title_column.set_visible(True)
	else:
		self.title_column.set_visible(False)
	if self.config.get('view_director', 'True') == 'True':
		self.director_column.set_visible(True)
	else:
		self.director_column.set_visible(False)
	if self.config.get('view_image', 'True') == 'True':
		self.image_column.set_visible(True)
	else:
		self.image_column.set_visible(False)
		
	for movie in movies:
		myiter = self.treemodel.append(None)
		
		self.treemodel.set_value(myiter,0,'%004d' % int(movie.number))

		if self.config.get('view_image', 'True') == 'True':
			tmp_dest = self.locations['posters']
			tmp_img = os.path.join(tmp_dest, "t_%s.jpg" % str(movie.image))
			if movie.image and os.path.isfile(tmp_img):
				image_path = tmp_img
			else:
				image_path = os.path.join(self.locations['images'], 'default_thumbnail.png')
			# lets see if we have a scaled down thumbnail already created
			if os.path.isfile(os.path.join(tmp_dest, "t_%s.jpg" % str(movie.image))):
				pass
			else:
				# if not, lets make one for future use :D
				original_image = os.path.join(tmp_dest, "%s.jpg" % movie.image)
				if os.path.isfile(original_image):
					gutils.make_thumbnail(self, "%s.jpg" % movie.image)
				else:
					self.Image.set_from_file("%s/default_thumbnail.png" % self.locations['images'])
					pixbuf = self.Image.get_pixbuf()
			self.Image.set_from_file(image_path)
			pixbuf = self.Image.get_pixbuf()
			self.treemodel.set_value(myiter, 1, pixbuf)
		self.treemodel.set_value(myiter,2,movie.o_title)
		self.treemodel.set_value(myiter,3,movie.title)
		self.treemodel.set_value(myiter,4,movie.director)
		
	# restore user sort column
	if sort_column_id is not None:
		self.treemodel.set_sort_column_id(sort_column_id, gtk.SORT_ASCENDING)
	
	# add new treemodel and allow refreshs again
	self.widgets['treeview'].set_model(self.treemodel)
	self.widgets['treeview'].thaw_child_notify()
	self.widgets['treeview'].set_cursor_on_cell(0)
예제 #9
0
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."))
예제 #10
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"))

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'])
예제 #11
0
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()
예제 #12
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"))


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
예제 #13
0
def populate(self, movies=None, where=None):#{{{
	from sqlalchemy import Select, desc
	
	if movies is None:
		movies = Select([self.db.Movie.c.number,
			self.db.Movie.c.o_title, self.db.Movie.c.title,
			self.db.Movie.c.director, self.db.Movie.c.image])

	if isinstance(movies, Select):
		if not where: # because of possible 'seen', 'loaned', 'collection_id' in where
			# seen / loaned
			loaned_only = self.widgets['menu']['loaned_movies'].get_active()
			not_seen_only = self.widgets['menu']['not_seen_movies'].get_active()
			if loaned_only:
				movies.append_whereclause(self.db.Movie.c.loaned==True)
			if not_seen_only:
				movies.append_whereclause(self.db.Movie.c.seen==False)
			# collection
			col_id = self.collection_combo_ids[self.widgets['filter']['collection'].get_active()]
			if col_id > 0:
				movies.append_whereclause(self.db.Movie.c.collection_id==col_id)
		
		# select sort column
		sort_column_name = self.config.get('sortby', 'number')
		sort_reverse = self.config.get('sortby_reverse', False)
		for i in sort_column_name.split(','):
			if self.db.Movie.c.has_key(i):
				if sort_reverse:
					movies.order_by_clause.append(desc(self.db.Movie.c[i]))
				else:
					movies.order_by_clause.append(self.db.Movie.c[i])
		
		# additional whereclause (volume_id, collection_id, ...)
		if where:
			for i in where:
				if self.db.Movie.c.has_key(i):
					movies.append_whereclause(self.db.Movie.c[i]==where[i])
		movies = movies.execute().fetchall()

	self.total = len(movies)
	self.treemodel.clear()
	for movie in movies:
		myiter = self.treemodel.append(None)
		self.treemodel.set_value(myiter,0,'%004d' % int(movie.number))

		# check preferences to hide or show columns
		if self.config.get('view_otitle') == 'True':
			self.otitle_column.set_visible(True)
		else:
			self.otitle_column.set_visible(False)
		if self.config.get('view_title') == 'True':
			self.title_column.set_visible(True)
		else:
			self.title_column.set_visible(False)
		if self.config.get('view_director') == 'True':
			self.director_column.set_visible(True)
		else:
			self.director_column.set_visible(False)
		if self.config['view_image'] == 'True':
			self.image_column.set_visible(True)
			tmp_dest = self.locations['posters']
			tmp_img = os.path.join(tmp_dest, "t_%s.jpg" % str(movie.image))
			if movie.image and os.path.isfile(tmp_img):
				image_path = tmp_img
			else:
				image_path = os.path.join(self.locations['images'], 'default_thumbnail.png')
			# lets see if we have a scaled down thumbnail already created
			if os.path.isfile(os.path.join(tmp_dest, "t_%s.jpg" % str(movie.image))):
				pass
			else:
				# if not, lets make one for future use :D
				original_image = os.path.join(tmp_dest, "%s.jpg" % movie.image)
				if os.path.isfile(original_image):
					gutils.make_thumbnail(self, "%s.jpg" % movie.image)
				else:
					self.Image.set_from_file("%s/default_thumbnail.png" % self.locations['images'])
					pixbuf = self.Image.get_pixbuf()
			self.Image.set_from_file(image_path)
			pixbuf = self.Image.get_pixbuf()
			self.treemodel.set_value(myiter, 1, pixbuf)

		else:
			# let's hide image column from main treeview since we don't want it to be visible
			self.image_column.set_visible(False)
		self.treemodel.set_value(myiter,2,movie.o_title)
		self.treemodel.set_value(myiter,3,movie.title)
		self.treemodel.set_value(myiter,4,movie.director)