<commit_before># -*- coding: utf-8 -*-

"""The user interface for our app"""

import os,sys,tempfile,re
from pprint import pprint
from multiprocessing import Process
from hashlib import md5
from cStringIO import StringIO
from rst2pdf.createpdf import RstToPdf 
from rst2pdf.log import log
import logging

log.setLevel(logging.INFO)

# Import Qt modules
from PyQt4 import QtCore,QtGui
from pypoppler import QtPoppler

# Syntax HL
from highlighter import Highlighter

# Import the compiled UI module
from Ui_main import Ui_MainWindow
from Ui_pdf import Ui_Form

import simplejson as json
from BeautifulSoup import BeautifulSoup

_renderer = RstToPdf(splittables=True)

def render(text, preview=True):
    '''Render text to PDF via rst2pdf'''
    # FIXME: get parameters for this from somewhere
    
    sio=StringIO()
    _renderer.createPdf(text=text, output=sio, debugLinesPdf=preview)
    return sio.getvalue()
    
class Main(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        self.lineMarks={}

        # This is always the same
        self.ui=Ui_MainWindow()
        self.ui.setupUi(self)
        
        self.pdf=PDFWidget()
        
        self.ui.pageNum = QtGui.QSpinBox()
        self.ui.pageNum.setMinimum(1)
        self.ui.pageNum.setValue(1)
        self.connect(self.pdf,QtCore.SIGNAL('pageCount'),
            self.ui.pageNum.setMaximum)
        self.connect(self.pdf,QtCore.SIGNAL('pageChanged'),
            self.ui.pageNum.setValue)
        self.connect(self.ui.pageNum,QtCore.SIGNAL('valueChanged(int)'),
            self.pdf.gotoPage)

        self.ui.actionShow_ToolBar=self.ui.toolBar.toggleViewAction()
        self.ui.actionShow_ToolBar.setText("Show Main Toolbar")
        self.ui.menuView.addAction(self.ui.actionShow_ToolBar)

        self.ui.pdfbar.addAction(self.pdf.ui.previous)
        self.ui.pdfbar.addWidget(self.ui.pageNum)        
        self.ui.pdfbar.addAction(self.pdf.ui.next)
        self.ui.pdfbar.addSeparator()
        self.ui.pdfbar.addAction(self.pdf.ui.zoomin)
        self.ui.pdfbar.addAction(self.pdf.ui.zoomout)
        self.ui.actionShow_PDFBar=self.ui.pdfbar.toggleViewAction()
        self.ui.actionShow_PDFBar.setText("Show PDF Toolbar")
        self.ui.menuView.addAction(self.ui.actionShow_PDFBar)

        self.ui.dockLayout.addWidget(self.ui.pdfbar)
        self.ui.dockLayout.addWidget(self.pdf)
        self.ui.actionShow_PDF=self.ui.dock.toggleViewAction()
        self.ui.actionShow_PDF.setText('Show Preview')
        self.ui.menuView.addAction(self.ui.actionShow_PDF)
        
        self.text_md5=''
        self.style_md5=''
        
        self.hl1 = Highlighter(self.ui.text.document(),'rest')
        self.hl2 = Highlighter(self.ui.style.document(),'javascript')
        
        self.editorPos=QtGui.QLabel()
        self.ui.statusBar.addWidget(self.editorPos)
        self.editorPos.show()
        
        self.statusMessage=QtGui.QLabel()
        self.ui.statusBar.addWidget(self.statusMessage)
        self.statusMessage.show()
        
        self.on_text_cursorPositionChanged()
        self.on_actionRender_triggered()

        # Connect editing actions to the editors
        self.ui.text.undoAvailable.connect(self.ui.actionUndo1.setEnabled)
        self.ui.actionUndo1.triggered.connect(self.ui.text.undo)
        self.ui.text.redoAvailable.connect(self.ui.actionRedo1.setEnabled)
        self.ui.actionRedo1.triggered.connect(self.ui.text.redo)
        
        self.ui.text.copyAvailable.connect(self.ui.actionCopy1.setEnabled)
        self.ui.actionCopy1.triggered.connect(self.ui.text.copy)
        self.ui.text.copyAvailable.connect(self.ui.actionCut1.setEnabled)
        self.ui.actionCut1.triggered.connect(self.ui.text.cut)
        self.ui.actionPaste1.triggered.connect(self.ui.text.paste)
        

        self.ui.style.undoAvailable.connect(self.ui.actionUndo2.setEnabled)
        self.ui.actionUndo2.triggered.connect(self.ui.style.undo)
        self.ui.style.redoAvailable.connect(self.ui.actionRedo2.setEnabled)
        self.ui.actionRedo2.triggered.connect(self.ui.style.redo)
        
        self.ui.style.copyAvailable.connect(self.ui.actionCopy2.setEnabled)
        self.ui.actionCopy2.triggered.connect(self.ui.style.copy)
        self.ui.style.copyAvailable.connect(self.ui.actionCut2.setEnabled)
        self.ui.actionCut2.triggered.connect(self.ui.style.cut)
        self.ui.actionPaste2.triggered.connect(self.ui.style.paste)
        
        self.hookEditToolbar(self.ui.text)
        
        self.text_fname=None
        self.style_fname=None
        self.pdf_fname=None

    def hookEditToolbar(self, editor):
        if editor == self.ui.text:
            self.ui.actionUndo2.setVisible(False)
            self.ui.actionRedo2.setVisible(False)
            self.ui.actionCut2.setVisible(False)
            self.ui.actionPaste2.setVisible(False)
            self.ui.actionCopy2.setVisible(False)
            self.ui.actionUndo1.setVisible(True)<commit_msg>paste hooked to the UI<commit_after># -*- coding: utf-8 -*-

"""The user interface for our app"""

import os,sys,tempfile,re
from pprint import pprint
from multiprocessing import Process
from hashlib import md5
from cStringIO import StringIO
from rst2pdf.createpdf import RstToPdf 
from rst2pdf.log import log
import logging

log.setLevel(logging.INFO)

# Import Qt modules
from PyQt4 import QtCore,QtGui
from pypoppler import QtPoppler

# Syntax HL
from highlighter import Highlighter

# Import the compiled UI module
from Ui_main import Ui_MainWindow
from Ui_pdf import Ui_Form

import simplejson as json
from BeautifulSoup import BeautifulSoup

_renderer = RstToPdf(splittables=True)

def render(text, preview=True):
    '''Render text to PDF via rst2pdf'''
    # FIXME: get parameters for this from somewhere
    
    sio=StringIO()
    _renderer.createPdf(text=text, output=sio, debugLinesPdf=preview)
    return sio.getvalue()
    
class Main(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        self.lineMarks={}

        # This is always the same
        self.ui=Ui_MainWindow()
        self.ui.setupUi(self)
        
        self.pdf=PDFWidget()
        
        self.ui.pageNum = QtGui.QSpinBox()
        self.ui.pageNum.setMinimum(1)
        self.ui.pageNum.setValue(1)
        self.connect(self.pdf,QtCore.SIGNAL('pageCount'),
            self.ui.pageNum.setMaximum)
        self.connect(self.pdf,QtCore.SIGNAL('pageChanged'),
            self.ui.pageNum.setValue)
        self.connect(self.ui.pageNum,QtCore.SIGNAL('valueChanged(int)'),
            self.pdf.gotoPage)

        self.ui.actionShow_ToolBar=self.ui.toolBar.toggleViewAction()
        self.ui.actionShow_ToolBar.setText("Show Main Toolbar")
        self.ui.menuView.addAction(self.ui.actionShow_ToolBar)

        self.ui.pdfbar.addAction(self.pdf.ui.previous)
        self.ui.pdfbar.addWidget(self.ui.pageNum)        
        self.ui.pdfbar.addAction(self.pdf.ui.next)
        self.ui.pdfbar.addSeparator()
        self.ui.pdfbar.addAction(self.pdf.ui.zoomin)
        self.ui.pdfbar.addAction(self.pdf.ui.zoomout)
        self.ui.actionShow_PDFBar=self.ui.pdfbar.toggleViewAction()
        self.ui.actionShow_PDFBar.setText("Show PDF Toolbar")
        self.ui.menuView.addAction(self.ui.actionShow_PDFBar)

        self.ui.dockLayout.addWidget(self.ui.pdfbar)
        self.ui.dockLayout.addWidget(self.pdf)
        self.ui.actionShow_PDF=self.ui.dock.toggleViewAction()
        self.ui.actionShow_PDF.setText('Show Preview')
        self.ui.menuView.addAction(self.ui.actionShow_PDF)
        
        self.text_md5=''
        self.style_md5=''
        
        self.hl1 = Highlighter(self.ui.text.document(),'rest')
        self.hl2 = Highlighter(self.ui.style.document(),'javascript')
        
        self.editorPos=QtGui.QLabel()
        self.ui.statusBar.addWidget(self.editorPos)
        self.editorPos.show()
        
        self.statusMessage=QtGui.QLabel()
        self.ui.statusBar.addWidget(self.statusMessage)
        self.statusMessage.show()
        
        self.on_text_cursorPositionChanged()
        self.on_actionRender_triggered()

        # Connect editing actions to the editors
        self.ui.text.undoAvailable.connect(self.ui.actionUndo1.setEnabled)
        self.ui.actionUndo1.triggered.connect(self.ui.text.undo)
        self.ui.text.redoAvailable.connect(self.ui.actionRedo1.setEnabled)
        self.ui.actionRedo1.triggered.connect(self.ui.text.redo)
        
        self.ui.text.copyAvailable.connect(self.ui.actionCopy1.setEnabled)
        self.ui.actionCopy1.triggered.connect(self.ui.text.copy)
        self.ui.text.copyAvailable.connect(self.ui.actionCut1.setEnabled)
        self.ui.actionCut1.triggered.connect(self.ui.text.cut)
        self.ui.actionPaste1.triggered.connect(self.ui.text.paste)
        

        self.ui.style.undoAvailable.connect(self.ui.actionUndo2.setEnabled)
        self.ui.actionUndo2.triggered.connect(self.ui.style.undo)
        self.ui.style.redoAvailable.connect(self.ui.actionRedo2.setEnabled)
        self.ui.actionRedo2.triggered.connect(self.ui.style.redo)
        
        self.ui.style.copyAvailable.connect(self.ui.actionCopy2.setEnabled)
        self.ui.actionCopy2.triggered.connect(self.ui.style.copy)
        self.ui.style.copyAvailable.connect(self.ui.actionCut2.setEnabled)
        self.ui.actionCut2.triggered.connect(self.ui.style.cut)
        self.ui.actionPaste2.triggered.connect(self.ui.style.paste)
        
        self.clipBoard=QtGui.QApplication.clipboard()
        self.clipBoard.changed.connect(self.clipChanged)
        
        self.hookEditToolbar(self.ui.text)
        self.clipChanged(QtGui.QClipboard.Clipboard)
        
        self.text_fname=None
        self.style_fname=None
        self.pdf_fname=None

    def clipChanged(self, mode=None):
        if mode is None: return
        if mode == QtGui.QClipboard.Clipboard:
            if unicode(self.clipBoard.text()):
                self.ui.actionPaste1.setEnabled(True)
                self.ui.actionPaste2.setEnabled(True)
            else:
                self.ui.actionPaste1.setEnabled(False)
                self.ui.actionPaste2.setEnabled(False)

    def hookEditToolbar(self, editor):
        if editor == self.ui.text:
            self.ui.actionUndo2.setVisible(False)
            self.ui.actionRedo2.setVisible(False)
            self.ui.actionCut2.setVisible(False)
            self.ui.actionPaste2.setVisible(False)
            self.ui.actionCopy2.setVisible(False)
            self.ui.actionUndo1.setVisible(True)
{'fraction_non_alphanumeric': 0.10969748374328527, 'fraction_numerical': 0.007162378663650928, 'mean_word_length': 2.748498763687743, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1006075', 'n_tokens_mistral': 3502, 'n_tokens_neox': 3472, 'n_words': 424}