for widget in self.widgetwidgets.values():
Don't be afraid to group everything! Continuing from points 2. and 3., it doesn't hurt to group widgets several times. If you get to the stage when you have a dozen buttons, a few more lineEdits etc, make groups for each of these structureswidget types.
self.widgets = {'deleteButton': self.deleteButton ...} self.buttons = {'delete': self.deleteButton, 'save': self.saveButton ...} self.lineEdits = {'password': self.passwordLineEdit ...}
for widget in self.widget.values():
Don't be afraid to group everything! Continuing from points 2. and 3., it doesn't hurt to group widgets several times. If you get to the stage when you have a dozen buttons, a few more lineEdits etc, make groups for each of these structures.
self.widgets = {'deleteButton': self.deleteButton ...} self.buttons = {'delete': self.deleteButton, 'save': self.saveButton ...} self.lineEdits = {'password': self.passwordLineEdit ...}
for widget in self.widgets.values():
Don't be afraid to group everything! Continuing from points 2. and 3., it doesn't hurt to group widgets several times. If you get to the stage when you have a dozen buttons, a few more lineEdits etc, make groups for each of these widget types.
self.widgets = {'deleteButton': self.deleteButton ...} self.buttons = {'delete': self.deleteButton, 'save': self.saveButton ...} self.lineEdits = {'password': self.passwordLineEdit ...}
My PySide is a bit rusty but I can't see anything immediately wrong with your structure. I have noticed a few places you could modify to make the code more readable/easier to manage though.
You've manually padded some strings to center them in widgets, don't push buttons center text automatically? If not you should be able to do something like
button.setStyleSheet("Text-align:center")
If that doesn't work, python strings can be padded using format()
. To pad "New Cycle List" with spaces to 42 characters use:
'{: ^42}'.format('New Cycle List')
See here in the documentation.
In
ExportBar.__init__
, perhaps group your widgets in a dictionary rather than a list. At the moment, you have to refer back to__init__
to see which widget the following code refers to:self.widgets[-1].clicked.connect(self.deleteWidget)
Whereas if self.widgets
was a dictionary, it would be clearer:
self.widgets['deleteButton'].clicked.connect(self.deleteWidget)
Of course one drawback is you'll need to iterate through the widgets with
for widget in self.widget.values():
Are you using an IDE which supports tab completion? If you are, make life easier for yourself by initialising widgets to stored variables before grouping them:
self.deleteButton = QtGui.QPushButton("Del") self.exportButton = QtGui.QPushButton({: ^30}.format("Export")) ... self.widgets = { 'deleteButton': self.deleteButton, 'exportButton': self.exportButton, ... }
In IDEs I've used, tab completion usually fails when accessing an element in a structure. (ie. ['one', 'two'][0].upp
+ TAB usually doesn't find upper()
). Having direct access to widgets in addition to grouping for iteration is handy in this regard.
It's generally bad form to initialise/call a potentially mutable object in definitions as you have done in the following:
class AnimationCycleSplitter(QtGui.QWidget): def __init__(self, parent=mayaMainWindow()):
Instead do:
def __init__(self, parent=None):
if parent is None:
parent = mayaMainWindow()
See here if you're unsure why.
Don't be afraid to group everything! Continuing from points 2. and 3., it doesn't hurt to group widgets several times. If you get to the stage when you have a dozen buttons, a few more lineEdits etc, make groups for each of these structures.
self.widgets = {'deleteButton': self.deleteButton ...} self.buttons = {'delete': self.deleteButton, 'save': self.saveButton ...} self.lineEdits = {'password': self.passwordLineEdit ...}
Summary
In my experience, when using PySide it helps to write everything as verbosely and clearly as possible. Use dictionaries with meaningful keys to group widgets and make sure your code allows tab completion to work!