611 return mask |
611 return mask |
612 |
612 |
613 #CANVAS_HIGHLIGHT_TYPES |
613 #CANVAS_HIGHLIGHT_TYPES |
614 [HIGHLIGHT_NONE, |
614 [HIGHLIGHT_NONE, |
615 HIGHLIGHT_BEFORE, |
615 HIGHLIGHT_BEFORE, |
616 HIGHLIGHT_BEFORE_DOUBLE, |
|
617 HIGHLIGHT_AFTER, |
616 HIGHLIGHT_AFTER, |
618 HIGHLIGHT_AFTER_DOUBLE, |
|
619 HIGHLIGHT_LEFT, |
617 HIGHLIGHT_LEFT, |
620 HIGHLIGHT_RIGHT] = range(7) |
618 HIGHLIGHT_RIGHT] = range(5) |
621 |
619 |
622 HIGHLIGHT_PEN = wx.Pen(wx.Colour(0, 128, 255)) |
620 HIGHLIGHT_PEN = wx.Pen(wx.Colour(0, 128, 255)) |
623 HIGHLIGHT_BRUSH = wx.Brush(wx.Colour(0, 128, 255, 128)) |
621 HIGHLIGHT_BRUSH = wx.Brush(wx.Colour(0, 128, 255, 128)) |
624 |
622 |
625 #CANVAS_SIZE_TYPES |
623 #CANVAS_SIZE_TYPES |
626 [SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI] = range(3) |
624 [SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI] = [0, 100, 200] |
|
625 |
|
626 DEFAULT_CANVAS_HEIGHT = 200. |
|
627 CANVAS_BORDER = (20., 10.) |
|
628 CANVAS_PADDING = 8.5 |
|
629 VALUE_LABEL_HEIGHT = 17. |
|
630 AXES_LABEL_HEIGHT = 12.75 |
627 |
631 |
628 class GraphButton(): |
632 class GraphButton(): |
629 |
633 |
630 def __init__(self, x, y, bitmap, callback): |
634 def __init__(self, x, y, bitmap, callback): |
631 self.Position = wx.Point(x, y) |
635 self.Position = wx.Point(x, y) |
682 self.ParentWindow = window |
686 self.ParentWindow = window |
683 self.Highlight = HIGHLIGHT_NONE |
687 self.Highlight = HIGHLIGHT_NONE |
684 self.CanvasSize = SIZE_MAXI |
688 self.CanvasSize = SIZE_MAXI |
685 |
689 |
686 self.Buttons = [] |
690 self.Buttons = [] |
|
691 self.SizeButtonsParams = dict( |
|
692 [(size, (GetBitmap(bitmap), self.GetOnChangeSizeButton(size))) |
|
693 for size, bitmap in zip([SIZE_MINI, SIZE_MIDDLE, SIZE_MAXI], |
|
694 ["minimize_graph", "middle_graph", "maximize_graph"])]) |
687 self.ContextualButtons = [] |
695 self.ContextualButtons = [] |
688 self.ContextualButtonsItem = None |
696 self.ContextualButtonsItem = None |
689 |
697 |
690 self.Buttons.append( |
698 for size in [SIZE_MINI, SIZE_MIDDLE]: |
691 GraphButton(0, 0, GetBitmap("minimize_graph"), self.OnChangeSizeButton)) |
699 self.Buttons.append(GraphButton(0, 0, *self.SizeButtonsParams[size])) |
692 self.Buttons.append( |
700 self.Buttons.append( |
693 GraphButton(0, 0, GetBitmap("delete_graph"), self.OnCloseButton)) |
701 GraphButton(0, 0, GetBitmap("delete_graph"), self.OnCloseButton)) |
694 |
702 |
695 self.ShowButtons(False) |
703 self.ShowButtons(False) |
696 |
704 |
846 if (x <= 0 or x >= width - 1 or |
854 if (x <= 0 or x >= width - 1 or |
847 y <= 0 or y >= height - 1): |
855 y <= 0 or y >= height - 1): |
848 self.ShowButtons(False) |
856 self.ShowButtons(False) |
849 event.Skip() |
857 event.Skip() |
850 |
858 |
851 def OnChangeSizeButton(self): |
859 def GetOnChangeSizeButton(self, size): |
852 if self.CanvasSize == SIZE_MAXI: |
860 def OnChangeSizeButton(): |
853 self.CanvasSize = SIZE_MIDDLE |
861 self.CanvasSize = size |
854 self.Parent.Minimize() |
862 self.Parent.SetCanvasSize(200, self.CanvasSize) |
855 else: |
863 params = [] |
856 self.CanvasSize = SIZE_MAXI |
864 if self.CanvasSize != SIZE_MINI: |
857 self.Parent.Maximize() |
865 params.append(self.SizeButtonsParams[SIZE_MINI]) |
|
866 else: |
|
867 params.append(self.SizeButtonsParams[SIZE_MIDDLE]) |
|
868 if self.CanvasSize != SIZE_MAXI: |
|
869 params.append(self.SizeButtonsParams[SIZE_MAXI]) |
|
870 else: |
|
871 params.append(self.SizeButtonsParams[SIZE_MIDDLE]) |
|
872 for button, (bitmap, callback) in zip(self.Buttons, params): |
|
873 button.SetBitmap(bitmap) |
|
874 button.SetCallback(callback) |
|
875 return OnChangeSizeButton |
858 |
876 |
859 def OnCloseButton(self): |
877 def OnCloseButton(self): |
860 self.ParentWindow.DeleteValue(self.Parent) |
878 self.ParentWindow.DeleteValue(self.Parent) |
861 |
879 |
862 def OnForceButton(self): |
880 def OnForceButton(self): |
880 buttons = self.Buttons[:] |
898 buttons = self.Buttons[:] |
881 buttons.reverse() |
899 buttons.reverse() |
882 for button in buttons: |
900 for button in buttons: |
883 w, h = button.GetSize() |
901 w, h = button.GetSize() |
884 button.SetPosition(width - 5 - w - offset, 5) |
902 button.SetPosition(width - 5 - w - offset, 5) |
885 offset += w |
903 offset += w + 2 |
886 event.Skip() |
904 event.Skip() |
887 |
905 |
888 class DebugVariableGraphic(DebugVariableViewer): |
906 class DebugVariableGraphic(DebugVariableViewer): |
889 |
907 |
890 def __init__(self, parent, window, items, graph_type): |
908 def __init__(self, parent, window, items, graph_type): |
912 |
930 |
913 main_sizer.AddWindow(self.Canvas, 1, flag=wx.GROW) |
931 main_sizer.AddWindow(self.Canvas, 1, flag=wx.GROW) |
914 self.SetSizer(main_sizer) |
932 self.SetSizer(main_sizer) |
915 |
933 |
916 self.ResetGraphics() |
934 self.ResetGraphics() |
917 |
935 self.RefreshLabelsPosition(200) |
918 def RefreshLabelsPosition(self, ratio): |
936 |
|
937 def RefreshLabelsPosition(self, height): |
|
938 canvas_ratio = 1. / height |
|
939 graph_ratio = 1. / ((1.0 - (CANVAS_BORDER[0] + CANVAS_BORDER[1]) * canvas_ratio) * height) |
|
940 |
|
941 self.Figure.subplotpars.update( |
|
942 top= 1.0 - CANVAS_BORDER[1] * canvas_ratio, |
|
943 bottom= CANVAS_BORDER[0] * canvas_ratio) |
|
944 |
919 if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas(): |
945 if self.GraphType == GRAPH_PARALLEL or self.Is3DCanvas(): |
920 num_item = len(self.Items) |
946 num_item = len(self.Items) |
921 for idx in xrange(num_item): |
947 for idx in xrange(num_item): |
922 if not self.Is3DCanvas(): |
948 if not self.Is3DCanvas(): |
923 self.AxesLabels[idx].set_position((0.05, 1.0 - (0.1 + 0.075 * idx) * ratio)) |
949 self.AxesLabels[idx].set_position( |
924 self.Labels[idx].set_position((0.95, 0.1 + (num_item - idx - 1) * 0.1 * ratio)) |
950 (0.05, |
925 else: |
951 1.0 - (CANVAS_PADDING + AXES_LABEL_HEIGHT * idx) * graph_ratio)) |
926 self.AxesLabels[0].set_position((0.1, 0.05 * ratio)) |
952 self.Labels[idx].set_position( |
927 self.Labels[0].set_position((0.95, 0.05 * ratio)) |
953 (0.95, |
928 self.AxesLabels[1].set_position((0.05, 0.1 * ratio)) |
954 CANVAS_PADDING * graph_ratio + |
929 self.Labels[1].set_position((0.05, 1.0 - 0.05 * ratio)) |
955 (num_item - idx - 1) * VALUE_LABEL_HEIGHT * graph_ratio)) |
930 |
956 else: |
931 def Minimize(self): |
957 self.AxesLabels[0].set_position((0.1, CANVAS_PADDING * graph_ratio)) |
932 self.Canvas.SetMinSize(wx.Size(200, 100)) |
958 self.Labels[0].set_position((0.95, CANVAS_PADDING * graph_ratio)) |
933 self.Figure.subplotpars.update(top=0.9, bottom=0.2) |
959 self.AxesLabels[1].set_position((0.05, 2 * CANVAS_PADDING * graph_ratio)) |
934 self.RefreshLabelsPosition(2) |
960 self.Labels[1].set_position((0.05, 1.0 - CANVAS_PADDING * graph_ratio)) |
|
961 |
935 self.Figure.subplots_adjust() |
962 self.Figure.subplots_adjust() |
936 self.ParentWindow.RefreshGraphicsSizer() |
963 |
937 |
964 def SetCanvasSize(self, width, height): |
938 def Maximize(self): |
965 height = max(height, |
939 self.Canvas.SetMinSize(wx.Size(200, 200)) |
966 CANVAS_BORDER[0] + CANVAS_BORDER[1] + |
940 self.Figure.subplotpars.update(top=0.95, bottom=0.1) |
967 2 * CANVAS_PADDING + VALUE_LABEL_HEIGHT * len(self.Items)) |
941 self.RefreshLabelsPosition(1) |
968 self.Canvas.SetMinSize(wx.Size(width, height)) |
942 self.Figure.subplots_adjust() |
969 self.RefreshLabelsPosition(height) |
943 self.ParentWindow.RefreshGraphicsSizer() |
970 self.ParentWindow.RefreshGraphicsSizer() |
944 |
971 |
945 def GetAxesBoundingBox(self, absolute=False): |
972 def GetAxesBoundingBox(self, absolute=False): |
946 bbox = self.Canvas.GetAxesBoundingBox() |
973 bbox = self.Canvas.GetAxesBoundingBox() |
947 if absolute: |
974 if absolute: |
1133 color = 'k' |
1160 color = 'k' |
1134 else: |
1161 else: |
1135 color = color_cycle[idx % len(color_cycle)] |
1162 color = color_cycle[idx % len(color_cycle)] |
1136 if not self.Is3DCanvas(): |
1163 if not self.Is3DCanvas(): |
1137 self.AxesLabels.append( |
1164 self.AxesLabels.append( |
1138 text_func(0, 0, "", size='small', |
1165 text_func(0, 0, "", size='small', |
|
1166 verticalalignment='top', |
1139 color=color, |
1167 color=color, |
1140 transform=self.Axes.transAxes)) |
1168 transform=self.Axes.transAxes)) |
1141 self.Labels.append( |
1169 self.Labels.append( |
1142 text_func(0, 0, "", size='large', |
1170 text_func(0, 0, "", size='large', |
1143 horizontalalignment='right', |
1171 horizontalalignment='right', |
1159 self.Labels.append( |
1187 self.Labels.append( |
1160 self.Axes.text(0, 0, "", size='large', |
1188 self.Axes.text(0, 0, "", size='large', |
1161 rotation='vertical', |
1189 rotation='vertical', |
1162 verticalalignment='top', |
1190 verticalalignment='top', |
1163 transform=self.Axes.transAxes)) |
1191 transform=self.Axes.transAxes)) |
1164 if self.Canvas.CanvasSize == SIZE_MAXI: |
1192 width, height = self.Canvas.GetSize() |
1165 self.RefreshLabelsPosition(1) |
1193 self.RefreshLabelsPosition(height) |
1166 else: |
|
1167 self.RefreshLabelsPosition(2) |
|
1168 |
1194 |
1169 def AddItem(self, item): |
1195 def AddItem(self, item): |
1170 DebugVariableViewer.AddItem(self, item) |
1196 DebugVariableViewer.AddItem(self, item) |
1171 self.ResetGraphics() |
1197 self.ResetGraphics() |
1172 |
1198 |