Python wx 模块,Window() 实例源码

我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用wx.Window()

项目:pyjam    作者:10se1ucgo    | 项目源码 | 文件源码
def update_check(parent):
    """Check for updates using the GitHub API

    Args:
        parent (wx.Window): The parent window (for the message dialog)

    Returns:
        None
    """
    r = requests.get('https://api.github.com/repos/10se1ucgo/pyjam/releases/latest')

    if not r.ok:
        return

    new = r.json()['tag_name']

    try:
        if StrictVersion(__version__) < StrictVersion(new.lstrip('v')):
            info = wx.MessageDialog(parent, message="pyjam {v} is now available!\nGo to download page?".format(v=new),
                                    caption="pyjam Update", style=wx.OK | wx.CANCEL | wx.ICON_INFORMATION)
            if info.ShowModal() == wx.ID_OK:
                webbrowser.open_new_tab(r.json()['html_url'])
            info.Destroy()
    except ValueError:
        pass
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
def OnSize(self, event):
        # The Buffer init is done here, to make sure the buffer is always
        # the same size as the Window
        Size = self.canvas.GetClientSize()
        if Size.width <= 0 or Size.height <= 0:
            return
        Size.width = max(1, Size.width)
        Size.height = max(1, Size.height)
        # Make new offscreen bitmap: this bitmap will always have the
        # current drawing in it, so it can be used to save the image to
        # a file, or whatever.
        #self._Buffer = wx.Bitmap(Size.width, Size.height)
        if IsNotWX4():
            self._img = wx.EmptyImage(Size.width,Size.height)
            self._Buffer = wx.BitmapFromImage(self._img)
        else:
            self._img = wx.Image(Size.width,Size.height)
            self._Buffer = wx.Bitmap(self._img)
        self._Buffer.SetHeight(Size.height)
        self._Buffer.SetWidth(Size.width)
        self._setSize()
        self.last_PointLabel = None  # reset pointLabel
        if self.last_draw is None:
            self.Clear()
        else:
            graphics, xSpec, ySpec = self.last_draw
            self._Draw(graphics, xSpec, ySpec)
项目:pyjam    作者:10se1ucgo    | 项目源码 | 文件源码
def about_dialog(parent):
    """An about dialog

    Args:
        parent (wx.Window): The parent window
    """
    license_text = """
    Copyright (C) 10se1ucgo 2016

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>."""

    about_info = wx.adv.AboutDialogInfo()
    about_info.SetName("pyjam")
    about_info.SetVersion("v{v}".format(v=__version__))
    about_info.SetCopyright("Copyright (C) 10se1ucgo 2016")
    about_info.SetDescription("An open source, cross-platform audio player for Source and GoldSrc engine based games.")
    about_info.SetWebSite("https://github.com/10se1ucgo/pyjam", "GitHub repository")
    about_info.AddDeveloper("10se1ucgo")
    about_info.AddDeveloper("Dx724")
    about_info.AddArtist("Dx724 - Icon")
    about_info.SetLicense(license_text)
    wx.adv.AboutBox(about_info, parent)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def SetFocus(self):
        """
        Called to give focus to LibraryPanel
        Override wx.Window SetFocus method
        """
        # Give focus to SearchCtrl
        self.SearchCtrl.SetFocus()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def __init__(self, parent, window, items=[]):
        """
        Constructor
        @param parent: Parent wx.Window of DebugVariableText
        @param window: Reference to the Debug Variable Panel
        @param items: List of DebugVariableItem displayed by Viewer
        """
        DebugVariableViewer.__init__(self, window, items)

        wx.Panel.__init__(self, parent)
        # Set panel background colour
        self.SetBackgroundColour(wx.WHITE)
        # Define panel drop target
        self.SetDropTarget(DebugVariableTextDropTarget(self, window))

        # Bind events
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
        self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
        self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
        self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
        self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
        self.Bind(wx.EVT_SIZE, self.OnResize)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
        self.Bind(wx.EVT_PAINT, self.OnPaint)

        # Define panel min size for parent sizer layout
        self.SetMinSize(wx.Size(0, 25))

        # Add buttons to Viewer
        for bitmap, callback in [("force", self.OnForceButton),
                                 ("release", self.OnReleaseButton),
                                 ("delete_graph", self.OnCloseButton)]:
            self.Buttons.append(GraphButton(0, 0, bitmap, callback))
