def display_model(self): """ Clear widget and display items. """ utils.clear_layout(self.layout) self.columns = [] j = 0 columns = [c.name for c in self.model.__table__.columns] + ['report'] for c in columns: if c not in self._columns_to_display: continue self.columns.append(c) l = QLabel(_(c)) l.setObjectName('header') l.setAlignment(Qt.AlignCenter) self.header_layout.addWidget(l, 0, j) j += 1 for i, item in enumerate(self.items[self.current_items_index:self.current_items_index + self.ITEMS_PER_PAGE], 0): self._add_row(i, item) empty = QWidget() empty.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) self.layout.addWidget(empty, self.layout.rowCount(), 0)
def hideEvent(self, event): """ Clear menu and templates. """ utils.clear_layout(self.menu_layout) utils.clear_layout(self.templates_layout)
def _fill_controls_layout(self, item): keywords = [_(key) for key in item.keys()] utils.clear_layout(self.controls_layout) for name in keywords: b = QPushButton(_(name)) b.clicked.connect(functools.partial(self.template_text_edit.insert_attribute, item, name)) self.controls_layout.addWidget(b) self.controls_layout.addStretch() return keywords
def show_event(event): utils.clear_layout(self.menu_layout) utils.clear_layout(self.templates_layout) self.visible_items = self._iterate_items() self._show_menu() self._show_templates() if not self.layout.currentIndex(): main_window.communication.action_button_toggle.emit( bool(self.visible_items), self.ACTION_BTN_ICON, self.action_btn_function )
def show_event(event): utils.clear_layout(self.menu_layout) utils.clear_layout(self.templates_layout) self.visible_items = self._iterate_items() self._show_menu() self._show_templates() if not self.layout.currentIndex(): main_window.communication.action_button_toggle.emit( bool(self.visible_items), self.ACTION_BTN_ICON, self.action_btn_function)
def _fill_controls_layout(self, item): keywords = [_(key) for key in item.keys()] utils.clear_layout(self.controls_layout) for name in keywords: b = QPushButton(_(name)) b.clicked.connect( functools.partial(self.template_text_edit.insert_attribute, item, name)) self.controls_layout.addWidget(b) self.controls_layout.addStretch() return keywords
def _update_content(self, *args): """ If new user or organization were created, update content. """ utils.clear_layout(self.content_layout) self.users = list(db.SESSION.query(db.User).filter(db.User.deleted == False, db.Organization.deleted == False)) organizations = list(db.SESSION.query(db.Organization).filter(db.Organization.deleted == False)) for organization in organizations: self.content_layout.addWidget(self._get_label(organization)) for user in self.users: if user.organization_id == organization.id: self.content_layout.addWidget(self._get_radio_btn(user)) if not self.users: l = QLabel("Создайте пользователей\nдля начала работы") l.setAlignment(Qt.AlignCenter) self.content_layout.addWidget(l) self.content_layout.addStretch()
def _filter(self, query_text): # Since it's not really important, # I'll keep columns hard-coded here. # Sqlalchemy doesn't care about ilike function at all if query_text and len(query_text) < 3: utils.clear_layout(self.layout) self.layout.addWidget(QLabel('Продолжайте печатать...')) return if query_text: query_text = '%{}%'.format(query_text.lower()) db.cursor.execute(options.SEARCH_QUERY, [query_text, query_text, query_text]) ids = [i[0] for i in db.cursor.fetchall()] if ids: self.items = db.SESSION.query(self.model).filter( self.model.id.in_(ids)) else: self.items = db.SESSION.query(self.model).filter(sql.false()) else: self.items = self._query self.display_model()
def _update_content(self, *args): """ If new user or organization were created, update content. """ utils.clear_layout(self.content_layout) self.users = list(db.SESSION.query(db.User).filter(db.User.deleted == False, db.Organization.deleted == False)) organizations = list(db.SESSION.query(db.Organization).filter(db.Organization.deleted == False)) for organization in organizations: self.content_layout.addWidget(self._get_label(organization)) for user in self.users: if user.organization_id == organization.id: self.content_layout.addWidget(self._get_radio_btn(user)) if not self.users: # l = QLabel('Создайте пользователей\nдля начала работы') l = QLabel('Crie usuários\npara começar') l.setAlignment(Qt.AlignCenter) self.content_layout.addWidget(l) self.content_layout.addStretch()
def _show_users_for_group(self, group_id): utils.clear_layout(self._users_layout) for user in db.SESSION.query(db.User).filter(db.User.organization_id == group_id, db.User.deleted == False, db.Organization.deleted == False): layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(QLabel(str(user))) layout.addStretch() for i, f in zip(('check', 'pencil_g'), (functools.partial(self._select_user, user), functools.partial(self._show_crud, db.User, user))): b = QPushButton() b.setIcon(QIcon(os.path.join(options.STATIC_DIR, 'icons', i))) b.clicked.connect(f) layout.addWidget(b) wrapper = QWidget() wrapper.setLayout(layout) self._users_layout.addWidget(wrapper) self._users_layout.addStretch()
def display_model(self): """ Clear widget and display items. """ utils.clear_layout(self.layout) self.columns = [] j = 0 for c in self._columns_to_display: self.columns.append(c) l = QLabel(_(c)) l.setObjectName('header') l.setAlignment(Qt.AlignCenter) self.header_layout.addWidget(l, 0, j) j += 1 for i, item in enumerate( self.items[self.current_items_index:self.current_items_index + self.ITEMS_PER_PAGE]): self._add_row(i, item) empty = QWidget() empty.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) self.layout.addWidget(empty, self.layout.rowCount(), 0) if self.current_items_index and self.current_items_index >= self.items.count( ): self.current_items_index = 0 return self.display_model() self.control_layout.setVisible( self.items.count() > self.ITEMS_PER_PAGE) page = round(self.current_items_index / self.ITEMS_PER_PAGE) + 1 page_count = math.floor( (self.items.count() - 1) / self.ITEMS_PER_PAGE) + 1 self._page_count_label.setText('{}/{}'.format(page, page_count))
def _clear_layout(self): utils.clear_layout(self._users_layout) self._text_field.setText('') for i in range(self._groups_combo_box.count()): self._groups_combo_box.removeItem(i)