Page MenuHomePhabricator

[electrum] extract sorting helper methods from MyTreeWidget to mixin class
ClosedPublic

Authored by PiRK on Jun 30 2023, 15:12.

Details

Summary

The end goal will be to switch from using MyTreeWidget to using a QTreeView as a base class for UtxoList (coins tab) and HistoryList (main tab of the application).
This extracts some useful features that will be needed not only for MyTreeWidget but also for these QTreeViews

See T3206

Depends on D14168

Test Plan

run the application, open a wallet that has multiple coins (currently only the UTXO list remembers sorting when closing and reopening the app), change the sorting of the utxo list in various ways by clicking on the column headers and check that after restarting the application the sorting is still the same.

Also check that the default sorting for other tabs still makes sense:

  • tx history should be sorted by descending dates
  • coins are sorted by descending amount
  • other widgets (addresses) don't have have a specified ordering so they are initially sorted by the order in which items are added (addresses by ascending index, receiving addresses before change addresses)

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 24267
Build 48144: Build Diff
Build 48143: arc lint + arc unit

Event Timeline

PiRK requested review of this revision.Jun 30 2023, 15:12
Fabien added inline comments.
electrum/electrumabc_gui/qt/tree_widget.py
1

Is that because of python 3.6 ?

electrum/electrumabc_gui/qt/tree_widget.py
1

It is for postponed evaluations of annotations https://peps.python.org/pep-0563/

forward references: when a type hint contains names that have not been defined yet, that definition needs to be expressed as a string literal;
type hints are executed at module import time, which is not computationally free.

The functionality described above can be enabled starting from Python 3.7 using the following special import:

from future import annotations

electrum/electrumabc_gui/qt/tree_widget.py
1

Technically it is for python 3.7 to 3.11. They initially planned to make this behavior the standard in 3.10, but it hasn't happened yet. I think it is still on the python roadmap, but the plan for the implementation details has changes.

$ python
Python 3.10.6 (main, May 29 2023, 11:10:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> class A:
...     def factory(self) -> A:
...         return A()
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in A
NameError: name 'A' is not defined
>>> 
>>> from __future__ import annotations
>>> class A:
...     def factory(self) -> A:
...        return A()
...
>>>
Fabien added inline comments.
electrum/electrumabc_gui/qt/tree_widget.py
52

Unrelated to this diff but this is an horrible function and should be split into logical chunks instead of being this all-in-one unbearable mess that maybe does what you expect

This revision is now accepted and ready to land.Jul 1 2023, 06:57