diff --git a/res/ui/wallets_tab.ui b/res/ui/wallets_tab.ui index 77685701387570ab1a377dd0f9f2ab853d1c22e1..0bb91ecf4c3ba4fe73afca102b788dc2964f6649 100644 --- a/res/ui/wallets_tab.ui +++ b/res/ui/wallets_tab.ui @@ -89,6 +89,15 @@ QGroupBox::title { <verstretch>0</verstretch> </sizepolicy> </property> + <property name="contextMenuPolicy"> + <enum>Qt::CustomContextMenu</enum> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::SingleSelection</enum> + </property> + <property name="selectionBehavior"> + <enum>QAbstractItemView::SelectRows</enum> + </property> <property name="sortingEnabled"> <bool>true</bool> </property> @@ -105,5 +114,26 @@ QGroupBox::title { <resources> <include location="../icons/icons.qrc"/> </resources> - <connections/> + <connections> + <connection> + <sender>table_wallets</sender> + <signal>customContextMenuRequested(QPoint)</signal> + <receiver>WalletsTab</receiver> + <slot>wallet_context_menu(QPoint)</slot> + <hints> + <hint type="sourcelabel"> + <x>199</x> + <y>346</y> + </hint> + <hint type="destinationlabel"> + <x>199</x> + <y>225</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>wallet_context_menu(QPoint)</slot> + <slot>wallet_changed()</slot> + </slots> </ui> diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 6baaf058a89877e9e7d3a7b39feb7a69ae950a58..3f88342b2ff00461ca6b9d62ee0d5d88a8975d42 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -13,7 +13,7 @@ from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication, \ QMessageBox, QDialog, QAbstractItemView, QHeaderView from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot, QObject, \ QThread, pyqtSignal, QDateTime -from PyQt5.QtGui import QIcon +from PyQt5.QtGui import QIcon, QCursor from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget from .community_tab import CommunityTabWidget from .transfer import TransferMoneyDialog @@ -80,9 +80,9 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.tab_community = CommunityTabWidget(self.app.current_account, self.community, self.password_asker) - self.tab_wallets = WalletsTabWidget(self.app.current_account, + self.tab_wallets = WalletsTabWidget(self.app, + self.app.current_account, self.community) - self.bc_watcher = BlockchainWatcher(self.app.current_account, community) self.bc_watcher.new_block_mined.connect(self.refresh_block) @@ -150,16 +150,17 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.tab_community = CommunityTabWidget(self.app.current_account, self.community, self.password_asker) + self.tabs_account.addTab(self.tab_community, + QIcon(':/icons/community_icon'), + "Community") - self.tab_wallets = WalletsTabWidget(self.app.current_account, + self.tab_wallets = WalletsTabWidget(self.app, + self.app.current_account, self.community) self.tabs_account.addTab(self.tab_wallets, QIcon(':/icons/wallet_icon'), "Wallets") - self.tabs_account.addTab(self.tab_community, - QIcon(':/icons/community_icon'), - "Community") self.tab_informations = InformationsTabWidget(self.app.current_account, self.community) self.tabs_account.addTab(self.tab_informations, @@ -182,11 +183,6 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): if self.tab_wallets: self.tab_wallets.refresh() - if self.list_wallet_content.model(): - self.list_wallet_content.model().dataChanged.emit( - QModelIndex(), - QModelIndex(), - []) if self.table_history.model(): self.table_history.model().dataChanged.emit( QModelIndex(), @@ -203,35 +199,8 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.status_label.setText(text) def refresh_wallets(self): - self.tab_wallets.refresh() - ''' if self.app.current_account: - wallets_list_model = WalletsListModel(self.app.current_account, - self.community) - wallets_list_model.dataChanged.connect(self.wallet_changed) - self.list_wallets.setModel(wallets_list_model) - self.refresh_wallet_content(QModelIndex()) - ''' - - def wallet_context_menu(self, point): - index = self.list_wallets.indexAt(point) - model = self.list_wallets.model() - if index.row() < model.rowCount(QModelIndex()): - wallet = model.wallets[index.row()] - menu = QMenu(model.data(index, Qt.DisplayRole), self) - - rename = QAction("Rename", self) - rename.triggered.connect(self.rename_wallet) - rename.setData(index) - - copy_pubkey = QAction("Copy pubkey to clipboard", self) - copy_pubkey.triggered.connect(self.copy_pubkey_to_clipboard) - copy_pubkey.setData(wallet) - - menu.addAction(rename) - menu.addAction(copy_pubkey) - # Show the context menu. - menu.exec_(self.list_wallets.mapToGlobal(point)) + self.tab_wallets.refresh() def history_context_menu(self, point): index = self.table_history.indexAt(point) @@ -265,11 +234,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): copy_pubkey.setData(person) menu.addAction(copy_pubkey) # Show the context menu. - menu.exec_(self.table_history.mapToGlobal(point)) - - def rename_wallet(self): - index = self.sender().data() - self.list_wallets.edit(index) + menu.exec_(QCursor.pos()) def copy_pubkey_to_clipboard(self): data = self.sender().data() @@ -309,9 +274,6 @@ QMessageBox.Ok | QMessageBox.Cancel) transfer.drop() self.table_history.model().invalidate() - def wallet_changed(self): - self.app.save(self.app.current_account) - def showEvent(self, event): blockid = self.community.current_blockid() block_number = blockid['number'] diff --git a/src/cutecoin/gui/wallets_tab.py b/src/cutecoin/gui/wallets_tab.py index 59623b3b5e7a4b7612007aecc7f302ef4a1a468b..2ba88f6c1cab573e710025631957b5b75e797226 100644 --- a/src/cutecoin/gui/wallets_tab.py +++ b/src/cutecoin/gui/wallets_tab.py @@ -5,9 +5,11 @@ Created on 15 févr. 2015 ''' import logging -from PyQt5.QtWidgets import QWidget -from PyQt5.QtCore import QDateTime +from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication +from PyQt5.QtCore import QDateTime, QModelIndex, Qt +from PyQt5.QtGui import QCursor from ..core.person import Person +from ..core.wallet import Wallet from ..models.wallets import WalletsTableModel, WalletsFilterProxyModel from ..tools.exceptions import MembershipNotFoundError from ..gen_resources.wallets_tab_uic import Ui_WalletsTab @@ -18,12 +20,13 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): classdocs ''' - def __init__(self, account, community): + def __init__(self, app, account, community): ''' Constructor ''' super().__init__() self.setupUi(self) + self.app = app self.account = account self.community = community @@ -88,6 +91,7 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): wallets_model = WalletsTableModel(self.account, self.community) proxy_model = WalletsFilterProxyModel() proxy_model.setSourceModel(wallets_model) + wallets_model.dataChanged.connect(self.wallet_changed) self.table_wallets.setModel(proxy_model) def get_referential_value(self, value): @@ -98,3 +102,50 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): def get_referential_name(self): return self.account.ref_name(self.community.short_currency) + + def wallet_context_menu(self, point): + index = self.table_wallets.indexAt(point) + model = self.table_wallets.model() + if index.row() < model.rowCount(QModelIndex()): + source_index = model.mapToSource(index) + + name_col = model.sourceModel().columns_types.index('name') + name_index = model.index(index.row(), + name_col) + + pubkey_col = model.sourceModel().columns_types.index('pubkey') + pubkey_index = model.sourceModel().index(source_index.row(), + pubkey_col) + + pubkey = model.sourceModel().data(pubkey_index, Qt.DisplayRole) + menu = QMenu(model.data(index, Qt.DisplayRole), self) + + rename = QAction("Rename", self) + rename.triggered.connect(self.rename_wallet) + rename.setData(name_index) + + copy_pubkey = QAction("Copy pubkey to clipboard", self) + copy_pubkey.triggered.connect(self.copy_pubkey_to_clipboard) + copy_pubkey.setData(pubkey) + + menu.addAction(rename) + menu.addAction(copy_pubkey) + # Show the context menu. + menu.exec_(QCursor.pos()) + + def rename_wallet(self): + index = self.sender().data() + self.table_wallets.edit(index) + + def wallet_changed(self): + self.app.save(self.app.current_account) + + def copy_pubkey_to_clipboard(self): + data = self.sender().data() + clipboard = QApplication.clipboard() + if data.__class__ is Wallet: + clipboard.setText(data.pubkey) + elif data.__class__ is Person: + clipboard.setText(data.pubkey) + elif data.__class__ is str: + clipboard.setText(data) diff --git a/src/cutecoin/models/wallet.py b/src/cutecoin/models/wallet.py deleted file mode 100644 index 8c67ae6ad6372162d8baecfcc1170fe45ccad792..0000000000000000000000000000000000000000 --- a/src/cutecoin/models/wallet.py +++ /dev/null @@ -1,33 +0,0 @@ -''' -Created on 8 févr. 2014 - -@author: inso -''' - -from PyQt5.QtCore import QAbstractListModel, Qt - - -class WalletListModel(QAbstractListModel): - - ''' - A Qt abstract item model to display communities in a tree - ''' - - def __init__(self, wallet, community, parent=None): - ''' - Constructor - ''' - super(WalletListModel, self).__init__(parent) - self.sources = wallet.sources(community) - - def rowCount(self, parent): - return len(self.sources) - - def data(self, index, role): - if role == Qt.DisplayRole: - row = index.row() - amount = self.sources[row].amount - return amount - - def flags(self, index): - return Qt.ItemIsSelectable | Qt.ItemIsEnabled diff --git a/src/cutecoin/models/wallets.py b/src/cutecoin/models/wallets.py index fe5f20ac2f4a804e4ec7cde322cadd072af225d9..8cc9614dfd0e942e0ee2be5b34d1a0455dda50ed 100644 --- a/src/cutecoin/models/wallets.py +++ b/src/cutecoin/models/wallets.py @@ -92,13 +92,15 @@ class WalletsTableModel(QAbstractTableModel): if role == Qt.DisplayRole: return self.wallet_data(row)[col] -# def setData(self, index, value, role): -# if role == Qt.EditRole: -# row = index.row() -# self.wallets[row].name = value -# self.dataChanged.emit(index, index) -# return True -# return False + def setData(self, index, value, role): + if role == Qt.EditRole: + row = index.row() + col = index.column() + if col == self.columns_types.index('name'): + self.wallets[row].name = value + self.dataChanged.emit(index, index) + return True + return False def flags(self, index): return Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable