diff --git a/res/ui/accountConfigurationDialog.ui b/res/ui/accountConfigurationDialog.ui index e1cfb9aa731770e7034a4af75889dde27a936873..28d83eec363069d6aca71b6b58c1c4263c689cac 100644 --- a/res/ui/accountConfigurationDialog.ui +++ b/res/ui/accountConfigurationDialog.ui @@ -18,131 +18,173 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QGroupBox" name="groupBox"> - <property name="title"> - <string>Account parameters</string> + <widget class="QStackedWidget" name="stacked_pages"> + <property name="currentIndex"> + <number>0</number> </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Account name</string> - </property> - </widget> - </item> - <item> - <widget class="QLineEdit" name="edit_account_name"/> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>PGPKey </string> - </property> - </widget> - </item> - <item> - <widget class="QComboBox" name="combo_keys_list"/> - </item> - </layout> - </item> - </layout> + <widget class="QWidget" name="page_init"> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Account parameters</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Account name</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="edit_account_name"/> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>PGPKey </string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="combo_keys_list"/> + </item> + </layout> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="page__communities"> + <layout class="QVBoxLayout" name="verticalLayout_5"> + <item> + <widget class="QGroupBox" name="groupBox_2"> + <property name="title"> + <string>Communities membership</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QListView" name="list_communities"> + <property name="contextMenuPolicy"> + <enum>Qt::DefaultContextMenu</enum> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QPushButton" name="button_add_community"> + <property name="text"> + <string>Add a community</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="button_remove_community"> + <property name="text"> + <string>Remove selected community</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + </layout> + </widget> </widget> </item> <item> - <widget class="QGroupBox" name="groupBox_2"> - <property name="title"> - <string>Communities membership</string> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <property name="topMargin"> + <number>5</number> </property> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <item> - <widget class="QListView" name="list_communities"> - <property name="contextMenuPolicy"> - <enum>Qt::DefaultContextMenu</enum> - </property> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QPushButton" name="button_add_community"> - <property name="text"> - <string>Add a community</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="button_remove_community"> - <property name="text"> - <string>Remove selected community</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QDialogButtonBox" name="button_box"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> + <item> + <widget class="QPushButton" name="button_previous"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Previous</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="button_next"> + <property name="text"> + <string>Next</string> + </property> + </widget> + </item> + </layout> </item> </layout> </widget> <resources/> <connections> <connection> - <sender>button_box</sender> - <signal>accepted()</signal> + <sender>button_add_community</sender> + <signal>clicked()</signal> <receiver>AccountConfigurationDialog</receiver> - <slot>accept()</slot> + <slot>open_process_add_community()</slot> <hints> <hint type="sourcelabel"> - <x>248</x> - <y>254</y> + <x>109</x> + <y>237</y> </hint> <hint type="destinationlabel"> - <x>157</x> - <y>274</y> + <x>199</x> + <y>149</y> </hint> </hints> </connection> <connection> - <sender>button_box</sender> - <signal>rejected()</signal> + <sender>button_remove_community</sender> + <signal>clicked()</signal> <receiver>AccountConfigurationDialog</receiver> - <slot>reject()</slot> + <slot>action_remove_community()</slot> <hints> <hint type="sourcelabel"> - <x>316</x> - <y>260</y> + <x>290</x> + <y>237</y> </hint> <hint type="destinationlabel"> - <x>286</x> - <y>274</y> + <x>199</x> + <y>149</y> </hint> </hints> </connection> <connection> - <sender>button_add_community</sender> - <signal>clicked()</signal> + <sender>list_communities</sender> + <signal>doubleClicked(QModelIndex)</signal> <receiver>AccountConfigurationDialog</receiver> - <slot>open_process_add_community()</slot> + <slot>open_process_edit_community(QModelIndex)</slot> <hints> <hint type="sourcelabel"> - <x>109</x> - <y>237</y> + <x>199</x> + <y>180</y> </hint> <hint type="destinationlabel"> <x>199</x> @@ -151,14 +193,14 @@ </hints> </connection> <connection> - <sender>button_remove_community</sender> + <sender>button_next</sender> <signal>clicked()</signal> <receiver>AccountConfigurationDialog</receiver> - <slot>action_remove_community()</slot> + <slot>next()</slot> <hints> <hint type="sourcelabel"> - <x>290</x> - <y>237</y> + <x>349</x> + <y>278</y> </hint> <hint type="destinationlabel"> <x>199</x> @@ -167,14 +209,14 @@ </hints> </connection> <connection> - <sender>list_communities</sender> - <signal>doubleClicked(QModelIndex)</signal> + <sender>button_previous</sender> + <signal>clicked()</signal> <receiver>AccountConfigurationDialog</receiver> - <slot>open_process_edit_community(QModelIndex)</slot> + <slot>previous()</slot> <hints> <hint type="sourcelabel"> - <x>199</x> - <y>180</y> + <x>49</x> + <y>278</y> </hint> <hint type="destinationlabel"> <x>199</x> @@ -188,5 +230,7 @@ <slot>key_changed(int)</slot> <slot>action_remove_community()</slot> <slot>open_process_edit_community(QModelIndex)</slot> + <slot>next()</slot> + <slot>previous()</slot> </slots> </ui> diff --git a/res/ui/walletTabWidget.ui b/res/ui/walletTabWidget.ui new file mode 100644 index 0000000000000000000000000000000000000000..7d0415553c789a089be642e0cbff3a9d99bbed46 --- /dev/null +++ b/res/ui/walletTabWidget.ui @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>WalletTabWidget</class> + <widget class="QWidget" name="WalletTabWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>walletTabWidget</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <layout class="QVBoxLayout" name="verticalLayout_6"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Trusts and hosters</string> + </property> + </widget> + </item> + <item> + <widget class="QTreeView" name="trusts_tree_view"/> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout"/> + </item> + </layout> + </widget> + <resources/> + <connections/> + <slots> + <slot>open_issuance_dialog()</slot> + </slots> +</ui> diff --git a/src/_cutecoin_test/models/account/test_account.py b/src/_cutecoin_test/models/account/test_account.py index aa3f06a6fd6d102bd04e34cd519dc50352fe8ad9..1c11562f90c14647895759b277fa48de28335617 100644 --- a/src/_cutecoin_test/models/account/test_account.py +++ b/src/_cutecoin_test/models/account/test_account.py @@ -1,5 +1,5 @@ import pytest -import ucoinpy as ucoin +import ucoin import gnupg from mock import Mock from cutecoin.models.account import Account @@ -103,7 +103,7 @@ def patch_transactions_sent_get(*arg, **kwargs): } }]) - + def patch_transactions_view_get(*arg, **kwargs): return { "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", @@ -131,7 +131,7 @@ def patch_transactions_view_get(*arg, **kwargs): "comment": "Too much coins ! Making big one." } } - + def patch_transactions_issuances_get(*arg, **kwargs): return iter([{ "hash": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", @@ -168,12 +168,12 @@ def mock_gpg(): 'fingerprint': '2E69197FAB029D8669EF85E82457A1587CA0ED9C', 'uids': [u'Mister Test <mister_test@testmail.com>'], 'expires': u'', - 'length': u'1024', + 'length': u'1024', 'algo': u'17', 'date': u'1221156445', 'type': u'pub' }] - + mock = Mock(spec=gnupg.GPG) instance = mock.return_value instance.list_keys = gpg_list_keys @@ -187,10 +187,6 @@ def mock_community(): return patch_transactions_recipient_get() elif type(request) is ucoin.hdc.transactions.sender.Last: return patch_transactions_sent_get() - elif type(request) is ucoin.hdc.transactions.View: - return patch_transactions_view_get() - elif type(request) is ucoin.hdc.transactions.sender.Issuance: - return patch_transactions_issuances_get() elif type(request) is ucoin.hdc.coins.List: return { "owner": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", @@ -202,7 +198,7 @@ def mock_community(): "issuer": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", "ids": ["10-1-2-F-14"] }] - } + } elif type(request) == ucoin.pks.Lookup: return user_keys[ get_args['search'] ] else: @@ -218,13 +214,12 @@ def mock_communities(): mock = Mock(spec=Communities, communities_list=[]) return mock - -#TODO: Test account + class Test_Account: def test_account_create1(self, mock_communities): account = Account.create("25500A07", "TestUser", mock_communities) assert account is not None - + def test_account_create2(self, monkeypatch, mock_communities, mock_community): monkeypatch.setattr(gnupg, 'GPG', mock_gpg) mock_communities.communities_list=[mock_community] @@ -256,12 +251,6 @@ class Test_Account: assert len(account.transactions_sent()) == 1 assert sum( trx.value() for trx in account.transactions_sent()) == 200 - def test_account_last_issuances(self, monkeypatch, mock_community, mock_communities): - monkeypatch.setattr(gnupg, 'GPG', mock_gpg) - mock_communities.communities_list=[mock_community] - account = Account.create("25500A07", "TestUser", mock_communities) - assert len(account.last_issuances(mock_community)) == 1 - def test_account_issued_last_dividend(self): pass diff --git a/src/_cutecoin_test/models/account/test_communities.py b/src/_cutecoin_test/models/account/test_communities.py index eedf10425d303d77fc76596505848b11aa666998..d446a8ed1e9827496f40ced16b599e89f2379129 100644 --- a/src/_cutecoin_test/models/account/test_communities.py +++ b/src/_cutecoin_test/models/account/test_communities.py @@ -1,5 +1,5 @@ import pytest -import ucoinpy as ucoin +import ucoin from cutecoin.models.account.communities import Communities diff --git a/src/_cutecoin_test/models/account/test_wallets.py b/src/_cutecoin_test/models/account/test_wallets.py index 7b2f39c8f74a41034b2bf12bf9ea5183e493be49..89df2a85d541a9fad5aaab6afbec85c84e605abc 100644 --- a/src/_cutecoin_test/models/account/test_wallets.py +++ b/src/_cutecoin_test/models/account/test_wallets.py @@ -1,12 +1,11 @@ import pytest -import ucoinpy as ucoin +import ucoin from mock import Mock, MagicMock from cutecoin.models.wallet import Wallet from cutecoin.models.account.wallets import Wallets from cutecoin.models.community import Community, CommunityNetwork - def mock_community(): def community_request(request): if type(request) is ucoin.hdc.coins.List: @@ -23,20 +22,19 @@ def mock_community(): } else: assert 0 - + mock_network = Mock(spec=CommunityNetwork, request=community_request) community = MagicMock(spec=Community, network=mock_network) return community - - + + def mock_wallet(): def wallet_eq(mock1, mock2): return mock1.community == mock2.community mock_wallet = MagicMock(spec=Wallet, __eq__=wallet_eq) - - -#TODO: Test wallets + + class Test_Wallets: def test_wallets_add_wallet(self): wallets = Wallets() @@ -53,7 +51,7 @@ class Test_Wallets: wallets = Wallets() wallets.wallets_list.append(mock_wallet1) wallets.wallets_list.append(mock_wallet2) - + assert wallets.get_wallet(mock_wallet1) is not None assert wallets.get_wallet(mock_wallet2) is not None assert wallets.get_wallet(mock_wallet3) is None @@ -66,7 +64,7 @@ class Test_Wallets: wallets = Wallets() wallets.wallets_list.append(mock_wallet1) wallets.wallets_list.append(mock_wallet2) - + wallets.remove_all_wallets_of(mock1) assert wallets.get_wallet(mock_wallet1) is None assert wallets.get_wallet(mock_wallet2) is not None diff --git a/src/_cutecoin_test/models/test_community.py b/src/_cutecoin_test/models/test_community.py index 704c6e2be8d4ec0f80f2335004fc1d5047d966ff..14aaa75ef23578afe115db545bdf3a20c5425f04 100644 --- a/src/_cutecoin_test/models/test_community.py +++ b/src/_cutecoin_test/models/test_community.py @@ -1,6 +1,6 @@ import pytest from mock import Mock -import ucoinpy as ucoin +import ucoin from cutecoin.models.community import Community from cutecoin.models.community import Node from cutecoin.models.account.wallets import Wallets @@ -11,7 +11,7 @@ from cutecoin.models.node import Node amendment_hash = "3682F828EFB1A1AFF45ACC6DDBB2BAD100DCD605" -def patch_amendment_current_get(*args, **kwargs): +def patch_amendment_Promoted_get(*args, **kwargs): return { "version": "1", "currency": "beta_brousouf", @@ -45,7 +45,7 @@ VotersChanges: -C73882B64B7E72237A2F460CE9CAB76D19A8651E """ } - + def patch_amendments_members_get(*args, **kwargs): return iter([{ @@ -87,41 +87,41 @@ def mock_node(): class Test_Community(): def test_community_create(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Current, - '__get__', patch_amendment_current_get) + monkeypatch.setattr(ucoin.hdc.amendments.Promoted, + '__get__', patch_amendment_Promoted_get) community = Community.create(mock_node) assert community is not None def test_community_dividend(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Current, - '__get__', patch_amendment_current_get) + monkeypatch.setattr(ucoin.hdc.amendments.Promoted, + '__get__', patch_amendment_Promoted_get) community = Community.create(mock_node) assert community.dividend() == 100 def test_community_coin_minimal_power(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Current, - '__get__', patch_amendment_current_get) + monkeypatch.setattr(ucoin.hdc.amendments.Promoted, + '__get__', patch_amendment_Promoted_get) community = Community.create(mock_node) assert community.coin_minimal_power() == 0 def test_community_amendment_id(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Current, - '__get__', patch_amendment_current_get) + monkeypatch.setattr(ucoin.hdc.amendments.Promoted, + '__get__', patch_amendment_Promoted_get) community = Community.create(mock_node) assert community.amendment_id() == "2-"+amendment_hash.upper() def test_community_amendment_number(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Current, - '__get__', patch_amendment_current_get) + monkeypatch.setattr(ucoin.hdc.amendments.Promoted, + '__get__', patch_amendment_Promoted_get) community = Community.create(mock_node) assert community.amendment_number() == 2 def test_community_person_quality(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Current, - '__get__', patch_amendment_current_get) - monkeypatch.setattr(ucoin.hdc.amendments.view.Members, + monkeypatch.setattr(ucoin.hdc.amendments.Promoted, + '__get__', patch_amendment_Promoted_get) + monkeypatch.setattr(ucoin.registry.community.Members, '__get__', patch_amendments_members_get) - monkeypatch.setattr(ucoin.hdc.amendments.view.Voters, + monkeypatch.setattr(ucoin.registry.community.Voters, '__get__', patch_amendments_voters_get) community = Community.create(mock_node) assert community.person_quality("2E69197FAB029D8669EF85E82457A1587CA0ED9C") == "voter" @@ -130,11 +130,11 @@ class Test_Community(): assert community.person_quality("3F871197FAB029D8669EF85E82457A1587CA0ED9C") == "nothing" def test_community_members_fingerprint(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Current, - '__get__', patch_amendment_current_get) - monkeypatch.setattr(ucoin.hdc.amendments.view.Members, + monkeypatch.setattr(ucoin.hdc.amendments.Promoted, + '__get__', patch_amendment_Promoted_get) + monkeypatch.setattr(ucoin.registry.community.Members, '__get__', patch_amendments_members_get) - monkeypatch.setattr(ucoin.hdc.amendments.view.Voters, + monkeypatch.setattr(ucoin.registry.community.Voters, '__get__', patch_amendments_voters_get) community = Community.create(mock_node) @@ -144,11 +144,11 @@ class Test_Community(): assert "3F871197FAB029D8669EF85E82457A1587CA0ED9C" not in community.members_fingerprints() def test_community_voters_fingerprint(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Current, - '__get__', patch_amendment_current_get) - monkeypatch.setattr(ucoin.hdc.amendments.view.Members, + monkeypatch.setattr(ucoin.registry.community.Members, + '__get__', patch_amendment_Promoted_get) + monkeypatch.setattr(ucoin.registry.community.Members, '__get__', patch_amendments_members_get) - monkeypatch.setattr(ucoin.hdc.amendments.view.Voters, + monkeypatch.setattr(ucoin.registry.community.Voters, '__get__', patch_amendments_voters_get) community = Community.create(mock_node) @@ -156,10 +156,9 @@ class Test_Community(): assert "3F870197FAB029D8669EF85E82457A1587CA0ED9C" in community.voters_fingerprints() assert "3F871197FAB029D8669EF85E82457A1587CA0ED9C" not in community.voters_fingerprints() - #TODO: Test community json def test_community_jsonify(self, monkeypatch): - monkeypatch.setattr(ucoin.hdc.amendments.Current, - '__get__', patch_amendment_current_get) + monkeypatch.setattr(ucoin.hdc.amendments.Promoted, + '__get__', patch_amendment_Promoted_get) main_node = Node(trust=True, hoster=True, server="192.168.100.10", port=3800) community = Community.create(main_node) @@ -167,5 +166,5 @@ class Test_Community(): json = community.jsonify(wallets) account = Mock(spec=Account) community2 = Community.load(json, account) - + assert community2.network.nodes[0].server == community.network.nodes[0].server diff --git a/src/_cutecoin_test/models/test_wallet.py b/src/_cutecoin_test/models/test_wallet.py index 0e239c78b049da6b4a126a5fea4166f6b1bfed43..7fd7f5accad056f9924294d72c671dff6e7fa7e3 100644 --- a/src/_cutecoin_test/models/test_wallet.py +++ b/src/_cutecoin_test/models/test_wallet.py @@ -1,5 +1,5 @@ import pytest -import ucoinpy as ucoin +import ucoin from mock import Mock, MagicMock, patch from cutecoin.models.wallet import Wallet from cutecoin.models.community import Community, CommunityNetwork @@ -21,10 +21,10 @@ def mock_community(): } else: assert 0 - + def community_eq(mock1, mock2): return mock1.amendment_id() == mock2.amendment_id() - + mock_network = Mock(spec=CommunityNetwork, request=community_request) community = MagicMock(spec=Community, network=mock_network, __eq__=community_eq) @@ -49,7 +49,7 @@ class Test_Wallet: def test_wallet_get_text(self): pass - + def test_eq(self): mock1 = mock_community() mock1.amendment_id.return_value = "2-AMENDMENTTEST" @@ -59,7 +59,7 @@ class Test_Wallet: wallet2 = Wallet([], mock2) assert wallet1 == wallet2 - + def test_not_eq(self): mock1 = mock_community() mock1.amendment_id.return_value = "2-AMENDMENTTEST" @@ -69,11 +69,11 @@ class Test_Wallet: wallet2 = Wallet([], mock2) assert wallet1 != wallet2 - + def test_wallet_jsonify(self, monkeypatch): wallet = Wallet([], mock_community()) wallet.refresh_coins("86F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8") json = wallet.jsonify() wallet2 = Wallet.load(json, mock_community()) same_coins = [coin1 for coin1, coin2 in zip(wallet.coins, wallet2.coins) if coin1 == coin2] - assert len(same_coins) == len(wallet.coins) and len(same_coins) == len(wallet2.coins) \ No newline at end of file + assert len(same_coins) == len(wallet.coins) and len(same_coins) == len(wallet2.coins) \ No newline at end of file diff --git a/src/cutecoin/__init__.py b/src/cutecoin/__init__.py index 51bcbecf1284d891f6e6e66f5c60546f15e02b15..be12c1445cad91114722ecb698545d94b8592a77 100644 --- a/src/cutecoin/__init__.py +++ b/src/cutecoin/__init__.py @@ -8,7 +8,6 @@ from PyQt5.QtWidgets import QApplication, QDialog from cutecoin.gui.mainWindow import MainWindow from cutecoin.core import Core -#TODO: Rename all functions to match python style if __name__ == '__main__': app = QApplication(sys.argv) diff --git a/src/cutecoin/gui/communityTabWidget.py b/src/cutecoin/gui/communityTabWidget.py index e53a9c2d56ac0c3c9ddc7adf769adfffb5c577b8..f9365ccbc5e8a836e1cb4ac7169b4cfe776a7cc7 100644 --- a/src/cutecoin/gui/communityTabWidget.py +++ b/src/cutecoin/gui/communityTabWidget.py @@ -24,5 +24,4 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): self.setupUi(self) self.community = community self.account = account - #TODO: Rename to list: self.list_community_members.setModel(MembersListModel(community)) diff --git a/src/cutecoin/gui/mainWindow.py b/src/cutecoin/gui/mainWindow.py index 9ec31b8d060a541eb605b04b8a3ab1abb02d5ca2..f6adbe6feebc82276706bfbf2274602bf7bbf174 100644 --- a/src/cutecoin/gui/mainWindow.py +++ b/src/cutecoin/gui/mainWindow.py @@ -6,7 +6,7 @@ Created on 1 févr. 2014 from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow from PyQt5.QtWidgets import QMainWindow, QAction, QErrorMessage, QDialogButtonBox from PyQt5.QtCore import QSignalMapper -from cutecoin.gui.configureAccountDialog import ConfigureAccountDialog +from cutecoin.gui.processConfigureAccount import ProcessConfigureAccount from cutecoin.gui.transferMoneyDialog import TransferMoneyDialog from cutecoin.gui.communityTabWidget import CommunityTabWidget from cutecoin.gui.addContactDialog import AddContactDialog @@ -35,10 +35,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.refresh() def open_add_account_dialog(self): - dialog = ConfigureAccountDialog(self.core, None) - dialog.button_box.button( - QDialogButtonBox.Ok).clicked.connect( - self.refresh) + dialog = ProcessConfigureAccount(self.core, None) + dialog.accepted.connect(self.refresh) dialog.exec_() def save(self): @@ -56,10 +54,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): AddContactDialog(self.core.current_account, self).exec_() def open_configure_account_dialog(self): - dialog = ConfigureAccountDialog(self.core, self.core.current_account) - dialog.button_box.button( - QDialogButtonBox.Ok).clicked.connect( - self.refresh) + dialog = ProcessConfigureAccount(self.core, self.core.current_account) + dialog.accepted.connect(self.refresh) dialog.exec_() ''' diff --git a/src/cutecoin/gui/configureAccountDialog.py b/src/cutecoin/gui/processConfigureAccount.py similarity index 57% rename from src/cutecoin/gui/configureAccountDialog.py rename to src/cutecoin/gui/processConfigureAccount.py index 434f1d42d23cecc76586c9029086650f2a4a4bdc..3a8fd2e8c76149cd6e83ac5f101d49ac016b05f6 100644 --- a/src/cutecoin/gui/configureAccountDialog.py +++ b/src/cutecoin/gui/processConfigureAccount.py @@ -16,7 +16,60 @@ from PyQt5.QtWidgets import QDialog, QErrorMessage, QInputDialog import gnupg -class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog): +class Step(): + def __init__(self, config_dialog, previous_step=None, next_step=None): + self.previous_step = previous_step + self.next_step = next_step + self.config_dialog = config_dialog + + +class StepPageInit(Step): + ''' + First step when adding a community + ''' + def __init__(self, config_dialog): + super().__init__(config_dialog) + + def is_valid(self): + return True + + def process_next(self): + pass + + def display_page(self): + self.config_dialog.button_previous.setEnabled(False) + + +class StepPageCommunities(Step): + ''' + First step when adding a community + ''' + def __init__(self, config_dialog): + super().__init__(config_dialog) + + def is_valid(self): + return True + + def process_next(self): + ''' + We create the community + ''' + server = self.config_dialog.lineedit_server.text() + port = self.config_dialog.spinbox_port.value() + default_node = Node(server, port, trust=True, hoster=True) + account = self.config_dialog.account + self.config_dialog.community = account.communities.add_community( + default_node) + #TODO: Get existing Wallet from ucoin node + account.wallets.add_wallet(account.fingerprint, + self.config_dialog.community) + + def display_page(self): + self.config_dialog.button_previous.setEnabled(False) + self.config_dialog.button_next.setText("Ok") + + +class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog): ''' classdocs ''' @@ -26,10 +79,14 @@ class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog): Constructor ''' # Set up the user interface from Designer. - super(ConfigureAccountDialog, self).__init__() + super(ProcessConfigureAccount, self).__init__() self.setupUi(self) self.account = account self.core = core + step_init = StepPageInit(self) + step_communities = StepPageCommunities(self) + step_init.next_step = step_communities + self.step = step_init if self.account is None: self.setWindowTitle("New account") else: @@ -61,6 +118,7 @@ class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog): def open_process_add_community(self): dialog = ProcessConfigureCommunity(self.account, None) + dialog.accepted.connect(self.action_add_community) dialog.exec_() def action_add_community(self): @@ -90,6 +148,24 @@ class ConfigureAccountDialog(QDialog, Ui_AccountConfigurationDialog): available_keys = gpg.list_keys(True) self.account.keyid = available_keys[key_index]['keyid'] + def next(self): + if self.step.next_step is not None: + if self.step.is_valid(): + self.step.process_next() + self.step = self.step.next_step + next_index = self.stacked_pages.currentIndex() + 1 + self.stacked_pages.setCurrentIndex(next_index) + self.step.display_page() + else: + self.accepted.emit() + + def previous(self): + if self.step.previous_step is not None: + self.step = self.step.previous_step + previous_index = self.stacked_pages.currentIndex() - 1 + self.stacked_pages.setCurrentIndex(previous_index) + self.step.display_page() + def accept(self): if self.account not in self.core.accounts: self.account.name = self.edit_account_name.text() diff --git a/src/cutecoin/gui/processConfigureCommunity.py b/src/cutecoin/gui/processConfigureCommunity.py new file mode 100644 index 0000000000000000000000000000000000000000..89df0821bf9f2af6c185c99315f39e1113f7e2c1 --- /dev/null +++ b/src/cutecoin/gui/processConfigureCommunity.py @@ -0,0 +1,175 @@ +''' +Created on 8 mars 2014 + +@author: inso +''' +import ucoin +from cutecoin.gen_resources.communityConfigurationDialog_uic import Ui_CommunityConfigurationDialog +from PyQt5.QtWidgets import QDialog, QMenu, QMessageBox +from cutecoin.models.community.treeModel import CommunityTreeModel +from cutecoin.models.community.trustsTreeModel import CommunityTrustsTreeModel +from cutecoin.models.node import Node +from cutecoin.gui.walletTabWidget import WalletTabWidget + + +class Step(): + def __init__(self, config_dialog, previous_step=None, next_step=None): + self.previous_step = previous_step + self.next_step = next_step + self.config_dialog = config_dialog + + +class StepPageInit(Step): + ''' + First step when adding a community + ''' + def __init__(self, config_dialog): + super().__init__(config_dialog) + + def is_valid(self): + server = self.config_dialog.lineedit_server.text() + port = self.config_dialog.spinbox_port.value() + try: + ucoin.network.Peering(server, port) + except: + QMessageBox.critical(self, "Server error", + "Cannot get node peering") + return False + return True + + def process_next(self): + ''' + We create the community + ''' + server = self.config_dialog.lineedit_server.text() + port = self.config_dialog.spinbox_port.value() + default_node = Node(server, port, trust=True, hoster=True) + account = self.config_dialog.account + self.config_dialog.community = account.communities.add_community( + default_node) + #TODO: Get existing Wallet from ucoin node + account.wallets.add_wallet(account.fingerprint, + self.config_dialog.community) + + def display_page(self): + self.config_dialog.button_previous.setEnabled(False) + + +class StepPageAddNodes(Step): + ''' + The step where the user add nodes + ''' + def __init__(self, config_dialog): + super().__init__(config_dialog) + + #TODO: Check page validity + def is_valid(self): + return True + + def process_next(self): + pass + + def display_page(self): + tree_model = CommunityTreeModel(self.config_dialog.community) + self.config_dialog.tree_nodes.setModel(tree_model) + self.config_dialog.button_previous.setEnabled(False) + self.config_dialog.button_next.setText("Next") + + +class StepPageSetWallets(Step): + ''' + The step where the user set his wallets + ''' + def __init__(self, config_dialog): + super().__init__(config_dialog) + + #TODO: Check page validity + def is_valid(self): + return True + + def display_page(self): + self.config_dialog.tabs_wallets.clear() + for wallet in self.config_dialog.account.wallets.wallets_list: + wallet_tab = WalletTabWidget(self.config_dialog.account, + self.config_dialog.community) + self.config_dialog.tabs_wallets.addTab(wallet_tab, wallet.name) + + tree_model = CommunityTrustsTreeModel(self.config_dialog.community) + current_tab = self.config_dialog.tabs_wallets.currentWidget() + current_tab.trusts_tree_view.setModel(tree_model) + self.config_dialog.button_previous.setEnabled(True) + self.config_dialog.button_next.setText("Ok") + + def process_next(self): + pass + + +class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): + + ''' + Dialog to configure or add a community + ''' + + def __init__(self, account, community, default_node=None): + ''' + Constructor + ''' + super(ProcessConfigureCommunity, self).__init__() + self.setupUi(self) + self.community = community + self.account = account + self.step = None + + step_init = StepPageInit(self) + step_add_nodes = StepPageAddNodes(self) + step_set_wallets = StepPageSetWallets(self) + + step_init.next_step = step_add_nodes + step_add_nodes.next_step = step_set_wallets + step_set_wallets.previous_step = step_add_nodes + + if self.community is not None: + self.stacked_pages.removeWidget(self.page_init) + self.step = step_add_nodes + self.setWindowTitle("Configure community " + + self.community.currency) + else: + self.step = step_init + self.setWindowTitle("Add a community") + + def next(self): + if self.step.next_step is not None: + if self.step.is_valid(): + self.step.process_next() + self.step = self.step.next_step + next_index = self.stacked_pages.currentIndex() + 1 + self.stacked_pages.setCurrentIndex(next_index) + self.step.display_page() + else: + self.accepted.emit() + self.close() + + def previous(self): + if self.step.previous_step is not None: + self.step = self.step.previous_step + previous_index = self.stacked_pages.currentIndex() - 1 + self.stacked_pages.setCurrentIndex(previous_index) + self.step.display_page() + + def add_node(self): + ''' + Add node slot + ''' + server = self.edit_server.text() + port = self.box_port.value() + if self.community is not None: + self.community.nodes.append(Node(server, port, trust=True)) + self.tree_nodes.setModel(CommunityTreeModel(self.community)) + + def showContextMenu(self, point): + menu = QMenu() + action = menu.addAction("Delete", self.removeNode) + if self.community is not None: + if len(self.community.nodes) == 1: + action.setEnabled(False) + menu.exec_(self.tree_nodes.mapToGlobal(point)) diff --git a/src/cutecoin/gui/walletTabWidget.py b/src/cutecoin/gui/walletTabWidget.py new file mode 100644 index 0000000000000000000000000000000000000000..197b7643e516d5f4589b94649c0286376a105062 --- /dev/null +++ b/src/cutecoin/gui/walletTabWidget.py @@ -0,0 +1,25 @@ +''' +Created on 2 févr. 2014 + +@author: inso +''' + +import logging +from PyQt5.QtWidgets import QWidget +from cutecoin.gen_resources.walletTabWidget_uic import Ui_WalletTabWidget + + +class WalletTabWidget(QWidget, Ui_WalletTabWidget): + + ''' + classdocs + ''' + + def __init__(self, account, community): + ''' + Constructor + ''' + super(WalletTabWidget, self).__init__() + self.setupUi(self) + self.community = community + self.account = account diff --git a/src/cutecoin/models/account/wallets/__init__.py b/src/cutecoin/models/account/wallets/__init__.py index f6804f781966acb41d6ade61e017d16fcfeb0b1f..2b4164006c360fd83065423b5f3c1ffcac06a7e9 100644 --- a/src/cutecoin/models/account/wallets/__init__.py +++ b/src/cutecoin/models/account/wallets/__init__.py @@ -19,13 +19,13 @@ class Wallets(object): ''' self.wallets_list = [] - def add_wallet(self, community): + def add_wallet(self, fingerprint, community, name="Main Wallet"): ''' Create a new wallet of a specific currency. This wallet must not already be present in the account, it means the wallet must have a different name or a different currency. ''' - wallet = Wallet.create(community) + wallet = Wallet.create(fingerprint, community, name) if wallet not in self.wallets_list: self.wallets_list.append(wallet) return wallet diff --git a/src/cutecoin/models/community/trustsTreeModel.py b/src/cutecoin/models/community/trustsTreeModel.py index 3a217772ac322dc3501cb4d8eaf4104b23dce01b..314a9d09c49c1117c16585c322effbb3394c9041 100644 --- a/src/cutecoin/models/community/trustsTreeModel.py +++ b/src/cutecoin/models/community/trustsTreeModel.py @@ -120,7 +120,7 @@ class CommunityTrustsTreeModel(QAbstractItemModel): node_item = NodeItem(node, self.root_item) logging.debug( "mainNode : " + - node.getText() + + node.get_text() + " / " + node_item.data(0)) self.root_item.appendChild(node_item) @@ -128,7 +128,7 @@ class CommunityTrustsTreeModel(QAbstractItemModel): child_node_item = NodeItem(node, node_item) logging.debug( "\t node : " + - node.getText() + + node.get_text() + " / " + child_node_item.data(0)) node_item.appendChild(child_node_item) diff --git a/src/cutecoin/models/wallet/__init__.py b/src/cutecoin/models/wallet/__init__.py index e1e23ee846bcca2ed3c6be52bc738fd5d823008d..2d918c765e3af2468ec4e833527c419e083f3dc8 100644 --- a/src/cutecoin/models/wallet/__init__.py +++ b/src/cutecoin/models/wallet/__init__.py @@ -19,7 +19,7 @@ class Wallet(object): It's only used to sort coins. ''' - def __init__(self, fingerprint, coins, community, name="Main Wallet"): + def __init__(self, fingerprint, coins, community, name): ''' Constructor ''' @@ -29,8 +29,8 @@ class Wallet(object): self.name = name @classmethod - def create(cls, community): - return cls([], community) + def create(cls, fingerprint, community, name): + return cls(fingerprint, [], community, name) @classmethod def load(cls, json_data, community): diff --git a/src/cutecoin/tools/__init__.py b/src/cutecoin/tools/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391