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

Chargement de données sauvegardées, documentation.

parent 3b24514b
No related branches found
No related tags found
No related merge requests found
Showing with 89 additions and 145 deletions
...@@ -121,7 +121,12 @@ ...@@ -121,7 +121,12 @@
<property name="title"> <property name="title">
<string>Account</string> <string>Account</string>
</property> </property>
<addaction name="actionChange_account"/> <widget class="QMenu" name="menuChange_account">
<property name="title">
<string>Change account</string>
</property>
</widget>
<addaction name="menuChange_account"/>
<addaction name="actionAdd_account"/> <addaction name="actionAdd_account"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionSave"/> <addaction name="actionSave"/>
...@@ -138,11 +143,6 @@ ...@@ -138,11 +143,6 @@
<addaction name="menuEdit"/> <addaction name="menuEdit"/>
</widget> </widget>
<widget class="QStatusBar" name="statusbar"/> <widget class="QStatusBar" name="statusbar"/>
<action name="actionChange_account">
<property name="text">
<string>Change account</string>
</property>
</action>
<action name="actionManage_accounts"> <action name="actionManage_accounts">
<property name="text"> <property name="text">
<string>Manage accounts</string> <string>Manage accounts</string>
...@@ -203,6 +203,11 @@ ...@@ -203,6 +203,11 @@
<string>Quit</string> <string>Quit</string>
</property> </property>
</action> </action>
<action name="actionAccount">
<property name="text">
<string>Account</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections> <connections>
...@@ -229,8 +234,8 @@ ...@@ -229,8 +234,8 @@
<slot>save()</slot> <slot>save()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>225</x> <x>-1</x>
<y>199</y> <y>-1</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>225</x> <x>225</x>
......
...@@ -4,17 +4,20 @@ Created on 1 févr. 2014 ...@@ -4,17 +4,20 @@ Created on 1 févr. 2014
@author: inso @author: inso
''' '''
from cutecoin.core import config import os
from cutecoin.core.exceptions import KeyAlreadyUsed import logging
import json import json
from cutecoin.core import config from cutecoin.core import config
from cutecoin.core.exceptions import KeyAlreadyUsed
from cutecoin.models.account import factory from cutecoin.models.account import factory
import os
class Core(object): class Core(object):
'''
Managing core application datas :
Accounts list and general configuration
'''
def __init__(self, argv): def __init__(self, argv):
''' '''
Constructor Constructor
...@@ -24,8 +27,11 @@ class Core(object): ...@@ -24,8 +27,11 @@ class Core(object):
config.parseArguments(argv) config.parseArguments(argv)
self.load() self.load()
def getAccounts(self): def getAccount(self, name):
return self.accounts for a in self.accounts:
logging.debug('Name : ' + a.name + '/' + name)
if name == a.name:
return a
def addAccount(self, account): def addAccount(self, account):
for a in self.accounts: for a in self.accounts:
...@@ -40,22 +46,24 @@ class Core(object): ...@@ -40,22 +46,24 @@ class Core(object):
def load(self): def load(self):
if (os.path.exists(config.data['home'])): if not os.path.exists(config.parameters['home']):
json_data=open(config.data['home'], 'w+') logging.info("Creating home directory")
os.makedirs((config.parameters['home']))
if (os.path.exists(config.parameters['data']) \
and os.path.isfile(config.parameters['data'])):
json_data=open(config.parameters['data'], 'r')
data = json.load(json_data) data = json.load(json_data)
json_data.close() json_data.close()
for accountData in data['localAccounts']: for accountData in data['localAccounts']:
self.accounts.append(factory.loadAccount(accountData)) self.accounts.append(factory.loadAccount(accountData))
def save(self): def save(self):
with open(config.data['home'], 'w+') as outfile: with open(config.parameters['data'], 'w') as outfile:
json.dump(self.jsonify(), outfile, indent = 4, sort_keys=True) json.dump(self.jsonify(), outfile, indent = 4, sort_keys=True)
def jsonifyAccounts(self): def jsonifyAccounts(self):
data = [] data = []
for account in self.accounts: for account in self.accounts:
......
...@@ -6,7 +6,13 @@ Created on 7 févr. 2014 ...@@ -6,7 +6,13 @@ Created on 7 févr. 2014
import logging import logging
from optparse import OptionParser from optparse import OptionParser
data = { 'home' : '~/.cutecoin'} import os.path
home = os.path.expanduser("~")
parameters = { 'home' : home + '/.config/cutecoin/',
'data' : home + '/.config/cutecoin/' 'data'}
def parseArguments(argv): def parseArguments(argv):
parser = OptionParser() parser = OptionParser()
...@@ -20,7 +26,7 @@ def parseArguments(argv): ...@@ -20,7 +26,7 @@ def parseArguments(argv):
help="Print DEBUG messages to stdout") help="Print DEBUG messages to stdout")
parser.add_option("--home", dest="home", default="~/.cutecoin", parser.add_option("--home", dest="home", default=parameters['home'],
help="Set another home for cutecoin.") help="Set another home for cutecoin.")
(options, args) = parser.parse_args(argv) (options, args) = parser.parse_args(argv)
...@@ -32,6 +38,6 @@ def parseArguments(argv): ...@@ -32,6 +38,6 @@ def parseArguments(argv):
else: else:
logging.getLogger().propagate = False logging.getLogger().propagate = False
data['home'] = options.home parameters['home'] = options.home
pass pass
\ No newline at end of file
...@@ -45,7 +45,7 @@ class KeyAlreadyUsed(Error): ...@@ -45,7 +45,7 @@ class KeyAlreadyUsed(Error):
Constructor Constructor
''' '''
super(KeyAlreadyUsed, self) \ super(KeyAlreadyUsed, self) \
.__init("Cannot add account " + newAccount.name + " : " \ .__init__("Cannot add account " + newAccount.name + " : " \
" the pgpKey " + keyId + " is already used by " + foundAccount.name) " the pgpKey " + keyId + " is already used by " + foundAccount.name)
...@@ -4,13 +4,17 @@ Created on 1 févr. 2014 ...@@ -4,13 +4,17 @@ 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 from PyQt5.QtWidgets import QMainWindow, QAction, QErrorMessage
from PyQt5.QtCore import QSignalMapper
from cutecoin.gui.addAccountDialog import AddAccountDialog from cutecoin.gui.addAccountDialog import AddAccountDialog
from cutecoin.gui.communityTabWidget import CommunityTabWidget from cutecoin.gui.communityTabWidget import CommunityTabWidget
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.wallet.listModel import WalletListModel
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
from cutecoin.core.exceptions import KeyAlreadyUsed
import logging
class MainWindow(QMainWindow, Ui_MainWindow): class MainWindow(QMainWindow, Ui_MainWindow):
''' '''
...@@ -26,6 +30,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -26,6 +30,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
super(MainWindow, self).__init__() super(MainWindow, self).__init__()
self.setupUi(self) self.setupUi(self)
self.core = core self.core = core
self.refreshMainWindow()
def openAddAccountDialog(self): def openAddAccountDialog(self):
self.addAccountDialog = AddAccountDialog(self) self.addAccountDialog = AddAccountDialog(self)
...@@ -34,23 +39,43 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -34,23 +39,43 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def actionAddAccount(self): def actionAddAccount(self):
self.addAccountDialog.account.name = self.addAccountDialog.accountName.text() self.addAccountDialog.account.name = self.addAccountDialog.accountName.text()
self.core.addAccount(self.addAccountDialog.account) try:
self.core.addAccount(self.addAccountDialog.account)
except KeyAlreadyUsed as e:
QErrorMessage(self).showMessage(e.message)
self.refreshMainWindow() self.refreshMainWindow()
def save(self): def save(self):
self.core.save() self.core.save()
def actionChangeAccount(self, accountName):
self.core.currentAccount = self.core.getAccount(accountName)
logging.info('Changing account to ' + self.core.currentAccount.name)
self.refreshMainWindow()
''' '''
Refresh main window Refresh main window
When the selected account changes, all the widgets When the selected account changes, all the widgets
in the window have to be refreshed in the window have to be refreshed
''' '''
def refreshMainWindow(self): def refreshMainWindow(self):
self.menuChange_account.clear()
signalMapper = QSignalMapper(self)
for account in self.core.accounts:
action = QAction(account.name, self)
self.menuChange_account.addAction(action)
signalMapper.setMapping(action, account.name)
action.triggered.connect(signalMapper.map)
signalMapper.mapped[str].connect(self.actionChangeAccount)
if self.core.currentAccount == None: if self.core.currentAccount == None:
self.accountTabs.setEnabled(False) self.accountTabs.setEnabled(False)
else: else:
self.accountTabs.setEnabled(True) self.accountTabs.setEnabled(True)
self.accountNameLabel = self.core.currentAccount.name self.accountNameLabel.setText("Current account : " + self.core.currentAccount.name)
self.walletsList.setModel(WalletsListModel(self.core.currentAccount)) self.walletsList.setModel(WalletsListModel(self.core.currentAccount))
self.walletContent.setModel(WalletListModel(self.core.currentAccount.wallets.walletsList[0])) self.walletContent.setModel(WalletListModel(self.core.currentAccount.wallets.walletsList[0]))
for community in self.core.currentAccount.communities.communitiesList: for community in self.core.currentAccount.communities.communitiesList:
...@@ -58,4 +83,3 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -58,4 +83,3 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.transactionsSent.setModel(SentListModel(self.core.currentAccount)) self.transactionsSent.setModel(SentListModel(self.core.currentAccount))
self.transactionsReceived.setModel(ReceivedListModel(self.core.currentAccount)) self.transactionsReceived.setModel(ReceivedListModel(self.core.currentAccount))
'''
Created on 5 févr. 2014
@author: inso
'''
from PyQt5.QtCore import QAbstractItemModel, Qt, QModelIndex
from cutecoin.models.account.communities.itemModel import CommunitiesItemModel
from cutecoin.models.community.itemModel import CommunityItemModel
from cutecoin.models.node.itemModel import MainNodeItem, NodeItem
#TODO: Use it somewhere or remove it from the code
class CommunitiesTreeModel(QAbstractItemModel):
'''
A Qt abstract item model to display communities in a tree
'''
def __init__(self, account):
'''
Constructor
'''
super(CommunitiesTreeModel, self).__init__(None)
self.communities = account.communities
self.rootItem = CommunitiesItemModel(account)
self.refreshTreeNodes()
def columnCount(self, parent):
return 1
def data(self, index, role):
if not index.isValid():
return None
if role != Qt.DisplayRole:
return None
item = index.internalPointer()
return item.data
def flags(self, index):
if not index.isValid():
return Qt.NoItemFlags
return Qt.ItemIsEnabled | Qt.ItemIsSelectable
def headerData(self, section, orientation, role):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return "Communities nodes"
return None
def index(self, row, column, parent):
if not self.hasIndex(row, column, parent):
return QModelIndex()
if not parent.isValid():
parentItem = self.rootItem
else:
parentItem = parent.internalPointer()
childItem = parentItem.child(row)
if childItem:
return self.createIndex(row, column, childItem)
else:
return QModelIndex()
def parent(self, index):
if not index.isValid():
return QModelIndex()
childItem = index.internalPointer()
parentItem = childItem.parent()
if parentItem == self.rootItem:
return QModelIndex()
return self.createIndex(parentItem.row(), 0, parentItem)
def rowCount(self, parent):
if parent.column() > 0:
return 0
if not parent.isValid():
parentItem = self.rootItem
else:
parentItem = parent.internalPointer()
return parentItem.childCount()
def refreshTreeNodes(self):
for community in self.communities.communitiesList:
communityItem = CommunityItemModel(community, self)
self.rootItem.appendChild(communityItem)
for mainNode in community.knownNodes:
mainNodeItem = MainNodeItem(mainNode, communityItem)
communityItem.appendChild(mainNodeItem)
for node in mainNode.downstreamPeers():
nodeItem = NodeItem(node, mainNodeItem)
mainNodeItem.appendChild(nodeItem)
...@@ -32,5 +32,5 @@ def loadAccount(jsonData): ...@@ -32,5 +32,5 @@ def loadAccount(jsonData):
account.communities.communitiesList.append(communityFactory.loadCommunity(communityData)) account.communities.communitiesList.append(communityFactory.loadCommunity(communityData))
account.wallets = Wallets() account.wallets = Wallets()
for walletData in jsonData['wallets']: for walletData in jsonData['wallets']:
account.wallets.walletsList.append(walletFactory.loadWallet(jsonData)) account.wallets.walletsList.append(walletFactory.loadWallet(walletData))
return account return account
\ No newline at end of file
...@@ -9,7 +9,7 @@ import math ...@@ -9,7 +9,7 @@ import math
class Coin(object): class Coin(object):
''' '''
classdocs A coin parsing a regex to read its value
''' '''
......
...@@ -15,7 +15,9 @@ class Community(object): ...@@ -15,7 +15,9 @@ class Community(object):
''' '''
def __init__(self): def __init__(self):
''' '''
Constructor A community is a group of nodes using the same currency.
They are all using the same amendment and are syncing their datas.
An account is a member of a community if he is a member of the current amendment.
''' '''
self.knownNodes = [] self.knownNodes = []
self.currency = "" self.currency = ""
...@@ -30,12 +32,12 @@ class Community(object): ...@@ -30,12 +32,12 @@ class Community(object):
members.append(f['value']) members.append(f['value'])
return members return members
def issuances(self): def issuances(self, accountFingerprint):
''' '''
Listing issuances the accounted emitted Listing issuances the accounted emitted
''' '''
#TODO:Return issuances #TODO:Return issuances
#issuances = self.ucoinRequest(ucoin.hdc.amendments.view.Members(amendmentId) #issuances = self.ucoinRequest(ucoin.hdc.transactions.sender.Issuance())
return [] return []
def ucoinRequest(self, request, get_args={}): def ucoinRequest(self, request, get_args={}):
......
...@@ -18,7 +18,7 @@ def createCommunity(mainNode): ...@@ -18,7 +18,7 @@ def createCommunity(mainNode):
def loadCommunity(jsonData): def loadCommunity(jsonData):
community = Community() community = Community()
for nodeData in jsonData['nodes']: for nodeData in jsonData['nodes']:
community.knownNodes.append(MainNode(jsonData['server'], jsonData['port'])) community.knownNodes.append(MainNode(nodeData['server'], nodeData['port']))
community.currency = jsonData['currency'] community.currency = jsonData['currency']
return community return community
...@@ -8,7 +8,7 @@ import ucoinpy as ucoin ...@@ -8,7 +8,7 @@ import ucoinpy as ucoin
class Node(object): class Node(object):
''' '''
classdocs A ucoin node
''' '''
def __init__(self, server, port): def __init__(self, server, port):
''' '''
...@@ -25,6 +25,10 @@ class Node(object): ...@@ -25,6 +25,10 @@ class Node(object):
class MainNode(Node): class MainNode(Node):
'''
MainNode is a node the community is reading to get informations.
The account sends data one of the community main nodes.
'''
def downstreamPeers(self): def downstreamPeers(self):
ucoin.settings['server'] = self.server ucoin.settings['server'] = self.server
ucoin.settings['port'] = self.port ucoin.settings['port'] = self.port
......
...@@ -8,8 +8,6 @@ from cutecoin.models.person import Person ...@@ -8,8 +8,6 @@ from cutecoin.models.person import Person
import ucoinpy as ucoin import ucoinpy as ucoin
def createPerson(pgpFingerprint, community): def createPerson(pgpFingerprint, community):
#TODO: Raise an exception and display a popup if member isnt found
#Maybe generate a person whose name is the fingerprint, and email is 'unknown'
keys = community.ucoinRequest(ucoin.pks.Lookup(), keys = community.ucoinRequest(ucoin.pks.Lookup(),
get_args={'search':"0x"+pgpFingerprint, 'op':'index'})['keys'] get_args={'search':"0x"+pgpFingerprint, 'op':'index'})['keys']
if len(keys) > 0: if len(keys) > 0:
......
...@@ -10,7 +10,8 @@ from cutecoin.models.person import factory ...@@ -10,7 +10,8 @@ from cutecoin.models.person import factory
class Transaction(object): class Transaction(object):
''' '''
classdocs A transaction which can be a transfer or an issuance.
At the moment the difference is not made
''' '''
def __init__(self, senderFingerprint, increment, community): def __init__(self, senderFingerprint, increment, community):
self.increment = increment self.increment = increment
......
...@@ -10,7 +10,8 @@ from cutecoin.models.coin import Coin ...@@ -10,7 +10,8 @@ from cutecoin.models.coin import Coin
class Wallet(object): class Wallet(object):
''' '''
classdocs A wallet is list of coins.
It's only used to sort coins.
''' '''
......
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