项目:wxWize    作者:AndersMunch    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        # Set by the subclass in create_preorder/create_postorder
        self.w = None # the wx.Window, if any, being created
        self.sized = None # the wx.Sizer or wx.Window which the parent Entity must put in its component sizer
        self._events = []
        self._queue = []
        if _zparent is not None:
            _zparent._queue.append(self)

        # Set attributes in accordance with the rules for the class set out in 'props', the list of allowed
        #  __init__ arguments, and 'positional', the subset that can be passed as positional parameters.
        if len(args) > len(self.positional):
            raise TypeError("%s takes positional arguments %s, %d more given" % (self, self.positional, len(args)-len(self.positional)))
        if 'kwargs' in self.props:
            self.kwargs = {}
        for k,v in dict(self._defaults, **kwargs).items():
            if k in self.props:
                setattr(self, k, v)
            else:
                if k.startswith('EVT_') and isinstance(self, Window):
                    self._events.append((k, v))
                elif 'kwargs' in self.props:
                    self.kwargs[k] = v
                else:
                    raise TypeError("%s does not have a writable '%s' attribute" % (type(self), k))
        for argname,arg in zip(self.positional, args):
            if argname in kwargs:
                raise TypeError("%s passed both by keyword and as positional argument %d" % (argname,self.positional.index(argname)+1))
            assert argname in self.props
            setattr(self, argname, arg)

        # Hierarchy management:
        self._entered = False # has __enter__/__exit__, which sets .w and .sized, been done yet?
        self.zparent = _zparent # above Entity
        self.zchildren = [] # Entity's nested below
        if self.zparent is not None:
            self.zparent.zchildren.append(self)

        if self.parent is None and self.zparent is None:
            assert isinstance(self, (TopLevelWindow,TopLevelMenu)), '%s does not have a parent' % (self,)
项目:wxWize    作者:AndersMunch    | 项目源码 | 文件源码
def as_parent(self):
        u"""Returns the wx.Window for child windows to use as a parent."""
        return self.get_parent() # overridden for windows
项目:wxWize    作者:AndersMunch    | 项目源码 | 文件源码
def get_parent(self):
        u"""Returns a suitable wx.Window for the parent argument."""
        if self.parent is not None:
            return self.parent
        elif self.zparent is not None:
            return self.zparent.as_parent()
项目:wxWize    作者:AndersMunch    | 项目源码 | 文件源码
def create_postorder(self):
        if len(self.zchildren)==0:
            # non-container wx.Window's: TextCtrl, StaticText, Choice, ...
            self.zchildren_sizer = None
        else:
            # Container: Frame, Dialog, Panel
            c0 = self.zchildren[0]
            if len(self.zchildren)==1 and isinstance(c0, Sizer) and c0.border==0 and c0.flag==wx.EXPAND and c0.proportion>0:
                # Promote an explicitly created sizer, provided it doesn't have settings (such as border>0)
                # which require a surrounding sizer to accomodate.
                self.zchildren_sizer = self.zchildren[0].sized
            else:
                # Supply a sizer created from Frame/Dialog/Panel arguments.
                self.zchildren_sizer = wx.BoxSizer(self.orient)
                for c in self.zchildren:
                    _add_to_sizer(self.zchildren_sizer, c)
            self.w.SetSizer(self.zchildren_sizer)
项目:wxWize    作者:AndersMunch    | 项目源码 | 文件源码
def create_postorder(self):
        Window.create_postorder(self)
项目:IntroPython2016a    作者:UWPCE-PythonCert    | 项目源码 | 文件源码
def __init__(self, parent, *args, **kwargs):
        """
        create a new switcher instance.

        :param parent: the parent frame -- this is designed to go on an
                       AddBookFrame object


        :params *args, **kwargs: all the other arguments that a wx.Window takes.       
        """
        wx.Panel.__init__(self, parent, *args, **kwargs)

        self.add_book_frame = parent

        ## add some widgets here to do the switching
