presik_pos/app/buttonpad.py

179 lines
5.9 KiB
Python

import os
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QGridLayout, QHBoxLayout, QStackedWidget
from neox.commons.custom_button import CustomButton
from .common import get_icon
DIR_SHARE = os.path.abspath(os.path.normpath(os.path.join(__file__,
'..', '..', 'share')))
__all__ = ['ButtonsFunction', 'ButtonsStacked', 'ButtonsNumber']
def factoryIcons():
pass
factoryIcons()
class ButtonsFunction(QGridLayout):
# Function Numpad
def __init__(self, parent, tablet_mode=False):
super(ButtonsFunction, self).__init__()
self.setHorizontalSpacing(1)
self.setVerticalSpacing(1)
rows = 4
columns = 3
self.values = [
['button_search_product', self.tr('SEARCH'), 'action_search_product'],
]
salesman_desc = self.tr('SALESMAN')
salesman_button = 'button_salesman'
if parent.enviroment == 'restaurant':
salesman_desc = self.tr('WAITER')
salesman_button = 'button_waiter'
self.values.extend([
['button_party', self.tr('CUSTOMER'), 'action_party'],
['button_cancel', self.tr('CANCEL'), 'action_cancel'],
['button_search_sale', self.tr('S. SALE'), 'action_search_sale'],
['button_print_sale', self.tr('PRINT'), 'action_print_sale'],
[salesman_button, salesman_desc, 'action_salesman'],
['button_global_discount', self.tr('GLOBAL DISCOUNT'), 'action_global_discount'],
['button_print_order', self.tr('ORDER'), 'action_print_order']
])
if parent.type_pos_user != 'cashier':
self.values.append(
['button_new_sale', self.tr('NEW SALE'), 'action_new_sale'])
if parent.type_pos_user != 'order':
self.values.append(['button_payment', self.tr('PAY MODE'), 'action_payment'])
if parent.enviroment == 'retail':
self.values.append([
'button_payment_term', self.tr('PAY TERM'), 'action_payment_term']
)
if parent.enviroment == 'restaurant':
rows = 3
columns = 5
self.values.extend([
['button_position', self.tr('POSITION'), 'action_position'],
# ['button_delete_line', self.tr('DELETE'), 'action_delete_line'],
['button_comment', self.tr('NOTE'), 'action_comment'],
])
if parent.enviroment == 'restaurant':
self.values.extend([
['button_tip', self.tr('TIP'), 'action_tip'],
['button_tables', self.tr('TABLES'), 'action_tables'],
['button_reservations', self.tr('RESERVATIONS'), 'action_reservations'],
])
positions = [(i, j) for i in range(rows) for j in range(columns)]
for position, value in zip(positions, self.values):
name_icon = value[0][7:]
button = CustomButton(
parent,
id=value[0],
icon=get_icon(name_icon),
desc=value[1],
method=value[2],
name_style='toolbar_button'
)
self.addWidget(button, *position)
class ButtonsStacked(QHBoxLayout):
def __init__(self, parent):
super(ButtonsStacked, self).__init__()
self.stacked = QStackedWidget()
self.button_accept = CustomButton(
id='button_accept',
parent=parent,
icon=get_icon('accept'),
name_style='toolbar',
method='button_accept_pressed'
)
self.button_cash = CustomButton(
id='button_cash',
parent=parent,
icon=get_icon('cash'),
name_style='toolbar',
method='button_cash_pressed'
)
if parent.type_pos_user != 'order' and not parent.tablet_mode:
self.stacked.addWidget(self.button_accept)
self.stacked.addWidget(self.button_cash)
self.addWidget(self.stacked, 0)
if parent.type_pos_user == 'cashier':
self.button_to_draft = CustomButton(
id='button_to_draft',
parent=parent,
icon=get_icon('draft'),
name_style='toolbar',
method='button_to_draft_pressed'
)
self.addWidget(self.button_to_draft, 0)
else:
self.button_plus = CustomButton(
id='button_plus',
parent=parent,
icon=get_icon('plus'),
method='button_plus_pressed',
name_style='toolbar',
)
#self.addWidget(self.button_plus, 0)
if parent.type_pos_user == 'order' or parent.type_pos_user == 'salesman':
self.button_send_order = CustomButton(
id='button_send_to_pay',
icon=get_icon('draft'),
parent=parent,
method='button_send_to_pay_pressed',
name_style='toolbar'
)
self.addWidget(self.button_send_order, 0)
class ButtonsNumber(QGridLayout):
def __init__(self, parent):
# Numpad for Numbers
super(ButtonsNumber, self).__init__()
self.setHorizontalSpacing(1)
self.setVerticalSpacing(1)
class Buttonpad(QWidget):
def __init__(self, parent):
super(Buttonpad, self).__init__()
self._text = ''
self._keyStates = {}
self.functions = ButtonsFunction(parent)
if parent.tablet_mode:
self.numbers = ButtonsNumber(parent)
self.stacked = ButtonsStacked(parent)
self.set_keys()
def set_keys(self):
q = Qt
self.keys_numbers = list(range(q.Key_0, q.Key_9 + 1))
self.keys_alpha = list(range(q.Key_A, q.Key_Z + 1))
self.keys_special = [
q.Key_Asterisk, q.Key_Comma, q.Key_Period,
q.Key_Minus, q.Key_Slash]
self.show_keys = self.keys_numbers + self.keys_alpha + self.keys_special