def _log(self, line, status='info'):
"""Writing given line to the log-textCtrl.
:Parameters:
- `line`: text to log
- `status`: status should be 'info' or 'error'. If 'info' the
text will be colored blue, if 'error' the text will
be red.
"""
start = self.txtCtrlLog.GetLastPosition()
self.txtCtrlLog.AppendText('%s\n' % line)
color = wx.BLACK
if status == 'info':
color = wx.BLUE
elif status == 'error':
color = wx.RED
self.txtCtrlLog.SetStyle(start, self.txtCtrlLog.GetLastPosition(),
wx.TextAttr(color))
python类BLACK的实例源码
def DrawPointLabel(self, dc, mDataDict):
"""This is the fuction that defines how the pointLabels are plotted
dc - DC that will be passed
mDataDict - Dictionary of data that you want to use for the pointLabel
As an example I have decided I want a box at the curve point
with some text information about the curve plotted below.
Any wxDC method can be used.
"""
# ----------
dc.SetPen(wx.Pen(wx.BLACK))
dc.SetBrush(wx.Brush(wx.BLACK, wx.BRUSHSTYLE_SOLID))
sx, sy = mDataDict["scaledXY"] # scaled x,y of closest point
# 10by10 square centered on point
dc.DrawRectangle(sx - 5, sy - 5, 10, 10)
px, py = mDataDict["pointXY"]
cNum = mDataDict["curveNum"]
pntIn = mDataDict["pIndex"]
legend = mDataDict["legend"]
# make a string to display
s = "Crv# %i, '%s', Pt. (%.2f,%.2f), PtInd %i" % (
cNum, legend, px, py, pntIn)
dc.DrawText(s, sx, sy + 1)
# -----------
def _updateColAttrs(self, grid):
"""
wx.grid.Grid -> update the column attributes to add the
appropriate renderer given the column name.
Otherwise default to the default renderer.
"""
for row in range(self.GetNumberRows()):
row_highlights = self.Highlights.get(row, {})
for col in range(self.GetNumberCols()):
colname = self.GetColLabelValue(col, False)
grid.SetReadOnly(row, col, True)
grid.SetCellEditor(row, col, None)
grid.SetCellRenderer(row, col, None)
highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
grid.SetCellBackgroundColour(row, col, highlight_colours[0])
grid.SetCellTextColour(row, col, highlight_colours[1])
self.ResizeRow(grid, row)
def Draw(self, dc):
scalex, scaley = dc.GetUserScale()
dc.SetUserScale(1, 1)
x, y = self.Parent.CalcUnscrolledPosition(self.x_offset, self.y_offset)
text = self.GetInstanceName()
if self.ActionState is not None:
text += " ("
dc.DrawText(text, x, y)
tw, th = dc.GetTextExtent(text)
if self.ActionState is not None:
text = self.VALUE_TRANSLATION[self.ActionState]
if self.ActionState:
dc.SetTextForeground(wx.GREEN)
dc.DrawText(text, x + tw, y)
if self.ActionState:
dc.SetTextForeground(wx.BLACK)
tw = tw + dc.GetTextExtent(text)[0]
text = ")"
dc.DrawText(text, x + tw, y)
dc.SetUserScale(scalex, scaley)
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
dc.SetPen(MiterPen(wx.BLACK))
dc.SetBrush(wx.BLACK_BRUSH)
# Draw a rectangle with the power rail size
if self.Type == LEFTRAIL:
dc.DrawRectangle(self.Pos.x + self.Size[0] - LD_POWERRAIL_WIDTH, self.Pos.y, LD_POWERRAIL_WIDTH + 1, self.Size[1] + 1)
else:
dc.DrawRectangle(self.Pos.x, self.Pos.y, LD_POWERRAIL_WIDTH + 1, self.Size[1] + 1)
# Draw connectors
for connector in self.Connectors:
connector.Draw(dc)
# -------------------------------------------------------------------------------
# Ladder Diagram Contact
# -------------------------------------------------------------------------------
def __init__(self, parent, type, name, id=None, extension=0, inputs=None, connectors={}, executionControl=False, executionOrder=0):
Graphic_Element.__init__(self, parent)
self.Type = None
self.Description = None
self.Extension = None
self.ExecutionControl = False
self.Id = id
self.SetName(name)
self.SetExecutionOrder(executionOrder)
self.Inputs = []
self.Outputs = []
self.Colour = wx.BLACK
self.Pen = MiterPen(wx.BLACK)
self.SetType(type, extension, inputs, connectors, executionControl)
self.Highlights = {}
# Make a clone of this FBD_Block
def _drawRubberBand(self, corner1, corner2):
"""Draws/erases rect box from corner1 to corner2"""
ptx, pty, rectWidth, rectHeight = self._point2ClientCoord(
corner1, corner2)
# draw rectangle
dc = wx.ClientDC(self.canvas)
dc.SetPen(wx.Pen(wx.BLACK))
dc.SetBrush(wx.Brush(wx.WHITE, wx.BRUSHSTYLE_TRANSPARENT))
dc.SetLogicalFunction(wx.INVERT)
dc.DrawRectangle(ptx, pty, rectWidth, rectHeight)
dc.SetLogicalFunction(wx.COPY)
def GenerateProjectTreeBranch(self, root, infos, item_alone=False):
to_delete = []
item_name = infos["name"]
if infos["type"] in ITEMS_UNEDITABLE:
if len(infos["values"]) == 1:
return self.GenerateProjectTreeBranch(root, infos["values"][0], True)
item_name = _(item_name)
self.ProjectTree.SetItemText(root, item_name)
self.ProjectTree.SetPyData(root, infos)
highlight_colours = self.Highlights.get(infos.get("tagname", None), (wx.Colour(255, 255, 255, 0), wx.BLACK))
self.ProjectTree.SetItemTextColour(root, highlight_colours[1])
self.ProjectTree.SetItemExtraImage(root, None)
if infos["type"] == ITEM_POU:
self.ProjectTree.SetItemImage(
root, self.TreeImageDict[self.Controler.GetPouBodyType(infos["name"])])
if item_alone:
self.ProjectTree.SetItemExtraImage(root, self.Controler.GetPouType(infos["name"]))
elif "icon" in infos and infos["icon"] is not None:
icon_name = infos["icon"]
if icon_name not in self.TreeImageDict:
self.TreeImageDict[icon_name] = self.TreeImageList.Add(GetBitmap(icon_name))
self.ProjectTree.SetItemImage(root, self.TreeImageDict[icon_name])
elif infos["type"] in self.TreeImageDict:
self.ProjectTree.SetItemImage(root, self.TreeImageDict[infos["type"]])
item, root_cookie = self.ProjectTree.GetFirstChild(root)
for values in infos["values"]:
if values["type"] not in ITEMS_UNEDITABLE or len(values["values"]) > 0:
if item is None or not item.IsOk():
item = self.ProjectTree.AppendItem(root, "")
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
self.GenerateProjectTreeBranch(item, values)
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
while item is not None and item.IsOk():
to_delete.append(item)
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
for item in to_delete:
self.ProjectTree.Delete(item)
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
if self.Value:
if self.Forced:
dc.SetPen(MiterPen(wx.CYAN))
else:
dc.SetPen(MiterPen(wx.GREEN))
elif self.Forced:
dc.SetPen(MiterPen(wx.BLUE))
else:
dc.SetPen(MiterPen(wx.BLACK))
dc.SetBrush(wx.WHITE_BRUSH)
if getattr(dc, "printing", False):
name_size = dc.GetTextExtent(self.Name)
else:
name_size = self.NameSize
# Draw two rectangles for representing the step
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
if self.Initial:
dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3)
# Draw step name
name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
self.Pos.y + (self.Size[1] - name_size[1]) / 2)
dc.DrawText(self.Name, name_pos[0], name_pos[1])
# Draw input and output connectors
if self.Input:
self.Input.Draw(dc)
if self.Output:
self.Output.Draw(dc)
if self.Action:
self.Action.Draw(dc)
if not getattr(dc, "printing", False):
DrawHighlightedText(dc, self.Name, self.Highlights, name_pos[0], name_pos[1])
# -------------------------------------------------------------------------------
# Sequencial Function Chart Transition
# -------------------------------------------------------------------------------
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
if self.Value:
dc.SetPen(MiterPen(wx.GREEN))
dc.SetBrush(wx.GREEN_BRUSH)
else:
dc.SetPen(MiterPen(wx.BLACK))
dc.SetBrush(wx.BLACK_BRUSH)
# Draw plain rectangle for representing the divergence
if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y,
self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y)
dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y + self.Size[1],
self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y + self.Size[1])
# Draw inputs and outputs connectors
for input in self.Inputs:
input.Draw(dc)
for output in self.Outputs:
output.Draw(dc)
# -------------------------------------------------------------------------------
# Sequencial Function Chart Jump to Step
# -------------------------------------------------------------------------------
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
if self.Value:
dc.SetPen(MiterPen(wx.GREEN))
dc.SetBrush(wx.GREEN_BRUSH)
else:
dc.SetPen(MiterPen(wx.BLACK))
dc.SetBrush(wx.BLACK_BRUSH)
if getattr(dc, "printing", False):
target_size = dc.GetTextExtent(self.Target)
else:
target_size = self.TargetSize
# Draw plain rectangle for representing the divergence
dc.DrawLine(self.Pos.x + self.Size[0] / 2, self.Pos.y, self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])
points = [wx.Point(self.Pos.x, self.Pos.y),
wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3),
wx.Point(self.Pos.x + self.Size[0], self.Pos.y),
wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])]
dc.DrawPolygon(points)
target_pos = (self.Pos.x + self.Size[0] + 2,
self.Pos.y + (self.Size[1] - target_size[1]) / 2)
dc.DrawText(self.Target, target_pos[0], target_pos[1])
# Draw input connector
if self.Input:
self.Input.Draw(dc)
if not getattr(dc, "printing", False):
DrawHighlightedText(dc, self.Target, self.Highlights, target_pos[0], target_pos[1])
# -------------------------------------------------------------------------------
# Sequencial Function Chart Action Block
# -------------------------------------------------------------------------------
def Draw(self, dc):
if not getattr(dc, "printing", False):
if self.Highlighted:
self.DrawHighlightment(dc)
if self.Selected:
scalex, scaley = dc.GetUserScale()
dc.SetUserScale(1, 1)
dc.SetPen(MiterPen(wx.BLACK))
dc.SetBrush(wx.BLACK_BRUSH)
left = (self.BoundingBox.x - 2) * scalex - HANDLE_SIZE
center = (self.BoundingBox.x + self.BoundingBox.width / 2) * scalex - HANDLE_SIZE / 2
right = (self.BoundingBox.x + self.BoundingBox.width + 2) * scalex
top = (self.BoundingBox.y - 2) * scaley - HANDLE_SIZE
middle = (self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE / 2
bottom = (self.BoundingBox.y + self.BoundingBox.height + 2) * scaley
for x, y in [(left, top), (center, top), (right, top),
(left, middle), (right, middle),
(left, bottom), (center, bottom), (right, bottom)]:
dc.DrawRectangle(x, y, HANDLE_SIZE, HANDLE_SIZE)
dc.SetUserScale(scalex, scaley)
# -------------------------------------------------------------------------------
# Group of graphic elements
# -------------------------------------------------------------------------------
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
dc.SetPen(MiterPen(wx.BLACK))
dc.SetBrush(wx.WHITE_BRUSH)
if getattr(dc, "printing", False):
name_size = dc.GetTextExtent(self.Name)
executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder))
else:
name_size = self.NameSize
executionorder_size = self.ExecutionOrderSize
text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
self.Pos.y + (self.Size[1] - name_size[1]) / 2)
# Draw a rectangle with the variable size
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
# Draw variable name
dc.DrawText(self.Name, text_pos[0], text_pos[1])
# Draw connectors
if self.Input:
self.Input.Draw(dc)
if self.Output:
self.Output.Draw(dc)
if self.ExecutionOrder != 0:
# Draw variable execution order
dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0],
self.Pos.y + self.Size[1] + 2)
if not getattr(dc, "printing", False):
DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1])
# -------------------------------------------------------------------------------
# Function Block Diagram Connector
# -------------------------------------------------------------------------------
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
dc.SetPen(MiterPen(wx.BLACK))
dc.SetBrush(wx.WHITE_BRUSH)
if getattr(dc, "printing", False):
name_size = dc.GetTextExtent(self.Name)
else:
name_size = self.NameSize
# Draw a rectangle with the connection size with arrows inside
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
arrowsize = min(self.Size[1] / 2, (self.Size[0] - name_size[0] - 10) / 2)
dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize,
self.Pos.y + self.Size[1] / 2)
dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2,
self.Pos.x, self.Pos.y + self.Size[1])
dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y,
self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2)
dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2,
self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1])
# Draw connection name
text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
self.Pos.y + (self.Size[1] - name_size[1]) / 2)
dc.DrawText(self.Name, text_pos[0], text_pos[1])
# Draw connector
if self.Connector:
self.Connector.Draw(dc)
if not getattr(dc, "printing", False):
DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1])
def __init__(
self, parent=None, id=-1, pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=wx.TAB_TRAVERSAL|wx.NO_BORDER|wx.FULL_REPAINT_ON_RESIZE,
name='SquareMap', model = None,
adapter = None,
labels = True, # set to True to draw textual labels within the boxes
highlight = True, # set to False to turn of highlighting
padding = 2, # amount to reduce the children's box from the parent's box
):
super( SquareMap, self ).__init__(
parent, id, pos, size, style, name
)
self.model = model
self.padding = padding
self.labels = labels
self.highlight = highlight
self.selectedNode = None
self.highlightedNode = None
self.Bind( wx.EVT_PAINT, self.OnPaint)
self.Bind( wx.EVT_SIZE, self.OnSize )
if highlight:
self.Bind( wx.EVT_MOTION, self.OnMouse )
self.Bind( wx.EVT_LEFT_UP, self.OnClickRelease )
self.Bind( wx.EVT_LEFT_DCLICK, self.OnDoubleClick )
self.Bind( wx.EVT_KEY_UP, self.OnKeyUp )
self.hot_map = []
self.adapter = adapter or DefaultAdapter()
self.DEFAULT_PEN = wx.Pen( wx.BLACK, 1, wx.SOLID )
self.SELECTED_PEN = wx.Pen( wx.WHITE, 2, wx.SOLID )
self.OnSize(None)
def __init__(
self, parent=None, id=-1, pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=wx.TAB_TRAVERSAL|wx.NO_BORDER|wx.FULL_REPAINT_ON_RESIZE,
name='SquareMap', model = None,
adapter = None,
labels = True,
highlight = True,
padding = 2,
margin = 0,
square_style = False,
):
"""Initialise the SquareMap
adapter -- a DefaultAdapter or same-interface instance providing SquareMap data api
labels -- set to True (default) to draw textual labels within the boxes
highlight -- set to True (default) to highlight nodes on mouse-over
padding -- spacing within each square and its children (within the square's border)
margin -- spacing around each square (on all sides)
square_style -- use a more-recursive, less-linear, more "square" layout style which
works better on objects with large numbers of children, such as Meliae memory
dumps, works fine on profile views as well, but the layout is less obvious wrt
what node is "next" "previous" etc.
"""
super( SquareMap, self ).__init__(
parent, id, pos, size, style, name
)
self.model = model
self.padding = padding
self.square_style = square_style
self.margin = margin
self.labels = labels
self.highlight = highlight
self.selectedNode = None
self.highlightedNode = None
self._buffer = wx.Bitmap(20, 20) # Have a default buffer ready
self.Bind( wx.EVT_PAINT, self.OnPaint)
self.Bind( wx.EVT_SIZE, self.OnSize )
if highlight:
self.Bind( wx.EVT_MOTION, self.OnMouse )
self.Bind( wx.EVT_LEFT_UP, self.OnClickRelease )
self.Bind( wx.EVT_LEFT_DCLICK, self.OnDoubleClick )
self.Bind( wx.EVT_KEY_UP, self.OnKeyUp )
self.hot_map = []
self.adapter = adapter or DefaultAdapter()
self.DEFAULT_PEN = wx.Pen( wx.BLACK, 1, wx.SOLID )
self.SELECTED_PEN = wx.Pen( wx.WHITE, 2, wx.SOLID )
self.OnSize(None)
def OnPrintPage(self, page):
dc = self.GetDC()
dc.SetUserScale(1.0, 1.0)
dc.SetDeviceOrigin(0, 0)
dc.printing = not self.Preview
# Get the size of the DC in pixels
ppiPrinterX, ppiPrinterY = self.GetPPIPrinter()
ppiScreenX, ppiScreenY = self.GetPPIScreen()
pw, ph = self.GetPageSizePixels()
dw, dh = dc.GetSizeTuple()
Xscale = (float(dw) * float(ppiPrinterX)) / (float(pw) * 25.4)
Yscale = (float(dh) * float(ppiPrinterY)) / (float(ph) * 25.4)
fontsize = self.FontSize * Yscale
text_margin = self.TextMargin * Yscale
margin_left = self.Margins[0].x * Xscale
margin_top = self.Margins[0].y * Yscale
area_width = dw - self.Margins[1].x * Xscale - margin_left
area_height = dh - self.Margins[1].y * Yscale - margin_top
dc.SetPen(MiterPen(wx.BLACK))
dc.SetBrush(wx.TRANSPARENT_BRUSH)
dc.DrawRectangle(margin_left, margin_top, area_width, area_height)
dc.SetFont(wx.Font(fontsize, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
dc.SetTextForeground(wx.BLACK)
block_name = " - ".join(self.Viewer.GetTagName().split("::")[1:])
text_width, text_height = dc.GetTextExtent(block_name)
dc.DrawText(block_name, margin_left, margin_top - text_height - self.TextMargin)
dc.DrawText(_("Page: %d") % page, margin_left, margin_top + area_height + self.TextMargin)
# Calculate the position on the DC for centering the graphic
posX = area_width * ((page - 1) % self.PageGrid[0])
posY = area_height * ((page - 1) / self.PageGrid[0])
scaleX = float(area_width) / float(self.PageSize[0])
scaleY = float(area_height) / float(self.PageSize[1])
scale = min(scaleX, scaleY)
# Set the scale and origin
dc.SetDeviceOrigin(-posX + margin_left, -posY + margin_top)
dc.SetClippingRegion(posX, posY, self.PageSize[0] * scale, self.PageSize[1] * scale)
dc.SetUserScale(scale, scale)
self.Viewer.DoDrawing(dc, True)
return True
def GenerateSearchResultsTreeBranch(self, root, infos):
to_delete = []
if infos["name"] == "body":
item_name = "%d:" % infos["data"][1][0]
else:
item_name = infos["name"]
self.SearchResultsTree.SetItemText(root, item_name)
self.SearchResultsTree.SetPyData(root, infos["data"])
self.SearchResultsTree.SetItemBackgroundColour(root, wx.WHITE)
self.SearchResultsTree.SetItemTextColour(root, wx.BLACK)
if infos["type"] is not None:
if infos["type"] == ITEM_POU:
self.SearchResultsTree.SetItemImage(root, self.TreeImageDict[self.ParentWindow.Controler.GetPouType(infos["name"])])
else:
self.SearchResultsTree.SetItemImage(root, self.TreeImageDict[infos["type"]])
text = None
if infos["text"] is not None:
text = infos["text"]
start, end = infos["data"][1:3]
text_lines = infos["text"].splitlines()
start_idx = start[1]
end_idx = reduce(lambda x, y: x + y, map(lambda x: len(x) + 1, text_lines[:end[0] - start[0]]), end[1] + 1)
style = wx.TextAttr(wx.BLACK, wx.Colour(206, 204, 247))
elif infos["type"] is not None and infos["matches"] > 1:
text = _("(%d matches)") % infos["matches"]
start_idx, end_idx = 0, len(text)
style = wx.TextAttr(wx.Colour(0, 127, 174))
if text is not None:
text_ctrl_style = wx.BORDER_NONE | wx.TE_READONLY | wx.TE_RICH2
if wx.Platform != '__WXMSW__' or len(text.splitlines()) > 1:
text_ctrl_style |= wx.TE_MULTILINE
text_ctrl = wx.TextCtrl(id=-1, parent=self.SearchResultsTree, pos=wx.Point(0, 0),
value=text, style=text_ctrl_style)
width, height = text_ctrl.GetTextExtent(text)
text_ctrl.SetClientSize(wx.Size(width + 1, height))
text_ctrl.SetBackgroundColour(self.SearchResultsTree.GetBackgroundColour())
text_ctrl.Bind(wx.EVT_LEFT_DOWN, self.GetTextCtrlClickFunction(root))
text_ctrl.Bind(wx.EVT_LEFT_DCLICK, self.GetTextCtrlDClickFunction(root))
text_ctrl.SetInsertionPoint(0)
text_ctrl.SetStyle(start_idx, end_idx, style)
self.SearchResultsTree.SetItemWindow(root, text_ctrl)
if wx.VERSION >= (2, 6, 0):
item, root_cookie = self.SearchResultsTree.GetFirstChild(root)
else:
item, root_cookie = self.SearchResultsTree.GetFirstChild(root, 0)
for child in infos["children"]:
if item is None:
item = self.SearchResultsTree.AppendItem(root, "")
item, root_cookie = self.SearchResultsTree.GetNextChild(root, root_cookie)
self.GenerateSearchResultsTreeBranch(item, child)
item, root_cookie = self.SearchResultsTree.GetNextChild(root, root_cookie)
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
if self.Value:
dc.SetPen(MiterPen(wx.GREEN))
else:
dc.SetPen(MiterPen(wx.BLACK))
dc.SetBrush(wx.WHITE_BRUSH)
colsize = [self.ColSize[0], self.Size[0] - self.ColSize[0] - self.ColSize[2], self.ColSize[2]]
# Draw plain rectangle for representing the action block
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
dc.DrawLine(self.Pos.x + colsize[0], self.Pos.y,
self.Pos.x + colsize[0], self.Pos.y + self.Size[1])
dc.DrawLine(self.Pos.x + colsize[0] + colsize[1], self.Pos.y,
self.Pos.x + colsize[0] + colsize[1], self.Pos.y + self.Size[1])
line_size = self.GetLineSize()
for i, action in enumerate(self.Actions):
if i != 0:
dc.DrawLine(self.Pos.x, self.Pos.y + i * line_size,
self.Pos.x + self.Size[0], self.Pos.y + i * line_size)
qualifier_size = dc.GetTextExtent(action.qualifier)
if action.duration != "":
qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2,
self.Pos.y + i * line_size + line_size / 2 - qualifier_size[1])
duration_size = dc.GetTextExtent(action.duration)
duration_pos = (self.Pos.x + (colsize[0] - duration_size[0]) / 2,
self.Pos.y + i * line_size + line_size / 2)
dc.DrawText(action.duration, duration_pos[0], duration_pos[1])
else:
qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2,
self.Pos.y + i * line_size + (line_size - qualifier_size[1]) / 2)
dc.DrawText(action.qualifier, qualifier_pos[0], qualifier_pos[1])
content_size = dc.GetTextExtent(action.value)
content_pos = (self.Pos.x + colsize[0] + (colsize[1] - content_size[0]) / 2,
self.Pos.y + i * line_size + (line_size - content_size[1]) / 2)
dc.DrawText(action.value, content_pos[0], content_pos[1])
if action.indicator != "":
indicator_size = dc.GetTextExtent(action.indicator)
indicator_pos = (self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - indicator_size[0]) / 2,
self.Pos.y + i * line_size + (line_size - indicator_size[1]) / 2)
dc.DrawText(action.indicator, indicator_pos[0], indicator_pos[1])
if not getattr(dc, "printing", False):
action_highlights = self.Highlights.get(i, {})
for name, attribute_highlights in action_highlights.iteritems():
if name == "qualifier":
DrawHighlightedText(dc, action.qualifier, attribute_highlights, qualifier_pos[0], qualifier_pos[1])
elif name == "duration":
DrawHighlightedText(dc, action.duration, attribute_highlights, duration_pos[0], duration_pos[1])
elif name in ["reference", "inline"]:
DrawHighlightedText(dc, action.value, attribute_highlights, content_pos[0], content_pos[1])
elif name == "indicator":
DrawHighlightedText(dc, action.indicator, attribute_highlights, indicator_pos[0], indicator_pos[1])
# Draw input connector
self.Input.Draw(dc)
def Set_ReadOnly(self):
#print "cols n rows",self.grid_1.GetNumberCols(),self.grid_1.GetNumberRows()
for i in range(1,self.grid_1.GetNumberCols(),1):
if self.grid_1.GetNumberCols()>8:# =="Basic Science":
for j in range(0,self.grid_1.GetNumberRows(),1):
if i==9:
self.grid_1.SetCellBackgroundColour(j, i, wx.RED)
self.grid_1.SetCellTextColour(j,i, wx.BLACK)
self.grid_1.SetReadOnly(j,i, True)
elif i==10:
self.grid_1.SetCellBackgroundColour(j, i, wx.GREEN)
self.grid_1.SetCellTextColour(j,i, wx.BLACK)
self.grid_1.SetReadOnly(j,i, True)
elif i==11:
self.grid_1.SetCellBackgroundColour(j, i, wx.BLUE)
self.grid_1.SetCellTextColour(j,i, wx.WHITE)
self.grid_1.SetReadOnly(j,i, True)
elif i==12:
self.grid_1.SetCellBackgroundColour(j, i, wx.BLACK)
self.grid_1.SetCellTextColour(j,i, wx.WHITE)
self.grid_1.SetReadOnly(j,i, True)
else:
self.grid_1.SetCellBackgroundColour(j, i, wx.WHITE)
self.grid_1.SetCellTextColour(j,i, wx.BLACK)
self.grid_1.SetReadOnly(j,i, False)
else:
for j in range(0,self.grid_1.GetNumberRows(),1):
if i==5:
self.grid_1.SetCellBackgroundColour(j, i, wx.BLUE)
self.grid_1.SetCellTextColour(j,i, wx.WHITE)
self.grid_1.SetReadOnly(j,i, True)
elif i==6:
self.grid_1.SetCellBackgroundColour(j, i, wx.BLACK)
self.grid_1.SetCellTextColour(j,i, wx.WHITE)
self.grid_1.SetReadOnly(j,i, True)
else:
self.grid_1.SetCellBackgroundColour(j, i, wx.WHITE)
self.grid_1.SetCellTextColour(j,i, wx.BLACK)
self.grid_1.SetReadOnly(j,i, False)
def __init__(self, *args, **kwargs):
wx.grid.Grid.__init__(self, *args, **kwargs)
self.Editable = True
self.AddButton = None
self.DeleteButton = None
self.UpButton = None
self.DownButton = None
self.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, 'Sans'))
self.SetLabelFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, 'Sans'))
self.SetSelectionBackground(wx.WHITE)
self.SetSelectionForeground(wx.BLACK)
self.DisableDragRowSize()
self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnSelectCell)
self.Bind(wx.grid.EVT_GRID_EDITOR_HIDDEN, self.OnEditorHidden)
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)