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 @@
<string>Transfer money to</string>
</property>
<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>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
......@@ -28,12 +49,15 @@
<string>Recipient fingerprint</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="edit_key_fingerprint">
<property name="enabled">
<bool>false</bool>
</property>
<property name="inputMask">
<string/>
</property>
......@@ -47,33 +71,36 @@
</item>
</layout>
</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>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QRadioButton" name="radio_contact">
<widget class="QRadioButton" name="radio_trusted_node">
<property name="text">
<string>Contact</string>
<string>Trusted node</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combo_contact">
<widget class="QComboBox" name="combo_trusted_node">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</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>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
......@@ -82,12 +109,15 @@
<string>Node</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="edit_node_address">
<property name="enabled">
<bool>false</bool>
</property>
<property name="inputMask">
<string/>
</property>
......@@ -105,6 +135,9 @@
</item>
<item>
<widget class="QSpinBox" name="spinbox_port">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximum">
<number>99999</number>
</property>
......@@ -115,24 +148,6 @@
</item>
</layout>
</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>
</widget>
</item>
......@@ -165,13 +180,6 @@
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="button_manage_coins">
<property name="text">
<string>Manage wallet coins</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_add">
<property name="text">
......@@ -325,22 +333,6 @@
</hint>
</hints>
</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>
<sender>combo_wallets</sender>
<signal>currentIndexChanged(int)</signal>
......
......@@ -6,15 +6,19 @@ Created on 7 févr. 2014
import logging
from optparse import OptionParser
import os.path
import gnupg
from os import environ
import ucoin
import gnupg
if "XDG_CONFIG_HOME" in environ:
config_path = environ["XDG_CONFIG_HOME"]
else:
config_path = environ["HOME"] + "/.config"
home = os.path.expanduser("~")
parameters = {'home': home + '/.config/cutecoin/',
'data': home + '/.config/cutecoin/' 'data'}
parameters = {'home': config_path + '/cutecoin/',
'data': config_path + '/cutecoin/' 'data'}
def parse_arguments(argv):
......
......@@ -4,14 +4,14 @@ Created on 1 févr. 2014
@author: inso
'''
from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow
from PyQt5.QtWidgets import QMainWindow, QAction, QErrorMessage, QDialogButtonBox
from PyQt5.QtCore import QSignalMapper
from PyQt5.QtWidgets import QMainWindow, QAction
from PyQt5.QtCore import QSignalMapper, QModelIndex
from cutecoin.gui.processConfigureAccount import ProcessConfigureAccount
from cutecoin.gui.transferMoneyDialog import TransferMoneyDialog
from cutecoin.gui.communityTabWidget import CommunityTabWidget
from cutecoin.gui.addContactDialog import AddContactDialog
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.receivedListModel import ReceivedListModel
......@@ -48,14 +48,16 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.refresh()
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):
AddContactDialog(self.core.current_account, self).exec_()
def open_configure_account_dialog(self):
dialog = ProcessConfigureAccount(self.core, self.core.current_account)
dialog.accepted.connect(self.refresh)
dialog.accepted.connect(self.refresh_wallets)
dialog.exec_()
'''
......@@ -83,11 +85,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
"Current account : " +
self.core.current_account.name)
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_wallets()
self.tabs_communities.clear()
for community in self.core.current_account.communities:
......@@ -109,9 +107,17 @@ class MainWindow(QMainWindow, Ui_MainWindow):
ReceivedListModel(
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):
if index.isValid():
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:
self.list_wallet_content.setModel(WalletListModel([]))
self.list_wallet_content.setModel(CoinsListModel(None, []))
......@@ -40,31 +40,19 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
def remove_coins_from_transfer(self):
selection = self.list_coins_sent.selectedIndexes()
wallet_coins = self.list_wallet.model().coins
sent_coins = self.list_coins_sent.model().coins
new_wallet = sent_coins
for selected in selection:
coin = sent_coins[selected.row()]
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))
for select in selection:
coins = self.list_coins_sent.model().remove_coins(select, 1)
self.list_wallet.model().add_coins(coins)
self.label_total.setText("Total : %d" %
self.list_coins_sent.model().total())
def add_coins_to_transfer(self):
selection = self.list_wallet.selectedIndexes()
wallet_coins = self.list_wallet.model().coins
sent_coins = self.list_coins_sent.model().coins
new_wallet_coins = wallet_coins
for selected in selection:
coin = wallet_coins[selected.row()]
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
for select in selection:
coins = self.list_wallet.model().remove_coins(select, 1)
self.list_coins_sent.model().add_coins(coins)
self.label_total.setText("Total : %d"
% self.list_coins_sent.model().total())
def accept(self):
sent_coins = self.list_coins_sent.model().to_list()
......@@ -90,6 +78,7 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
if error:
QErrorMessage(self).showMessage("Cannot transfer coins " + error)
else:
self.accepted.emit()
self.close()
def change_displayed_wallet(self, index):
......
......@@ -18,23 +18,65 @@ class CoinsListModel(QAbstractListModel):
Constructor
'''
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
def rowCount(self, parent):
return len(self.coins)
return len(self.ordered_values)
def data(self, index, role):
if role == Qt.DisplayRole:
row = index.row()
value = str(self.coins[row].value(self.wallet))
return value
coins_list = self.sorted_coins[self.ordered_values[row]]
text = """%d coins of %d""" % (len(coins_list),
self.ordered_values[row])
return text
def flags(self, index):
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):
coins_list = []
for c in self.coins:
coins_list.append(c.get_id())
for value in self.coin_values:
for coin in self.sorted_coins[value]:
coins_list.append(coin.get_id())
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.
Finish editing this message first!
Please register or to comment