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 @@
<property name="title">
<string>Account</string>
</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="separator"/>
<addaction name="actionSave"/>
......@@ -138,11 +143,6 @@
<addaction name="menuEdit"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionChange_account">
<property name="text">
<string>Change account</string>
</property>
</action>
<action name="actionManage_accounts">
<property name="text">
<string>Manage accounts</string>
......@@ -203,6 +203,11 @@
<string>Quit</string>
</property>
</action>
<action name="actionAccount">
<property name="text">
<string>Account</string>
</property>
</action>
</widget>
<resources/>
<connections>
......@@ -229,8 +234,8 @@
<slot>save()</slot>
<hints>
<hint type="sourcelabel">
<x>225</x>
<y>199</y>
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>225</x>
......
......@@ -4,17 +4,20 @@ Created on 1 févr. 2014
@author: inso
'''
from cutecoin.core import config
from cutecoin.core.exceptions import KeyAlreadyUsed
import os
import logging
import json
from cutecoin.core import config
from cutecoin.core.exceptions import KeyAlreadyUsed
from cutecoin.models.account import factory
import os
class Core(object):
'''
Managing core application datas :
Accounts list and general configuration
'''
def __init__(self, argv):
'''
Constructor
......@@ -24,8 +27,11 @@ class Core(object):
config.parseArguments(argv)
self.load()
def getAccounts(self):
return self.accounts
def getAccount(self, name):
for a in self.accounts:
logging.debug('Name : ' + a.name + '/' + name)
if name == a.name:
return a
def addAccount(self, account):
for a in self.accounts:
......@@ -40,22 +46,24 @@ class Core(object):
def load(self):
if (os.path.exists(config.data['home'])):
json_data=open(config.data['home'], 'w+')
if not os.path.exists(config.parameters['home']):
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)
json_data.close()
for accountData in data['localAccounts']:
self.accounts.append(factory.loadAccount(accountData))
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)
def jsonifyAccounts(self):
data = []
for account in self.accounts:
......
......@@ -6,7 +6,13 @@ Created on 7 févr. 2014
import logging
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):
parser = OptionParser()
......@@ -20,7 +26,7 @@ def parseArguments(argv):
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.")
(options, args) = parser.parse_args(argv)
......@@ -32,6 +38,6 @@ def parseArguments(argv):
else:
logging.getLogger().propagate = False
data['home'] = options.home
parameters['home'] = options.home
pass
\ No newline at end of file
......@@ -45,7 +45,7 @@ class KeyAlreadyUsed(Error):
Constructor
'''
super(KeyAlreadyUsed, self) \
.__init("Cannot add account " + newAccount.name + " : " \
.__init__("Cannot add account " + newAccount.name + " : " \
" the pgpKey " + keyId + " is already used by " + foundAccount.name)
......@@ -4,13 +4,17 @@ Created on 1 févr. 2014
@author: inso
'''
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.communityTabWidget import CommunityTabWidget
from cutecoin.models.account.wallets.listModel import WalletsListModel
from cutecoin.models.wallet.listModel import WalletListModel
from cutecoin.models.transaction.sentListModel import SentListModel
from cutecoin.models.transaction.receivedListModel import ReceivedListModel
from cutecoin.core.exceptions import KeyAlreadyUsed
import logging
class MainWindow(QMainWindow, Ui_MainWindow):
'''
......@@ -26,6 +30,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
super(MainWindow, self).__init__()
self.setupUi(self)
self.core = core
self.refreshMainWindow()
def openAddAccountDialog(self):
self.addAccountDialog = AddAccountDialog(self)
......@@ -34,23 +39,43 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def actionAddAccount(self):
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()
def save(self):
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
When the selected account changes, all the widgets
in the window have to be refreshed
'''
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:
self.accountTabs.setEnabled(False)
else:
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.walletContent.setModel(WalletListModel(self.core.currentAccount.wallets.walletsList[0]))
for community in self.core.currentAccount.communities.communitiesList:
......@@ -58,4 +83,3 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.transactionsSent.setModel(SentListModel(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):
account.communities.communitiesList.append(communityFactory.loadCommunity(communityData))
account.wallets = Wallets()
for walletData in jsonData['wallets']:
account.wallets.walletsList.append(walletFactory.loadWallet(jsonData))
account.wallets.walletsList.append(walletFactory.loadWallet(walletData))
return account
\ No newline at end of file
......@@ -9,7 +9,7 @@ import math
class Coin(object):
'''
classdocs
A coin parsing a regex to read its value
'''
......
......@@ -15,7 +15,9 @@ class Community(object):
'''
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.currency = ""
......@@ -30,12 +32,12 @@ class Community(object):
members.append(f['value'])
return members
def issuances(self):
def issuances(self, accountFingerprint):
'''
Listing issuances the accounted emitted
'''
#TODO:Return issuances
#issuances = self.ucoinRequest(ucoin.hdc.amendments.view.Members(amendmentId)
#issuances = self.ucoinRequest(ucoin.hdc.transactions.sender.Issuance())
return []
def ucoinRequest(self, request, get_args={}):
......
......@@ -18,7 +18,7 @@ def createCommunity(mainNode):
def loadCommunity(jsonData):
community = Community()
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']
return community
......@@ -8,7 +8,7 @@ import ucoinpy as ucoin
class Node(object):
'''
classdocs
A ucoin node
'''
def __init__(self, server, port):
'''
......@@ -25,6 +25,10 @@ class Node(object):
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):
ucoin.settings['server'] = self.server
ucoin.settings['port'] = self.port
......
......@@ -8,8 +8,6 @@ from cutecoin.models.person import Person
import ucoinpy as ucoin
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(),
get_args={'search':"0x"+pgpFingerprint, 'op':'index'})['keys']
if len(keys) > 0:
......
......@@ -10,7 +10,8 @@ from cutecoin.models.person import factory
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):
self.increment = increment
......
......@@ -10,7 +10,8 @@ from cutecoin.models.coin import Coin
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