Skip to content
Snippets Groups Projects
Commit f2df4cc6 authored by inso's avatar inso
Browse files

Better UI and bug fix

parent e87b9edf
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,27 @@ ...@@ -20,6 +20,27 @@
<string>Transfer money to</string> <string>Transfer money to</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QRadioButton" name="radio_contact">
<property name="text">
<string>Contact</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combo_contact">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
...@@ -28,12 +49,15 @@ ...@@ -28,12 +49,15 @@
<string>Recipient fingerprint</string> <string>Recipient fingerprint</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="edit_key_fingerprint"> <widget class="QLineEdit" name="edit_key_fingerprint">
<property name="enabled">
<bool>false</bool>
</property>
<property name="inputMask"> <property name="inputMask">
<string/> <string/>
</property> </property>
...@@ -47,33 +71,36 @@ ...@@ -47,33 +71,36 @@
</item> </item>
</layout> </layout>
</item> </item>
</layout>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Transfer using node</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QRadioButton" name="radio_contact"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QRadioButton" name="radio_trusted_node">
<property name="text"> <property name="text">
<string>Contact</string> <string>Trusted node</string>
</property>
<property name="checked">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="combo_contact"> <widget class="QComboBox" name="combo_trusted_node">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Transfer using node</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
...@@ -82,12 +109,15 @@ ...@@ -82,12 +109,15 @@
<string>Node</string> <string>Node</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="edit_node_address"> <widget class="QLineEdit" name="edit_node_address">
<property name="enabled">
<bool>false</bool>
</property>
<property name="inputMask"> <property name="inputMask">
<string/> <string/>
</property> </property>
...@@ -105,6 +135,9 @@ ...@@ -105,6 +135,9 @@
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinbox_port"> <widget class="QSpinBox" name="spinbox_port">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximum"> <property name="maximum">
<number>99999</number> <number>99999</number>
</property> </property>
...@@ -115,24 +148,6 @@ ...@@ -115,24 +148,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QRadioButton" name="radio_trusted_node">
<property name="text">
<string>Trusted node</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combo_trusted_node">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
...@@ -165,13 +180,6 @@ ...@@ -165,13 +180,6 @@
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>0</number>
</property> </property>
<item>
<widget class="QPushButton" name="button_manage_coins">
<property name="text">
<string>Manage wallet coins</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="button_add"> <widget class="QPushButton" name="button_add">
<property name="text"> <property name="text">
...@@ -325,22 +333,6 @@ ...@@ -325,22 +333,6 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>button_manage_coins</sender>
<signal>clicked()</signal>
<receiver>TransferMoneyDialog</receiver>
<slot>open_manage_wallet_coins()</slot>
<hints>
<hint type="sourcelabel">
<x>201</x>
<y>281</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>244</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>combo_wallets</sender> <sender>combo_wallets</sender>
<signal>currentIndexChanged(int)</signal> <signal>currentIndexChanged(int)</signal>
......
...@@ -6,15 +6,19 @@ Created on 7 févr. 2014 ...@@ -6,15 +6,19 @@ Created on 7 févr. 2014
import logging import logging
from optparse import OptionParser from optparse import OptionParser
import os.path from os import environ
import gnupg
import ucoin import ucoin
import gnupg
home = os.path.expanduser("~") if "XDG_CONFIG_HOME" in environ:
config_path = environ["XDG_CONFIG_HOME"]
else:
config_path = environ["HOME"] + "/.config"
parameters = {'home': home + '/.config/cutecoin/', parameters = {'home': config_path + '/cutecoin/',
'data': home + '/.config/cutecoin/' 'data'} 'data': config_path + '/cutecoin/' 'data'}
def parse_arguments(argv): def parse_arguments(argv):
......
...@@ -4,14 +4,14 @@ Created on 1 févr. 2014 ...@@ -4,14 +4,14 @@ Created on 1 févr. 2014
@author: inso @author: inso
''' '''
from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow
from PyQt5.QtWidgets import QMainWindow, QAction, QErrorMessage, QDialogButtonBox from PyQt5.QtWidgets import QMainWindow, QAction
from PyQt5.QtCore import QSignalMapper from PyQt5.QtCore import QSignalMapper, QModelIndex
from cutecoin.gui.processConfigureAccount import ProcessConfigureAccount from cutecoin.gui.processConfigureAccount import ProcessConfigureAccount
from cutecoin.gui.transferMoneyDialog import TransferMoneyDialog from cutecoin.gui.transferMoneyDialog import TransferMoneyDialog
from cutecoin.gui.communityTabWidget import CommunityTabWidget from cutecoin.gui.communityTabWidget import CommunityTabWidget
from cutecoin.gui.addContactDialog import AddContactDialog from cutecoin.gui.addContactDialog import AddContactDialog
from cutecoin.models.account.wallets.listModel import WalletsListModel from cutecoin.models.account.wallets.listModel import WalletsListModel
from cutecoin.models.wallet.listModel import WalletListModel from cutecoin.models.coin.listModel import CoinsListModel
from cutecoin.models.transaction.sentListModel import SentListModel from cutecoin.models.transaction.sentListModel import SentListModel
from cutecoin.models.transaction.receivedListModel import ReceivedListModel from cutecoin.models.transaction.receivedListModel import ReceivedListModel
...@@ -48,14 +48,16 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -48,14 +48,16 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.refresh() self.refresh()
def open_transfer_money_dialog(self): def open_transfer_money_dialog(self):
TransferMoneyDialog(self.core.current_account).exec_() dialog = TransferMoneyDialog(self.core.current_account)
dialog.accepted.connect(self.refresh_wallets)
dialog.exec_()
def open_add_contact_dialog(self): def open_add_contact_dialog(self):
AddContactDialog(self.core.current_account, self).exec_() AddContactDialog(self.core.current_account, self).exec_()
def open_configure_account_dialog(self): def open_configure_account_dialog(self):
dialog = ProcessConfigureAccount(self.core, self.core.current_account) dialog = ProcessConfigureAccount(self.core, self.core.current_account)
dialog.accepted.connect(self.refresh) dialog.accepted.connect(self.refresh_wallets)
dialog.exec_() dialog.exec_()
''' '''
...@@ -83,11 +85,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -83,11 +85,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
"Current account : " + "Current account : " +
self.core.current_account.name) self.core.current_account.name)
for wallet in self.core.current_account.wallets: self.refresh_wallets()
wallet.refresh_coins()
wallets_list_model = WalletsListModel(self.core.current_account)
self.list_wallets.setModel(wallets_list_model)
self.tabs_communities.clear() self.tabs_communities.clear()
for community in self.core.current_account.communities: for community in self.core.current_account.communities:
...@@ -109,9 +107,17 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -109,9 +107,17 @@ class MainWindow(QMainWindow, Ui_MainWindow):
ReceivedListModel( ReceivedListModel(
self.core.current_account)) self.core.current_account))
def refresh_wallets(self):
for wallet in self.core.current_account.wallets:
wallet.refresh_coins()
wallets_list_model = WalletsListModel(self.core.current_account)
self.list_wallets.setModel(wallets_list_model)
self.refresh_wallet_content(QModelIndex())
def refresh_wallet_content(self, index): def refresh_wallet_content(self, index):
if index.isValid(): if index.isValid():
current_wallet = self.core.current_account.wallets[index.row()] current_wallet = self.core.current_account.wallets[index.row()]
self.list_wallet_content.setModel(WalletListModel(current_wallet)) self.list_wallet_content.setModel(CoinsListModel(current_wallet, current_wallet.coins))
else: else:
self.list_wallet_content.setModel(WalletListModel([])) self.list_wallet_content.setModel(CoinsListModel(None, []))
...@@ -40,31 +40,19 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): ...@@ -40,31 +40,19 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
def remove_coins_from_transfer(self): def remove_coins_from_transfer(self):
selection = self.list_coins_sent.selectedIndexes() selection = self.list_coins_sent.selectedIndexes()
wallet_coins = self.list_wallet.model().coins for select in selection:
sent_coins = self.list_coins_sent.model().coins coins = self.list_coins_sent.model().remove_coins(select, 1)
new_wallet = sent_coins self.list_wallet.model().add_coins(coins)
for selected in selection: self.label_total.setText("Total : %d" %
coin = sent_coins[selected.row()] self.list_coins_sent.model().total())
sent_coins.remove(coin)
wallet_coins.append(coin)
self.list_wallet.setModel(CoinsListModel(self.wallet, wallet_coins))
self.list_coins_sent.setModel(CoinsListModel(self.wallet, new_wallet))
def add_coins_to_transfer(self): def add_coins_to_transfer(self):
selection = self.list_wallet.selectedIndexes() selection = self.list_wallet.selectedIndexes()
wallet_coins = self.list_wallet.model().coins for select in selection:
sent_coins = self.list_coins_sent.model().coins coins = self.list_wallet.model().remove_coins(select, 1)
new_wallet_coins = wallet_coins self.list_coins_sent.model().add_coins(coins)
for selected in selection: self.label_total.setText("Total : %d"
coin = wallet_coins[selected.row()] % self.list_coins_sent.model().total())
new_wallet_coins.remove(coin)
sent_coins.append(coin)
self.list_wallet.setModel(CoinsListModel(self.wallet,
new_wallet_coins))
self.list_coins_sent.setModel(CoinsListModel(self.wallet, sent_coins))
def open_manage_wallet_coins(self):
pass
def accept(self): def accept(self):
sent_coins = self.list_coins_sent.model().to_list() sent_coins = self.list_coins_sent.model().to_list()
...@@ -90,6 +78,7 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): ...@@ -90,6 +78,7 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
if error: if error:
QErrorMessage(self).showMessage("Cannot transfer coins " + error) QErrorMessage(self).showMessage("Cannot transfer coins " + error)
else: else:
self.accepted.emit()
self.close() self.close()
def change_displayed_wallet(self, index): def change_displayed_wallet(self, index):
......
...@@ -18,23 +18,65 @@ class CoinsListModel(QAbstractListModel): ...@@ -18,23 +18,65 @@ class CoinsListModel(QAbstractListModel):
Constructor Constructor
''' '''
super(CoinsListModel, self).__init__(parent) super(CoinsListModel, self).__init__(parent)
self.coins = coins self.sorted_coins = {}
self.coin_values = set()
for c in coins:
value = c.value(wallet)
if value not in self.sorted_coins:
self.sorted_coins[value] = []
self.sorted_coins[value] += [c]
self.coin_values.update([value])
self.ordered_values = list(self.coin_values)
self.ordered_values.sort()
self.wallet = wallet self.wallet = wallet
def rowCount(self, parent): def rowCount(self, parent):
return len(self.coins) return len(self.ordered_values)
def data(self, index, role): def data(self, index, role):
if role == Qt.DisplayRole: if role == Qt.DisplayRole:
row = index.row() row = index.row()
value = str(self.coins[row].value(self.wallet)) coins_list = self.sorted_coins[self.ordered_values[row]]
return value
text = """%d coins of %d""" % (len(coins_list),
self.ordered_values[row])
return text
def flags(self, index): def flags(self, index):
return Qt.ItemIsSelectable | Qt.ItemIsEnabled return Qt.ItemIsSelectable | Qt.ItemIsEnabled
def remove_coins(self, index, number):
removed = []
value = self.ordered_values[index.row()]
removed += self.sorted_coins[value][-number:]
self.sorted_coins[value] = self.sorted_coins[value][:-number]
self.dataChanged.emit(index, index, [Qt.DisplayRole])
return removed
def add_coins(self, coins):
for c in coins:
value = c.value(self.wallet)
if value not in self.sorted_coins:
self.sorted_coins[value] = []
self.sorted_coins[value] += [c]
self.coin_values.update([value])
self.ordered_values = list(self.coin_values)
self.ordered_values.sort()
self.layoutChanged.emit()
def to_list(self): def to_list(self):
coins_list = [] coins_list = []
for c in self.coins: for value in self.coin_values:
coins_list.append(c.get_id()) for coin in self.sorted_coins[value]:
coins_list.append(coin.get_id())
return coins_list return coins_list
def total(self):
total = 0
for value in self.coin_values:
for coin in self.sorted_coins[value]:
total += coin.value(self.wallet)
return total
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment