This repository has been archived by the owner on Dec 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_form.py
executable file
·66 lines (56 loc) · 2.29 KB
/
view_form.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
# * coding: utf8 *
from PySide import QtGui, QtCore
import controller
from form import Ui_Form
class Form(QtGui.QDialog):
def __init__(self, parent=None, name=None):
QtGui.QDialog.__init__(self, parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
brands = controller.get_brands()
for brand in brands:
self.ui.brand.addItem(brand["name"], brand["id_brand"])
if name is None:
self.ui.btn_add.clicked.connect(self.add)
else:
self.setWindowTitle(u"Editar producto")
self.name = name
product_data = controller.get_product(name)
self.ui.name.setText(product_data["prod"])
self.ui.desc.setText(product_data["description"])
self.ui.color.setText(product_data["color"])
self.ui.price.setValue(product_data["price"])
self.ui.brand.currentText()
self.ui.btn_add.clicked.connect(self.edit)
self.ui.btn_cancel.clicked.connect(self.cancel)
def add(self):
#Take the values from the ui form and add the new product
name = self.ui.name.text()
description = self.ui.desc.text()
color = self.ui.color.text()
price = self.ui.price.value()
brand = self.ui.brand.currentText()
id_brand = controller.get_id_brand(brand)
result = controller.add_product(name, description, color, price, id_brand)
if result:
self.reject()
else:
self.ui.message.setText("Hubo un problema al intentar agregar el producto")
def edit(self):
#Take the values form a product, then save the edited values
id_product = controller.get_id_product(self.name)
name = self.ui.name.text()
description = self.ui.desc.text()
color = self.ui.color.text()
price = self.ui.price.value()
brand = self.ui.brand.currentText()
id_brand = controller.get_id_brand(brand)
result = controller.edit_product(id_product, name, description, color, price, id_brand)
if result:
self.reject()
else:
self.ui.message.setText("Hubo un problema al intentar editar el producto")
def cancel(self):
#Cancel the operation on the ui form
self.reject()