def __init__(self, lis, form, title="", parent=None): self.title = title self.lis = lis self.form = form self.widget = QtWidgets.QWidget(parent) # create a new widget self.lay = QtWidgets.QVBoxLayout( self.widget) # attach layout to that widget self.label = QtWidgets.QLabel(self.title, self.widget) self.subwidget = QtWidgets.QWidget(self.widget) self.sublay = QtWidgets.QHBoxLayout(self.subwidget) self.lay.addWidget(self.label) self.lay.addWidget(self.subwidget) self.lis.widget.setParent( self.subwidget ) # get widget from List and set its parent to widget self.form.widget.setParent(self.subwidget) self.sublay.addWidget( self.lis.widget) # add List's internal widget to widget's layout self.sublay.addWidget(self.form.widget) self.lis.widget.currentItemChanged.connect( self.form.chooseForm_slot) # connections between list and the form self.form.signals.new_record.connect(self.lis.update_slot) self.form.signals.save_record.connect(self.lis.update_slot) self.form.signals.delete_record.connect(self.lis.update_slot) self.delete = self.form.signals.delete_record # shorthand self.modified = self.form.signals.modified
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 800, 800)) self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) self.lay = QtWidgets.QHBoxLayout(self.w) # Create a list self.lis = self.data_model.PersonList( collection=self.data_model.collection) # Get lists's widget self.lis.widget.setParent(self.w) # Add to main layout self.lay.addWidget(self.lis.widget) # Create a group of forms self.formset = EditFormSet(collection=self.data_model.collection) # Get form's widget and set it's parent to the current main widget self.formset.widget.setParent(self.w) # Add formset to layout self.lay.addWidget(self.formset.widget) # Inform formset about the item in question. "self.lis.widget" is a QListWidget instance. self.lis.widget.currentItemChanged.connect( self.formset.chooseForm_slot) # inform list when a new record has been added or when a record has been saved self.formset.signals.new_record.connect(self.lis.update_slot) self.formset.signals.save_record.connect(self.lis.update_slot)
def setupUi(self): # self.setGeometry(QtCore.QRect(100,100,800,800)) self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) self.lay = QtWidgets.QHBoxLayout(self.w) self.person_view = ListAndForm( self.data_model.PersonList(collection=self.data_model.collection), EditFormSet(collection=self.data_model.collection), "Persons", self.w) self.food_view = ListAndForm( self.data_model.FoodList( collection=self.data_model.food_collection), EditFormSet(collection=self.data_model.food_collection), "Foods", self.w) self.food_view.modified.connect(self.person_view.update) # instantiate PersonFormSet => instantiate rows => row instantiates widgets based on the columns => .. # updating: call row's updateWidget method => re-creates column widgets self.lay.addWidget(self.person_view.widget) self.lay.addWidget(self.food_view.widget) # self.data_model.dump() self.data_model.purge()
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 800, 800)) self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) self.lay = QtWidgets.QHBoxLayout(self.w) # Create a list self.lis = PersonList(collection=collection) # Get lists's widget self.lis.widget.setParent(self.w) # Add to main layout self.lay.addWidget(self.lis.widget) # Create a group of forms self.formset = FormSet(collection=collection) # Get form's widget. It encapsulates the form widgets of each row type self.formset.widget.setParent(self.w) # Add formset to layout self.lay.addWidget(self.formset.widget) # Inform formset about the item in question self.lis.widget.currentItemChanged.connect( self.formset.chooseForm_slot)
def makeWidget(self): self.widget = QtWidgets.QWidget() self.lay = QtWidgets.QVBoxLayout(self.widget) self.makeForm() # from mother class self.lay.insertWidget(0, self.form) self.row_dialog = RowDialog(self.row_instance_by_name.keys()) self.makeButtons() self.lay.insertWidget(1, self.buttons)
def makeForm(self): self.makeRows() self.form = QtWidgets.QWidget(self.widget) self.form.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.form_lay = QtWidgets.QVBoxLayout(self.form) for key, row in self.row_instance_by_name.items(): if (row.widget): row.widget.setParent(self.form) self.form_lay.addWidget(row.widget)
def makeWidget(self): self.widget = QtWidgets.QWidget() self.lay = QtWidgets.QHBoxLayout(self.widget) self.line = QtWidgets.QLineEdit(self.widget) self.line.setReadOnly(True) self.button = QtWidgets.QPushButton("Choose", self.widget) self.lay.addWidget(self.line) self.lay.addWidget(self.button) self.button.clicked.connect(self.open_dialog_slot)
def __init__(self, maintitle, lis1, lis2, form, titles=["", "", ""], parent=None): self.maintitle = maintitle self.lis1 = lis1 self.lis2 = lis2 self.form = form self.titles = titles self.parent = parent self.widget = QtWidgets.QWidget(parent) # create a new widget self.lay = QtWidgets.QHBoxLayout( self.widget) # attach layout to that widget # create three subwidgets self.sections = [] self.layouts = [] self.labels = [] for i in range(0, 3): self.sections.append(QtWidgets.QWidget( self.widget)) # create a widget self.layouts.append(QtWidgets.QVBoxLayout( self.sections[-1])) # .. create a layout to that widget self.labels.append(QtWidgets.QLabel( titles[i], self.sections[-1])) # add a QLabel to the widget self.layouts[-1].addWidget( self.labels[-1]) # add the QLabel to widget's layout self.lay.addWidget( self.sections[-1]) # add the widget to main layout self.lis1.widget.setParent(self.sections[0]) self.layouts[0].addWidget(self.lis1.widget) self.lis2.widget.setParent(self.sections[1]) self.layouts[1].addWidget(self.lis2.widget) self.form.widget.setParent(self.sections[2]) self.layouts[2].addWidget(self.form.widget) # Connect the user/car pair to the permission form self.lis1.widget.currentItemChanged.connect( self.form.chooseRecord1_slot ) # inform form about the item in question self.lis2.widget.currentItemChanged.connect( self.form.chooseRecord2_slot ) # inform form about the item in question
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 800, 800)) self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) self.lay = QtWidgets.QHBoxLayout(self.w) # Create a list view of a collection. We need to provide a collection, of course self.lis = PersonList(collection=collection) # Get lists's widget, set its parent to the current main widget self.lis.widget.setParent(self.w) # Add to main layout self.lay.addWidget(self.lis.widget)
def makeButtons(self): self.buttons = QtWidgets.QWidget(self.widget) self.buttons_lay = QtWidgets.QHBoxLayout(self.buttons) self.save_button = QtWidgets.QPushButton("SAVE", self.buttons) self.clear_button = QtWidgets.QPushButton("CLEAR", self.buttons) self.save_button.clicked.connect(self.save_slot) self.clear_button.clicked.connect(self.clear_slot) self.buttons_lay.addWidget(self.save_button) self.buttons_lay.addWidget(self.clear_button) self.signals.save_record.connect(self.signals.modified.emit)
def setupUi(self): # self.setGeometry(QtCore.QRect(100,100,800,800)) self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) self.lay = QtWidgets.QHBoxLayout(self.w) # List view of person_collection self.person_lis = PersonList(collection=person_collection) self.person_lis.widget.setParent(self.w) self.lay.addWidget(self.person_lis.widget) # Form views of individual records in the person_collection self.person_form = FormSet(collection=person_collection) self.person_form.widget.setParent(self.w) self.lay.addWidget(self.person_form.widget) # List view of car_collection self.car_lis = CarList(collection=car_collection) self.car_lis.widget.setParent(self.w) self.lay.addWidget(self.car_lis.widget) # Form view of records in car_collection self.car_form = FormSet(collection=car_collection) self.car_form.widget.setParent(self.w) self.lay.addWidget(self.car_form.widget) # Form view of the Link table self.permission_form = PermissionFormSet(collection=link_collection, key1_name="user_key", key2_name="car_key") self.permission_form.widget.setParent(self.w) self.lay.addWidget(self.permission_form.widget) # Create connections between list views, forms, etc. self.person_lis.widget.currentItemChanged.connect( self.person_form.chooseForm_slot ) # inform person formset about the item in question self.car_lis.widget.currentItemChanged.connect( self.car_form.chooseForm_slot ) # inform car formset about the item in question # Connect the user/car pair to the permission form self.person_lis.widget.currentItemChanged.connect( self.permission_form.chooseRecord1_slot ) # inform formset about the item in question self.car_lis.widget.currentItemChanged.connect( self.permission_form.chooseRecord2_slot ) # inform formset about the item in question
def updateWidget(self): self.widget.clear() self.items = [] it = self.collection.get() for i, item in enumerate(it): el = QtWidgets.QListWidgetItem() el.setText(item[self.foreign_label_name]) el.key = item[self.foreign_key_name] # attach an extra attribute self.widget.addItem(el) self.items.append(el)
def makeWidget(self): self.widget = QtWidgets.QWidget() self.lay = QtWidgets.QVBoxLayout(self.widget) self.makeForm() # from mother class self.dropdown_widget = QtWidgets.QComboBox(self.widget) self.row_instance_by_index = [] for i, key in enumerate(self.row_instance_by_name.keys()): row_instance = self.row_instance_by_name[key] self.row_instance_by_index.append(row_instance) classname = key display_name = row_instance.getName() self.dropdown_widget.insertItem(i, display_name) self.dropdown_widget.currentIndexChanged.connect( self.dropdown_changed_slot) self.lay.insertWidget(0, self.dropdown_widget) self.lay.insertWidget(1, self.form) self.makeButtons() self.lay.insertWidget(2, self.buttons)
def placeWidget(self, i, key_name): """Place column widget to line i """ column = self[key_name] labelname = column.label_name label = QtWidgets.QLabel(labelname, self.widget) column.widget.setParent(self.widget) self.qlabel_by_name[column.key_name] = label # add to the layout self.lay.addWidget(label, i, 0) self.lay.addWidget(column.widget, i, 1)
def makeWidget(self): """Creates a Qt form, using the column structure """ self.widget = QtWidgets.QWidget() self.lay = QtWidgets.QGridLayout(self.widget) """ for key in self.column_by_name: print(self.pre,"makeWidget: >>",key) """ """ policy = QtWidgets.QSizePolicy() policy.setVerticalPolicy(QtWidgets.QSizePolicy.Minimum) """ for i, column in enumerate(self.columns_): if (column.widget is not None): #""" labelname = column.label_name label = QtWidgets.QLabel(labelname, self.widget) self.qlabel_by_name[column.key_name] = label if column.label_alignment is not None: label.setAlignment(column.label_alignment) if column.label_size_policy is not None: label.setSizePolicy(column.label_size_policy) # label.setAlignment(QtCore.Qt.AlignTop) # label.setSizePolicy(policy) column.widget.setParent(self.widget) # add to the layout self.lay.addWidget(label, i, 0) self.lay.addWidget(column.widget, i, 1) #""" # self.placeWidget(i, column.key_name) # print(self.pre,"makeWidget :",labelname,label,column.widget) # print("column visible", column.visible, column.label_name) if column.visible == False: qlabel.setVisible(False) column.widget.setVisible(False) self.connectNotifications()
def __init__(self, typenames, title="", parent=None): super().__init__(parent) self.setWindowTitle(title) self.layout = QtWidgets.QVBoxLayout(self) self.qlis = QtWidgets.QListWidget(self) self.create = QtWidgets.QPushButton("Create", self) self.cancel = QtWidgets.QPushButton("Cancel", self) self.layout.addWidget(self.qlis) self.layout.addWidget(self.create) self.layout.addWidget(self.cancel) for typename in typenames: item = QtWidgets.QListWidgetItem() item.setText(typename) item.typename = typename self.qlis.addItem(item) self.create.clicked.connect(lambda: self.done(1)) self.cancel.clicked.connect(lambda: self.reject()) self.clear()
def makeWidget(self): self.widget = QtWidgets.QWidget() # self.widget.setAlignment(QtCore.Qt.AlignTop) # nopes self.sublay = QtWidgets.QVBoxLayout(self.widget) self.sublay.setAlignment(QtCore.Qt.AlignTop) lis = self.getList() self.radio_buttons_by_value = {} # policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) policy = QtWidgets.QSizePolicy() policy.setVerticalPolicy(QtWidgets.QSizePolicy.Minimum) # policy.setVerticalPolicy(QtWidgets.QSizePolicy.ShrinkFlag) self.widget.setSizePolicy(policy) # self.widget.setMaximumHeight(40) for i, (label, value) in enumerate(lis): # print("ConstantRadioButtonColumn: makeWidget: label, value>", label, value) rb = QtWidgets.QRadioButton(label, self.widget) # rb = QtWidgets.QLabel("test") rb.setSizePolicy(policy) self.radio_buttons_by_value[value] = rb self.sublay.addWidget(rb) self.updateWidget()
def makeWidget(self): self.widget = QtWidgets.QLineEdit() """ # (1) regexp validator ipRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])"; # You may want to use QRegularExpression for new code with Qt 5 (not mandatory) ip_regex = QtCore.QRegExp("^" + ipRange + "\\." + ipRange + "\\." + ipRange + "\\." + ipRange + "$") self.ip_validator = QtGui.QRegExpValidator(ip_regex) self.widget.setValidator(self.ip_validator) """ # (2) input mask self.widget.setInputMask("000.000.000.000")
def makeWidget(self): # self.validator = QtGui.QIntValidator(self.min_value, self.max_value) self.widget = QtWidgets.QSpinBox() self.widget.setMinimum(self.min_value) self.widget.setMaximum(self.max_value) self.widget.setValue(self.def_value)
def makeWidget(self): self.validator = QtGui.QIntValidator(self.min_value, self.max_value) self.widget = QtWidgets.QLineEdit() self.widget.setValidator(self.validator)
def makeWidget(self): self.widget = QtWidgets.QLabel(self.label_name)
def makeWidget(self): self.widget = QtWidgets.QComboBox() self.widget.clear() lis = self.getList() for i, (label, value) in enumerate(lis): self.widget.insertItem(i, label, value)
def main(): app=QtWidgets.QApplication([]) gui=MyGui() gui.show() app.exec_()
def makeWidget(self): self.widget = QtWidgets.QComboBox() self.updateWidget()
self.setCentralWidget(self.w) self.lay = QtWidgets.QHBoxLayout(self.w) self.person_view = ListAndForm( self.data_model.PersonList(collection=self.data_model.collection), EditFormSet(collection=self.data_model.collection), "Persons", self.w) self.food_view = ListAndForm( self.data_model.FoodList( collection=self.data_model.food_collection), EditFormSet(collection=self.data_model.food_collection), "Foods", self.w) self.food_view.modified.connect(self.person_view.update) # instantiate PersonFormSet => instantiate rows => row instantiates widgets based on the columns => .. # updating: call row's updateWidget method => re-creates column widgets self.lay.addWidget(self.person_view.widget) self.lay.addWidget(self.food_view.widget) """<rtf> Start the Qt program <rtf>""" if (__name__ == "__main__"): app = QtWidgets.QApplication([]) gui = MyGui() gui.show() app.exec_()
def makeWidget(self): self.widget = QtWidgets.QCheckBox() self.widget.stateChanged.connect(self.state_changed_slot)
def makeWidget(self): self.widget = QtWidgets.QListWidget() self.widget.setSelectionMode( QtWidgets.QAbstractItemView.MultiSelection) self.updateWidget()
def main(i): app = QtWidgets.QApplication(["test_app_" + str(i)]) st = "mg=TestGui" + str(i) + "()" exec(st, globals()) mg.show() app.exec_()
def setupUi(self): self.setGeometry(QtCore.QRect(100, 100, 800, 800)) self.w = QtWidgets.QWidget(self) self.setCentralWidget(self.w) # self.lay=QtWidgets.QGridLayout(self.w) self.lay = QtWidgets.QHBoxLayout(self.w)
def setupUi(self): self.setGeometry(QtCore.QRect(100,100,800,800)) self.w=QtWidgets.QWidget(self) self.setCentralWidget(self.w) self.lay=QtWidgets.QHBoxLayout(self.w) self.person_view =ListAndForm(self.data_model.getPersonList(), self.data_model.getPersonForm(), "Registered Persons", self.w) self.vehicle_view =ListAndForm(self.data_model.getVehicleList(),self.data_model.getVehicleForm(), "Registered Vehicles", self.w) self.device_view =ListAndForm(self.data_model.getDeviceList(), self.data_model.getDeviceForm(), "Registered Cameras", self.w) self.company_view =ListAndForm(self.data_model.getCompanyList(),self.data_model.getCompanyForm(), "Registered Companies",self.w) self.area_view =ListAndForm(self.data_model.getAreaList(), self.data_model.getAreaForm(), "Registered Areas", self.w) self.area_permission_view =PermissionListsAndForm("Area Permissions", self.data_model.getAreaList(), self.data_model.getVehicleList(), self.data_model.getAreaPermissionForm(), titles=["AREA","VEHICLE","PERMISSION"], parent=self.w) self.area_permission_per_company_view =PermissionListsAndForm("Area Permission per Company", self.data_model.getAreaList(), self.data_model.getCompanyList(), self.data_model.getAreaPerCompanyPermissionForm(), titles=["AREA","COMPANY","PERMISSION"], parent=self.w) # Update GUI's if relation targets change: self.device_view.modified. connect(self.area_view.update) self.vehicle_view.modified.connect(self.area_view.update) self.area_view.modified. connect(self.area_permission_view.update) self.vehicle_view.modified.connect(self.area_permission_view.update) self.area_view.modified. connect(self.area_permission_per_company_view.update) self.company_view.modified.connect(self.area_permission_per_company_view.update) self.all_views=[self.person_view, self.vehicle_view, self.device_view, self.company_view, self.area_view, self.area_permission_view, self.area_permission_per_company_view] self.hideAll() for view in self.all_views: self.lay.addWidget(view.widget) self.file_menu =self.menuBar().addMenu("File") self.config_menu =self.menuBar().addMenu("Configuration") self.perm_menu =self.menuBar().addMenu("Permissions") self.exit_action =self.file_menu.addAction("Exit") self.exit_action.triggered.connect(self.exit_slot) self.person_menu_action =self.config_menu.addAction("Persons") self.vehicle_menu_action =self.config_menu.addAction("Vehicles") self.device_menu_action =self.config_menu.addAction("Devices") self.company_menu_action =self.config_menu.addAction("Companies") self.area_menu_action =self.config_menu.addAction("Areas") self.area_permissions_action =self.perm_menu.addAction("Area Permissions") self.area_per_company_action =self.perm_menu.addAction("Area per Company Permissions") self.person_menu_action.triggered. connect(self.person_menu_slot) self.vehicle_menu_action.triggered. connect(self.vehicle_menu_slot) self.device_menu_action.triggered. connect(self.device_menu_slot) self.company_menu_action.triggered. connect(self.company_menu_slot) self.area_menu_action.triggered. connect(self.area_menu_slot) self.area_permissions_action.triggered. connect(self.area_permission_slot) self.area_per_company_action.triggered. connect(self.area_per_company_slot)