我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用wx.Size()。
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 )
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 ): 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
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 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, 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 )