<commit_before>from Windows import ExpirationBox_ui
from PyQt5.QtWidgets import QApplication, QWidget, QDialog
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from Util import constants
from Util import scroller
from datetime import datetime

class ExpirationBox(QDialog, ExpirationBox_ui.Ui_ExpirationBox):
    def __init__(self, config, centralWindow, name, parent=None):
        super(ExpirationBox, self).__init__(parent)
        self.setupUi(self)

        self.config = config
        self.centralWindow = centralWindow

        if name:
            self.itemNameLabel.setText(name)

        # Remove title bar
        self.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint)

        scroller.setupScrolling(self.month_combo.view())
        # Set the combobox view to scroll per pixel so the kinetic scrolling via touchscreen isnt ridiculously fast
        self.month_combo.view().setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
        # Disabling mouse tracking means that when you first use touchscreen to scroll through items, then it wont
        # select that item
        self.month_combo.view().setMouseTracking(False)
        for d in range(1, 13):
            self.month_combo.addItem(str(d))

        scroller.setupScrolling(self.day_combo.view())
        self.day_combo.view().setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
        self.day_combo.view().setMouseTracking(False)
        for d in range(1, 32):
            self.day_combo.addItem(str(d))

        scroller.setupScrolling(self.year_combo.view())
        self.year_combo.view().setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
        self.year_combo.view().setMouseTracking(False)
        year = datetime.now().year
        for y in range(year, year + constants.maxExpirationYear + 1):
            self.year_combo.addItem(str(y))

        scroller.setupScrolling(self.qty_combo.view())
        self.qty_combo.view().setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
        self.qty_combo.view().setMouseTracking(False)
        for q in range(1, 51):
            self.qty_combo.addItem(str(q))

        self.callbackFunction = None
        self.callbackParam = None

    @pyqtSlot()
    def showEvent(self, event):
        # Setup timer to regularly poll for new barcodes from scanners
        self.scannerPoll = QTimer()
        self.scannerPoll.timeout.connect(self.scannerPoll_ticked)
        self.scannerPoll.start(constants.scannerPollInterval)

        # Disconnect the function within centralWindow to handle barcode scanning and setup our own custom functions
        self.centralWindow.primaryScanner.barcodeReceived.connect(self.primaryScanner_barcodeReceived)
        self.centralWindow.secondaryScanner.barcodeReceived.connect(self.secondaryScanner_barcodeReceived)
        self.centralWindow.primaryScanner.barcodeReceived.disconnect(self.centralWindow.primaryScanner_barcodeReceived)
        self.centralWindow.secondaryScanner.barcodeReceived.disconnect(self.centralWindow.secondaryScanner_barcodeReceived)

    @pyqtSlot()
    def hideEvent(self, event):
        # Reconnect the function within centralWindow to handle barcode scanning and disconnect our custom functions
        self.centralWindow.primaryScanner.barcodeReceived.disconnect(self.primaryScanner_barcodeReceived)
        self.centralWindow.secondaryScanner.barcodeReceived.disconnect(self.secondaryScanner_barcodeReceived)
        self.centralWindow.primaryScanner.barcodeReceived.connect(self.centralWindow.primaryScanner_barcodeReceived)
        self.centralWindow.secondaryScanner.barcodeReceived.connect(self.centralWindow.secondaryScanner_barcodeReceived)

    @pyqtSlot()
    def scannerPoll_ticked(self):
        self.centralWindow.primaryScanner.poll()
        self.centralWindow.secondaryScanner.poll()

    @pyqtSlot(str)
    def primaryScanner_barcodeReceived(self, barcode):
        print("Primary barcode scan2342ner got: %s, %s" % (barcode, str(datetime.now())))
        self.close()
        #self.centralWindow.primaryScanner_barcodeReceived(barcode)

        self.callbackFunction = self.centralWindow.primaryScanner_barcodeReceived
        self.callbackParam = barcode

    @pyqtSlot(str)
    def secondaryScanner_barcodeReceived(self, barcode):
        print("Secondary barc423423ode scanner got: %s" % barcode)
        self.close()
        #self.centralWindow.secondaryScanner_barcodeReceived(barcode)

        self.callbackFunction = self.centralWindow.secondaryScanner_barcodeReceived
        self.callbackParam = barcode

    @pyqtSlot(bool, bool)
    def on_accept_button_clicked(self, checked, longPressed):
        self.accept()

    @pyqtSlot(bool, bool)
    def on_cancel_button_clicked(self, checked, longPressed):<commit_msg>Finished work with scan to cancel functionality. It is only on the expiration dialog and as of now, this is the only place where it needs to be.<commit_after>from Windows import ExpirationBox_ui
from PyQt5.QtWidgets import QApplication, QWidget, QDialog
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from Util import constants
from Util import scroller
from datetime import datetime

class ExpirationBox(QDialog, ExpirationBox_ui.Ui_ExpirationBox):
    def __init__(self, config, centralWindow, name, parent=None):
        super(ExpirationBox, self).__init__(parent)
        self.setupUi(self)

        self.config = config
        self.centralWindow = centralWindow

        if name:
            self.itemNameLabel.setText(name)

        # Remove title bar
        self.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint)

        scroller.setupScrolling(self.month_combo.view())
        # Set the combobox view to scroll per pixel so the kinetic scrolling via touchscreen isnt ridiculously fast
        self.month_combo.view().setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
        # Disabling mouse tracking means that when you first use touchscreen to scroll through items, then it wont
        # select that item
        self.month_combo.view().setMouseTracking(False)
        for d in range(1, 13):
            self.month_combo.addItem(str(d))

        scroller.setupScrolling(self.day_combo.view())
        self.day_combo.view().setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
        self.day_combo.view().setMouseTracking(False)
        for d in range(1, 32):
            self.day_combo.addItem(str(d))

        scroller.setupScrolling(self.year_combo.view())
        self.year_combo.view().setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
        self.year_combo.view().setMouseTracking(False)
        year = datetime.now().year
        for y in range(year, year + constants.maxExpirationYear + 1):
            self.year_combo.addItem(str(y))

        scroller.setupScrolling(self.qty_combo.view())
        self.qty_combo.view().setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
        self.qty_combo.view().setMouseTracking(False)
        for q in range(1, 51):
            self.qty_combo.addItem(str(q))

        self.callbackFunction = None
        self.callbackParam = None

    @pyqtSlot()
    def showEvent(self, event):
        # Setup timer to regularly poll for new barcodes from scanners
        self.scannerPoll = QTimer()
        self.scannerPoll.timeout.connect(self.scannerPoll_ticked)
        self.scannerPoll.start(constants.scannerPollInterval)

        # Disconnect the function within centralWindow to handle barcode scanning and setup our own custom functions
        self.centralWindow.primaryScanner.barcodeReceived.connect(self.primaryScanner_barcodeReceived)
        self.centralWindow.secondaryScanner.barcodeReceived.connect(self.secondaryScanner_barcodeReceived)
        self.centralWindow.primaryScanner.barcodeReceived.disconnect(self.centralWindow.primaryScanner_barcodeReceived)
        self.centralWindow.secondaryScanner.barcodeReceived.disconnect(self.centralWindow.secondaryScanner_barcodeReceived)

    @pyqtSlot()
    def hideEvent(self, event):
        # Reconnect the function within centralWindow to handle barcode scanning and disconnect our custom functions
        self.centralWindow.primaryScanner.barcodeReceived.disconnect(self.primaryScanner_barcodeReceived)
        self.centralWindow.secondaryScanner.barcodeReceived.disconnect(self.secondaryScanner_barcodeReceived)
        self.centralWindow.primaryScanner.barcodeReceived.connect(self.centralWindow.primaryScanner_barcodeReceived)
        self.centralWindow.secondaryScanner.barcodeReceived.connect(self.centralWindow.secondaryScanner_barcodeReceived)

    @pyqtSlot()
    def scannerPoll_ticked(self):
        self.centralWindow.primaryScanner.poll()
        self.centralWindow.secondaryScanner.poll()

    @pyqtSlot(str)
    def primaryScanner_barcodeReceived(self, barcode):
        # Close this dialog box, indicate to parent what the callback function and parameter should be
        self.close()

        self.callbackFunction = self.centralWindow.primaryScanner_barcodeReceived
        self.callbackParam = barcode

    @pyqtSlot(str)
    def secondaryScanner_barcodeReceived(self, barcode):
        # Close this dialog box, indicate to parent what the callback function and parameter should be
        self.close()

        self.callbackFunction = self.centralWindow.secondaryScanner_barcodeReceived
        self.callbackParam = barcode

    @pyqtSlot(bool, bool)
    def on_accept_button_clicked(self, checked, longPressed):
        self.accept()

    @pyqtSlot(bool, bool)
    def on_cancel_button_clicked(self, checked, longPressed):
{'fraction_non_alphanumeric': 0.07819658475635152, 'fraction_numerical': 0.003956684714702207, 'mean_word_length': 3.75259772389906, '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': '6925227', 'n_tokens_mistral': 2781, 'n_tokens_neox': 2670, 'n_words': 534}