Changeset f2e199e in sasview


Ignore:
Timestamp:
Nov 22, 2018 1:47:13 AM (5 years ago)
Author:
Piotr Rozyczko <piotr.rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
72651df
Parents:
21e71f1
Message:

Allow editing models with corresponding C-files. SASVIEW-1208

Location:
src/sas/qtgui/Utilities
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Utilities/ModelEditor.py

    r3933ee9 rf2e199e  
    1212    """ 
    1313    modelModified = QtCore.pyqtSignal() 
    14     def __init__(self, parent=None): 
     14    def __init__(self, parent=None, is_python=True): 
    1515        super(ModelEditor, self).__init__(parent) 
    1616        self.setupUi(self) 
     17 
     18        self.is_python = is_python 
    1719 
    1820        self.setupWidgets() 
     
    2931        # DO NOT MOVE TO TOP 
    3032        from sas.qtgui.Utilities.PythonSyntax import PythonHighlighter 
    31         self.highlight = PythonHighlighter(self.txtEditor.document()) 
     33        self.highlight = PythonHighlighter(self.txtEditor.document(), is_python=self.is_python) 
    3234 
    3335        self.txtEditor.setFont(GuiUtils.getMonospaceFont()) 
  • src/sas/qtgui/Utilities/PythonSyntax.py

    r8b480d27 rf2e199e  
    3636    """ 
    3737    # Python keywords 
    38     keywords = [ 
     38    python_keywords = [ 
    3939        'and', 'assert', 'break', 'class', 'continue', 'def', 
    4040        'del', 'elif', 'else', 'except', 'exec', 'finally', 
     
    4343        'raise', 'return', 'try', 'while', 'yield', 
    4444        'None', 'True', 'False', 
     45    ] 
     46 
     47    # C keywords 
     48    c_keywords = [ 
     49        'auto', 'break', 'case', 'char', 
     50        'const', 'continue', 'default', 'do', 
     51        'double', 'else', 'enum', 'extern', 
     52        'float', 'for', 'goto', 'if', 
     53        'int', 'long', 'register', 'return', 
     54        'short', 'signed', 'sizeof', 'static', 
     55        'struct', 'switch', 'typedef', 'union', 
     56        'unsigned', 'void', 'volatile', 'while' 
    4557    ] 
    4658 
     
    6274        '\{', '\}', '\(', '\)', '\[', '\]', 
    6375    ] 
    64     def __init__(self, document): 
     76    def __init__(self, document, is_python=True): 
    6577        QSyntaxHighlighter.__init__(self, document) 
    6678 
     
    7486 
    7587        # Keyword, operator, and brace rules 
     88        keywords = PythonHighlighter.python_keywords if is_python \ 
     89            else PythonHighlighter.c_keywords 
    7690        rules += [(r'\b%s\b' % w, 0, STYLES['keyword']) 
    77             for w in PythonHighlighter.keywords] 
     91            for w in keywords] 
    7892        rules += [(r'%s' % o, 0, STYLES['operator']) 
    7993            for o in PythonHighlighter.operators] 
     
    104118            (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0, STYLES['numbers']), 
    105119        ] 
     120        # Add "//" to comments for C 
     121        if not is_python: 
     122            rules.append((r'//[^\n]*', 0, STYLES['comment']),) 
    106123 
    107124        # Build a QRegExp for each pattern 
  • src/sas/qtgui/Utilities/TabbedModelEditor.py

    rc5e0d84 rf2e199e  
    117117            return 
    118118 
     119        # remove c-plugin tab, if present. 
     120        if self.tabWidget.count()>1: 
     121            self.tabWidget.removeTab(1) 
    119122        self.loadFile(filename) 
    120123 
     
    130133        self.filename = filename 
    131134        display_name, _ = os.path.splitext(os.path.basename(filename)) 
    132  
    133135        self.setWindowTitle(self.window_title + " - " + display_name) 
     136        # Name the tab with .py filename 
     137        display_name = os.path.basename(filename) 
     138        self.tabWidget.setTabText(0, display_name) 
     139 
     140        # See if there is filename.c present 
     141        c_path = self.filename.replace(".py", ".c") 
     142        if not os.path.isfile(c_path): return 
     143        # add a tab with the same highlighting 
     144        display_name = os.path.basename(c_path) 
     145        self.c_editor_widget = ModelEditor(self, is_python=False) 
     146        self.tabWidget.addTab(self.c_editor_widget, display_name) 
     147        # Read in the file and set in on the widget 
     148        with open(c_path, 'r') as plugin: 
     149            self.c_editor_widget.txtEditor.setPlainText(plugin.read()) 
     150        self.c_editor_widget.modelModified.connect(self.editorModelModified) 
    134151 
    135152    def onModifiedExit(self): 
Note: See TracChangeset for help on using the changeset viewer.