I've been trying to make my classes completely self contained, but I'm having some problems, which are probably coming from my missing something that everybody else knew first off...
Anyway, take this example:
class Main_Window (QtGui.QMainWindow):
def __init__ (self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_bookingSystemMain()
self.ui.setupUi(self)
# Connect slots
QtCore.QObject.connect(self.ui.submitRecord, QtCore.SIGNAL("clicked()"), self.__clickSubmitRecord)
QtCore.QObject.connect(self.ui.btnListBookings, QtCore.SIGNAL("clicked()"), self.__show_list)
def __clickSubmitRecord (self):
global bookings
name = self.ui.edtName.text()
event = str(self.ui.comEvent.currentText())
amount = self.ui.spinBox.value()
if name == '':
QtGui.QMessageBox.warning(self, "Error", "Please enter a name!")
elif amount == 0:
QtGui.QMessageBox.warning(self, "Error", "You can't reserve 0 tickets!")
elif event == '':
QtGui.QMessageBox.warning(self, "Error", "Please choose an event!")
else:
bookings.append(Booking(name, event, amount))
QtGui.QMessageBox.information(self, "Booking added", "Your booking for " + str(amount) + " ticket(s) to see " + event + " in the name of " + name + " was sucessful.")
self.__clear_widgets()
def __clear_widgets (self):
self.ui.edtName.clear()
self.ui.comEvent.setCurrentIndex(-1)
self.ui.spinBox.setValue(0)
def __show_list (self):
listdialog = List_Window(self)
listdialog.show()
Which implements a UI described in another module. The clickSubmitRecord() method uses the global 'booking' list and adds to it - now surely this class shouldn't have anything to do with anything other than that UI?
How would I implement this in a good ood way? As I said I'm probably missing some kind of technique or obvious design feature...
Thanks!