Commit 3576e924 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Merge branch 'master' of https://github.com/esa/opengeode

parents dc9496bd 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
......
......@@ -6,7 +6,7 @@
SDL is the Specification and Description Language (Z100 standard from ITU)
Copyright (c) 2012-2013 European Space Agency
Copyright (c) 2012-2018 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
......
......@@ -17,18 +17,8 @@
"""
import os
import sys
import logging
import argparse
import subprocess
import unittest
import difflib
import re
import string
import time
import test
import shutil
import glob
import logging
LOG = logging.getLogger(__name__)
......@@ -37,15 +27,7 @@ def call_qgensdl(options):
''' Call QGen-SDL tool with the required arguments '''
qgen_dir = os.environ.get('QGEN_REPO_ROOT')
sdl_importer_proj_name = "ee.ibk.sdl.importer"
sdl_importer_launcher = "qgen-sdl"
sdl_importer_loc = "gms/eclipse/" + sdl_importer_proj_name + "/target" + \
"/sdl-importer/lib/" + sdl_importer_launcher
sdl_importer_path = os.path.join (qgen_dir,sdl_importer_loc)
lang=''
if options.toC:
lang = 'c'
elif options.toAda:
......@@ -54,22 +36,29 @@ def call_qgensdl(options):
LOG.debug('Generating ' + lang + ' code using QGen from ' + str(options.files))
outfolder = 'qgen_generated_' + lang
cmd = [sdl_importer_path, options.files[0],
'--language', lang,
cmd = ["qgen-sdl", '--language', lang,
'--output', outfolder,
'--type-prefix', 'asn1Scc']
'--type-prefix', 'asn1Scc',
options.files[0]]
if os.path.exists(outfolder):
shutil.rmtree(outfolder, ignore_errors=True)
LOG.debug('Qgen-sdl command: ' + str(cmd))
p1 = subprocess.Popen(cmd,
LOG.debug('QGen-sdl command: ' + str(cmd))
try:
p1 = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p1.communicate()
errcode = p1.wait()
errcode = p1.wait()
stdout, stderr = p1.communicate()
if errcode:
LOG.error(stderr)
LOG.info(stdout)
except OSError as e:
errcode = 1
if e.errno == os.errno.ENOENT:
LOG.error ('QGen-SDL tool is not found on your path')
else:
raise
LOG.info(stdout)
if errcode:
LOG.error(stderr)
return (errcode)
\ No newline at end of file
......@@ -141,7 +141,7 @@ except ImportError:
__all__ = ['opengeode', 'SDL_Scene', 'SDL_View', 'parse']
__version__ = '2.0.15'
__version__ = '2.0.16'
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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment