On Tue, 18 Oct 2016, 5:51 AM likage <[email protected]> wrote: > Hi Justin, thanks for the feedback. > So I tried doing the following.. > > ### UI File, manager_ui.py ### > > import functools > import manager_main > > class manager_ui(QtGui.QDialog): > def __init__(self, parent=None): > QtGui.QDialog.__init__(self, parent) > self.setWindowTitle('UI Manager') > > > # Build the GUI > self.init_ui() > self.populate_table_data() > self.connect_signals() > self.resize(QtCore.QSize(600, 350)) > > def init_ui(self): > self.color_table = QtGui.QTableWidget() > self.color_table.setRowCount(5) > self.color_table.setColumnCount(2) > self.color_table.setHorizontalHeaderLabels(['Geos in Scene', > 'Colors']) > self.set_color_btn = QPushButton() > ... > > def connect_signals(self): > > #self.reset_colors_btn.clicked.connect(self.reset_color) > self.reset_colors_btn.clicked.connect(functools.partial( > manager_main.reset_color, self.color_table)) > > ''' > # Function is to be called in the main file > > def reset_color(self): > for row in xrange(self.variant_table.rowCount()): > self.color_table.cellWidget(row, 1).setCurrentIndex(0) > ''' > > def populate_data(self): > ... > self.color_combobox = QtGui.QComboBox() > self.color_combobox.addItems(list(sorted(new_itempath))) > self.color_table.setCellWidget(index, 1, self.color_combobox) > > > And this is my main file: > ### Main File, manager_main.py ### > > def reset_color(table): > for row in xrange(table.rowCount()): > table.cellWidget(row, 1).setCurrentIndex(0) > > > While it seems to work, can I check with you if this is the correct > approach to go about? >
Well it's actually backwards from what I was thinking. But that might just be the names of your modules throwing me off because I don't really know what the full contents of manager_main will be. If you expect manager_main to also import manager_ui then you have circular dependencies and that would be undesirable. My thought was that your UI would not connect up the external signals, because it shouldn't know about the outside world that will consume it. It can wire up its own internal signals though, to its own slots. I was thinking manager_main would hook up the signals to its own slots when it creates an instance of the UI. What you can do is hide the details of your UI class by not having outside users access the composed widgets, and just exposing signals and function that you want users to call. An example of forwarding a signal can be class Ui(QDialog) resetRequested = QtCore.Signal() def __init__(...) : self.reset_colors_btn.clicked.connect(self.resetRequested) I know in this case your main will need to access the table widgets, and that is OK since you specifically wanted a small amount of coupling and just a separation of the UI and business logic. Justin > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/0fe1980d-d9b5-436f-aa11-8174ac8b38f1%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/0fe1980d-d9b5-436f-aa11-8174ac8b38f1%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2oX46VLKVywjKW5x0p1DkWJVFcAuvTDZ7tTHtc6sqksw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
