<commit_before>import os
import sys
import time
import yaml
import logging
import logging.handlers
import queue
import datetime
import re
from fatsecret import Fatsecret
from PyQt5.QtCore import (QObject, QThread, pyqtSlot, pyqtSignal, Qt)
from PyQt5.QtWidgets import (QWidget, QLabel, QMessageBox, QListWidget,
                             QPushButton, QApplication, QTableWidget,
                             QGridLayout, QListWidgetItem, QTableWidgetItem,
                             QLineEdit)
from PyQt5.QtGui import (QIcon, QIntValidator)


class PiFoodScale(QWidget):
    config = {}
    fatsecret = None

    def __init__(self, config):
        self.config = config
        super().__init__()
        self.initUI()
        self.initWorkers()

    def initWorkers(self):

        self.currentFood = None
        self.currentServingAmount = None
        self.currentServingName = None
        self.currentServingId = None
        self.currentFoodEntry = None

        self.scaleThread = QThread()
        self.scaleReader = ReadScale(self.config)
        self.scaleReader.data[str].connect(self.onData)
        self.scaleReader.moveToThread(self.scaleThread)
        self.scaleThread.started.connect(self.scaleReader.run)
        self.scaleThread.start()

        self.connected = False
        self.fsThread = QThread()
        self.fatsecret = FatSecretApi(self.config)
        self.fatsecret.onLogin[dict].connect(self.onLogin)
        self.fatsecret.onEaten[dict].connect(self.onEaten)
        self.fatsecret.onEntries[dict].connect(self.onEntries)
        self.fatsecret.onFoodEntryCreate[dict].connect(self.onFoodEntryCreate)
        self.fatsecret.onFoodEntryDelete[dict].connect(self.onFoodEntryDelete)
        self.fatsecret.moveToThread(self.fsThread)
        self.fsThread.started.connect(self.fatsecret.run)
        self.fsThread.start()
        self.fatsecret.q.put({'func': 'login'})
        self.fatsecret.q.put({'func': 'get_entries',
                              'date': datetime.datetime.now()})

        self.txtAmount.textChanged.connect(self.onAmountChanged)

    def initUI(self):
        self.setStyleSheet('font-size: 12px')

        btnQuit = QPushButton('Quit', self)
        btnQuit.clicked.connect(self.close)

        self.btnAdd = QPushButton("Add", self)
        self.btnAdd.setEnabled(False)
        self.btnAdd.clicked.connect(self.doAdd)
        self.btnDel = QPushButton("Del", self)
        self.btnDel.setEnabled(False)
        self.btnDel.clicked.connect(self.doDel)

        self.lblScale = QLabel('Scale', self)
        self.lblScale.setStyleSheet('border: 1px solid black')

        self.listEaten = QListWidget()
        self.listEaten.setMinimumWidth(600)
        self.listEaten.setMaximumHeight(200)
        self.listEaten.setStyleSheet("font-size: 10px;")
        self.listEaten.itemClicked.connect(self.eatenClick)

        self.tableToday = QTableWidget()
        self.tableToday.setStyleSheet("font-size: 10px;")
        vh = self.tableToday.verticalHeader()
        vh.setDefaultSectionSize(vh.fontMetrics().height()+5)
        vh.setVisible(False)
        self.tableToday.setMinimumWidth(600)
        self.tableToday.itemClicked.connect(self.todayClick)

        self.txtAmount = QLineEdit('', self)
        self.txtAmount.setStyleSheet('border: 1px solid black')
        self.txtAmount.setMaximumWidth(100)
        self.txtAmount.setValidator(QIntValidator(1, 9999, self.txtAmount))
        self.lblName = QLabel('', self)
        self.lblServing = QLabel('', self)
        self.lblServingAmount = QLabel('', self)
        self.lblCalories = QLabel('', self)
        self.lblProtein = QLabel('', self)
        self.lblFat = QLabel('', self)
        self.lblCarbs = QLabel('', self)

        self.lblTCalories = QLabel('', self)
        self.lblTProtein = QLabel('', self)
        self.lblTFat = QLabel('', self)
        self.lblTCarbs = QLabel('', self)

        grid = QGridLayout()
        grid.setSpacing(1)
        # line 1 is the scale
        #   row, col, rowspan, colspan
        grid.addWidget(self.lblScale, 1, 1, 1, 5)
<commit_msg>resizing<commit_after>import os
import sys
import time
import yaml
import logging
import logging.handlers
import queue
import datetime
import re
from fatsecret import Fatsecret
from PyQt5.QtCore import (QObject, QThread, pyqtSlot, pyqtSignal, Qt)
from PyQt5.QtWidgets import (QWidget, QLabel, QMessageBox, QListWidget,
                             QPushButton, QApplication, QTableWidget,
                             QGridLayout, QListWidgetItem, QTableWidgetItem,
                             QLineEdit)
from PyQt5.QtGui import (QIcon, QIntValidator)


class PiFoodScale(QWidget):
    config = {}
    fatsecret = None

    def __init__(self, config):
        self.config = config
        super().__init__()
        self.initUI()
        self.initWorkers()

    def initWorkers(self):

        self.currentFood = None
        self.currentServingAmount = None
        self.currentServingName = None
        self.currentServingId = None
        self.currentFoodEntry = None

        self.scaleThread = QThread()
        self.scaleReader = ReadScale(self.config)
        self.scaleReader.data[str].connect(self.onData)
        self.scaleReader.moveToThread(self.scaleThread)
        self.scaleThread.started.connect(self.scaleReader.run)
        self.scaleThread.start()

        self.connected = False
        self.fsThread = QThread()
        self.fatsecret = FatSecretApi(self.config)
        self.fatsecret.onLogin[dict].connect(self.onLogin)
        self.fatsecret.onEaten[dict].connect(self.onEaten)
        self.fatsecret.onEntries[dict].connect(self.onEntries)
        self.fatsecret.onFoodEntryCreate[dict].connect(self.onFoodEntryCreate)
        self.fatsecret.onFoodEntryDelete[dict].connect(self.onFoodEntryDelete)
        self.fatsecret.moveToThread(self.fsThread)
        self.fsThread.started.connect(self.fatsecret.run)
        self.fsThread.start()
        self.fatsecret.q.put({'func': 'login'})
        self.fatsecret.q.put({'func': 'get_entries',
                              'date': datetime.datetime.now()})

        self.txtAmount.textChanged.connect(self.onAmountChanged)

    def initUI(self):
        self.setStyleSheet('font-size: 12px')

        btnQuit = QPushButton('Quit', self)
        btnQuit.clicked.connect(self.close)

        self.btnAdd = QPushButton("Add", self)
        self.btnAdd.setEnabled(False)
        self.btnAdd.clicked.connect(self.doAdd)
        self.btnDel = QPushButton("Del", self)
        self.btnDel.setEnabled(False)
        self.btnDel.clicked.connect(self.doDel)

        self.lblScale = QLabel('Scale', self)
        self.lblScale.setStyleSheet('border: 1px solid black')

        self.listEaten = QListWidget()
        self.listEaten.setMinimumWidth(600)
        self.listEaten.setMaximumHeight(200)
        self.listEaten.setStyleSheet("font-size: 10px;")
        self.listEaten.itemClicked.connect(self.eatenClick)

        self.tableToday = QTableWidget()
        self.tableToday.setStyleSheet("font-size: 10px;")
        vh = self.tableToday.verticalHeader()
        vh.setDefaultSectionSize(12)
        vh.setVisible(False)
        self.tableToday.setMinimumWidth(600)
        self.tableToday.itemClicked.connect(self.todayClick)

        self.txtAmount = QLineEdit('', self)
        self.txtAmount.setStyleSheet('border: 1px solid black')
        self.txtAmount.setMaximumWidth(100)
        self.txtAmount.setValidator(QIntValidator(1, 9999, self.txtAmount))
        self.lblName = QLabel('', self)
        self.lblServing = QLabel('', self)
        self.lblServingAmount = QLabel('', self)
        self.lblCalories = QLabel('', self)
        self.lblProtein = QLabel('', self)
        self.lblFat = QLabel('', self)
        self.lblCarbs = QLabel('', self)

        self.lblTCalories = QLabel('', self)
        self.lblTProtein = QLabel('', self)
        self.lblTFat = QLabel('', self)
        self.lblTCarbs = QLabel('', self)

        grid = QGridLayout()
        grid.setSpacing(1)
        # line 1 is the scale
        #   row, col, rowspan, colspan
        grid.addWidget(self.lblScale, 1, 1, 1, 5)

{'fraction_non_alphanumeric': 0.11245717082721488, 'fraction_numerical': 0.008688203622124326, 'mean_word_length': 2.6437806509139543, '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': '1820572', 'n_tokens_mistral': 2620, 'n_tokens_neox': 2469, 'n_words': 412}