#!/usr/bin/env python3

import io
import sys
from cnocr import CnOcr
#import pytesseract
from PIL import Image
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt
from tkinterEditor import *


ocr=CnOcr()
class Snipper(QtWidgets.QWidget):
    def __init__(self, parent=None, flags=Qt.WindowFlags()):
        super().__init__(parent=parent, flags=flags)

        self.setWindowTitle("TextShot")
        self.setWindowFlags(
            Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Dialog
        )
        self.setWindowState(self.windowState() | Qt.WindowFullScreen)

        self.screen = QtWidgets.QApplication.screenAt(QtGui.QCursor.pos()).grabWindow(0)
        palette = QtGui.QPalette()
        palette.setBrush(self.backgroundRole(), QtGui.QBrush(self.screen))
        self.setPalette(palette)

        QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.CrossCursor))

        self.start, self.end = QtCore.QPoint(), QtCore.QPoint()

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            QtWidgets.QApplication.quit()

        return super().keyPressEvent(event)

    def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        painter.setPen(Qt.NoPen)
        painter.setBrush(QtGui.QColor(0, 0, 0, 100))
        painter.drawRect(0, 0, self.width(), self.height())

        if self.start == self.end:
            return super().paintEvent(event)

        painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255), 3))
        painter.setBrush(painter.background())
        painter.drawRect(QtCore.QRect(self.start, self.end))
        return super().paintEvent(event)

    def mousePressEvent(self, event):
        self.start = self.end = event.pos()
        self.update()
        return super().mousePressEvent(event)

    def mouseMoveEvent(self, event):
        self.end = event.pos()
        self.update()
        return super().mousePressEvent(event)

    def mouseReleaseEvent(self, event):
        if self.start == self.end:
            return super().mouseReleaseEvent(event)

        self.hide()
        QtWidgets.QApplication.processEvents()
        shot = self.screen.copy(QtCore.QRect(self.start, self.end))
        shot.save('./test.png', "PNG")
        result = ocr.ocr('./test.png')
        print(len(result))
        resulttest = ''
        for i in range(len(result)):
            for a in range(len(result[i][0])):
                resulttest+=result[i][0][a]

            resulttest = resulttest+'\n'
            print(resulttest)
        result=str(resulttest)


        #processImage(shot)
        if result:
            f=open('temp.txt','w')
            f.write(result)
            f.close()

            MainEditorProgram(True)



        else:
            print(f"INFO: Unable to read text from image, did not copy")


        QtWidgets.QApplication.quit()









def runApps():
    QtCore.QCoreApplication.setAttribute(Qt.AA_DisableHighDpiScaling)
    app = QtWidgets.QApplication(sys.argv)


    window = QtWidgets.QMainWindow()
    snipper = Snipper(window)
    snipper.show()
    app.exec_()


eeb19dbcb95567617f7e5781496340d5bdac6d82
<mask token>


class Snipper(QtWidgets.QWidget):
    <mask token>

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            QtWidgets.QApplication.quit()
        return super().keyPressEvent(event)
    <mask token>

    def mousePressEvent(self, event):
        self.start = self.end = event.pos()
        self.update()
        return super().mousePressEvent(event)
    <mask token>

    def mouseReleaseEvent(self, event):
        if self.start == self.end:
            return super().mouseReleaseEvent(event)
        self.hide()
        QtWidgets.QApplication.processEvents()
        shot = self.screen.copy(QtCore.QRect(self.start, self.end))
        shot.save('./test.png', 'PNG')
        result = ocr.ocr('./test.png')
        print(len(result))
        resulttest = ''
        for i in range(len(result)):
            for a in range(len(result[i][0])):
                resulttest += result[i][0][a]
            resulttest = resulttest + '\n'
            print(resulttest)
        result = str(resulttest)
        if result:
            f = open('temp.txt', 'w')
            f.write(result)
            f.close()
            MainEditorProgram(True)
        else:
            print(f'INFO: Unable to read text from image, did not copy')
        QtWidgets.QApplication.quit()


<mask token>

<mask token>


class Snipper(QtWidgets.QWidget):

    def __init__(self, parent=None, flags=Qt.WindowFlags()):
        super().__init__(parent=parent, flags=flags)
        self.setWindowTitle('TextShot')
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.
            WindowStaysOnTopHint | Qt.Dialog)
        self.setWindowState(self.windowState() | Qt.WindowFullScreen)
        self.screen = QtWidgets.QApplication.screenAt(QtGui.QCursor.pos()
            ).grabWindow(0)
        palette = QtGui.QPalette()
        palette.setBrush(self.backgroundRole(), QtGui.QBrush(self.screen))
        self.setPalette(palette)
        QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.
            CrossCursor))
        self.start, self.end = QtCore.QPoint(), QtCore.QPoint()

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            QtWidgets.QApplication.quit()
        return super().keyPressEvent(event)
    <mask token>

    def mousePressEvent(self, event):
        self.start = self.end = event.pos()
        self.update()
        return super().mousePressEvent(event)

    def mouseMoveEvent(self, event):
        self.end = event.pos()
        self.update()
        return super().mousePressEvent(event)

    def mouseReleaseEvent(self, event):
        if self.start == self.end:
            return super().mouseReleaseEvent(event)
        self.hide()
        QtWidgets.QApplication.processEvents()
        shot = self.screen.copy(QtCore.QRect(self.start, self.end))
        shot.save('./test.png', 'PNG')
        result = ocr.ocr('./test.png')
        print(len(result))
        resulttest = ''
        for i in range(len(result)):
            for a in range(len(result[i][0])):
                resulttest += result[i][0][a]
            resulttest = resulttest + '\n'
            print(resulttest)
        result = str(resulttest)
        if result:
            f = open('temp.txt', 'w')
            f.write(result)
            f.close()
            MainEditorProgram(True)
        else:
            print(f'INFO: Unable to read text from image, did not copy')
        QtWidgets.QApplication.quit()


<mask token>

<mask token>


class Snipper(QtWidgets.QWidget):

    def __init__(self, parent=None, flags=Qt.WindowFlags()):
        super().__init__(parent=parent, flags=flags)
        self.setWindowTitle('TextShot')
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.
            WindowStaysOnTopHint | Qt.Dialog)
        self.setWindowState(self.windowState() | Qt.WindowFullScreen)
        self.screen = QtWidgets.QApplication.screenAt(QtGui.QCursor.pos()
            ).grabWindow(0)
        palette = QtGui.QPalette()
        palette.setBrush(self.backgroundRole(), QtGui.QBrush(self.screen))
        self.setPalette(palette)
        QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.
            CrossCursor))
        self.start, self.end = QtCore.QPoint(), QtCore.QPoint()

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            QtWidgets.QApplication.quit()
        return super().keyPressEvent(event)

    def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        painter.setPen(Qt.NoPen)
        painter.setBrush(QtGui.QColor(0, 0, 0, 100))
        painter.drawRect(0, 0, self.width(), self.height())
        if self.start == self.end:
            return super().paintEvent(event)
        painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255), 3))
        painter.setBrush(painter.background())
        painter.drawRect(QtCore.QRect(self.start, self.end))
        return super().paintEvent(event)

    def mousePressEvent(self, event):
        self.start = self.end = event.pos()
        self.update()
        return super().mousePressEvent(event)

    def mouseMoveEvent(self, event):
        self.end = event.pos()
        self.update()
        return super().mousePressEvent(event)

    def mouseReleaseEvent(self, event):
        if self.start == self.end:
            return super().mouseReleaseEvent(event)
        self.hide()
        QtWidgets.QApplication.processEvents()
        shot = self.screen.copy(QtCore.QRect(self.start, self.end))
        shot.save('./test.png', 'PNG')
        result = ocr.ocr('./test.png')
        print(len(result))
        resulttest = ''
        for i in range(len(result)):
            for a in range(len(result[i][0])):
                resulttest += result[i][0][a]
            resulttest = resulttest + '\n'
            print(resulttest)
        result = str(resulttest)
        if result:
            f = open('temp.txt', 'w')
            f.write(result)
            f.close()
            MainEditorProgram(True)
        else:
            print(f'INFO: Unable to read text from image, did not copy')
        QtWidgets.QApplication.quit()


def runApps():
    QtCore.QCoreApplication.setAttribute(Qt.AA_DisableHighDpiScaling)
    app = QtWidgets.QApplication(sys.argv)
    window = QtWidgets.QMainWindow()
    snipper = Snipper(window)
    snipper.show()
    app.exec_()

<mask token>
ocr = CnOcr()


class Snipper(QtWidgets.QWidget):

    def __init__(self, parent=None, flags=Qt.WindowFlags()):
        super().__init__(parent=parent, flags=flags)
        self.setWindowTitle('TextShot')
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.
            WindowStaysOnTopHint | Qt.Dialog)
        self.setWindowState(self.windowState() | Qt.WindowFullScreen)
        self.screen = QtWidgets.QApplication.screenAt(QtGui.QCursor.pos()
            ).grabWindow(0)
        palette = QtGui.QPalette()
        palette.setBrush(self.backgroundRole(), QtGui.QBrush(self.screen))
        self.setPalette(palette)
        QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.
            CrossCursor))
        self.start, self.end = QtCore.QPoint(), QtCore.QPoint()

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            QtWidgets.QApplication.quit()
        return super().keyPressEvent(event)

    def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        painter.setPen(Qt.NoPen)
        painter.setBrush(QtGui.QColor(0, 0, 0, 100))
        painter.drawRect(0, 0, self.width(), self.height())
        if self.start == self.end:
            return super().paintEvent(event)
        painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255), 3))
        painter.setBrush(painter.background())
        painter.drawRect(QtCore.QRect(self.start, self.end))
        return super().paintEvent(event)

    def mousePressEvent(self, event):
        self.start = self.end = event.pos()
        self.update()
        return super().mousePressEvent(event)

    def mouseMoveEvent(self, event):
        self.end = event.pos()
        self.update()
        return super().mousePressEvent(event)

    def mouseReleaseEvent(self, event):
        if self.start == self.end:
            return super().mouseReleaseEvent(event)
        self.hide()
        QtWidgets.QApplication.processEvents()
        shot = self.screen.copy(QtCore.QRect(self.start, self.end))
        shot.save('./test.png', 'PNG')
        result = ocr.ocr('./test.png')
        print(len(result))
        resulttest = ''
        for i in range(len(result)):
            for a in range(len(result[i][0])):
                resulttest += result[i][0][a]
            resulttest = resulttest + '\n'
            print(resulttest)
        result = str(resulttest)
        if result:
            f = open('temp.txt', 'w')
            f.write(result)
            f.close()
            MainEditorProgram(True)
        else:
            print(f'INFO: Unable to read text from image, did not copy')
        QtWidgets.QApplication.quit()


def runApps():
    QtCore.QCoreApplication.setAttribute(Qt.AA_DisableHighDpiScaling)
    app = QtWidgets.QApplication(sys.argv)
    window = QtWidgets.QMainWindow()
    snipper = Snipper(window)
    snipper.show()
    app.exec_()

#!/usr/bin/env python3

import io
import sys
from cnocr import CnOcr
#import pytesseract
from PIL import Image
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt
from tkinterEditor import *


ocr=CnOcr()
class Snipper(QtWidgets.QWidget):
    def __init__(self, parent=None, flags=Qt.WindowFlags()):
        super().__init__(parent=parent, flags=flags)

        self.setWindowTitle("TextShot")
        self.setWindowFlags(
            Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Dialog
        )
        self.setWindowState(self.windowState() | Qt.WindowFullScreen)

        self.screen = QtWidgets.QApplication.screenAt(QtGui.QCursor.pos()).grabWindow(0)
        palette = QtGui.QPalette()
        palette.setBrush(self.backgroundRole(), QtGui.QBrush(self.screen))
        self.setPalette(palette)

        QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.CrossCursor))

        self.start, self.end = QtCore.QPoint(), QtCore.QPoint()

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            QtWidgets.QApplication.quit()

        return super().keyPressEvent(event)

    def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        painter.setPen(Qt.NoPen)
        painter.setBrush(QtGui.QColor(0, 0, 0, 100))
        painter.drawRect(0, 0, self.width(), self.height())

        if self.start == self.end:
            return super().paintEvent(event)

        painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255), 3))
        painter.setBrush(painter.background())
        painter.drawRect(QtCore.QRect(self.start, self.end))
        return super().paintEvent(event)

    def mousePressEvent(self, event):
        self.start = self.end = event.pos()
        self.update()
        return super().mousePressEvent(event)

    def mouseMoveEvent(self, event):
        self.end = event.pos()
        self.update()
        return super().mousePressEvent(event)

    def mouseReleaseEvent(self, event):
        if self.start == self.end:
            return super().mouseReleaseEvent(event)

        self.hide()
        QtWidgets.QApplication.processEvents()
        shot = self.screen.copy(QtCore.QRect(self.start, self.end))
        shot.save('./test.png', "PNG")
        result = ocr.ocr('./test.png')
        print(len(result))
        resulttest = ''
        for i in range(len(result)):
            for a in range(len(result[i][0])):
                resulttest+=result[i][0][a]

            resulttest = resulttest+'\n'
            print(resulttest)
        result=str(resulttest)


        #processImage(shot)
        if result:
            f=open('temp.txt','w')
            f.write(result)
            f.close()

            MainEditorProgram(True)



        else:
            print(f"INFO: Unable to read text from image, did not copy")


        QtWidgets.QApplication.quit()









def runApps():
    QtCore.QCoreApplication.setAttribute(Qt.AA_DisableHighDpiScaling)
    app = QtWidgets.QApplication(sys.argv)


    window = QtWidgets.QMainWindow()
    snipper = Snipper(window)
    snipper.show()
    app.exec_()

