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
# -------------------------------------------------------------------------------
python类Size()的实例源码
def RefreshBoundingBox(self):
# Calculate the size of the name outside the contact
text_width, text_height = self.Parent.GetTextExtent(self.Name)
# Calculate the bounding box size
if self.Name != "":
bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2)
bbx_width = max(self.Size[0], text_width)
bbx_y = self.Pos.y - (text_height + 2)
bbx_height = self.Size[1] + (text_height + 2)
else:
bbx_x = self.Pos.x
bbx_width = self.Size[0]
bbx_y = self.Pos.y
bbx_height = self.Size[1]
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
# Returns the block 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
left_left = (self.Pos.x - 1) * scalex - 2
right_left = (self.Pos.x + self.Size[0] - 2) * scalex - 2
top = (self.Pos.y - 1) * scaley - 2
width = 4 * scalex + 5
height = (self.Size[1] + 3) * scaley + 5
dc.DrawRectangle(left_left, top, width, height)
dc.DrawRectangle(right_left, top, width, height)
dc.SetLogicalFunction(wx.COPY)
dc.SetUserScale(scalex, scaley)
# Adds an highlight to the connection
def DrawHighlightment(self, dc):
scalex, scaley = dc.GetUserScale()
dc.SetUserScale(1, 1)
dc.SetPen(MiterPen(HIGHLIGHTCOLOR, (3 * scalex + 5), wx.SOLID))
dc.SetBrush(wx.TRANSPARENT_BRUSH)
dc.SetLogicalFunction(wx.AND)
# Draw a two circle arcs for representing the coil
dc.DrawEllipticArc(round(self.Pos.x * scalex),
round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley),
round(self.Size[0] * scalex),
round((int(self.Size[1] * sqrt(2)) - 1) * scaley),
135, 225)
dc.DrawEllipticArc(round(self.Pos.x * scalex),
round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley),
round(self.Size[0] * scalex),
round((int(self.Size[1] * sqrt(2)) - 1) * scaley),
-45, 45)
dc.SetLogicalFunction(wx.COPY)
dc.SetUserScale(scalex, scaley)
# Adds an highlight to the connection
def RefreshBoundingBox(self):
if self.Type in (OUTPUT, INOUT):
bbx_x = self.Pos.x - CONNECTOR_SIZE
else:
bbx_x = self.Pos.x
if self.Type == INOUT:
bbx_width = self.Size[0] + 2 * CONNECTOR_SIZE
else:
bbx_width = self.Size[0] + CONNECTOR_SIZE
bbx_x = min(bbx_x, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2)
bbx_width = max(bbx_width, self.NameSize[0])
bbx_height = self.Size[1]
if self.ExecutionOrder != 0:
bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0])
bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0])
bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, bbx_height + 1)
# Refresh the position of the variable connector
def add_slide(self, rang, title, key, unit):
sizer = wx.BoxSizer( wx.HORIZONTAL )
lab_title = wx.StaticText( self, wx.ID_ANY, title,
wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE )
lab_title.Wrap( -1 )
sizer.Add( lab_title, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
iswin = platform.system() == 'Windows'
lab = wx.SL_VALUE_LABEL if iswin else wx.SL_LABELS
ctrl = wx.Slider( self, wx.ID_ANY, 50, rang[0], rang[1],
wx.DefaultPosition, wx.Size( -1,-1 ), wx.SL_HORIZONTAL|lab )
self.ctrl_dic[key] = ctrl
ctrl.Bind(wx.EVT_SCROLL, lambda x : self.para_changed(key))
sizer.Add( ctrl, 2, wx.ALL, 5 )
lab_unit = wx.StaticText( self, wx.ID_ANY, unit,
wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE )
lab_unit.Wrap( -1 )
sizer.Add( lab_unit, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
self.tus.append((lab_title, lab_unit))
self.lst.Add( sizer, 0, wx.EXPAND, 5 )
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='KIARA')
panel = wx.Panel(self)
my_sizer = wx.BoxSizer(wx.VERTICAL)
lbl = wx.StaticText(panel, label='''Hello I\'m Kiara the Python
Digital Assistant. 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('Welcome my friend. I am Kiara. How can I help ?')
def __init__(self, parent, **kwargs):
self.chat_modules = kwargs.get('chat_modules')
wx.Panel.__init__(self, parent, size=wx.Size(-1, 24))
self.SetBackgroundColour('cream')
self.chats = {}
self.border_sizer = self._create_sizer()
for chat_name, chat_settings in self.chat_modules.items():
if chat_name == 'chat':
continue
if chat_settings['class'].get_queue('status_frame'):
for item in chat_settings['class'].get_queue('status_frame'):
if item['action'] == 'add':
self.set_chat_online(chat_name, item['channel'])
for item in chat_settings['class'].get_queue('status_frame'):
if item['action'] == 'set_online':
self.set_online(chat_name, item['channel'])
self.Fit()
self.Layout()
self.Show(True)
def CreateEditorCtrl(self, parent, rect, value):
OM = ObjectManager(self)
acceptable_tids = LogPlotController.get_acceptable_tids()
tids = list(set([obj._TID_FRIENDLY_NAME for obj in OM.list() \
if obj.tid in acceptable_tids
]
)
)
#print 'tids:', tids
_editor = wx.Choice(parent,
wx.ID_ANY,
rect.GetTopLeft(),
wx.Size(rect.GetWidth(), -1),
choices=tids
)
_editor.SetRect(rect)
return _editor
def Reposition(self):
# print '\nPlotStatusBar.Reposition'
if self.sb.IsShown():
rect = self.GetFieldRect(1)
rect.x += 1
rect.y += 1
self.sb.SetPosition([rect.x, rect.y])
size = wx.Size(rect.GetWidth()-2, rect.GetHeight())
self.sb.SetSize(size)
else:
rect = self.GetFieldRect(1)
rect.x += 1
rect.y += 1
#self.panelDummy.SetPosition([rect.x, rect.y])
size = wx.Size(rect.GetWidth()-2, 20)
#self.panelDummy.SetSize(size)
def insert_track_title(self, idx, track_name=None, width=None):
if idx >= 0 and idx <= self.tracks.lenght():
if width:
try:
width = float(width)
if width <= 0:
raise ValueError('Width must be greater than zero.')
except Exception:
raise
else:
width = UI.logplotformat.LogPlotFormat.DEFAULT_TRACK_WIDTH
if not track_name:
track_name = str(idx+1)
#size = wx.Size(width, self._get_height())
plot_label = UI.logplot_base.PlotLabel(self.tracks)
plot_label.update_title(text=track_name, bgcolor=self._track_title_color)
#TitleFigureCanvas(self.tracks, size, track_name,
# self._track_title_color)
self.tracks.InsertWindow(idx, plot_label, int(width * lpb.DPI * lpb.FACTOR))
return plot_label
def DoGetBestSize(self):
"""
Overridden base class virtual. Determines the best size of
the control based on the best sizes of the child windows.
"""
best = wx.Size(0, 100)
if not self._windows:
return best
sashsize = self._sash_size
for idx, sash in enumerate(self._sashes):
window = self.GetWindow(idx)
if window.IsShown():
best.width += max(self._minimumPaneSize, sash)
best.height = max(best.height, self.GetClientSize().height - 2*self._border_size)
best.width += sashsize * (len(self._windows))
best.width += self._border_size
best.height += 2*self._border_size
return best
# -------------------------------------
# Event handlers
def OnInit(self):
"""
Run automatically when the wxPython application starts.
"""
self.frame = wx.Frame(None, title="PyUpdater wxPython Demo")
self.frame.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
self.frame.SetSize(wx.Size(400, 100))
self.statusBar = wx.StatusBar(self.frame)
self.statusBar.SetStatusText(self.status)
self.frame.SetStatusBar(self.statusBar)
self.panel = wx.Panel(self.frame)
self.sizer = wx.BoxSizer()
self.sizer.Add(
wx.StaticText(self.frame, label="Version %s" % __version__))
self.panel.SetSizerAndFit(self.sizer)
self.frame.Show()
if hasattr(sys, "frozen") and \
not os.environ.get('PYUPDATER_FILESERVER_DIR'):
dlg = wx.MessageDialog(
self.frame,
"The PYUPDATER_FILESERVER_DIR environment variable "
"is not set!", "PyUpdaterWxDemo File Server Error",
wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
return True
def main(argv):
"""
The default host will be None if the environment variable
PYRO_NS_HOSTNAME is not set.
The default port will be 9090 (Pyro.config.PYRO_NS_PORT) if
PYRO_NS_BC_PORT environment variable is not set.
"""
nsHost = os.getenv('PYRO_NS_HOSTNAME')
nsPort = os.getenv('PYRO_NS_BC_PORT') or Pyro.config.PYRO_NS_PORT
bcAddr = Pyro.config.PYRO_NS_BC_ADDR
if bcAddr:
bcAddr=bcAddr.strip()
bcAddr=bcAddr or None
class wx_NSCApp(wx.App):
def OnInit(self):
Pyro.core.initClient()
frame = wx_NSC(nsHost, nsPort, bcAddr)
frame.SetSize(wx.Size(630,500))
frame.Show(True)
return True
app = wx_NSCApp(0)
app.MainLoop()
# allow easy usage with python -m
def __init__(self, parent, name):
wxskinDialog.__init__(self, parent, -1, "Phonebook import")
self.SetAutoLayout(True)
self.function = 0
# Main window resizer object
border = wx.BoxSizer(wx.VERTICAL)
label = wx.StaticText(self, -1, "Name '%s' already exists in SIM phonebook.\n\nDo you want to overwrite exisiting, duplicate or skip!?" % (name))
border.Add(label, 1, wx.ALL, 10)
buttons = wx.BoxSizer(wx.HORIZONTAL)
buttons.Add(wx.Button(self, ID_BUTTON_OVERWRITE, "Overwrite"), 1, wx.ALIGN_LEFT | wx.ALL, 20)
buttons.Add(wx.Button(self, ID_BUTTON_COPY, "Duplicate"), 1, wx.ALIGN_RIGHT | wx.ALL, 20)
buttons.Add(wx.Button(self, ID_BUTTON_SKIP, "Skip"), 1, wx.ALIGN_RIGHT | wx.ALL, 20)
buttons.Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 1, wx.ALIGN_RIGHT | wx.ALL, 20)
border.Add(buttons, 1, wx.ALL)
self.applyAll = wx.CheckBox(self, ID_CHECKBOX_APPLY_ALL, " Apply to all", wx.Point(65, 40), wx.Size(150, 20), wx.NO_BORDER)
border.Add(self.applyAll, 1, wx.ALIGN_CENTER | wx.ALL)
wx.EVT_BUTTON(self, ID_BUTTON_OVERWRITE, self.onOverwrite)
wx.EVT_BUTTON(self, ID_BUTTON_COPY, self.onDuplicate)
wx.EVT_BUTTON(self, ID_BUTTON_SKIP, self.onSkip)
self.SetAutoLayout(1);
self.SetSizer(border)
border.Fit(self)
self.Layout()
def createWidgets(self):
sizer = wx.GridSizer(3,3,5,5)
self.SIM.gatherInfo()
sizer.Add(wx.Size(0,0), 10, 1, wx.LEFT, 10) # Spacer
sizer.Add(wxskinStaticText(self, -1, "Activated"), 1, wx.LEFT | wx.RIGHT, 10)
sizer.Add(wxskinStaticText(self, -1, "Tries left"), 1, wx.RIGHT, 10)
sizer.Add(wxskinStaticText(self, -1, "PIN1"), 1, wx.LEFT, 10)
if self.SIM.chv1_enabled:
sizer.Add(wx.TextCtrl(self, -1, "Yes", style=wx.TE_READONLY), 1, wx.RIGHT, 10)
else:
sizer.Add(wx.TextCtrl(self, -1, "No", style=wx.TE_READONLY), 1, wx.RIGHT, 10)
sizer.Add(wx.TextCtrl(self, -1, "%d" % self.SIM.chv1_tries_left, style=wx.TE_READONLY), 1, wx.RIGHT, 10)
sizer.Add(wxskinStaticText(self, -1, "PIN2"), 1, wx.LEFT, 10)
if self.SIM.chv2_enabled:
sizer.Add(wx.TextCtrl(self, -1, "Yes", style=wx.TE_READONLY), 1, wx.RIGHT, 10)
else:
sizer.Add(wx.TextCtrl(self, -1, "No", style=wx.TE_READONLY), 1, wx.RIGHT, 10)
sizer.Add(wx.TextCtrl(self, -1, "%d" % self.SIM.chv2_tries_left, style=wx.TE_READONLY), 1, wx.RIGHT, 10)
self.SetSizer(sizer)
self.SetAutoLayout(1)
sizer.Fit(self)
sizer.Layout()
def __init__(self, parent, name):
wxskinDialog.__init__(self, parent, -1, "Phonebook import")
self.SetAutoLayout(True)
self.function = 0
# Main window resizer object
border = wx.BoxSizer(wx.VERTICAL)
label = wx.StaticText(self, -1, "Name '%s' already exists in SIM phonebook.\n\nDo you want to overwrite exisiting, duplicate or skip!?" % (name))
border.Add(label, 1, wx.ALL, 10)
buttons = wx.BoxSizer(wx.HORIZONTAL)
buttons.Add(wx.Button(self, ID_BUTTON_OVERWRITE, "Overwrite"), 1, wx.ALIGN_LEFT | wx.ALL, 20)
buttons.Add(wx.Button(self, ID_BUTTON_COPY, "Duplicate"), 1, wx.ALIGN_RIGHT | wx.ALL, 20)
buttons.Add(wx.Button(self, ID_BUTTON_SKIP, "Skip"), 1, wx.ALIGN_RIGHT | wx.ALL, 20)
buttons.Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 1, wx.ALIGN_RIGHT | wx.ALL, 20)
border.Add(buttons, 1, wx.ALL)
self.applyAll = wx.CheckBox(self, ID_CHECKBOX_APPLY_ALL, " Apply to all", wx.Point(65, 40), wx.Size(150, 20), wx.NO_BORDER)
border.Add(self.applyAll, 1, wx.ALIGN_CENTER | wx.ALL)
wx.EVT_BUTTON(self, ID_BUTTON_OVERWRITE, self.onOverwrite)
wx.EVT_BUTTON(self, ID_BUTTON_COPY, self.onDuplicate)
wx.EVT_BUTTON(self, ID_BUTTON_SKIP, self.onSkip)
self.SetAutoLayout(1);
self.SetSizer(border)
border.Fit(self)
self.Layout()
def __init__(self, parent, date, number):
wxskinDialog.__init__(self, parent, -1, "SMS import")
self.SetAutoLayout(False)
self.function = 0
# Main window resizer object
border = wx.BoxSizer(wx.VERTICAL)
label = wx.StaticText(self, -1, "SMS from '%s' on '%s' already exists in SMS folder.\n\nDo you want to overwrite exisiting, duplicate or skip!?" % (number, date))
border.Add(label, 1, wx.ALL, 10)
buttons = wx.BoxSizer(wx.HORIZONTAL)
buttons.Add(wx.Button(self, ID_BUTTON_OVERWRITE, "Overwrite"), 1, wx.ALIGN_LEFT | wx.ALL, 20)
buttons.Add(wx.Button(self, ID_BUTTON_COPY, "Duplicate"), 1, wx.ALIGN_RIGHT | wx.ALL, 20)
buttons.Add(wx.Button(self, ID_BUTTON_SKIP, "Skip"), 1, wx.ALIGN_RIGHT | wx.ALL, 20)
buttons.Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 1, wx.ALIGN_RIGHT | wx.ALL, 20)
border.Add(buttons, 1, wx.ALL)
self.applyAll = wx.CheckBox(self, ID_CHECKBOX_APPLY_ALL, " Apply to all", wx.Point(65, 40), wx.Size(150, 20), wx.NO_BORDER)
border.Add(self.applyAll, 1, wx.ALIGN_CENTER | wx.ALL)
wx.EVT_BUTTON(self, ID_BUTTON_OVERWRITE, self.onOverwrite)
wx.EVT_BUTTON(self, ID_BUTTON_COPY, self.onDuplicate)
wx.EVT_BUTTON(self, ID_BUTTON_SKIP, self.onSkip)
#EVT_CHECKBOX(self, ID_CHECKBOX_APPLY_ALL, self.EvtCheckBox)
self.SetAutoLayout(1);
self.SetSizer(border)
border.Fit(self)
self.Layout()
def SetSize(self, value):
"""
Sets the tab size.
:param `value`: the new tab size, an instance of :class:`Size`.
"""
self._size = value
def __init__( self, parent ):
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( -1,-1 ), style = wx.TAB_TRAVERSAL )
bSizer111 = wx.BoxSizer( wx.VERTICAL )
self.m_textCtrlDocument = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size( -1,-1 ), wx.TE_AUTO_URL|wx.TE_MULTILINE|wx.TE_READONLY )
bSizer111.Add( self.m_textCtrlDocument, 1, wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND, 5 )
self.SetSizer( bSizer111 )
self.Layout()
bSizer111.Fit( self )