def _get_controls_layout(self, layout): """ Return buttons layout """ hbox = QHBoxLayout() hbox.addStretch() hbox.setContentsMargins(0, 0, 0, 0) hbox.setSpacing(10) # args = ((' Сохранить', ' Закрыть'), # ('save', 'close'), # ('save_w.png', 'close.png'), # (self._save, self._close)) args = ((' Salvar', ' Fechar'), ('save', 'close'), ('save_w.png', 'close.png'), (self._save, self._close)) for l, n, i, f in zip(*args): b = QPushButton(l) b.clicked.connect(f) b.setObjectName(n) b.setIcon(QIcon(os.path.join(options.STATIC_DIR, 'icons', i))) b.setGraphicsEffect(utils.get_shadow()) hbox.addWidget(b) if self.item: # b = QPushButton('Удалить') b = QPushButton('Excluir') b.setObjectName('delete') b.clicked.connect(self._delete) b.setGraphicsEffect(utils.get_shadow()) hbox.addWidget(b) return hbox
def _get_controls_layout(self, layout): """ Return buttons layout """ hbox = QHBoxLayout() hbox.addStretch() hbox.setContentsMargins(0, 0, 0, 0) hbox.setSpacing(10) args = ((' Сохранить', ' Закрыть'), ('save', 'close'), ('save_w.png', 'close.png'), (self._save, self._close)) for l, n, i, f in zip(*args): b = QPushButton(l) b.clicked.connect(f) b.setObjectName(n) b.setIcon(QIcon(os.path.join(options.STATIC_DIR, 'icons', i))) b.setGraphicsEffect(utils.get_shadow()) hbox.addWidget(b) if self.item: b = QPushButton('Удалить') b.setObjectName('delete') b.clicked.connect(self._delete) b.setGraphicsEffect(utils.get_shadow()) hbox.addWidget(b) return hbox
def __init__(self, items, highlighter=None): super().__init__() self.setGraphicsEffect(utils.get_shadow()) if highlighter: self.highlighter = highlighter(items, self) self.keywords = []
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 __init__(self, parent, main_window, text, callback=None): """ Widget for alert messages. Also can be user to ask user about something. In this case it calls `callback` function with boolean value. """ super().__init__(parent) self._close = self._get_close_func(parent, callback) vbox = QVBoxLayout() l = QLabel(text) l.setAlignment(Qt.AlignCenter) vbox.addWidget(l) vbox.addStretch() hbox = QHBoxLayout() b = QPushButton('ok') b.clicked.connect(functools.partial(self._close, True)) hbox.addWidget(b) if callback: hbox.addStretch() b = QPushButton('Отмена') b.clicked.connect(functools.partial(self._close, False)) hbox.addWidget(b) vbox.addLayout(hbox) self.setLayout(vbox) self.show() self.raise_() self.move((main_window.width() - self.width()) / 2, (main_window.height() - self.height()) / 2) self.setGraphicsEffect(utils.get_shadow())
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 __init__(self, main_window, items): super().__init__() vbox = QVBoxLayout() vbox.setSpacing(0) vbox.setContentsMargins(0, 0, 0, 0) self.setLayout(vbox) top_system_buttons = TopSystemButtons(main_window) vbox.addWidget(top_system_buttons) vbox.addStretch() hbox = QHBoxLayout() hbox.addSpacing(25) hbox.setSpacing(0) hbox.setContentsMargins(0, 0, 0, 0) vbox.addLayout(hbox) l = QLabel() hbox.addWidget(l) vbox.addStretch() vbox.addWidget(SelectMenu(main_window, items)) main_window.communication.input_changed_signal.connect(l.setText) self.resizeEvent = functools.partial(main_window.resized, self, top_system_buttons) self.setGraphicsEffect(utils.get_shadow())
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 _get_search_layout(self): hbox = QHBoxLayout() _input = QLineEdit() _input.setGraphicsEffect(utils.get_shadow()) _input.setPlaceholderText('Поиск...') _input.textEdited.connect(self._filter) hbox.addWidget(_input) return hbox
def __init__(self, main_window): """ Connect signals. Hide the button, it will be shown only when required signals are emited """ super().__init__(main_window) self.hide() self.setGraphicsEffect(utils.get_shadow()) main_window.communication.resized.connect(self._move) main_window.communication.action_button_toggle.connect(self.toggle_state)
def __init__(self, main_window): """ Connect signals. Hide the button, it will be shown only when required signals are emited """ super().__init__(main_window) self.hide() self.setGraphicsEffect(utils.get_shadow()) main_window.communication.resized.connect(self._move) main_window.communication.action_button_toggle.connect( self.toggle_state)
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, text_edit): super().__init__() layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) for n in 'b', 'i', 'u', 'la', 'ca', 'ra': b = QPushButton() b.setIcon(QIcon(os.path.join(options.STATIC_DIR, 'icons', n + '.png'))) b.clicked.connect(functools.partial(text_edit.format_selected, n)) layout.addWidget(b) layout.addStretch() self.setGraphicsEffect(utils.get_shadow())
def _get_text_layout(self): """ Create TextEdit widgets. """ layout = QVBoxLayout() self.template_edit_widget = TextEditWithFormatControls(self.items, SyntaxHighlighter) self.template_text_edit = self.template_edit_widget.template_text_edit self.conclusion_text_edit = QTextEdit() self.name_text_edit = QLineEdit() for w, p, s in zip(self._get_all_text_fields(), ("Имя", "Шаблон", "Заключение"), (5, 80, 15)): w.setPlaceholderText(p) w.setGraphicsEffect(utils.get_shadow()) layout.addWidget(w, stretch=s) return layout
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 _create_layout_and_get_label(self, main_window): vbox = QVBoxLayout() vbox.setContentsMargins(0, 0, 0, 0) self.setLayout(vbox) l = QLabel() l.setAlignment(Qt.AlignCenter) l.setScaledContents(True) vbox.addWidget(l) self.setGraphicsEffect(utils.get_shadow()) self.hide() w = main_window.width() / 5 self.setFixedSize(w, w * 0.3) self.x_pos = main_window.width() - self.width() - self.RIGHT_MARGIN self.move(self.x_pos, main_window.height()) return l
def __init__(self, text_edit, excluded_controls=None): super().__init__() layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) excluded_controls = excluded_controls or [] for n in 'b', 'i', 'u', 'la', 'ca', 'ra': if n in excluded_controls: continue b = QPushButton() b.setIcon( QIcon(os.path.join(options.STATIC_DIR, 'icons', n + '.png'))) b.clicked.connect(functools.partial(text_edit.format_selected, n)) layout.addWidget(b) layout.addStretch() self.setGraphicsEffect(utils.get_shadow())
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 _get_text_layout(self): """ Create TextEdit widgets. """ layout = QVBoxLayout() self.template_edit_widget = TextEditWithFormatControls( self.items, SyntaxHighlighter) self.template_text_edit = self.template_edit_widget.template_text_edit self.conclusion_text_edit = TextEditWithFormatControls( self.items, SyntaxHighlighter, ['la', 'ca', 'ra']) self.name_text_edit = QLineEdit() for w, p, s in zip(self._get_all_text_fields(), ('Имя', 'Шаблон', 'Заключение'), (5, 60, 35)): w.setPlaceholderText(p) w.setGraphicsEffect(utils.get_shadow()) layout.addWidget(w, stretch=s) return layout
def __init__(self, parent, main_window, label_text): super().__init__() # if label_text.startswith('_'): # return self.label_text = label_text self.input = QLineEdit() main_window.communication.clean_items.connect(self.clean) hbox = QHBoxLayout() self.setLayout(hbox) hbox.addWidget(QLabel(_(label_text))) hbox.addStretch() self.input.setAlignment(Qt.AlignRight) # self.input.setFixedWidth(190) self.input.textEdited.connect(functools.partial(parent.input_changed, label_text)) self.setGraphicsEffect(utils.get_shadow()) hbox.addWidget(self.input)
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 __init__(self, main_window, select_menu, items): super().__init__(main_window) self.HINTS = self._get_hints_list() self.items = items self.resize(main_window.width() * 0.6, main_window.height() * 0.4) self.hide() main_window.communication.toggle_select_item.connect(self.toggle_visibility) main_window.communication.set_select_item_visibility.connect(self.set_visible) main_window.communication.ctrl_hotkey.connect(self._show_with_hints) main_window.communication.resized.connect(self._move) main_window.communication.shortcut_pressed.connect(self._select_for_shortcut) grid = QGridLayout() self.setLayout(grid) grid.setSpacing(0) grid.setContentsMargins(0, 0, 0, 0) self._btn_clicked_func = self._get_btn_clicked_func(main_window, select_menu) cols = 3 self.hints_labels = [] for i, item in enumerate(items): row, col = i // cols, i % cols b = QPushButton(_(item.name)) b.clicked.connect(functools.partial(self._btn_clicked_func, i)) grid.addWidget(b, row, col) print(self.HINTS[i][0]) l = QLabel(self.HINTS[i][0], self) l.setAlignment(Qt.AlignCenter) l.hide() self.hints_labels.append(l) self.setGraphicsEffect(utils.get_shadow())
def __init__(self, main_window, select_menu, items): super().__init__(main_window) self.HINTS = self._get_hints_list() self.items = items self.resize(main_window.width() * 0.6, main_window.height() * 0.4) self.hide() main_window.communication.toggle_select_item.connect(self.toggle_visibility) main_window.communication.set_select_item_visibility.connect(self.set_visible) main_window.communication.ctrl_hotkey.connect(self._show_with_hints) main_window.communication.resized.connect(self._move) main_window.communication.shortcut_pressed.connect(self._select_for_shortcut) grid = QGridLayout() self.setLayout(grid) grid.setSpacing(0) grid.setContentsMargins(0, 0, 0, 0) self._btn_clicked_func = self._get_btn_clicked_func(main_window, select_menu) cols = 3 self.hints_labels = [] for i, item in enumerate(items): row, col = i // cols, i % cols b = QPushButton(_(item.name)) b.clicked.connect(functools.partial(self._btn_clicked_func, i)) grid.addWidget(b, row, col) l = QLabel(self.HINTS[i][0], self) l.setAlignment(Qt.AlignCenter) l.hide() self.hints_labels.append(l) self.setGraphicsEffect(utils.get_shadow())
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())