项目:IntroPython2016a    作者:UWPCE-PythonCert    | 项目源码 | 文件源码
def __init__(self, parent, *args, **kwargs):
        """
        create a new swither instance.

        :param parent: the parent frame -- this is designed to go on an
                       AddBookFrame object


        :params *args, **kwargs: all the other arguments that a wx.Window takes.       
        """
        print "in __init__"
        wx.Panel.__init__(self, parent, *args, **kwargs)

        self.add_book_frame = parent

        ##Create the buttons to scroll through add_book_frame
        prev_button = wx.Button(self, label="Previous")
        prev_button.Bind(wx.EVT_BUTTON, self.onPrev)

        next_button = wx.Button(self, label="Next")
        next_button.Bind(wx.EVT_BUTTON, self.onNext)

        ## use a Sizer to lay it out
        S = wx.BoxSizer(wx.HORIZONTAL)

        S.Add(prev_button, 1, wx.ALL, 4)
        S.Add((10,1),0)
        S.Add(wx.StaticText(self,label="AddressBook"),
              0,
              wx.ALIGN_CENTER_HORIZONTAL|wx.ALL,
              4)
        S.Add((10,1),0)
        S.Add(next_button, 1,wx.ALL, 4)

        self.SetSizerAndFit(S)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def __init__(self, parent, controller, tagname, initial=False):
        """
        Constructor
        @param parent: Parent wx.Window of dialog for modal
        @param controller: Reference to project controller
        @param tagname: Tagname of project POU edited
        @param initial: True if step is initial (default: False)
        """
        BlockPreviewDialog.__init__(self, parent, controller, tagname,
                                    title=_('Edit Step'))

        # Init common sizers
        self._init_sizers(2, 0, 6, None, 2, 1)

        # Create label for SFC step name
        name_label = wx.StaticText(self, label=_('Name:'))
        self.LeftGridSizer.AddWindow(name_label, flag=wx.GROW)

        # Create text control for defining SFC step name
        self.StepName = wx.TextCtrl(self)
        self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.StepName)
        self.LeftGridSizer.AddWindow(self.StepName, flag=wx.GROW)

        # Create label for SFC step connectors
        connectors_label = wx.StaticText(self, label=_('Connectors:'))
        self.LeftGridSizer.AddWindow(connectors_label, flag=wx.GROW)

        # Create check boxes for defining connectors available on SFC step
        self.ConnectorsCheckBox = {}
        for name, label in [("input", _("Input")),
                            ("output", _("Output")),
                            ("action", _("Action"))]:
            check_box = wx.CheckBox(self, label=label)
            if name == "output" or (name == "input" and not initial):
                check_box.SetValue(True)
            self.Bind(wx.EVT_CHECKBOX, self.OnConnectorsChanged, check_box)
            self.LeftGridSizer.AddWindow(check_box, flag=wx.GROW)
            self.ConnectorsCheckBox[name] = check_box

        # Add preview panel and associated label to sizers
        self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
        self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)

        # Add buttons sizer to sizers
        self.MainSizer.AddSizer(
            self.ButtonSizer, border=20,
            flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT)

        # Save flag that indicates that step is initial
        self.Initial = initial

        # Set default name for step
        self.StepName.ChangeValue(controller.GenerateNewName(
               tagname, None, "Step%d", 0))

        self.Fit()

        # Step name text control is default control having keyboard focus
        self.StepName.SetFocus()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def __init__(self, parent, controller, tagname):
        """
        Constructor
        @param parent: Parent wx.Window of dialog for modal
        @param controller: Reference to project controller
        @param tagname: Tagname of project POU edited
        """
        BlockPreviewDialog.__init__(self, parent, controller, tagname,
                                    title=_('Power Rail Properties'))

        # Init common sizers
        self._init_sizers(2, 0, 5, None, 2, 1)

        # Create label for connection type
        type_label = wx.StaticText(self, label=_('Type:'))
        self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW)

        # Create radio buttons for selecting power rail type
        self.TypeRadioButtons = {}
        first = True
        for type, label in [(LEFTRAIL, _('Left PowerRail')),
                            (RIGHTRAIL, _('Right PowerRail'))]:
            radio_button = wx.RadioButton(self, label=label,
                                          style=(wx.RB_GROUP if first else 0))
            radio_button.SetValue(first)
            self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
            self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW)
            self.TypeRadioButtons[type] = radio_button
            first = False

        # Create label for power rail pin number
        pin_number_label = wx.StaticText(self, label=_('Pin number:'))
        self.LeftGridSizer.AddWindow(pin_number_label, flag=wx.GROW)

        # Create spin control for defining power rail pin number
        self.PinNumber = wx.SpinCtrl(self, min=1, max=50,
                                     style=wx.SP_ARROW_KEYS)
        self.PinNumber.SetValue(1)
        self.Bind(wx.EVT_SPINCTRL, self.OnPinNumberChanged, self.PinNumber)
        self.LeftGridSizer.AddWindow(self.PinNumber, flag=wx.GROW)

        # Add preview panel and associated label to sizers
        self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
        self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)

        # Add buttons sizer to sizers
        self.MainSizer.AddSizer(
            self.ButtonSizer, border=20,
            flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT)
        self.Fit()

        # Left Power Rail radio button is default control having keyboard focus
        self.TypeRadioButtons[LEFTRAIL].SetFocus()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def __init__(self, parent, controller, tagname, title):
        """
        Constructor
        @param parent: Parent wx.Window of dialog for modal
        @param controller: Reference to project controller
        @param tagname: Tagname of project POU edited
        @param title: Title of dialog frame
        """
        wx.Dialog.__init__(self, parent, title=title)

        # Save reference to
        self.Controller = controller
        self.TagName = tagname

        # Label for preview
        self.PreviewLabel = wx.StaticText(self, label=_('Preview:'))

        # Create Preview panel
        self.Preview = wx.Panel(self, style=wx.SIMPLE_BORDER)
        self.Preview.SetBackgroundColour(wx.WHITE)

        # Add function to preview panel so that it answers to graphic elements
        # like Viewer
        setattr(self.Preview, "GetDrawingMode", lambda: FREEDRAWING_MODE)
        setattr(self.Preview, "GetScaling", lambda: None)
        setattr(self.Preview, "GetBlockType", controller.GetBlockType)
        setattr(self.Preview, "IsOfType", controller.IsOfType)

        # Bind paint event on Preview panel
        self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)

        # Add default dialog buttons sizer
        self.ButtonSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.CENTRE)
        self.Bind(wx.EVT_BUTTON, self.OnOK,
                  self.ButtonSizer.GetAffirmativeButton())

        self.Element = None            # Graphic element to display in preview
        self.MinElementSize = None     # Graphic element minimal size

        # Variable containing the graphic element name when dialog is opened
        self.DefaultElementName = None
        self.Fit()

        # List of variables defined in POU {var_name: (var_class, var_type),...}
        self.VariableList = {}