def selected_target_index(self): target_name = self.layout.target_account_name if not target_name: return 0 index = first(i for i, t in enumerate(self._target_accounts) if t.name == target_name) return index + 1 if index is not None else 0
def delete_entries(self, entries): """Remove transactions in which ``entries`` belong from the document's transaction list. :param entries: list of :class:`.Entry` """ from_account = first(entries).account transactions = dedupe(e.transaction for e in entries) self.delete_transactions(transactions, from_account=from_account)
def select_pane_of_type(self, pane_type, clear_filter=True): if clear_filter: self.filter_string = '' index = first(i for i, p in enumerate(self.panes) if p.view.VIEW_TYPE == pane_type) if index is None: self._add_pane(self._create_pane(pane_type)) else: self.current_pane_index = index
def assign_imbalance(self): """Assigns remaining imbalance to the selected split. If the selected split is not an assigned split, does nothing. """ split = first(self._selected_splits) if split is not None: self.transaction.assign_imbalance(split) self.split_table.refresh_splits()
def open_account(self, account): if account is not None: # Try to find a suitable pane, or add a new one index = first(i for i, p in enumerate(self.panes) if p.account == account) if index is None: self._add_pane(self._create_pane(PaneType.Account, account)) else: self.current_pane_index = index elif self._current_pane.view.VIEW_TYPE == PaneType.Account: self.select_pane_of_type(PaneType.NetWorth)
def select_layout(self, name): if not name: new_layout = self._default_layout else: new_layout = first(layout for layout in self._layouts if layout.name == name) if new_layout is self.layout: return self.layout = new_layout self.layout.adjust_columns(self._colcount) self.view.refresh_columns_name() self.view.refresh_lines() self.view.refresh_targets()
def mct_balance(self): """Balances the mct by using xchange rates. The currency of the new split is the currency of the currently selected split. """ self.split_table.stop_editing() split = first(self._selected_splits) new_split_currency = self.document.default_currency if split is not None and split.amount != 0: new_split_currency = split.amount.currency_code self.transaction.mct_balance(new_split_currency) self.split_table.refresh_splits()
def _revalidate(self): self.stop_editing() self._invalidate_visible_entries() self._close_irrelevant_account_panes() self._ensure_selection_valid() self.view.refresh_undo_actions() self._current_pane.view.revalidate() # An account might have been renamed. If so, update pane metadata. tochange = first(p for p in self.panes if p.account is not None and p.account.name != p.label) if tochange is not None: tochange.label = tochange.account.name self.view.refresh_panes()
def continue_import(self): loader = self.mainwindow.loader loader.columns = self.layout.columns lines = [line for index, line in enumerate(self.lines) if not self.line_is_excluded(index)] loader.lines = lines target_name = self.layout.target_account_name target_account = first(t for t in self._target_accounts if t.name == target_name) try: return self.mainwindow.load_parsed_file_for_import(target_account) except FileLoadError as e: self.view.show_message(str(e)) return None
def setAccelKeys(menu): actions = menu.actions() titles = [a.text() for a in actions] available_characters = {c.lower() for s in titles for c in s if c.isalpha()} for action in actions: text = action.text() c = first(c for c in text if c.lower() in available_characters) if c is None: continue i = text.index(c) newtext = text[:i] + '&' + text[i:] available_characters.remove(c.lower()) action.setText(newtext)
def _revalidate(self): self.stop_editing() self._invalidate_visible_entries() self._close_irrelevant_account_panes() self._ensure_selection_valid() self.view.refresh_undo_actions() self._current_pane.view.revalidate() # An account might have been renamed. If so, update pane metadata. tochange = first( p for p in self.panes if p.account is not None and p.account.name != p.label) if tochange is not None: tochange.label = tochange.account.name self.view.refresh_panes()
def _firstEditableIndex(self, originalIndex, columnIndexes=None): """Returns the first editable index in `originalIndex`'s row or None. If `columnIndexes` is not None, the scan for an editable index will be limited to these columns. """ model = self.model() h = self._headerView() editedRow = originalIndex.row() if columnIndexes is None: columnIndexes = (h.logicalIndex(i) for i in range(h.count())) create = lambda col: model.createIndex(editedRow, col, originalIndex.internalPointer()) scannedIndexes = (create(i) for i in columnIndexes if not h.isSectionHidden(i)) editableIndex = first(index for index in scannedIndexes if model.flags(index) & Qt.ItemIsEditable) return editableIndex
def fit(self, element, expandH=False, expandV=False): # Go through all available rects and take the first one that fits. fits = lambda rect: rect.width() >= element.rect.width() and rect.height() >= element.rect.height() fittingRect = first(r for r in self.availableRects if fits(r)) if fittingRect is None: return False element.rect.moveTopLeft(fittingRect.topLeft()) if expandH: element.rect.setWidth(fittingRect.width()) if expandV: element.rect.setHeight(fittingRect.height()) self.elements.append(element) element.placed() self._computeAvailableRects() return True
def setAccelKeys(menu): actions = menu.actions() titles = [a.text() for a in actions] available_characters = { c.lower() for s in titles for c in s if c.isalpha() } for action in actions: text = action.text() c = first(c for c in text if c.lower() in available_characters) if c is None: continue i = text.index(c) newtext = text[:i] + '&' + text[i:] available_characters.remove(c.lower()) action.setText(newtext)
def continue_import(self): loader = self.mainwindow.loader loader.columns = self.layout.columns lines = [ line for index, line in enumerate(self.lines) if not self.line_is_excluded(index) ] loader.lines = lines target_name = self.layout.target_account_name target_account = first(t for t in self._target_accounts if t.name == target_name) try: return self.mainwindow.load_parsed_file_for_import(target_account) except FileLoadError as e: self.view.show_message(str(e)) return None
def find_schedule_of_spawn(spawn, schedules): return first(s for s in schedules if s.contains_spawn(spawn))
def find_schedule_of_ref(ref, schedules): return first(s for s in schedules if s.contains_ref(ref))
def _load(self): schedule = first(self.mainwindow.selected_schedules) self._load_schedule(schedule)
def get_line(self, line_header): return first(line for line in self.lines if line.header == line_header)
def _load(self): budget = first(self.mainwindow.selected_budgets) self._load_budget(budget)