<commit_before>
# --------------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <<EMAIL>> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return -<NAME>
# --------------------------------------------------------------------------------


import gtk
import poppler
import os.path

ORIGINAL_HEIGHT = 841.89 
ORIGINAL_WIDTH  = 595.276 


class PdfPane:

	def __init__(self, drawarea):
		self.drawarea = drawarea
		self.scale = 1
		self.maxscale = 1.6 
		self.minscale = 1.0
		self.page_displayed = 0
		self.page_total = None

	def create_preview(self, pdffile):
		self.pdffile = pdffile	
		self.uri = "file://" + pdffile
		self.document = poppler.document_new_from_file(self.uri, None)
		self.page_total = self.document.get_n_pages()
		self.current_page = self.document.get_page(0)
		self.width, self.height = self.current_page.get_size()
		self.drawarea.set_size_request(int(self.width), int(self.height))
		self.drawarea.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(6400, 6400, 6440))
		self.drawarea.connect("expose-event", self.on_expose)

	def refresh_preview(self):
		if os.path.exists(self.pdffile): # only attempt refresh if file exists
			self.drawarea.show()
			self.uri = "file://" + self.pdffile
			self.document = poppler.document_new_from_file(self.uri, None)
			self.page_total = self.document.get_n_pages()
			if self.page_total <= (self.page_displayed):		
				self.current_page = self.document.get_page(self.page_total - 1)			
			else:		
				self.current_page = self.document.get_page(self.page_displayed)
			self.drawarea.queue_draw()

	def jump_to_nextpage(self):
		if (self.page_displayed + 1) < self.page_total:
			self.page_displayed = self.page_displayed + 1
			self.uri = "file://" + self.pdffile
			self.document = poppler.document_new_from_file(self.uri, None)
			self.page_total = self.document.get_n_pages()
			self.current_page = self.document.get_page(self.page_displayed)
			self.drawarea.queue_draw()<commit_msg>preview pane will attempt to start after initial failed document<commit_after>
# --------------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <<EMAIL>> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return -<NAME>
# --------------------------------------------------------------------------------


import gtk
import poppler
import traceback
import os.path

ORIGINAL_HEIGHT = 841.89 
ORIGINAL_WIDTH  = 595.276 


class PdfPane:

	def __init__(self, drawarea):
		self.drawarea = drawarea
		self.scale = 1
		self.maxscale = 1.6 
		self.minscale = 1.0
		self.page_displayed = 0
		self.page_total = None
		self.previewactive = 0

	def create_preview(self, pdffile):
		self.pdffile = pdffile	
		self.uri = "file://" + pdffile
		self.document = poppler.document_new_from_file(self.uri, None)
		self.page_total = self.document.get_n_pages()
		self.current_page = self.document.get_page(0)
		self.width, self.height = self.current_page.get_size()
		self.drawarea.set_size_request(int(self.width), int(self.height))
		self.drawarea.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(6400, 6400, 6440))
		self.drawarea.connect("expose-event", self.on_expose)
		self.previewactive = 1

	def refresh_preview(self):
		if self.previewactive is 0: self.create_preview(self.pdffile)
		try:
			if os.path.exists(self.pdffile): # only attempt refresh if file exists
				self.drawarea.show()
				self.uri = "file://" + self.pdffile
				self.document = poppler.document_new_from_file(self.uri, None)
				self.page_total = self.document.get_n_pages()
				if self.page_total <= (self.page_displayed):		
					self.current_page = self.document.get_page(self.page_total - 1)			
				else:		
					self.current_page = self.document.get_page(self.page_displayed)
				self.drawarea.queue_draw()
		except: print traceback.print_exc()

	def jump_to_nextpage(self):
		if (self.page_displayed + 1) < self.page_total:
			self.page_displayed = self.page_displayed + 1
			self.uri = "file://" + self.pdffile
			self.document = poppler.document_new_from_file(self.uri, None)
			self.page_total = self.document.get_n_pages()
			self.current_page = self.document.get_page(self.page_displayed)
			self.drawarea.queue_draw()
{'fraction_non_alphanumeric': 0.17756594990024385, 'fraction_numerical': 0.01618266459765019, 'mean_word_length': 2.9200695047784535, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4691632', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1523, 'n_words': 323}