controls/DebugVariablePanel/DebugVariableTextViewer.py
author Laurent Bessard
Mon, 03 Jun 2013 22:09:01 +0200
changeset 1215 786f2533200a
parent 1214 2ef048b5383c
child 1218 a5a6072ac944
permissions -rw-r--r--
Rewrite DebugVariablePanel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
    25
from types import TupleType
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
1199
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
    29
from DebugVariableItem import DebugVariableItem
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    30
from DebugVariableViewer import DebugVariableViewer
1199
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
    31
from GraphButton import GraphButton
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
    32
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    33
#-------------------------------------------------------------------------------
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    34
#                     Debug Variable Text Viewer Drop Target
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    35
#-------------------------------------------------------------------------------
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    36
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    37
"""
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    38
Class that implements a custom drop target class for Debug Variable Text Viewer
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    39
"""
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    40
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    41
class DebugVariableTextDropTarget(wx.TextDropTarget):
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    42
    
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    43
    def __init__(self, parent, window):
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    44
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    45
        Constructor
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    46
        @param parent: Reference to Debug Variable Text Viewer
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    47
        @param window: Reference to the Debug Variable Panel
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    48
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
        wx.TextDropTarget.__init__(self)
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    50
        self.ParentControl = parent
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    51
        self.ParentWindow = window
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
    
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
    53
    def __del__(self):
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    54
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    55
        Destructor
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    56
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    57
        # Remove reference to Debug Variable Text Viewer and Debug Variable
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    58
        # Panel
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    59
        self.ParentControl = None
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 912
diff changeset
    60
        self.ParentWindow = None
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    61
        
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
    62
    def OnDragOver(self, x, y, d):
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    63
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    64
        Function called when mouse is dragged over Drop Target
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    65
        @param x: X coordinate of mouse pointer
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    66
        @param y: Y coordinate of mouse pointer
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    67
        @param d: Suggested default for return value
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    68
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    69
        # Signal parent that mouse is dragged over
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    70
        self.ParentControl.OnMouseDragging(x, y)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    71
        
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
    72
        return wx.TextDropTarget.OnDragOver(self, x, y, d)
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
    73
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
    def OnDropText(self, x, y, data):
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    75
        """
1215
786f2533200a Rewrite DebugVariablePanel
Laurent Bessard
parents: 1214
diff changeset
    76
        Function called when mouse is released in Drop Target
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    77
        @param x: X coordinate of mouse pointer
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    78
        @param y: Y coordinate of mouse pointer
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    79
        @param data: Text associated to drag'n drop
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    80
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
        message = None
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    82
        
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    83
        # Check that data is valid regarding DebugVariablePanel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
        try:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
            values = eval(data)
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    86
            if not isinstance(values, TupleType):
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1200
diff changeset
    87
                raise ValueError
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
        except:
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    89
            message = _("Invalid value \"%s\" for debug variable") % data
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
            values = None
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    91
        
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    92
        # Display message if data is invalid
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        if message is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
            wx.CallAfter(self.ShowMessage, message)
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    95
        
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    96
        # Data contain a reference to a variable to debug
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    97
        elif values[1] == "debug":
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    98
            
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
    99
            # Get Before which Viewer the variable has to be moved or added
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   100
            # according to the position of mouse in Viewer.
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   101
            width, height = self.ParentControl.GetSize()
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   102
            target_idx = self.ParentControl.GetIndex()
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   103
            if y > height / 2:
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   104
                target_idx += 1
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   105
            
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   106
            # Drag'n Drop is an internal is an internal move inside Debug
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   107
            # Variable Panel 
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   108
            if len(values) > 2 and values[2] == "move":
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   109
                self.ParentWindow.MoveValue(values[0], 
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   110
                                            target_idx)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   111
            
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   112
            # Drag'n Drop was initiated by another control of Beremiz
945
c1159acb0886 Added support for drag'n dropping non-numeric variables
Laurent Bessard
parents: 943
diff changeset
   113
            else:
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   114
                self.ParentWindow.InsertValue(values[0], 
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   115
                                              target_idx, 
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   116
                                              force=True)
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   117
    
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   118
    def OnLeave(self):
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   119
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   120
        Function called when mouse is leave Drop Target
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   121
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   122
        # Signal Debug Variable Panel to reset highlight
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   123
        self.ParentWindow.ResetHighlight()
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   124
        
928
a94e7fea7051 Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 927
diff changeset
   125
        return wx.TextDropTarget.OnLeave(self)
934
fc00c11feff5 Fixed highlights for dropping graphs between the others
Laurent Bessard
parents: 932
diff changeset
   126
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
    def ShowMessage(self, message):
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   128
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   129
        Show error message in Error Dialog
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   130
        @param message: Error message to display
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   131
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   132
        dialog = wx.MessageDialog(self.ParentWindow, 
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   133
                                  message, 
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   134
                                  _("Error"), 
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   135
                                  wx.OK|wx.ICON_ERROR)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
        dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   139
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   140
#-------------------------------------------------------------------------------
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   141
#                      Debug Variable Text Viewer Class
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   142
#-------------------------------------------------------------------------------
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   143
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   144
"""
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   145
Class that implements a Viewer that display variable values as a text
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   146
"""
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   147
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   148
class DebugVariableTextViewer(DebugVariableViewer, wx.Panel):
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   149
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   150
    def __init__(self, parent, window, items=[]):
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   151
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   152
        Constructor
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   153
        @param parent: Parent wx.Window of DebugVariableText
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   154
        @param window: Reference to the Debug Variable Panel
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   155
        @param items: List of DebugVariableItem displayed by Viewer
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   156
        """
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   157
        DebugVariableViewer.__init__(self, window, items)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   158
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   159
        wx.Panel.__init__(self, parent)
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   160
        # Set panel background colour
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   161
        self.SetBackgroundColour(wx.WHITE)
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   162
        # Define panel drop target
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   163
        self.SetDropTarget(DebugVariableTextDropTarget(self, window))
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   164
        
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   165
        # Bind events
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   166
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   167
        self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
1214
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   168
        self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   169
        self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   170
        self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   171
        self.Bind(wx.EVT_SIZE, self.OnResize)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   172
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   173
        self.Bind(wx.EVT_PAINT, self.OnPaint)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   174
        
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   175
        # Define panel min size for parent sizer layout
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   176
        self.SetMinSize(wx.Size(0, 25))
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   177
        
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   178
        # Add buttons to Viewer
1199
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   179
        for bitmap, callback in [("force", self.OnForceButton),
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   180
                                 ("release", self.OnReleaseButton),
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   181
                                 ("delete_graph", self.OnCloseButton)]:
fc0e7d80494f Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents: 1198
diff changeset
   182
            self.Buttons.append(GraphButton(0, 0, bitmap, callback))
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   183
    
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   184
    def RefreshViewer(self):
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   185
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   186
        Method that refresh the content displayed by Viewer
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   187
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   188
        # Create buffered DC for drawing in panel
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   189
        width, height = self.GetSize()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   190
        bitmap = wx.EmptyBitmap(width, height)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   191
        dc = wx.BufferedDC(wx.ClientDC(self), bitmap)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   192
        dc.Clear()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   193
        
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   194
        # Get Graphics Context for DC, for anti-aliased and transparent
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   195
        # rendering
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   196
        gc = wx.GCDC(dc)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   197
        
1209
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   198
        gc.BeginDrawing()
953a8f14040a Rewrite DebugVariablePanel and fixed bugs
Laurent Bessard
parents: 1207
diff changeset
   199
        
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   200
        # Get first item
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   201
        item = self.ItemsDict.values()[0]
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   202
        
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   203
        # Get item variable path masked according Debug Variable Panel mask
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   204
        item_path = item.GetVariable(
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   205
                self.ParentWindow.GetVariableNameMask())
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   206
        
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   207
        # Draw item variable path at Viewer left side
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   208
        w, h = gc.GetTextExtent(item_path)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   209
        gc.DrawText(item_path, 20, (height - h) / 2)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   210
        
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   211
        # Update 'Release' button state and text color according to item forced
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   212
        # flag value
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   213
        item_forced = item.IsForced()
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   214
        self.Buttons[1].Enable(item_forced)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   215
        self.RefreshButtonsPosition()
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   216
        if item_forced:
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   217
            gc.SetTextForeground(wx.BLUE)
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   218
        
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   219
        # Draw item current value at right side of Viewer
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   220
        item_value = item.GetValue()
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   221
        w, h = gc.GetTextExtent(item_value)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   222
        gc.DrawText(item_value, width - 40 - w, (height - h) / 2)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   223
        
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   224
        # Draw other Viewer common elements
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   225
        self.DrawCommonElements(gc)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   226
        
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   227
        gc.EndDrawing()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   228
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   229
    def OnLeftDown(self, event):
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   230
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   231
        Function called when mouse left button is pressed
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   232
        @param event: wx.MouseEvent
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   233
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   234
        # Get first item
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   235
        item = self.ItemsDict.values()[0]
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   236
        
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   237
        # Calculate item path bounding box
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   238
        width, height = self.GetSize()
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   239
        item_path = item.GetVariable(
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   240
                self.ParentWindow.GetVariableNameMask())
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   241
        w, h = self.GetTextExtent(item_path)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   242
        
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   243
        # Test if mouse has been pressed in this bounding box. In that case
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   244
        # start a move drag'n drop of item variable 
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   245
        x, y = event.GetPosition()
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   246
        item_path_bbox = wx.Rect(20, (height - h) / 2, w, h)
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   247
        if item_path_bbox.InsideXY(x, y):
1214
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   248
            self.ShowButtons(False)
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   249
            data = wx.TextDataObject(str((item.GetVariable(), "debug", "move")))
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   250
            dragSource = wx.DropSource(self)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   251
            dragSource.SetData(data)
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   252
            dragSource.DoDragDrop()
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   253
        
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   254
        # In other case handle event normally
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   255
        else:
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   256
            event.Skip()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   257
    
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   258
    def OnLeftUp(self, event):
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   259
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   260
        Function called when mouse left button is released
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   261
        @param event: wx.MouseEvent
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   262
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   263
        # Execute callback on button under mouse pointer if it exists
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   264
        x, y = event.GetPosition()
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   265
        wx.CallAfter(self.HandleButton, x, y)
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   266
        event.Skip()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   267
    
1214
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   268
    def OnLeftDClick(self, event):
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   269
        """
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   270
        Function called when mouse left button is double clicked
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   271
        @param event: wx.MouseEvent
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   272
        """
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   273
        # Only numeric variables can be toggled to graph canvas
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   274
        if self.ItemsDict.values()[0].IsNumVariable():
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   275
            self.ParentWindow.ToggleViewerType(self)
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1209
diff changeset
   276
    
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   277
    def OnPaint(self, event):
1200
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   278
        """
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   279
        Function called when redrawing Viewer content is needed
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   280
        @param event: wx.PaintEvent
501cb0bb4c05 Splitted DebugVariableGraphicPanel.py into several files
Laurent Bessard
parents: 1199
diff changeset
   281
        """
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   282
        self.RefreshViewer()
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1194
diff changeset
   283
        event.Skip()