示例#1
0
 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
示例#2
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)
示例#3
0
 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
示例#4
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)
示例#5
0
    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()
示例#6
0
 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
示例#7
0
    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()
示例#8
0
 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)
示例#9
0
 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)
示例#10
0
 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()
示例#11
0
    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()
示例#12
0
    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()
示例#13
0
 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()
示例#14
0
 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
示例#15
0
 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()
示例#16
0
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)
示例#17
0
 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()
示例#18
0
    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
示例#19
0
 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
示例#20
0
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)
示例#21
0
 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
示例#22
0
    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
示例#23
0
def find_schedule_of_spawn(spawn, schedules):
    return first(s for s in schedules if s.contains_spawn(spawn))
示例#24
0
def find_schedule_of_ref(ref, schedules):
    return first(s for s in schedules if s.contains_ref(ref))
示例#25
0
 def _load(self):
     schedule = first(self.mainwindow.selected_schedules)
     self._load_schedule(schedule)
示例#26
0
 def get_line(self, line_header):
     return first(line for line in self.lines if line.header == line_header)
示例#27
0
 def _load(self):
     schedule = first(self.mainwindow.selected_schedules)
     self._load_schedule(schedule)
示例#28
0
 def _load(self):
     budget = first(self.mainwindow.selected_budgets)
     self._load_budget(budget)
示例#29
0
 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
示例#30
0
 def _load(self):
     budget = first(self.mainwindow.selected_budgets)
     self._load_budget(budget)
示例#31
0
def find_schedule_of_spawn(spawn, schedules):
    return first(s for s in schedules if s.contains_spawn(spawn))