Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
sakia
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
78
Issues
78
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
clients
python
sakia
Commits
41970ce4
Commit
41970ce4
authored
Apr 02, 2020
by
Vincent Texier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[enh] #798 add send as source menu for all transactions and dividend in expert mode
Check is source exists before display menu
parent
317b41e0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
17 deletions
+66
-17
src/sakia/gui/widgets/context_menu.py
src/sakia/gui/widgets/context_menu.py
+66
-17
No files found.
src/sakia/gui/widgets/context_menu.py
View file @
41970ce4
...
...
@@ -7,7 +7,7 @@ from duniterpy.constants import PUBKEY_REGEX
from
duniterpy.documents.crc_pubkey
import
CRCPubkey
from
sakia.app
import
Application
from
sakia.data.entities
import
Identity
,
Transaction
,
Dividend
,
Connection
from
sakia.data.entities
import
Identity
,
Transaction
,
Dividend
,
Connection
,
Source
from
sakia.data.processors
import
BlockchainProcessor
,
TransactionsProcessor
from
sakia.decorators
import
asyncify
from
sakia.gui.sub.certification.controller
import
CertificationController
...
...
@@ -106,7 +106,7 @@ class ContextMenu(QObject):
menu
.
qmenu
.
addAction
(
copy_selfcert
)
@
staticmethod
def
_add_transfer
s
_actions
(
menu
,
transfer
):
def
_add_transfer_actions
(
menu
,
transfer
):
"""
:param ContextMenu menu: the qmenu to add actions to
:param Transfer transfer: the transfer
...
...
@@ -132,16 +132,26 @@ class ContextMenu(QObject):
)
menu
.
qmenu
.
addAction
(
cancel
)
# if special lock condition on transaction
...
if
transfer
.
conditions
is
not
None
:
send_as_source
=
QAction
(
QCoreApplication
.
translate
(
"ContextMenu"
,
"Send as source"
),
menu
.
qmenu
.
parent
(),
)
s
end_as_source
.
triggered
.
connect
(
lambda
checked
,
tr
=
transfer
:
menu
.
send_as_source
(
tr
)
# if special lock condition on transaction
or
# all transaction received in expert mode...
if
transfer
.
conditions
is
not
None
or
(
transfer
.
pubkey
in
transfer
.
receivers
and
menu
.
_app
.
parameters
.
expert_mode
):
# get source from conditions and transaction hash
s
ource
=
menu
.
_app
.
sources_service
.
get_one
(
identifier
=
transfer
.
sha_hash
,
conditions
=
transfer
.
conditions
)
menu
.
qmenu
.
addAction
(
send_as_source
)
if
source
:
# add send as source menu
send_as_source
=
QAction
(
QCoreApplication
.
translate
(
"ContextMenu"
,
"Send as source"
),
menu
.
qmenu
.
parent
(),
)
send_as_source
.
triggered
.
connect
(
lambda
checked
,
src
=
source
:
menu
.
send_as_source
(
src
)
)
menu
.
qmenu
.
addAction
(
send_as_source
)
if
menu
.
_app
.
parameters
.
expert_mode
:
copy_doc
=
QAction
(
QCoreApplication
.
translate
(
...
...
@@ -168,6 +178,32 @@ class ContextMenu(QObject):
)
menu
.
qmenu
.
addAction
(
copy_doc
)
@
staticmethod
def
_add_dividend_actions
(
menu
,
dividend
):
"""
:param ContextMenu menu: the qmenu to add actions to
:param Transfer transfer: the transfer
"""
menu
.
qmenu
.
addSeparator
().
setText
(
QCoreApplication
.
translate
(
"ContextMenu"
,
"Dividend"
)
)
if
menu
.
_app
.
parameters
.
expert_mode
:
# get dividend source from block number and type
source
=
menu
.
_app
.
sources_service
.
get_one
(
noffset
=
dividend
.
block_number
,
type
=
Source
.
TYPE_DIVIDEND
)
if
source
:
# add send as source menu
send_as_source
=
QAction
(
QCoreApplication
.
translate
(
"ContextMenu"
,
"Send as source"
),
menu
.
qmenu
.
parent
(),
)
send_as_source
.
triggered
.
connect
(
lambda
checked
,
src
=
source
:
menu
.
send_dividend_as_source
(
src
)
)
menu
.
qmenu
.
addAction
(
send_as_source
)
@
staticmethod
def
_add_string_actions
(
menu
,
str_value
):
if
re
.
match
(
PUBKEY_REGEX
,
str_value
):
...
...
@@ -219,8 +255,8 @@ class ContextMenu(QObject):
menu
=
cls
(
QMenu
(
parent
),
app
,
connection
)
build_actions
=
{
Identity
:
ContextMenu
.
_add_identity_actions
,
Transaction
:
ContextMenu
.
_add_transfer
s
_actions
,
Dividend
:
lambda
m
,
d
:
None
,
Transaction
:
ContextMenu
.
_add_transfer_actions
,
Dividend
:
ContextMenu
.
_add_dividend_actions
,
str
:
ContextMenu
.
_add_string_actions
,
dict
:
lambda
m
,
d
:
None
,
type
(
None
):
lambda
m
,
d
:
None
,
...
...
@@ -298,11 +334,24 @@ This money transfer will be removed and not sent.""",
self
.
_app
.
db
.
commit
()
self
.
_app
.
transaction_state_changed
.
emit
(
transfer
)
def
send_as_source
(
self
,
transfer
:
Transaction
):
# get source from conditions and transaction hash
source
=
self
.
_app
.
sources_service
.
get_one
(
identifier
=
transfer
.
sha_hash
,
conditions
=
transfer
.
conditions
def
send_as_source
(
self
,
source
:
Source
):
"""
Open transfer dialog with a transaction as source
:param Source source: Source entity to send
:return:
"""
TransferController
.
send_money_to_pubkey
(
None
,
self
.
_app
,
self
.
_connection
,
None
,
source
)
def
send_dividend_as_source
(
self
,
source
:
Source
):
"""
Open transfer dialog with a dividend as source
:param Source source: Source entity to send
:return:
"""
TransferController
.
send_money_to_pubkey
(
None
,
self
.
_app
,
self
.
_connection
,
None
,
source
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment