See the proposed changes in this Pull Request under def add_talk
.
date = self.talkDetailsWidget.dateEdit.date()
time = self.talkDetailsWidget.timeEdit.time()
presentation = Presentation(
unicode(self.talkDetailsWidget.titleLineEdit.text()).strip(),
unicode(self.talkDetailsWidget.presenterLineEdit.text()).strip(),
unicode(self.talkDetailsWidget.descriptionTextEdit.toPlainText()).strip(),
unicode(self.talkDetailsWidget.categoryLineEdit.text()).strip(),
unicode(self.talkDetailsWidget.eventLineEdit.text()).strip(),
unicode(self.talkDetailsWidget.roomLineEdit.text()).strip(),
unicode(date.toString(Qt.ISODate)),
unicode(time.toString(Qt.ISODate)))
There's a lot of boilerplate code (e.g. unicode()
, seld.talkDetailsWidget
, text()
, strip()
, etc.) How could you reduce that and still have the code be easy to understand?
My thinking is if something along the lines of this were possible:
map(str.strip,
map(unicode,
map(QLineEdit.text,
map(self.talkDetailsWidget, fields))))
functools.singledispatch
to create an overload ofPresentation.__init__
taking aTalkDetailsWidget
parameter. – Morwenn Mar 25 '14 at 10:27