def _get_control_layout(self): """ Create static layout. """ widget = QWidget() vbox = QVBoxLayout() widget.setLayout(vbox) vbox.setContentsMargins(0, 0, 0, 0) self.template_combo_box = QComboBox() self.template_combo_box.currentIndexChanged.connect(self._item_selected) vbox.addWidget(self.template_combo_box) scrollable_vbox = utils.get_scrollable(self.controls_layout) vbox.addWidget(scrollable_vbox, stretch=80) buttons_layout = QHBoxLayout() vbox.addLayout(buttons_layout, stretch=20) b = QPushButton("Назад") b.setObjectName("controls") b.clicked.connect(self._close) buttons_layout.addWidget(b) widget.setGraphicsEffect(utils.get_shadow()) return widget
def _create_layout(self, main_window): """ Create main layout of widget. """ layout = QVBoxLayout() self.setLayout(layout) layout.setContentsMargins(30, 10, 30, 10) layout.setSpacing(0) print(self.model.__table__.name) l = QLabel(_(self.model.__table__.name)) l.setText(self.model.__table__.name) l.setObjectName('title') layout.addWidget(l) scrollable = QVBoxLayout() for row in self._get_rows(self.model, main_window): for w in row: scrollable.addWidget(w) scrollable = utils.get_scrollable(scrollable) controls_layout = self._get_controls_layout(layout) layout.addWidget(scrollable) layout.addLayout(controls_layout) self.show() self.raise_() self.move((main_window.width() - self.width()) / 2, (main_window.height() - self.height()) / 2)
def _show_templates(self): """ Update templates on shoeEvent. """ cols = 3 templates = template_module.Template.get_all() for j, item in enumerate(self.visible_items): if not templates[item.id]: l = QLabel("Нет шаблонов для данного объекта\nУправлять шаблонами можно на вкладке настроек") l.setAlignment(Qt.AlignCenter) self.templates_layout.addWidget(l) continue layouts = [QVBoxLayout() for _ in range(cols)] for i, each in enumerate(templates[item.id]): b = QRadioButton(each.name) b.setChecked(item.template == each) b.clicked.connect(functools.partial(self._template_clicked, j, each)) b.mouseDoubleClickEvent = functools.partial(self.open_template_edit_widget, j, each) layouts[i % cols].addWidget(b) wrapper = QHBoxLayout() for each in layouts: each.addStretch() wrapper.addLayout(each, stretch=int(100 / cols)) self.templates_layout.addWidget(utils.get_scrollable(wrapper))
def _get_control_layout(self): """ Create static layout. """ widget = QWidget() vbox = QVBoxLayout() widget.setLayout(vbox) vbox.setContentsMargins(0, 0, 0, 0) self.template_combo_box = QComboBox() self.template_combo_box.currentIndexChanged.connect( self._item_selected) vbox.addWidget(self.template_combo_box) scrollable_vbox = utils.get_scrollable(self.controls_layout) vbox.addWidget(scrollable_vbox, stretch=80) buttons_layout = QHBoxLayout() vbox.addLayout(buttons_layout, stretch=20) # b = QPushButton('Назад') b = QPushButton('Voltar') b.setObjectName('controls') b.clicked.connect(self._close) buttons_layout.addWidget(b) widget.setGraphicsEffect(utils.get_shadow()) return widget
def _create_layout(self, main_window): """ Create main layout of widget. """ layout = QVBoxLayout() self.setLayout(layout) layout.setContentsMargins(30, 10, 30, 10) layout.setSpacing(0) l = QLabel(_(self.model.__table__.name)) l.setObjectName('title') layout.addWidget(l) scrollable = QVBoxLayout() for row in self._get_rows(self.model, main_window): for w in row: scrollable.addWidget(w) scrollable = utils.get_scrollable(scrollable) controls_layout = self._get_controls_layout(layout) layout.addWidget(scrollable) layout.addLayout(controls_layout) self.show() self.raise_() self.move((main_window.width() - self.width()) / 2, (main_window.height() - self.height()) / 2)
def _create_layout(self, main_window): wrapper = QHBoxLayout() self.layout.addWidget(utils.get_scrollable(wrapper)) rows = 8 cols = 3 vboxes = [QVBoxLayout() for _ in range(cols)] widgets = ((TemplateWidgetInOptions(main_window, self.items, self), 'Шаблоны'), (UsersAndGroupsWidget(main_window, self), 'Пользователи и группы'), (self._switch_user, 'Сменить пользователя'), (self._get_template_export_func(main_window), 'Экспортировать шаблоны'), (self._get_template_import_func(main_window), 'Импортировать шаблоны')) for i, widget in enumerate(widgets): b = QPushButton(widget[1]) if callable(widget[0]): b.clicked.connect(widget[0]) else: b.clicked.connect(functools.partial(self.layout.setCurrentIndex, i + 1)) self.layout.addWidget(widget[0]) b.setGraphicsEffect(utils.get_shadow()) vboxes[(i // rows) % cols].addWidget(b) for each in vboxes: each.addStretch() wrapper.addLayout(each, stretch=int(100 / cols))
def _get_static_widgets(self): """ Create layout that does not depend on content. """ hbox = QHBoxLayout() self.menu_wrapper.addWidget(utils.get_scrollable(self.menu_layout)) hbox.addLayout(self.menu_wrapper, stretch=30) hbox.addLayout(self.templates_layout, stretch=70) widget = QWidget() widget.setLayout(hbox) widget.setGraphicsEffect(utils.get_shadow()) return widget
def __init__(self, main_window): """ Widget to show Client model. """ super().__init__(main_window) self.items = [] self.current_items_index = 0 self.model = db.Client self._query = db.SESSION.query(self.model).order_by( self.model.id.desc()) self._open_report = self._get_open_report_func(main_window) self._delete_item = self._get_delete_item_func(main_window) self.columns = [] self._columns_to_display = [ 'fullname', 'user', 'date_of_birth', 'examined', 'controls' ] self.layout = QGridLayout() self.header_layout = QGridLayout() self.control_layout = QWidget() self._page_count_label = QLabel('') self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(0) vbox = QVBoxLayout() vbox.setSpacing(0) vbox.addLayout(self._get_search_layout()) vbox.addLayout(self.header_layout) vbox.addWidget(utils.get_scrollable(self.layout)) vbox.addWidget(self.control_layout) self.setLayout(vbox) control_layout = QHBoxLayout() control_layout.addStretch() control_layout.addWidget(self._page_count_label) for icon, direciton in zip(('left.png', 'right.png'), (-1, 1)): b = QPushButton() b.setIcon(QIcon(os.path.join(options.STATIC_DIR, 'icons', icon))) b.clicked.connect(functools.partial(self._move, direciton)) b.setObjectName(icon) control_layout.addWidget(b) self.control_layout.setLayout(control_layout) self.setGraphicsEffect(utils.get_shadow()) self.showEvent = self._get_show_event(main_window)
def __init__(self, main_window): super().__init__() self.main_window = main_window self.content_layout = QVBoxLayout() self._update_content() vbox = QVBoxLayout() vbox.addWidget(utils.get_scrollable(self.content_layout)) hbox = QHBoxLayout() hbox.addStretch(25) hbox.addLayout(vbox, stretch=50) hbox.addStretch(25) self.setLayout(hbox) self.showEvent = self._get_show_event(main_window) self.setGraphicsEffect(utils.get_shadow())
def _show_templates(self): """ Update templates on shoeEvent. """ cols = 3 templates = template_module.Template.get_all() check_templates = [] for j, item in enumerate(self.visible_items): if not templates[item.id]: # l = QLabel('Нет шаблонов для данного объекта\nУправлять шаблонами можно на вкладке настроек') l = QLabel( 'Não há modelos para este objeto\nOs modelos de gerenciamento podem estar na guia de configurações' ) l.setAlignment(Qt.AlignCenter) self.templates_layout.addWidget(l) continue layouts = [QVBoxLayout() for _ in range(cols)] for i, each in enumerate(templates[item.id]): b = QRadioButton(each.name) b.setChecked(item.template == each) b.clicked.connect( functools.partial(self._template_clicked, j, each)) if len(templates[item.id]) == 1: check_templates.append((b, j, each)) b.mouseDoubleClickEvent = functools.partial( self.open_template_edit_widget, j, each) layouts[i % cols].addWidget(b) wrapper = QHBoxLayout() for each in layouts: each.addStretch() wrapper.addLayout(each, stretch=int(100 / cols)) self.templates_layout.addWidget(utils.get_scrollable(wrapper)) for i, each in enumerate(check_templates): b, j, template = each self._template_clicked(j, template, i == 0) b.setChecked(True)
def _create_layout(self, main_window): wrapper = QHBoxLayout() self.layout.addWidget(utils.get_scrollable(wrapper)) rows = 8 cols = 3 vboxes = [QVBoxLayout() for _ in range(cols)] # widgets = ((TemplateWidgetInOptions(main_window, self.items, self), 'Шаблоны'), # (UsersAndGroupsWidget(main_window, self), 'Пользователи и группы'), # (self._switch_user, 'Сменить пользователя'), # (self._get_template_export_func(main_window), 'Экспортировать шаблоны'), # (self._get_template_import_func(main_window), 'Импортировать шаблоны')) widgets = ((TemplateWidgetInOptions(main_window, self.items, self), 'Templates'), (UsersAndGroupsWidget(main_window, self), 'Usuários e Grupos'), (self._switch_user, 'Alterar usuário'), (self._get_template_export_func(main_window), 'Modelos de exportação'), (self._get_template_import_func(main_window), 'Importar modelos')) for i, widget in enumerate(widgets): b = QPushButton(widget[1]) if callable(widget[0]): b.clicked.connect(widget[0]) else: b.clicked.connect( functools.partial(self.layout.setCurrentIndex, i + 1)) self.layout.addWidget(widget[0]) b.setGraphicsEffect(utils.get_shadow()) vboxes[(i // rows) % cols].addWidget(b) for each in vboxes: each.addStretch() wrapper.addLayout(each, stretch=int(100 / cols))
def __init__(self, main_window): """ Widget to show Client model. """ super().__init__(main_window) self.items = [] self.current_items_index = 0 self.model = db.Client self._open_report = self._get_open_report_func(main_window) self.columns = [] self._columns_to_display = {'id', 'name', 'surname', 'patronymic', 'user', 'age', 'examined', 'report'} self.layout = QGridLayout() self.header_layout = QGridLayout() self.control_layout = QHBoxLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(0) vbox = QVBoxLayout() vbox.setSpacing(0) vbox.addLayout(self.header_layout) vbox.addWidget(utils.get_scrollable(self.layout)) vbox.addLayout(self.control_layout) self.setLayout(vbox) self.control_layout.addStretch() for icon, direciton in zip(('left.png', 'right.png'), (-1, 1)): b = QPushButton() b.setIcon(QIcon(os.path.join(options.STATIC_DIR, 'icons', icon))) b.clicked.connect(functools.partial(self._move, direciton)) b.setObjectName(icon) self.control_layout.addWidget(b) self.setGraphicsEffect(utils.get_shadow()) self.showEvent = self._get_show_event(main_window)
def _create_layout(self, parent): self._groups_combo_box = QComboBox() self._users_layout = QVBoxLayout() self._text_field = TextEditWithFormatControls() # self._text_field.setPlaceholderText('Заголовок появится в начале отчета') self._text_field.setPlaceholderText( 'Um título aparecerá no início do relatório.') self._groups_combo_box.currentIndexChanged.connect( self._group_selected) layout = QHBoxLayout() layout.setContentsMargins(15, 15, 15, 15) layout.setSpacing(20) right_side = QVBoxLayout() right_side.setContentsMargins(0, 0, 0, 0) right_side.setSpacing(0) hbox = QHBoxLayout() hbox.setContentsMargins(0, 0, 0, 0) hbox.setSpacing(0) for i, f in zip(('save_w', 'delete'), (self._save, self._delete)): b = QPushButton() b.setIcon(QIcon(os.path.join(options.STATIC_DIR, 'icons', i))) b.setObjectName('button') b.clicked.connect(f) hbox.addWidget(b) self._related_to_group_buttons.append(b) hbox.addSpacing(5) hbox.addStretch() right_side.addLayout(hbox) right_side.addSpacing(5) # l = QLabel('Заголовок') l = QLabel('Headline') l.setObjectName('text-header') right_side.addWidget(l) right_side.addWidget(self._text_field) left_side = QVBoxLayout() left_side.setContentsMargins(0, 0, 0, 0) left_side.setSpacing(0) left_side.addWidget(self._groups_combo_box) wrapper = QWidget() hbox = QHBoxLayout() hbox.setContentsMargins(0, 0, 0, 0) hbox.setSpacing(0) # l = QLabel('Пользователи') l = QLabel('Usuários') l.setObjectName('header') hbox.addWidget(l) hbox.addStretch() b = QPushButton() b.setIcon(QIcon(os.path.join(options.STATIC_DIR, 'icons', 'plus'))) b.clicked.connect(functools.partial(self._show_crud, db.User)) hbox.addWidget(b) wrapper.setLayout(hbox) wrapper.setObjectName('header') left_side.addWidget(wrapper) left_side.addWidget(utils.get_scrollable(self._users_layout)) # b = QPushButton('Назад') b = QPushButton('Voltar') b.setObjectName('button') b.clicked.connect(functools.partial(parent.set_current_index, 0)) left_side.addSpacing(5) left_side.addWidget(b) layout.addLayout(left_side, stretch=30) layout.addLayout(right_side, stretch=70) self.setLayout(layout) self.setGraphicsEffect(utils.get_shadow())