# We need an application to get things done. app = QApplication(sys.argv) # Define a controller that encapsulates handling of two UI components that # are closely linked together. class UiController: pass # Create two UI widgets spinner = QSpinBox() line_edit = QLineEdit() # Create controller and update the instance with new property and functions. ctrl = UiController() add_traits(ctrl, line_edit.text, line_edit.setText) setproperty(ctrl, spinner.value, spinner.setValue, name="answer") # Then modify the widgets through the controller. ctrl.answer = 42 ctrl.setText("Life, Universe...") # And here's the proof that properties and functions are working and they # modify correct widgets. assert ctrl.answer == 42, "Spinner property is unaware of the answer!" assert ctrl.text( ) == "Life, Universe...", "Text property is unaware of nature of the answer!" assert ctrl.answer == spinner.value( ), "UiController and QSpinBox widget are not communicating!" assert ctrl.text() == line_edit.text( ), "UiController and QLineEdit widget are not communicating!" except ImportError:
# We need an application to get things done. app = QApplication(sys.argv) # Define a controller that encapsulates handling of two UI components that # are closely linked together. class UiController: pass # Create two UI widgets spinner = QSpinBox() line_edit = QLineEdit() # Update controller by adding functions and property from builtin components. add_traits(UiController, line_edit.text, line_edit.setText) setproperty(UiController, spinner.value, spinner.setValue, name="answer") # Create controller ctrl = UiController() ctrl.answer = 42 ctrl.setText("Life, Universe...") # And here's the proof that properties and functions are working and they # modify correct widgets. assert ctrl.answer == 42, "Spinner property is unaware of the answer!" assert ctrl.text() == "Life, Universe...", "Text property is unaware of nature of the answer!" assert ctrl.answer == spinner.value(), "UiController and QSpinBox widget are not communicating!" assert ctrl.text() == line_edit.text(), "UiController and QLineEdit widget are not communicating!" except ImportError: pass # Skipping since PyQt is not available
return self.public, self._hidden, self.__private def del_all(self): self.public, self._hidden, self.__private = (42, 43, 44) # Create new instances for each situation example1 = ExampleClass() example2 = ExampleClass() example3 = ExampleClass() example4 = ExampleClass() # Use functions from class setproperty(example1, ExampleClass.get_all, ExampleClass.set_all, ExampleClass.del_all, name="all") # Create property using functions from other instance setproperty(example2, example1.get_all, example1.set_all, example1.del_all, name="all") # Create property for current instance setproperty(example3, "get_all", "set_all", name="all") # Create property referring functions in other instance setproperty(example4, "get_all", "set_all", "del_all", example1, name="all")
# We need an application to get things done. app = QApplication(sys.argv) # Define a controller that encapsulates handling of two UI components that # are closely linked together. class UiController: pass # Create two UI widgets spinner = QSpinBox() line_edit = QLineEdit() # Update controller by adding functions and property from builtin components. add_traits(UiController, line_edit.text, line_edit.setText) setproperty(UiController, spinner.value, spinner.setValue, name="answer") # Create controller ctrl = UiController() ctrl.answer = 42 ctrl.setText("Life, Universe...") # And here's the proof that properties and functions are working and they # modify correct widgets. assert ctrl.answer == 42, "Spinner property is unaware of the answer!" assert ctrl.text( ) == "Life, Universe...", "Text property is unaware of nature of the answer!" assert ctrl.answer == spinner.value( ), "UiController and QSpinBox widget are not communicating!" assert ctrl.text() == line_edit.text( ), "UiController and QLineEdit widget are not communicating!"
# We need an application to get things done. app = QApplication(sys.argv) # Define a controller that encapsulates handling of two UI components that # are closely linked together. class UiController: pass # Create two UI widgets spinner = QSpinBox() line_edit = QLineEdit() # Create controller and update the instance with new property and functions. ctrl = UiController() add_traits(ctrl, line_edit.text, line_edit.setText) setproperty(ctrl, spinner.value, spinner.setValue, name="answer") # Then modify the widgets through the controller. ctrl.answer = 42 ctrl.setText("Life, Universe...") # And here's the proof that properties and functions are working and they # modify correct widgets. assert ctrl.answer == 42, "Spinner property is unaware of the answer!" assert ctrl.text() == "Life, Universe...", "Text property is unaware of nature of the answer!" assert ctrl.answer == spinner.value(), "UiController and QSpinBox widget are not communicating!" assert ctrl.text() == line_edit.text(), "UiController and QLineEdit widget are not communicating!" except ImportError: pass # Skipping since PyQt is not available