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

cutecoin 0.2.0

Merge branch 'dev'
parents 7332369c ae043912
No related branches found
No related tags found
No related merge requests found
Showing
with 603 additions and 15 deletions
......@@ -6,11 +6,11 @@ RESOURCE_DIR = res/ui
COMPILED_DIR = src/cutecoin/gen_resources
#UI files to compile
UI_FILES = mainwindow.ui addAccountDialog.ui addCommunityDialog.ui communityTabWidget.ui issuanceDialog.ui
UI_FILES = mainwindow.ui addAccountDialog.ui addCommunityDialog.ui communityTabWidget.ui issuanceDialog.ui transferDialog.ui
#Qt resource files to compile
RESOURCES =
#pyuic4 and pyrcc4 binaries
#pyuic5 and pyrcc5 binaries
PYUIC = pyuic5
PYRCC = pyrcc5
......
......@@ -139,8 +139,15 @@
<addaction name="separator"/>
<addaction name="actionAdd_a_contact"/>
</widget>
<widget class="QMenu" name="menuActions">
<property name="title">
<string>Actions</string>
</property>
<addaction name="actionTransfer_money"/>
</widget>
<addaction name="menuTr_File"/>
<addaction name="menuEdit"/>
<addaction name="menuActions"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionManage_accounts">
......@@ -208,6 +215,11 @@
<string>Account</string>
</property>
</action>
<action name="actionTransfer_money">
<property name="text">
<string>Transfer money</string>
</property>
</action>
</widget>
<resources/>
<connections>
......@@ -259,9 +271,26 @@
</hint>
</hints>
</connection>
<connection>
<sender>actionTransfer_money</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>openTransferMoneyDialog()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>248</x>
<y>218</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>openAddAccountDialog()</slot>
<slot>save()</slot>
<slot>openTransferMoneyDialog()</slot>
</slots>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TransferMoneyDialog</class>
<widget class="QDialog" name="TransferMoneyDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>489</height>
</rect>
</property>
<property name="windowTitle">
<string>Transfer money</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Transfer money to</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="radio_keyFingerprint">
<property name="text">
<string>Recipient fingerprint</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="edit_keyFingerprint">
<property name="inputMask">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Key fingerprint</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QRadioButton" name="radio_contact">
<property name="text">
<string>Contact</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_contact">
<property name="enabled">
<bool>false</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>
<widget class="QRadioButton" name="radio_nodeAddress">
<property name="text">
<string>Node</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="edit_nodeAddress">
<property name="inputMask">
<string/>
</property>
<property name="placeholderText">
<string>Node address</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="edit_port">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="placeholderText">
<string>Port</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QRadioButton" name="radio_trustedNode">
<property name="text">
<string>Trusted node</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_trustedNode">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Coins</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="topMargin">
<number>5</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="leftMargin">
<number>6</number>
</property>
<item>
<widget class="QComboBox" name="comboBox_wallets"/>
</item>
<item>
<widget class="QListView" name="listView_wallet"/>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="button_manageCoins">
<property name="text">
<string>Manage wallet coins</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_add">
<property name="text">
<string>&gt;&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_remove">
<property name="text">
<string>&lt;&lt;</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="edit_message">
<property name="placeholderText">
<string>A message</string>
</property>
</widget>
</item>
<item>
<widget class="QListView" name="listView_coinsSent">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>8</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<property name="topMargin">
<number>5</number>
</property>
<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="QLabel" name="label_total">
<property name="text">
<string>Total money transfered : 0 </string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>TransferMoneyDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>TransferMoneyDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>button_add</sender>
<signal>clicked()</signal>
<receiver>TransferMoneyDialog</receiver>
<slot>addCoinsToTransfer()</slot>
<hints>
<hint type="sourcelabel">
<x>201</x>
<y>327</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>244</y>
</hint>
</hints>
</connection>
<connection>
<sender>button_remove</sender>
<signal>clicked()</signal>
<receiver>TransferMoneyDialog</receiver>
<slot>removeCoinsFromTransfer()</slot>
<hints>
<hint type="sourcelabel">
<x>201</x>
<y>373</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>244</y>
</hint>
</hints>
</connection>
<connection>
<sender>button_manageCoins</sender>
<signal>clicked()</signal>
<receiver>TransferMoneyDialog</receiver>
<slot>openManageWalletCoins()</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>comboBox_wallets</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>TransferMoneyDialog</receiver>
<slot>changeDisplayedWallet()</slot>
<hints>
<hint type="sourcelabel">
<x>82</x>
<y>264</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>244</y>
</hint>
</hints>
</connection>
<connection>
<sender>radio_keyFingerprint</sender>
<signal>toggled(bool)</signal>
<receiver>TransferMoneyDialog</receiver>
<slot>recipientModeChanged(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>87</x>
<y>51</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>244</y>
</hint>
</hints>
</connection>
<connection>
<sender>radio_nodeAddress</sender>
<signal>toggled(bool)</signal>
<receiver>TransferMoneyDialog</receiver>
<slot>transferModeChanged(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>70</x>
<y>155</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>244</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>addCoinsToTransfer()</slot>
<slot>removeCoinsFromTransfer()</slot>
<slot>openManageWalletCoins()</slot>
<slot>changeDisplayedWallet(int)</slot>
<slot>transferModeChanged(bool)</slot>
<slot>recipientModeChanged(bool)</slot>
</slots>
</ui>
......@@ -7,6 +7,7 @@ from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow
from PyQt5.QtWidgets import QMainWindow, QAction, QErrorMessage
from PyQt5.QtCore import QSignalMapper
from cutecoin.gui.addAccountDialog import AddAccountDialog
from cutecoin.gui.transferMoneyDialog import TransferMoneyDialog
from cutecoin.gui.communityTabWidget import CommunityTabWidget
from cutecoin.models.account.wallets.listModel import WalletsListModel
from cutecoin.models.wallet.listModel import WalletListModel
......@@ -55,6 +56,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.refreshMainWindow()
def openTransferMoneyDialog(self):
transferMoneyDialog = TransferMoneyDialog(self.core.currentAccount)
transferMoneyDialog.exec_()
'''
Refresh main window
When the selected account changes, all the widgets
......
'''
Created on 2 févr. 2014
@author: inso
'''
import logging
from math import pow
from PyQt5.QtWidgets import QDialog,QFrame, QSlider, QLabel, QDialogButtonBox
from PyQt5.QtCore import Qt, QSignalMapper
from cutecoin.models.coin import Coin
from cutecoin.models.person import Person
from cutecoin.models.node import Node
from cutecoin.models.coin.listModel import CoinsListModel
from cutecoin.gen_resources.transferDialog_uic import Ui_TransferMoneyDialog
class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
'''
classdocs
'''
def __init__(self, sender):
'''
Constructor
'''
super(TransferMoneyDialog, self).__init__()
self.setupUi(self)
self.sender = sender
for wallet in sender.wallets.walletsList:
self.comboBox_wallets.addItem(wallet.getText())
self.refreshTransaction(sender.wallets.walletsList[0])
def removeCoinsFromTransfer(self):
selection = self.listView_coinsSent.selectedIndexes()
walletCoins = self.listView_wallet.model().coins
sentCoins = self.listView_coinsSent.model().coins
newWallet = sentCoins
for selected in selection:
coin = sentCoins[selected.row()]
sentCoins.remove(coin)
walletCoins.append(coin)
self.listView_wallet.setModel(CoinsListModel(walletCoins))
self.listView_coinsSent.setModel(CoinsListModel(newWallet))
def addCoinsToTransfer(self):
selection = self.listView_wallet.selectedIndexes()
walletCoins = self.listView_wallet.model().coins
sentCoins = self.listView_coinsSent.model().coins
newWallet = walletCoins
for selected in selection:
coin = walletCoins[selected.row()]
newWallet.remove(coin)
sentCoins.append(coin)
self.listView_wallet.setModel(CoinsListModel(newWallet))
self.listView_coinsSent.setModel(CoinsListModel(sentCoins))
def openManageWalletCoins(self):
pass
def accept(self):
sentCoins = self.listView_coinsSent.model().toString()
recipient = None
if self.radio_keyFingerprint.isChecked():
recipient = Person("", self.edit_keyFingerprint.text(), "")
else:
#TODO: Manage contacts
recipient = Person("", self.edit_keyFingerprint.text(), "")
if self.radio_nodeAddress.isChecked():
node = Node(self.edit_nodeAddress.text(), int(self.edit_port.text()))
else:
#TODO: Manage trusted nodes
node = Node(self.edit_nodeAddress.text(), int(self.edit_port.text()))
message = self.edit_message.text()
#TODO: Transfer money, and validate the window if no error happened
print(self.sender.transferCoins(node, recipient, sentCoins, message))
def changeDisplayedWallet(self, index):
wallet = self.sender.wallets.walletsList[index]
self.refreshTransaction(wallet)
def refreshTransaction(self, wallet):
coinsSentModel = CoinsListModel([])
self.listView_coinsSent.setModel(coinsSentModel)
walletCoinsModel = CoinsListModel(list(wallet.coins))
self.listView_wallet.setModel(walletCoinsModel)
def recipientModeChanged(self, fingerprintToggled):
self.edit_keyFingerprint.setEnabled(fingerprintToggled)
self.comboBox_contact.setEnabled(not fingerprintToggled)
def transferModeChanged(self, nodeAddressToggled):
self.edit_nodeAddress.setEnabled(nodeAddressToggled)
self.comboBox_trustedNode.setEnabled(not nodeAddressToggled)
......@@ -111,6 +111,10 @@ class Account(object):
issuance = ucoin.wrappers.transactions.Issue(self.keyFingerprint(), community.amendmentNumber(), coins, keyId=self.pgpKeyId)
return issuance()
def transferCoins(self, node, recipient, coins, message):
transfer = ucoin.wrappers.transactions.Transfer(self.keyFingerprint(), recipient.fingerprint, coins, message, keyid=self.pgpKeyId, server=node.server, port=node.port)
return transfer()
def jsonify(self):
data = {'name' : self.name,
'pgpKeyId' : self.pgpKeyId,
......
......@@ -31,6 +31,9 @@ class Coin(object):
origin = m.group(5)
return cls(issuer, number, base, power, origin)
def __eq__(self, other):
return self.getId() == other.getId()
def value(self):
return self.base*math.pow(10, self.power)
......
'''
Created on 8 févr. 2014
@author: inso
'''
from PyQt5.QtCore import QAbstractListModel, Qt
class CoinsListModel(QAbstractListModel):
'''
A Qt abstract item model to display communities in a tree
'''
def __init__(self, coins, parent=None):
'''
Constructor
'''
super(CoinsListModel, self).__init__(parent)
self.coins = coins
def rowCount(self ,parent):
return len(self.coins)
def data(self,index,role):
if role == Qt.DisplayRole:
row=index.row()
value = str(self.coins[row].value())
return value
def flags(self,index):
return Qt.ItemIsSelectable | Qt.ItemIsEnabled
def toString(self):
coinsList = []
for c in self.coins:
coinsList.append(c.getId())
coinsStr = ",".join(coinsList)
return coinsStr
\ No newline at end of file
......@@ -42,11 +42,12 @@ class Community(object):
community = cls(knownNodes)
for walletsData in jsonData['wallets']:
account.wallets.walletsList.append(Wallet.load(walletsData, community))
wallet = Wallet.load(walletsData, community)
wallet.refreshCoins(account.keyFingerprint())
account.wallets.walletsList.append(wallet)
return community
def membersFingerprints(self):
'''
Listing members of a community
......
......@@ -19,7 +19,7 @@ class MembersListModel(QAbstractListModel):
fingerprints = community.membersFingerprints()
self.members = []
for f in fingerprints:
self.members.append(Person.create(f, community))
self.members.append(Person.lookup(f, community))
def rowCount(self ,parent):
return len(self.members)
......
......@@ -22,8 +22,9 @@ class Person(object):
self.fingerprint = fingerprint
self.email = email
@classmethod
def create(cls, pgpFingerprint, community):
def lookup(cls, pgpFingerprint, community):
'''
Create a person from the pgpFingerprint found in a community
'''
......
......@@ -42,11 +42,9 @@ class Transfer(Transaction):
def __init__(self):
super(Transfer).__init__()
def getReceivedText(self):
def getText(self):
return str(self.value()) + " " + self.currency() + " from " + self.sender.name
def getSentText(self):
return str(self.value()) + " " + self.currency() + " from " + self.recipient.name
class Issuance(Transaction):
......
......@@ -22,7 +22,7 @@ def createTransaction(senderFingerprint, increment, community):
if transaction != None:
transaction.increment = increment
transaction.community = community
transaction.sender = Person.create(senderFingerprint, community)
transaction.recipient = Person.create(ucoinTransaction['recipient'], community)
transaction.sender = Person.lookup(senderFingerprint, community)
transaction.recipient = Person.lookup(ucoinTransaction['recipient'], community)
return transaction
......@@ -26,7 +26,7 @@ class ReceivedListModel(QAbstractListModel):
if role == Qt.DisplayRole:
row=index.row()
value = self.transactions[row].getReceivedText()
value = self.transactions[row].getText()
return value
def flags(self,index):
......
......@@ -26,7 +26,7 @@ class SentListModel(QAbstractListModel):
if role == Qt.DisplayRole:
row=index.row()
value = self.transactions[row].getSendText()
value = self.transactions[row].getText()
return value
def flags(self,index):
......
......@@ -47,12 +47,12 @@ class Wallet(object):
return value
def refreshCoins(self, pgpFingerprint):
dataList = self.community.ucoinRequest(lambda : ucoin.hdc.coins.List, ctor_args={'pgp_fingerprint':pgpFingerprint})
dataList = self.community.ucoinRequest(ucoin.hdc.coins.List({'pgp_fingerprint':pgpFingerprint}))
for issaunces in dataList['coins']:
issuer = issaunces['issuer']
for coinsIds in issaunces['ids']:
shortened_id = coinsIds
coin = Coin.fromId(pgpFingerprint, issuer+"-"+shortened_id)
coin = Coin.fromId(issuer+"-"+shortened_id)
self.coins.append(coin)
def getText(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment