<commit_before>#!/usr/bin/python2
# -*- coding: utf-8 -*-

import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
import sys
import os
import datetime
from PyQt5.QtWidgets import (
        QApplication,
        QWidget,
        QPushButton,
        QVBoxLayout,
        QHBoxLayout,
        QFormLayout,
        QLabel,
        QSizePolicy,
        QCheckBox,
        QListWidget,
        QListWidgetItem,
        QLineEdit,
        QMainWindow,
        QAction,
        QProgressBar,
        QDialog,
        QTableWidget,
        QTableWidgetItem,
        QFileDialog,
        QDialogButtonBox,
        QGraphicsScene,
        QGraphicsView,
        QGraphicsPixmapItem
        )
from PyQt5.QtGui import (
        QIcon,
        QPixmap,
        QImage,
        QPalette
        )
from PyQt5.QtCore import (QCoreApplication, QThread, QBasicTimer, QUrl, pyqtProperty, pyqtSlot, pyqtSignal, Qt)
from PyQt5.QtQml import (qmlRegisterType, QQmlComponent, QQmlEngine)
from PyQt5.QtQuick import (QQuickView)
from PyQt5.QtQuickWidgets import (QQuickWidget)
import locale
os_encoding = locale.getpreferredencoding()
import microphone_match
import scannerSettingsDialog
import matcherSettingsDialog
import audioSettingsDialog

def main(argv):
    app = QApplication(argv)
    w = MainWindow()
    sys.exit(app.exec_())

class RecorderMatcherThread(QThread):
    def __init__(self, matcher):
        super(self.__class__, self).__init__()
        self.matcher = matcher

    def __del__(self):
        self.wait()

    def run(self):
        # database_file_path = QApplication.instance().arguments()[1] if len(QApplication.instance().arguments())>1 else os.path.join(os.path.dirname(os.path.abspath(__file__)),'fpdbase.pklz')
        # microphone_match.recordAndMatch(database_file_path)
        # self.recordButton.setText('Record')
        self.result = self.matcher.recordAndMatch2()

class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow,self).__init__()
        self.fullscreenWindow = None
        self.initUI()

    def initUI(self):
        self.setWindowTitle('Whistler')

        self.centralWidget = QWidget(self)
        # self.continuousMatching = True
        self.continuousMatching = False
        self.threadInterrupter = {'interrupted':False}
        self.continuousMatcher = microphone_match.ContinuousMatcher(self.threadInterrupter)
        self.matcherThread = RecorderMatcherThread(self.continuousMatcher)
        self.matcherThread.finished.connect(self.recordingFinished)

        self.recordButton = QPushButton(u'Nagrywaj')
        self.recordButton.resize(self.recordButton.sizeHint())
        self.recordButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.recordButton.clicked.connect(self.recordAndMatch)

        self.resultLabel = QLabel()
        if self.continuousMatcher.ready:
            self.resultLabel.setText(u'Gotowy')
        else:
            self.resultLabel.setText(u'Proszę wybrać katalog z bazą danych')

        self.pictureLabel = QLabel();
        self.pictureImage = QImage("image.jpg")
        self.pictureImage = self.pictureImage.scaled(200,200,Qt.IgnoreAspectRatio,Qt.FastTransformation)
        self.pictureLabel.setAlignment( Qt.AlignRight | Qt.AlignVCenter );
        self.pictureLabel.setPixmap(QPixmap.fromImage(self.pictureImage))

        # self.continuousCheckBox = QCheckBox()
        # self.continuousCheckBox.setText('Continuous')
        # self.continuousCheckBox.setChecked(self.continuousMatching)
        # self.continuousCheckBox.stateChanged.connect(self.toggleContinuous)

        self.progress = 0.0
        self.progressBar = QProgressBar()
        self.progressTimer = QBasicTimer()

        self.recentList = []
        self.recentListWidget = QListWidget()

        self.optionsHBox = QHBoxLayout()
        # self.optionsHBox.addWidget(self.continuousCheckBox)

        self.recResHBox = QHBoxLayout()
        self.recResHBox.addWidget(self.recordButton)
        self.recResHBox.addWidget(self.resultLabel)
        self.recResHBox.addWidget(self.pictureLabel)

        self.mainVBox = QVBoxLayout()
        self.mainVBox.addLayout(self.recResHBox)
        self.mainVBox.addLayout(self.optionsHBox)
        # self.mainVBox.addWidget(self.recentListWidget)
        self.mainVBox.addWidget(self.progressBar)
        # self.mainVBox.addStretch(1)
        self.centralWidget.setLayout(self.mainVBox)
        self.setCentralWidget(self.centralWidget)
        self.setupMenuBar()
        self.show()

    def setupMenuBar(self):
        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&Plik')
        settingsMenu = menubar.addMenu('&Ustawienia')

        runFullscreenAction = QAction(QIcon.fromTheme('fullscreen'), u'&Pełny ekran', self)
        runFullscreenAction.setShortcut('F11')
        runFullscreenAction.setStatusTip(u'Uruchom widok pełnoekranowy')
        runFullscreenAction.triggered.connect(self.runFullscreen)

        databaseManagementAction = QAction(QIcon.fromTheme('database'), u'&Baza danych', self)
        databaseManagementAction.setShortcut('Ctrl+B')
        databaseManagementAction.setStatusTip(u'Zarządzaj bazą danych')
        databaseManagementAction.triggered.connect(self.openDatabaseManagement)

        chooseDatabaseAction = QAction(QIcon.fromTheme('fileopen'), u'&Otwórz bazę danych', self)
        chooseDatabaseAction.setShortcut('Ctrl+O')
        chooseDatabaseAction.setStatusTip('Otwórz katalog zawierający bazę danych')
        chooseDatabaseAction.triggered.connect(self.chooseDatabaseDirectory)

        exitAction = QAction(QIcon.fromTheme('application-exit'), u'&Wyjście', self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Zamknij program')
        exitAction.triggered.connect(QApplication.quit)

        audioSettingsAction = QAction(QIcon.fromTheme('gnome-settings'), u'Ustawienia &nagrywania', self)
        audioSettingsAction.setShortcut('Ctrl+Shift+R')
        audioSettingsAction.setStatusTip(u'Zmień ustawienia nagrywania')
        audioSettingsAction.triggered.connect(self.openAudioSettings)

        matcherSettingsAction = QAction(QIcon.fromTheme('gnome-settings'), u'Ustawienia &dopasowywania', self)
        matcherSettingsAction.setShortcut('Ctrl+Shift+M')
        matcherSettingsAction.setStatusTip(u'Zmień ustawienia dopasowywania')
        matcherSettingsAction.triggered.connect(self.openMatcherSettings)

        scannerSettingsAction = QAction(QIcon.fromTheme('gnome-settings'), u'Ustawienia &skanowania', self)
        scannerSettingsAction.setShortcut('Ctrl+Shift+S')
        scannerSettingsAction.setStatusTip(u'Zmień ustawienia skanowania')
        scannerSettingsAction.triggered.connect(self.openScannerSettings)

        fileMenu.addAction(runFullscreenAction)
        fileMenu.addAction(chooseDatabaseAction)
        fileMenu.addAction(databaseManagementAction)
        fileMenu.addAction(exitAction)
        settingsMenu.addAction(audioSettingsAction)
        settingsMenu.addAction(matcherSettingsAction)
        settingsMenu.addAction(scannerSettingsAction)

    def runFullscreen(self):
        if self.fullscreenWindow == None:
            self.fullscreenWindow = QDialog(self)
            widget = QQuickWidget(self.fullscreenWindow)
            layout = QVBoxLayout(self.fullscreenWindow)
            layout.setContentsMargins(0,0,0,0)
            layout.addWidget(widget)
            self.fullscreenWindow.setLayout(layout)
            widget.setResizeMode(QQuickWidget.SizeRootObjectToView)
            # view = QQuickView()
            widget.setSource(QUrl('fullscreen.qml'))
            # engine = widget.engine()
            mainRootObject = widget.rootObject()
            mainRootObject.startRecording.connect(self.recordAndMatch)
            mainRootObject.closeWindow.connect(self.closeFullscreenWindow)
            self.recordingStartedSignal.connect(mainRootObject.stateRecording)
            self.recordingFinishedSignal.connect(mainRootObject.stateReady)
            self.fullscreenWindow.showFullScreen()
        else:
            self.fullscreenWindow.show()

    def closeFullscreenWindow(self):
        if self.fullscreenWindow != None:
            self.fullscreenWindow.close()
            del self.fullscreenWindow
            self.fullscreenWindow = None

    def openDatabaseManagement(self, newValue):
        databaseDialog = QDialog(self)

        databaseTable = QTableWidget()
        self.fillDatabaseManagementTable(databaseTable)

        rescanButton = QPushButton(u'Skanuj ponownie')<commit_msg>make the qml loading work when script is launched from any folder<commit_after>#!/usr/bin/python2
# -*- coding: utf-8 -*-

import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
import sys
import os
import datetime
from PyQt5.QtWidgets import (
        QApplication,
        QWidget,
        QPushButton,
        QVBoxLayout,
        QHBoxLayout,
        QFormLayout,
        QLabel,
        QSizePolicy,
        QCheckBox,
        QListWidget,
        QListWidgetItem,
        QLineEdit,
        QMainWindow,
        QAction,
        QProgressBar,
        QDialog,
        QTableWidget,
        QTableWidgetItem,
        QFileDialog,
        QDialogButtonBox,
        QGraphicsScene,
        QGraphicsView,
        QGraphicsPixmapItem
        )
from PyQt5.QtGui import (
        QIcon,
        QPixmap,
        QImage,
        QPalette
        )
from PyQt5.QtCore import (QCoreApplication, QThread, QBasicTimer, QUrl, pyqtProperty, pyqtSlot, pyqtSignal, Qt)
from PyQt5.QtQml import (qmlRegisterType, QQmlComponent, QQmlEngine)
from PyQt5.QtQuick import (QQuickView)
from PyQt5.QtQuickWidgets import (QQuickWidget)
import locale
os_encoding = locale.getpreferredencoding()
import microphone_match
import scannerSettingsDialog
import matcherSettingsDialog
import audioSettingsDialog

def main(argv):
    app = QApplication(argv)
    w = MainWindow()
    sys.exit(app.exec_())

class RecorderMatcherThread(QThread):
    def __init__(self, matcher):
        super(self.__class__, self).__init__()
        self.matcher = matcher

    def __del__(self):
        self.wait()

    def run(self):
        # database_file_path = QApplication.instance().arguments()[1] if len(QApplication.instance().arguments())>1 else os.path.join(os.path.dirname(os.path.abspath(__file__)),'fpdbase.pklz')
        # microphone_match.recordAndMatch(database_file_path)
        # self.recordButton.setText('Record')
        self.result = self.matcher.recordAndMatch2()

class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow,self).__init__()
        self.fullscreenWindow = None
        self.initUI()

    def initUI(self):
        self.setWindowTitle('Whistler')

        self.centralWidget = QWidget(self)
        # self.continuousMatching = True
        self.continuousMatching = False
        self.threadInterrupter = {'interrupted':False}
        self.continuousMatcher = microphone_match.ContinuousMatcher(self.threadInterrupter)
        self.matcherThread = RecorderMatcherThread(self.continuousMatcher)
        self.matcherThread.finished.connect(self.recordingFinished)

        self.recordButton = QPushButton(u'Nagrywaj')
        self.recordButton.resize(self.recordButton.sizeHint())
        self.recordButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.recordButton.clicked.connect(self.recordAndMatch)

        self.resultLabel = QLabel()
        if self.continuousMatcher.ready:
            self.resultLabel.setText(u'Gotowy')
        else:
            self.resultLabel.setText(u'Proszę wybrać katalog z bazą danych')

        self.pictureLabel = QLabel();
        self.pictureImage = QImage("image.jpg")
        self.pictureImage = self.pictureImage.scaled(200,200,Qt.IgnoreAspectRatio,Qt.FastTransformation)
        self.pictureLabel.setAlignment( Qt.AlignRight | Qt.AlignVCenter );
        self.pictureLabel.setPixmap(QPixmap.fromImage(self.pictureImage))

        # self.continuousCheckBox = QCheckBox()
        # self.continuousCheckBox.setText('Continuous')
        # self.continuousCheckBox.setChecked(self.continuousMatching)
        # self.continuousCheckBox.stateChanged.connect(self.toggleContinuous)

        self.progress = 0.0
        self.progressBar = QProgressBar()
        self.progressTimer = QBasicTimer()

        self.recentList = []
        self.recentListWidget = QListWidget()

        self.optionsHBox = QHBoxLayout()
        # self.optionsHBox.addWidget(self.continuousCheckBox)

        self.recResHBox = QHBoxLayout()
        self.recResHBox.addWidget(self.recordButton)
        self.recResHBox.addWidget(self.resultLabel)
        self.recResHBox.addWidget(self.pictureLabel)

        self.mainVBox = QVBoxLayout()
        self.mainVBox.addLayout(self.recResHBox)
        self.mainVBox.addLayout(self.optionsHBox)
        # self.mainVBox.addWidget(self.recentListWidget)
        self.mainVBox.addWidget(self.progressBar)
        # self.mainVBox.addStretch(1)
        self.centralWidget.setLayout(self.mainVBox)
        self.setCentralWidget(self.centralWidget)
        self.setupMenuBar()
        self.show()

    def setupMenuBar(self):
        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&Plik')
        settingsMenu = menubar.addMenu('&Ustawienia')

        runFullscreenAction = QAction(QIcon.fromTheme('fullscreen'), u'&Pełny ekran', self)
        runFullscreenAction.setShortcut('F11')
        runFullscreenAction.setStatusTip(u'Uruchom widok pełnoekranowy')
        runFullscreenAction.triggered.connect(self.runFullscreen)

        databaseManagementAction = QAction(QIcon.fromTheme('database'), u'&Baza danych', self)
        databaseManagementAction.setShortcut('Ctrl+B')
        databaseManagementAction.setStatusTip(u'Zarządzaj bazą danych')
        databaseManagementAction.triggered.connect(self.openDatabaseManagement)

        chooseDatabaseAction = QAction(QIcon.fromTheme('fileopen'), u'&Otwórz bazę danych', self)
        chooseDatabaseAction.setShortcut('Ctrl+O')
        chooseDatabaseAction.setStatusTip('Otwórz katalog zawierający bazę danych')
        chooseDatabaseAction.triggered.connect(self.chooseDatabaseDirectory)

        exitAction = QAction(QIcon.fromTheme('application-exit'), u'&Wyjście', self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Zamknij program')
        exitAction.triggered.connect(QApplication.quit)

        audioSettingsAction = QAction(QIcon.fromTheme('gnome-settings'), u'Ustawienia &nagrywania', self)
        audioSettingsAction.setShortcut('Ctrl+Shift+R')
        audioSettingsAction.setStatusTip(u'Zmień ustawienia nagrywania')
        audioSettingsAction.triggered.connect(self.openAudioSettings)

        matcherSettingsAction = QAction(QIcon.fromTheme('gnome-settings'), u'Ustawienia &dopasowywania', self)
        matcherSettingsAction.setShortcut('Ctrl+Shift+M')
        matcherSettingsAction.setStatusTip(u'Zmień ustawienia dopasowywania')
        matcherSettingsAction.triggered.connect(self.openMatcherSettings)

        scannerSettingsAction = QAction(QIcon.fromTheme('gnome-settings'), u'Ustawienia &skanowania', self)
        scannerSettingsAction.setShortcut('Ctrl+Shift+S')
        scannerSettingsAction.setStatusTip(u'Zmień ustawienia skanowania')
        scannerSettingsAction.triggered.connect(self.openScannerSettings)

        fileMenu.addAction(runFullscreenAction)
        fileMenu.addAction(chooseDatabaseAction)
        fileMenu.addAction(databaseManagementAction)
        fileMenu.addAction(exitAction)
        settingsMenu.addAction(audioSettingsAction)
        settingsMenu.addAction(matcherSettingsAction)
        settingsMenu.addAction(scannerSettingsAction)

    def runFullscreen(self):
        if self.fullscreenWindow == None:
            self.fullscreenWindow = QDialog(self)
            widget = QQuickWidget(self.fullscreenWindow)
            layout = QVBoxLayout(self.fullscreenWindow)
            layout.setContentsMargins(0,0,0,0)
            layout.addWidget(widget)
            self.fullscreenWindow.setLayout(layout)
            widget.setResizeMode(QQuickWidget.SizeRootObjectToView)
            # view = QQuickView()
            widget.setSource(QUrl(os.path.join(self.continuousMatcher.applicationPath,'fullscreen.qml')))
            # engine = widget.engine()
            mainRootObject = widget.rootObject()
            mainRootObject.startRecording.connect(self.recordAndMatch)
            mainRootObject.closeWindow.connect(self.closeFullscreenWindow)
            self.recordingStartedSignal.connect(mainRootObject.stateRecording)
            self.recordingFinishedSignal.connect(mainRootObject.stateReady)
            self.fullscreenWindow.showFullScreen()
        else:
            self.fullscreenWindow.show()

    def closeFullscreenWindow(self):
        if self.fullscreenWindow != None:
            self.fullscreenWindow.close()
            del self.fullscreenWindow
            self.fullscreenWindow = None

    def openDatabaseManagement(self, newValue):
        databaseDialog = QDialog(self)

        databaseTable = QTableWidget()
        self.fillDatabaseManagementTable(databaseTable)

        rescanButton = QPushButton(u'Skanuj ponownie')
{'fraction_non_alphanumeric': 0.09345089622367887, 'fraction_numerical': 0.003016416265444631, 'mean_word_length': 3.2525900345337937, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3479387', 'n_tokens_mistral': 5119, 'n_tokens_neox': 5017, 'n_words': 680}