Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
OpenGEODE
Commits
0140db63
Commit
0140db63
authored
Jul 26, 2018
by
Maxime Perrotin
Browse files
Add interaction with system clipboard
parent
6d73973e
Changes
3
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
0140db63
...
...
@@ -135,6 +135,9 @@ The background pattern was downloaded from www.subtlepatterns.com
Changelog
=========
2.
0.16 (07/2018)
-
Added interaction with system clipboard (basic for floating items)
2.
0.15 (07/2018)
-
Fix many bugs in type checking system
...
...
opengeode/Clipboard.py
View file @
0140db63
...
...
@@ -6,7 +6,7 @@
SDL is the Specification and Description Language (Z100 standard from ITU)
Copyright (c) 2012-201
3
European Space Agency
Copyright (c) 2012-201
8
European Space Agency
Designed and implemented by Maxime Perrotin
...
...
@@ -15,12 +15,14 @@
This module is managing the Copy and Paste functions.
"""
import
os
import
traceback
import
logging
from
itertools
import
chain
import
PySide
import
ogAST
import
ogParser
import
sdlSymbols
import
genericSymbols
import
Renderer
...
...
@@ -36,6 +38,9 @@ COPY_PASTE = []
# Actual scene clipboard
CLIPBOARD
=
None
# System clipboard used to copy-paste between instances of Opengeode
# Value is set when Opengeode is initialized
SYS_CLIPBOARD
=
None
def
copy
(
selection
):
''' Create a copy (duplicate) of the selected symbols in AST form '''
...
...
@@ -82,9 +87,9 @@ def copy_branch(top_level_item):
if
not
isinstance
(
top_level_item
,
genericSymbols
.
HorizontalSymbol
):
next_aligned
=
top_level_item
.
next_aligned_symbol
()
while
next_aligned
and
next_aligned
.
grabber
.
isSelected
():
pr_text
=
'
\n
'
.
join
(
Pr
.
generate
(
next_aligned
,
cpy
=
True
,
next_
pr_text
=
'
\n
'
.
join
(
Pr
.
generate
(
next_aligned
,
cpy
=
True
,
nextstate
=
False
,
recursive
=
True
))
next_ast
,
next_terminators
=
next_aligned
.
get_ast
(
pr_text
)
next_ast
,
next_terminators
=
next_aligned
.
get_ast
(
next_
pr_text
)
terminators
.
extend
(
next_terminators
)
branch
.
append
(
next_ast
)
next_aligned
=
next_aligned
.
next_aligned_symbol
()
...
...
@@ -102,6 +107,15 @@ def copy_branch(top_level_item):
term_branch
,
term_inators
=
copy_branch
(
symbol
)
branch
.
extend
(
term_branch
)
res_terminators
.
extend
(
term_inators
)
if
SYS_CLIPBOARD
is
not
None
:
# Basic copy of a single branch to the system clipboard
ident
=
top_level_item
.
common_name
\
if
not
isinstance
(
top_level_item
,
sdlSymbols
.
State
)
\
else
'state'
SYS_CLIPBOARD
.
setText
(
"OG_SDL@-@{}@-@{}@-@{}"
.
format
(
os
.
getpid
(),
ident
,
pr_text
))
return
branch
,
res_terminators
...
...
@@ -109,11 +123,33 @@ def paste(parent, scene):
'''
Paste previously copied symbols at selection point
'''
remove_after_paste
=
False
if
SYS_CLIPBOARD
is
not
None
:
# Get from clipboard only if it comes from another process
# otherwise use the local clipboard which contains more data
# (for the moment the shared clipboard only stores top-level items)
shared
=
SYS_CLIPBOARD
.
text
().
split
(
'@-@'
)
or
[]
if
len
(
shared
)
>=
4
\
and
shared
[
0
]
==
"OG_SDL"
\
and
shared
[
1
]
!=
str
(
os
.
getpid
()):
common_name
=
shared
[
2
]
pr_text
=
shared
[
3
]
# Copy to the local clipboard
ast
,
_
,
_
,
_
,
terminators
=
\
ogParser
.
parseSingleElement
(
common_name
,
pr_text
)
COPY_PASTE
.
append
(([
ast
],
terminators
))
remove_after_paste
=
True
CLIPBOARD
.
clear
()
if
not
parent
:
new_symbols
=
paste_floating_objects
(
scene
)
else
:
new_symbols
=
paste_below_item
(
parent
,
scene
)
if
remove_after_paste
:
# Remove from local clipboard if it came from system clipboard
# otherwise it would be added over and over
COPY_PASTE
.
pop
()
return
new_symbols
...
...
opengeode/opengeode.py
View file @
0140db63
...
...
@@ -141,7 +141,7 @@ except ImportError:
__all__
=
[
'opengeode'
,
'SDL_Scene'
,
'SDL_View'
,
'parse'
]
__version__
=
'2.0.1
5
'
__version__
=
'2.0.1
6
'
if
hasattr
(
sys
,
'frozen'
):
# Detect if we are running on Windows (py2exe-generated)
...
...
@@ -3011,6 +3011,7 @@ def gui(options):
# Initialize the clipboard
Clipboard
.
CLIPBOARD
=
SDL_Scene
(
context
=
'clipboard'
)
Clipboard
.
SYS_CLIPBOARD
=
app
.
clipboard
()
# Load the application layout from the .ui file
loader
=
QUiLoader
()
...
...
Write
Preview
Supports
Markdown
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