# Path: FabLabKasse/UI/GUIHelper.py
# def resize_table_columns(table, widths):
#     """resize Qt table columns by the weight factors specified in widths,
#     using the whole width (excluding scrollbar width)
#     """
#     w = table.width() - table.verticalScrollBar().width() - 5
#     for i, width in enumerate(widths):
#         table.setColumnWidth(i, int(width * w / sum(widths)))


import sys
import re
import locale
import logging
import datetime
import os
import functools
import scriptHelper
import importlib
        import rpdb2
from decimal import Decimal, DecimalException
from PyQt4 import QtGui, QtCore, Qt
from ConfigParser import Error as ConfigParserError
from libs.flickcharm import FlickCharm
from libs.pxss import pxss
from FabLabKasse.UI.GUIHelper import resize_table_columns
from UI.uic_generated.Kassenterminal import Ui_Kassenterminal
from UI.PaymentMethodDialogCode import PaymentMethodDialog
from UI.KeyboardDialogCode import KeyboardDialog
from cashPayment.client.PaymentDevicesManager import PaymentDevicesManager
from shopping.cart_from_app.cart_gui import MobileAppCartGUI
from shopping.backend.abstract import ProductNotFound, PrinterError

        # set "all products" button to bold if the root category is selected
        font = self.pushButton_start.font()
        font.setBold(len(category_path) == 0)
        self.pushButton_start.setFont(font)

        prod_model = QtGui.QStandardItemModel(len(products), 4)
        for i, p in enumerate(products):
            name = QtGui.QStandardItem(p.name)
            name.setData(p.prod_id)
            prod_model.setItem(i, 0, name)

            loc = QtGui.QStandardItem()
            loc.setText(p.location)
            prod_model.setItem(i, 1, loc)

            uos = QtGui.QStandardItem(p.unit)
            prod_model.setItem(i, 2, uos)

            price = QtGui.QStandardItem(self.shoppingBackend.format_money(p.price))
            prod_model.setItem(i, 3, price)

        prod_model.setHorizontalHeaderItem(0, QtGui.QStandardItem("Artikel"))
        prod_model.setHorizontalHeaderItem(1, QtGui.QStandardItem("Lagerort"))
        prod_model.setHorizontalHeaderItem(2, QtGui.QStandardItem("Einheit"))
        prod_model.setHorizontalHeaderItem(3, QtGui.QStandardItem("Einzelpreis"))

        self.table_products.setModel(prod_model)
        # Change column width to useful values
        # needs to be delayed so that resize events for the scrollbar happens first, otherwise it reports a scrollbar width of 100px at the very first call

# Path: FabLabKasse/UI/GUIHelper.py
# def resize_table_columns(table, widths):
#     """resize Qt table columns by the weight factors specified in widths,
#     using the whole width (excluding scrollbar width)
#     """
#     w = table.width() - table.verticalScrollBar().width() - 5
#     for i, width in enumerate(widths):
#         table.setColumnWidth(i, int(width * w / sum(widths)))


# Path: FabLabKasse/gui.py
import sys
import re
import locale
import logging
import datetime
import os
import functools
import scriptHelper
import importlib
        import rpdb2
from decimal import Decimal, DecimalException
from PyQt4 import QtGui, QtCore, Qt
from ConfigParser import Error as ConfigParserError
from libs.flickcharm import FlickCharm
from libs.pxss import pxss
from FabLabKasse.UI.GUIHelper import resize_table_columns
from UI.uic_generated.Kassenterminal import Ui_Kassenterminal
from UI.PaymentMethodDialogCode import PaymentMethodDialog
from UI.KeyboardDialogCode import KeyboardDialog
from cashPayment.client.PaymentDevicesManager import PaymentDevicesManager
from shopping.cart_from_app.cart_gui import MobileAppCartGUI
from shopping.backend.abstract import ProductNotFound, PrinterError


        # set "all products" button to bold if the root category is selected
        font = self.pushButton_start.font()
        font.setBold(len(category_path) == 0)
        self.pushButton_start.setFont(font)

        prod_model = QtGui.QStandardItemModel(len(products), 4)
        for i, p in enumerate(products):
            name = QtGui.QStandardItem(p.name)
            name.setData(p.prod_id)
            prod_model.setItem(i, 0, name)

            loc = QtGui.QStandardItem()
            loc.setText(p.location)
            prod_model.setItem(i, 1, loc)

            uos = QtGui.QStandardItem(p.unit)
            prod_model.setItem(i, 2, uos)

            price = QtGui.QStandardItem(self.shoppingBackend.format_money(p.price))
            prod_model.setItem(i, 3, price)

        prod_model.setHorizontalHeaderItem(0, QtGui.QStandardItem("Artikel"))
        prod_model.setHorizontalHeaderItem(1, QtGui.QStandardItem("Lagerort"))
        prod_model.setHorizontalHeaderItem(2, QtGui.QStandardItem("Einheit"))
        prod_model.setHorizontalHeaderItem(3, QtGui.QStandardItem("Einzelpreis"))

        self.table_products.setModel(prod_model)
        # Change column width to useful values
        # needs to be delayed so that resize events for the scrollbar happens first, otherwise it reports a scrollbar width of 100px at the very first call

        QtCore.QTimer.singleShot(0, functools.partial(resize_table_columns, self.table_products, [5, 2.5, 2, 1]))