def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Encrypted Files", pos = wx.DefaultPosition, size = wx.Size( 600,400 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
BodySizer = wx.BoxSizer( wx.VERTICAL )
self.m_panel4 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
TextCtrlSizer = wx.BoxSizer( wx.VERTICAL )
self.EncryptedFilesTextCtrl = wx.TextCtrl( self.m_panel4, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_DONTWRAP|wx.TE_MULTILINE|wx.TE_READONLY )
TextCtrlSizer.Add( self.EncryptedFilesTextCtrl, 1, wx.ALL|wx.EXPAND, 5 )
self.m_panel4.SetSizer( TextCtrlSizer )
self.m_panel4.Layout()
TextCtrlSizer.Fit( self.m_panel4 )
BodySizer.Add( self.m_panel4, 1, wx.EXPAND |wx.ALL, 5 )
self.SetSizer( BodySizer )
self.Layout()
self.Centre( wx.BOTH )
python类Size()的实例源码
def __init__(self):
wx.Frame.__init__(self, None,
pos=wx.DefaultPosition, size=wx.Size(450, 100),
style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION |
wx.CLOSE_BOX | wx.CLIP_CHILDREN,
title="BRUNO")
panel = wx.Panel(self)
ico = wx.Icon('boy.ico', wx.BITMAP_TYPE_ICO)
self.SetIcon(ico)
my_sizer = wx.BoxSizer(wx.VERTICAL)
lbl = wx.StaticText(panel,
label="Bienvenido Sir. How can I help you?")
my_sizer.Add(lbl, 0, wx.ALL, 5)
self.txt = wx.TextCtrl(panel, style=wx.TE_PROCESS_ENTER,
size=(400, 30))
self.txt.SetFocus()
self.txt.Bind(wx.EVT_TEXT_ENTER, self.OnEnter)
my_sizer.Add(self.txt, 0, wx.ALL, 5)
panel.SetSizer(my_sizer)
self.Show()
speak.Speak('''Welcome back Sir, Broono at your service.''')
def __init__(self, strCaption="", imageIndex=-1, enabled=True):
"""
Default class constructor.
:param `strCaption`: the tab caption;
:param `imageIndex`: the tab image index based on the assigned (set)
:class:`ImageList` (if any);
:param `enabled`: sets the tab as enabled or disabled.
"""
self._pos = wx.Point()
self._size = wx.Size()
self._strCaption = strCaption
self._ImageIndex = imageIndex
self._captionRect = wx.Rect()
self._bEnabled = enabled
def FillTextCtrl(self, textctrl, fname, srcdir='appdir'):
if srcdir == 'appdir':
fpath = appconstants.getapppath(fname)
else:
fpath = appconstants.getdatapath(fname)
try:
f = open(fpath, 'r')
except IOError:
fcontent = fname + filemissing + appconstants.AppURL
else:
fcontent = f.read()
textctrl.SetFont(self.font)
textctrl.SetValue(fcontent)
winDC = wx.ClientDC(textctrl)
width, height = winDC.GetTextExtent(text_82)
height *= 26
textctrl.SetMinSize(wx.Size(width, height))
def add_toolbar(self):
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
if wx.Platform == '__WXMAC__':
# Mac platform (OSX 10.3, MacPython) does not seem to cope with
# having a toolbar in a sizer. This work-around gets the buttons
# back, but at the expense of having the toolbar at the top
self.SetToolBar(self.toolbar)
else:
# On Windows platform, default window size is incorrect, so set
# toolbar width to figure width.
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
# By adding toolbar in sizer, we are able to put it at the bottom
# of the frame - so appearance is closer to GTK version.
# As noted above, doesn't work for Mac.
self.toolbar.SetSize(wx.Size(fw, th))
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
# update the axes menu on the toolbar
self.toolbar.update()
def __init__(self, parent, size=wx.Size(128,128), dpi=None, **kwargs):
self.size = size
self.dragging_curview_is_active = False
wx.Panel.__init__(self, parent, wx.ID_ANY, wx.DefaultPosition, size, 0, **kwargs)
self.ztv_frame = self.GetTopLevelParent()
self.figure = Figure(None, dpi)
self.axes = self.figure.add_axes([0., 0., 1., 1.])
self.curview_rectangle = Rectangle((0, 0), 1, 1, color='orange', fill=False, zorder=100)
self.axes.add_patch(self.curview_rectangle)
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self.overview_zoom_factor = 1.
self._SetSize()
self.set_xy_limits()
self.axes_widget = AxesWidget(self.figure.gca())
self.axes_widget.connect_event('button_press_event', self.on_button_press)
self.axes_widget.connect_event('button_release_event', self.on_button_release)
self.axes_widget.connect_event('motion_notify_event', self.on_motion)
pub.subscribe(self.redraw_overview_image, 'redraw-image')
pub.subscribe(self.redraw_box, 'primary-xy-limits-changed')
def __init__(self, parent, size=wx.Size(128,128), dpi=None, **kwargs):
self.size = size
self.dragging_curview_is_active = False
wx.Panel.__init__(self, parent, wx.ID_ANY, wx.DefaultPosition, size, 0, **kwargs)
self.ztv_frame = self.GetTopLevelParent()
self.figure = Figure(None, dpi)
self.axes = self.figure.add_axes([0., 0., 1., 1.])
self.curview_rectangle = Rectangle((0, 0), 1, 1, color='orange', fill=False, zorder=100)
self.axes.add_patch(self.curview_rectangle)
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self.overview_zoom_factor = 1.
self._SetSize()
self.set_xy_limits()
self.axes_widget = AxesWidget(self.figure.gca())
self.axes_widget.connect_event('button_press_event', self.on_button_press)
self.axes_widget.connect_event('button_release_event', self.on_button_release)
self.axes_widget.connect_event('motion_notify_event', self.on_motion)
pub.subscribe(self.redraw_overview_image, 'redraw-image')
pub.subscribe(self.redraw_box, 'primary-xy-limits-changed')
def __init__( self, parent ):
win_height = parent.GetSize()[1]
height_of_pannels_above = 230
space_left = win_height - height_of_pannels_above
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = (0, height_of_pannels_above), size = wx.Size(285, space_left), style = wx.TAB_TRAVERSAL )
# Start drawing the UI elements
wx.StaticText(self, label='Pigrow Config', pos=(25, 10))
self.update_config_btn = wx.Button(self, label='read config from pigrow', pos=(15, 60), size=(175, 30))
self.update_config_btn.Bind(wx.EVT_BUTTON, self.update_config_click)
self.name_box_btn = wx.Button(self, label='change box name', pos=(15, 95), size=(175, 30))
self.name_box_btn.Bind(wx.EVT_BUTTON, self.name_box_click)
self.config_lamp_btn = wx.Button(self, label='config lamp', pos=(15, 130), size=(175, 30))
self.config_lamp_btn.Bind(wx.EVT_BUTTON, self.config_lamp_click)
self.config_dht_btn = wx.Button(self, label='config dht', pos=(15, 165), size=(175, 30))
self.config_dht_btn.Bind(wx.EVT_BUTTON, self.config_dht_click)
self.new_gpio_btn = wx.Button(self, label='Add new relay device', pos=(15, 200), size=(175, 30))
self.new_gpio_btn.Bind(wx.EVT_BUTTON, self.add_new_device_relay)
self.update_settings_btn = wx.Button(self, label='update pigrow settings', pos=(15, 235), size=(175, 30))
self.update_settings_btn.Bind(wx.EVT_BUTTON, self.update_setting_click)
def __init__( self, parent ):
win_height = parent.GetSize()[1]
win_width = parent.GetSize()[0]
w_space_left = win_width - 285
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = (285, 0), size = wx.Size(w_space_left , 800), style = wx.TAB_TRAVERSAL )
## Draw UI elements
png = wx.Image('./config_info.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
wx.StaticBitmap(self, -1, png, (0, 0), (png.GetWidth(), png.GetHeight()))
#SDcard details
config_info_pnl.boxname_text = wx.TextCtrl(self, pos=(25, 150), size=(265,65))
config_info_pnl.location_text = wx.StaticText(self, label='locations', pos=(520, 120), size=(200,30))
config_info_pnl.config_text = wx.StaticText(self, label='config', pos=(520, 185), size=(200,30))
config_info_pnl.lamp_text = wx.StaticText(self, label='lamp', pos=(10, 330), size=(200,30))
config_info_pnl.dht_text = wx.StaticText(self, label='dht', pos=(10, 415), size=(200,30))
config_info_pnl.gpio_table = self.GPIO_list(self, 1)
config_info_pnl.gpio_table.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onDoubleClick_GPIO)
def __init__( self, parent ):
win_height = parent.GetSize()[1]
height_of_pannels_above = 230
space_left = win_height - height_of_pannels_above
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = (0, height_of_pannels_above), size = wx.Size(285, space_left), style = wx.TAB_TRAVERSAL )
wx.StaticText(self, label='Cron Config Menu', pos=(25, 10))
self.read_cron_btn = wx.Button(self, label='Read Crontab', pos=(10, 40), size=(175, 30))
self.read_cron_btn.Bind(wx.EVT_BUTTON, self.read_cron_click)
self.new_cron_btn = wx.Button(self, label='New cron job', pos=(10, 80), size=(175, 30))
self.new_cron_btn.Bind(wx.EVT_BUTTON, self.new_cron_click)
self.update_cron_btn = wx.Button(self, label='Update Cron', pos=(10, 120), size=(175, 30))
self.update_cron_btn.Bind(wx.EVT_BUTTON, self.update_cron_click)
self.SetBackgroundColour('sea green') #TESTING ONLY REMOVE WHEN SIZING IS DONE AND ALL THAT BUSINESS
bSizer = wx.BoxSizer(wx.VERTICAL)
bSizer.Add(self.read_cron_btn, 0, wx.ALL, 5)
bSizer.Add(self.new_cron_btn, 0, wx.ALL, 5)
bSizer.Add(self.update_cron_btn, 0, wx.ALL, 5)
self.SetSizer(bSizer)
def __init__( self, parent ):
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = (0,0), size = wx.Size( 285,190 ), style = wx.TAB_TRAVERSAL )
self.SetBackgroundColour((150,230,170)) #TESTING ONLY REMOVE WHEN SIZING IS DONE AND ALL THAT BUSINESS
pi_link_pnl.target_ip = ''
pi_link_pnl.target_user = ''
pi_link_pnl.target_pass = ''
pi_link_pnl.config_location_on_pi = '/home/pi/Pigrow/config/pigrow_config.txt'
## the three boxes for pi's connection details, IP, Username and Password
self.l_ip = wx.StaticText(self, label='address', pos=(10, 20))
self.tb_ip = wx.TextCtrl(self, pos=(125, 25), size=(150, 25))
self.tb_ip.SetValue("192.168.1.")
self.l_user = wx.StaticText(self, label='Username', pos=(10, 60))
self.tb_user = wx.TextCtrl(self, pos=(125, 60), size=(150, 25))
self.tb_user.SetValue("pi")
self.l_pass = wx.StaticText(self, label='Password', pos=(10, 95))
self.tb_pass = wx.TextCtrl(self, pos=(125, 95), size=(150, 25))
self.tb_pass.SetValue("raspberry")
## link with pi button
self.link_with_pi_btn = wx.Button(self, label='Link to Pi', pos=(10, 125), size=(175, 30))
self.link_with_pi_btn.Bind(wx.EVT_BUTTON, self.link_with_pi_btn_click)
self.link_status_text = wx.StaticText(self, label='-- no link --', pos=(25, 160))
## seek next pi button
self.seek_for_pigrows_btn = wx.Button(self, label='Seek next', pos=(190,125))
self.seek_for_pigrows_btn.Bind(wx.EVT_BUTTON, self.seek_for_pigrows_click)
def _init_ctrls(self, prnt):
wx.Panel.__init__(self, id=ID_SEARCHRESULTPANEL,
name='SearchResultPanel', parent=prnt, pos=wx.Point(0, 0),
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
self.HeaderLabel = wx.StaticText(id=ID_SEARCHRESULTPANELHEADERLABEL,
name='HeaderLabel', parent=self,
pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
search_results_tree_style = CT.TR_HAS_BUTTONS | CT.TR_NO_LINES | CT.TR_HAS_VARIABLE_ROW_HEIGHT
self.SearchResultsTree = CT.CustomTreeCtrl(id=ID_SEARCHRESULTPANELSEARCHRESULTSTREE,
name="SearchResultsTree", parent=self,
pos=wx.Point(0, 0), style=search_results_tree_style)
if wx.VERSION >= (2, 8, 11):
self.SearchResultsTree.SetAGWWindowStyleFlag(search_results_tree_style)
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnSearchResultsTreeItemActivated,
id=ID_SEARCHRESULTPANELSEARCHRESULTSTREE)
self.ResetButton = wx.lib.buttons.GenBitmapButton(
self, bitmap=GetBitmap("reset"),
size=wx.Size(28, 28), style=wx.NO_BORDER)
self.ResetButton.SetToolTipString(_("Reset search result"))
self.Bind(wx.EVT_BUTTON, self.OnResetButton, self.ResetButton)
self._init_sizers()
def __init__(self, parent):
wx.Control.__init__(self, parent)
main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
main_sizer.AddGrowableCol(0)
main_sizer.AddGrowableRow(0)
# create location text control
self.Duration = wx.TextCtrl(self, size=wx.Size(0, -1),
style=wx.TE_PROCESS_ENTER)
self.Duration.Bind(wx.EVT_KEY_DOWN, self.OnDurationChar)
main_sizer.AddWindow(self.Duration, flag=wx.GROW)
# create browse button
self.EditButton = wx.Button(self, label='...', size=wx.Size(30, -1))
self.Bind(wx.EVT_BUTTON, self.OnEditButtonClick, self.EditButton)
main_sizer.AddWindow(self.EditButton, flag=wx.GROW)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.SetSizer(main_sizer)
self.Default = None
def SetChoices(self, choices):
max_text_width = 0
max_text_height = 0
self.ListBox.Clear()
for choice in choices:
self.ListBox.Append(choice)
w, h = self.ListBox.GetTextExtent(choice)
max_text_width = max(max_text_width, w)
max_text_height = max(max_text_height, h)
itemcount = min(len(choices), MAX_ITEM_SHOWN)
width = self.Parent.GetSize()[0]
height = \
max_text_height * itemcount + \
LISTBOX_INTERVAL_HEIGHT * max(0, itemcount - 1) + \
2 * LISTBOX_BORDER_HEIGHT
if max_text_width + 10 > width:
height += 15
size = wx.Size(width, height)
if wx.Platform == '__WXMSW__':
size.width -= 2
self.ListBox.SetSize(size)
self.SetClientSize(size)
def EditCommentContent(self, comment):
dialog = wx.TextEntryDialog(self.ParentWindow,
_("Edit comment"),
_("Please enter comment text"),
comment.GetContent(),
wx.OK | wx.CANCEL | wx.TE_MULTILINE)
width, height = comment.GetSize()
dialogSize = wx.Size(max(width + 30, 400), max(height + 60, 200))
dialog.SetClientSize(dialogSize)
if dialog.ShowModal() == wx.ID_OK:
value = dialog.GetValue()
rect = comment.GetRedrawRect(1, 1)
comment.SetContent(value)
comment.SetSize(*self.GetScaledSize(*comment.GetSize()))
rect = rect.Union(comment.GetRedrawRect())
self.RefreshCommentModel(comment)
self.RefreshBuffer()
self.RefreshScrollBars()
self.RefreshVisibleElements()
comment.Refresh(rect)
dialog.Destroy()
# -------------------------------------------------------------------------------
# Model update functions
# -------------------------------------------------------------------------------
def _create_NetworkEditor(self, prnt):
self.NetworkEditor = wx.Panel(
id=-1, parent=prnt, pos=wx.Point(0, 0),
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
NetworkEditorTemplate._init_ctrls(self, self.NetworkEditor)
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0)
main_sizer.AddGrowableCol(0)
main_sizer.AddGrowableRow(0)
main_sizer.AddWindow(self.NetworkNodes, 0, border=5, flag=wx.GROW | wx.ALL)
self.NetworkEditor.SetSizer(main_sizer)
return self.NetworkEditor
def __init__(self, parent, name, initial=False, id=None):
Graphic_Element.__init__(self, parent)
DebugDataConsumer.__init__(self)
self.SetName(name)
self.Initial = initial
self.Id = id
self.Highlights = []
self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1])
# Create an input and output connector
if not self.Initial:
self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)
else:
self.Input = None
self.Output = None
self.Action = None
self.PreviousValue = None
self.PreviousSpreading = False
def RefreshBoundingBox(self):
# Calculate the bounding box size
if self.Action:
bbx_width = self.Size[0] + CONNECTOR_SIZE
else:
bbx_width = self.Size[0]
if self.Initial:
bbx_y = self.Pos.y
bbx_height = self.Size[1]
if self.Output:
bbx_height += CONNECTOR_SIZE
else:
bbx_y = self.Pos.y - CONNECTOR_SIZE
bbx_height = self.Size[1] + CONNECTOR_SIZE
if self.Output:
bbx_height += CONNECTOR_SIZE
# self.BoundingBox = wx.Rect(self.Pos.x, bbx_y, bbx_width + 1, bbx_height + 1)
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
# Refresh the positions of the step connectors
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
horizontal_pos = self.Size[0] / 2
vertical_pos = self.Size[1] / 2
if scaling is not None:
horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x
vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y
# Update input position if it exists
if self.Input:
self.Input.SetPosition(wx.Point(horizontal_pos, 0))
# Update output position
if self.Output:
self.Output.SetPosition(wx.Point(horizontal_pos, self.Size[1]))
# Update action position if it exists
if self.Action:
self.Action.SetPosition(wx.Point(self.Size[0], vertical_pos))
self.RefreshConnected()
# Refresh the position of wires connected to step
def RefreshBoundingBox(self):
bbx_x, bbx_y, bbx_width, bbx_height = self.Pos.x, self.Pos.y, self.Size[0], self.Size[1]
if self.Priority != 0:
bbx_y = self.Pos.y - self.PrioritySize[1] - 2
bbx_width = max(self.Size[0], self.PrioritySize[0])
bbx_height = self.Size[1] + self.PrioritySize[1] + 2
if self.Type == "connection":
bbx_x = self.Pos.x - CONNECTOR_SIZE
bbx_width = bbx_width + CONNECTOR_SIZE
else:
text_width, text_height = self.ConditionSize
# Calculate the bounding box size
bbx_width = max(bbx_width, self.Size[0] + 5 + text_width)
bbx_y = min(bbx_y, self.Pos.y - max(0, (text_height - self.Size[1]) / 2))
bbx_height = max(bbx_height, self.Pos.y - bbx_y + (self.Size[1] + text_height) / 2)
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
# Returns the connector connected to input
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
horizontal_pos = self.Size[0] / 2
vertical_pos = self.Size[1] / 2
if scaling is not None:
horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x
vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y
# Update input position
self.Input.SetPosition(wx.Point(horizontal_pos, 0))
# Update output position
self.Output.SetPosition(wx.Point(horizontal_pos, self.Size[1]))
if self.Type == "connection":
self.Condition.SetPosition(wx.Point(0, vertical_pos))
self.RefreshConnected()
# Refresh the position of the wires connected to transition
def SetType(self, type, condition=None):
if self.Type != type:
if self.Type == "connection":
self.Condition.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
self.Type = type
if type == "connection":
self.Condition = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2), WEST)
else:
if condition is None:
condition = ""
self.Condition = condition
self.RefreshConditionSize()
elif self.Type != "connection":
if condition is None:
condition = ""
self.Condition = condition
self.RefreshConditionSize()
self.RefreshBoundingBox()
# Returns the transition type
def AddBranch(self):
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
maxx = 0
for output in self.Outputs:
pos = output.GetRelPosition()
maxx = max(maxx, pos.x)
connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone=True)
self.Outputs.append(connector)
self.MoveConnector(connector, 0)
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
maxx = 0
for input in self.Inputs:
pos = input.GetRelPosition()
maxx = max(maxx, pos.x)
connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone=True)
self.Inputs.append(connector)
self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL)
# Remove a branch from the divergence
def SetSize(self, width, height):
height = self.GetMinSize()[1]
for i, input in enumerate(self.Inputs):
position = input.GetRelPosition()
if self.RealConnectors:
input.SetPosition(wx.Point(int(round(self.RealConnectors["Inputs"][i] * width)), 0))
else:
input.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), 0))
input.MoveConnected()
for i, output in enumerate(self.Outputs):
position = output.GetRelPosition()
if self.RealConnectors:
output.SetPosition(wx.Point(int(round(self.RealConnectors["Outputs"][i] * width)), height))
else:
output.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), height))
output.MoveConnected()
self.Size = wx.Size(width, height)
self.RefreshBoundingBox()
# Returns the divergence minimum size
def DrawHighlightment(self, dc):
scalex, scaley = dc.GetUserScale()
dc.SetUserScale(1, 1)
dc.SetPen(MiterPen(HIGHLIGHTCOLOR))
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
dc.SetLogicalFunction(wx.AND)
# Draw two rectangles for representing the contact
posx = self.Pos.x
width = self.Size[0]
if self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
posx -= SFC_SIMULTANEOUS_SEQUENCE_EXTRA
width += SFC_SIMULTANEOUS_SEQUENCE_EXTRA * 2
dc.DrawRectangle(int(round((posx - 1) * scalex)) - 2,
int(round((self.Pos.y - 1) * scaley)) - 2,
int(round((width + 3) * scalex)) + 5,
int(round((self.Size.height + 3) * scaley)) + 5)
dc.SetLogicalFunction(wx.COPY)
dc.SetUserScale(scalex, scaley)
# Draws divergence
def DrawHighlightment(self, dc):
scalex, scaley = dc.GetUserScale()
dc.SetUserScale(1, 1)
dc.SetPen(MiterPen(HIGHLIGHTCOLOR))
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
dc.SetLogicalFunction(wx.AND)
points = [wx.Point(int(round((self.Pos.x - 2) * scalex)) - 3,
int(round((self.Pos.y - 2) * scaley)) - 2),
wx.Point(int(round((self.Pos.x + self.Size[0] + 2) * scalex)) + 4,
int(round((self.Pos.y - 2) * scaley)) - 2),
wx.Point(int(round((self.Pos.x + self.Size[0] / 2) * scalex)),
int(round((self.Pos.y + self.Size[1] + 3) * scaley)) + 4)]
dc.DrawPolygon(points)
dc.SetLogicalFunction(wx.COPY)
dc.SetUserScale(scalex, scaley)
# Draws divergence
def RefreshBoundingBox(self):
if len(self.Elements) > 0:
bbox = self.Elements[0].GetBoundingBox()
minx, miny = bbox.x, bbox.y
maxx = bbox.x + bbox.width
maxy = bbox.y + bbox.height
for element in self.Elements[1:]:
bbox = element.GetBoundingBox()
minx = min(minx, bbox.x)
miny = min(miny, bbox.y)
maxx = max(maxx, bbox.x + bbox.width)
maxy = max(maxy, bbox.y + bbox.height)
self.BoundingBox = wx.Rect(minx, miny, maxx - minx, maxy - miny)
else:
self.BoundingBox = wx.Rect(0, 0, 0, 0)
self.Pos = wx.Point(self.BoundingBox.x, self.BoundingBox.y)
self.Size = wx.Size(self.BoundingBox.width, self.BoundingBox.height)
# Forbids to change the group position
def DrawHighlightment(self, dc):
scalex, scaley = dc.GetUserScale()
dc.SetUserScale(1, 1)
dc.SetPen(MiterPen(HIGHLIGHTCOLOR))
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
dc.SetLogicalFunction(wx.AND)
left = (self.Pos.x - 1) * scalex - 2
right = (self.Pos.x + self.Size[0] + 1) * scalex + 2
top = (self.Pos.y - 1) * scaley - 2
bottom = (self.Pos.y + self.Size[1] + 1) * scaley + 2
angle_top = (self.Pos.x + self.Size[0] - 9) * scalex + 2
angle_right = (self.Pos.y + 9) * scaley - 2
polygon = [wx.Point(left, top), wx.Point(angle_top, top),
wx.Point(right, angle_right), wx.Point(right, bottom),
wx.Point(left, bottom)]
dc.DrawPolygon(polygon)
dc.SetLogicalFunction(wx.COPY)
dc.SetUserScale(scalex, scaley)
# Draws the comment and its content
def MoveConnector(self, connector, movey):
position = connector.GetRelPosition()
connector.SetPosition(wx.Point(position.x, position.y + movey))
miny = self.Size[1]
maxy = 0
for connect in self.Connectors:
connect_pos = connect.GetRelPosition()
miny = min(miny, connect_pos.y - self.Extensions[0])
maxy = max(maxy, connect_pos.y - self.Extensions[0])
min_pos = self.Pos.y + miny
self.Pos.y = min(min_pos, self.Pos.y)
if min_pos == self.Pos.y:
for connect in self.Connectors:
connect_pos = connect.GetRelPosition()
connect.SetPosition(wx.Point(connect_pos.x, connect_pos.y - miny))
self.Connectors.sort(lambda x, y: cmp(x.Pos.y, y.Pos.y))
maxy = 0
for connect in self.Connectors:
connect_pos = connect.GetRelPosition()
maxy = max(maxy, connect_pos.y)
self.Size[1] = max(maxy + self.Extensions[1], self.Size[1])
connector.MoveConnected()
self.RefreshBoundingBox()
# Returns the index in connectors list for the connector given
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
height = self.Size[1] - self.Extensions[0] - self.Extensions[1]
interval = float(height) / float(max(len(self.Connectors) - 1, 1))
for i, connector in enumerate(self.Connectors):
if self.RealConnectors:
position = self.Extensions[0] + int(round(self.RealConnectors[i] * height))
else:
position = self.Extensions[0] + int(round(i * interval))
if scaling is not None:
position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y
if self.Type == LEFTRAIL:
connector.SetPosition(wx.Point(self.Size[0], position))
elif self.Type == RIGHTRAIL:
connector.SetPosition(wx.Point(0, position))
self.RefreshConnected()
# Refresh the position of wires connected to power rail