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

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

项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
def BindEvents(self):
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_ERASE_BACKGROUND, lambda e: None)
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnButtonDown)
        self.Bind(wx.EVT_LEFT_DOWN, self.OnButtonDown)
        self.Bind(wx.EVT_MIDDLE_DOWN, self.OnButtonDown)
        self.Bind(wx.EVT_RIGHT_UP, self.OnButtonUp)
        self.Bind(wx.EVT_LEFT_UP, self.OnButtonUp)
        self.Bind(wx.EVT_MIDDLE_UP, self.OnButtonUp)
        self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
        self.Bind(wx.EVT_MOTION, self.OnMotion)
        self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
        self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
        self.Bind(wx.EVT_CHAR, self.OnKeyDown)
        self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
        if wx.Platform == "__WXGTK__":
            # wxGTK requires that the window be created before you can
            # set its shape, so delay the call to SetWindowShape until
            # this event.
            self.Bind(wx.EVT_WINDOW_CREATE, self.OnWindowCreate)
        else:
            # On wxMSW and wxMac the window has already been created.
            self.Bind(wx.EVT_SIZE, self.OnSize)
        if _useCapture and hasattr(wx, 'EVT_MOUSE_CAPTURE_LOST'):
            self.Bind(wx.EVT_MOUSE_CAPTURE_LOST, self.OnMouseCaptureLost)
项目:fmc-dialer    作者:sguron    | 项目源码 | 文件源码
def DropShadow(self, drop=True):
        if wx.Platform != "__WXMSW__":
            # This works only on windows
            return

        hwnd = self.GetHandle()
        print "handle wizard=", hwnd
        CS_DROPSHADOW = 0x00020000
        GCL_STYLE = -26

        csstyle = ctypes.windll.user32.GetWindowLongA(hwnd, GCL_STYLE)
        if drop:
            if csstyle & CS_DROPSHADOW:
                return
            else:
                csstyle |= CS_DROPSHADOW     #Nothing to be done
        else:
            csstyle &= ~CS_DROPSHADOW

        cstyle= ctypes.windll.user32.GetClassLongA(hwnd, GCL_STYLE)
        if drop:
            if cstyle & CS_DROPSHADOW == 0:
                ctypes.windll.user32.SetClassLongA(hwnd, GCL_STYLE, cstyle | CS_DROPSHADOW)
        else:
            ctypes.windll.user32.SetClassLongA(hwnd, GCL_STYLE, cstyle & ~CS_DROPSHADOW)
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
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()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def open_pdf(pdffile, pagenum=None):
    if wx.Platform == '__WXMSW__':
        try:
            readerpath = get_acroversion()
        except Exception:
            wx.MessageBox("Acrobat Reader is not found or installed !")
            return None

        readerexepath = os.path.join(readerpath, "AcroRd32.exe")
        if(os.path.isfile(readerexepath)):
            open_win_pdf(readerexepath, pdffile, pagenum)
        else:
            return None
    else:
        readerexepath = os.path.join("/usr/bin", "xpdf")
        if(os.path.isfile(readerexepath)):
            open_lin_pdf(readerexepath, pdffile, pagenum)
        else:
            wx.MessageBox("xpdf is not found or installed !")
            return None
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GenerateLocationsTreeBranch(self, root, locations):
        to_delete = []
        item, root_cookie = self.LocationsTree.GetFirstChild(root)
        for loc_infos in locations:
            infos = loc_infos.copy()
            if infos["type"] in [LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP] or\
               infos["type"] in self.DirFilter and self.FilterType(infos["IEC_type"], infos["size"]):
                children = [child for child in infos.pop("children")]
                if not item.IsOk():
                    item = self.LocationsTree.AppendItem(root, infos["name"])
                    if wx.Platform != '__WXMSW__':
                        item, root_cookie = self.LocationsTree.GetNextChild(root, root_cookie)
                else:
                    self.LocationsTree.SetItemText(item, infos["name"])
                self.LocationsTree.SetPyData(item, infos)
                self.LocationsTree.SetItemImage(item, self.TreeImageDict[infos["type"]])
                self.GenerateLocationsTreeBranch(item, children)
                item, root_cookie = self.LocationsTree.GetNextChild(root, root_cookie)
        while item.IsOk():
            to_delete.append(item)
            item, root_cookie = self.LocationsTree.GetNextChild(root, root_cookie)
        for item in to_delete:
            self.LocationsTree.Delete(item)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GenerateTreeBranch(self, root, folderpath):
        item, item_cookie = self.Tree.GetFirstChild(root)
        for idx, (filename, item_type, children) in enumerate(self._GetFolderChildren(folderpath)):
            if not item.IsOk():
                item = self.Tree.AppendItem(root, filename, self.TreeImageDict[item_type])
                if wx.Platform != '__WXMSW__':
                    item, item_cookie = self.Tree.GetNextChild(root, item_cookie)
            elif self.Tree.GetItemText(item) != filename:
                item = self.Tree.InsertItemBefore(root, idx, filename, self.TreeImageDict[item_type])
            filepath = os.path.join(folderpath, filename)
            if item_type != FILE:
                if self.Tree.IsExpanded(item):
                    self.GenerateTreeBranch(item, filepath)
                elif children > 0:
                    self.Tree.SetItemHasChildren(item)
            item, item_cookie = self.Tree.GetNextChild(root, item_cookie)
        to_delete = []
        while item.IsOk():
            to_delete.append(item)
            item, item_cookie = self.Tree.GetNextChild(root, item_cookie)
        for item in to_delete:
            self.Tree.Delete(item)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def OnMotion(self, event):
        if wx.Platform == '__WXMSW__':
            if not event.Dragging():
                x, y = event.GetPosition()
                margin_width = reduce(
                        lambda x, y: x + y,
                        [self.GetMarginWidth(i)
                         for i in xrange(3)],
                        0)
                if x <= margin_width:
                    self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
                else:
                    self.SetCursor(wx.StockCursor(wx.CURSOR_IBEAM))
            else:
                event.Skip()
        else:
            event.Skip()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
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)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def PopupListBox(self):
        if self.listbox is None:
            self.listbox = PopupWithListbox(self)

            # Show the popup right below or above the button
            # depending on available screen space...
            pos = self.ClientToScreen((0, 0))
            sz = self.GetSize()
            if wx.Platform == '__WXMSW__':
                pos.x -= 2
                pos.y -= 2
            self.listbox.Position(pos, (0, sz[1]))

            self.RefreshListBoxChoices()

            self.listbox.Show()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def OnScrollWindow(self, event):
        if self.Editor.HasCapture() and self.StartMousePos is not None:
            return
        if wx.Platform == '__WXMSW__':
            wx.CallAfter(self.RefreshVisibleElements)
            self.Editor.Freeze()
            wx.CallAfter(self.Editor.Thaw)
        elif event.GetOrientation() == wx.HORIZONTAL:
            self.RefreshVisibleElements(xp=event.GetPosition())
        else:
            self.RefreshVisibleElements(yp=event.GetPosition())

        # Handle scroll in debug to fully redraw area and ensuring
        # instance path is fully draw without flickering
        if self.Debug and wx.Platform != '__WXMSW__':
            x, y = self.GetViewStart()
            if event.GetOrientation() == wx.HORIZONTAL:
                self.Scroll(event.GetPosition(), y)
            else:
                self.Scroll(x, event.GetPosition())
        else:
            event.Skip()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def kill(self, gently=True):
        # avoid running kill before start is finished
        self.startsem.acquire()
        self.startsem.release()

        self.outt.killed = True
        self.errt.killed = True
        if wx.Platform == '__WXMSW__':
            PROCESS_TERMINATE = 1
            handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, self.Proc.pid)
            ctypes.windll.kernel32.TerminateProcess(handle, -1)
            ctypes.windll.kernel32.CloseHandle(handle)
        else:
            if gently:
                sig = SIGTERM
            else:
                sig = SIGKILL
            try:
                os.kill(self.Proc.pid, sig)
            except Exception:
                pass
        self.outt.join()
        self.errt.join()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def SaveProjectAs(self):
        # Ask user to choose a path with write permissions
        if wx.Platform == '__WXMSW__':
            path = os.getenv("USERPROFILE")
        else:
            path = os.getenv("HOME")
        dirdialog = wx.DirDialog(self.AppFrame, _("Choose a directory to save project"), path, wx.DD_NEW_DIR_BUTTON)
        answer = dirdialog.ShowModal()
        dirdialog.Destroy()
        if answer == wx.ID_OK:
            newprojectpath = dirdialog.GetPath()
            if os.path.isdir(newprojectpath):
                if self.CheckNewProjectPath(self.ProjectPath, newprojectpath):
                    self.ProjectPath, old_project_path = newprojectpath, self.ProjectPath
                    self.SaveProject(old_project_path)
                    self._setBuildPath(self.BuildPath)
                return True
        return False
项目:PandasDataFrameGUI    作者:bluenote10    | 项目源码 | 文件源码
def __OnColClick(self, evt):
        if self.preSortCallback is not None:
          self.preSortCallback()
        oldCol = self._col
        self._col = col = evt.GetColumn()
        self._colSortFlag[col] = int(not self._colSortFlag[col])
        self.GetListCtrl().SortItems(self.GetColumnSorter())
        if wx.Platform != "__WXMAC__" or wx.SystemOptions.GetOptionInt("mac.listctrl.always_use_generic") == 1:
            self.__updateImages(oldCol)
        evt.Skip()
        self.OnSortOrderChanged()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def OnLinkClick(self, event):
            url = event.linkinfo[0]
            try:
                if wx.Platform == '__WXMSW__':
                    import webbrowser
                    webbrowser.open(url)
                elif subprocess.call("firefox %s" % url, shell=True) != 0:
                    wx.MessageBox("""Firefox browser not found.\nPlease point your browser at :\n%s""" % url)
            except ImportError:
                wx.MessageBox('Please point your browser at: %s' % url)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def open_svg(svgfile):
    """ Generic function to open SVG file """
    if wx.Platform == '__WXMSW__':
        try:
            open_win_svg(get_inkscape_path(), svgfile)
        except Exception:
            wx.MessageBox("Inkscape is not found or installed !")
            return None
    else:
        svgexepath = os.path.join("/usr/bin", "inkscape")
        if(os.path.isfile(svgexepath)):
            open_lin_svg(svgexepath, svgfile)
        else:
            wx.MessageBox("Inkscape is not found or installed !")
            return None
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetCopyBuffer(self, primary_selection=False):
        data = None
        if primary_selection and wx.Platform == '__WXMSW__':
            return data
        else:
            wx.TheClipboard.UsePrimarySelection(primary_selection)
        if wx.TheClipboard.Open():
            dataobj = wx.TextDataObject()
            if wx.TheClipboard.GetData(dataobj):
                data = dataobj.GetText()
            wx.TheClipboard.Close()
        return data
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetButtonPressedFunction(self, call_function):
        def OnButtonPressed(event):
            if wx.Platform != '__WXMSW__' or not self.Editing:
                func = getattr(self, call_function, None)
                if func is not None:
                    func(event)
                    wx.CallAfter(self.EnsureCurrentItemVisible)
                else:
                    wx.CallAfter(self.EnsureCurrentItemVisible)
                    event.Skip()
        return OnButtonPressed
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def _GetFolderChildren(self, folderpath, recursive=True):
        items = []
        if wx.Platform == '__WXMSW__' and folderpath == "/":
            for c in xrange(ord('a'), ord('z')):
                drive = os.path.join("%s:\\" % chr(c))
                if os.path.exists(drive):
                    items.append((drive, DRIVE, self._GetFolderChildren(drive, False)))
        else:
            try:
                files = os.listdir(folderpath)
            except Exception:
                return []
            for filename in files:
                if not filename.startswith("."):
                    filepath = os.path.join(folderpath, filename)
                    if os.path.isdir(filepath):
                        if recursive:
                            children = len(self._GetFolderChildren(filepath, False))
                        else:
                            children = 0
                        items.append((filename, FOLDER, children))
                    elif (self.CurrentFilter == "" or
                          os.path.splitext(filename)[1] == self.CurrentFilter):
                        items.append((filename, FILE, None))
        if recursive:
            items.sort(sort_folder)
        return items
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def ResetHighlight(self):
        for panel in self.GraphicPanels:
            panel.SetHighlight(HIGHLIGHT_NONE)
        if wx.Platform == "__WXMSW__":
            self.RefreshView()
        else:
            self.ForceRefresh()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def Scroll(self, x, y):
        if self.Debug and wx.Platform == '__WXMSW__':
            self.Editor.Freeze()
        self.Editor.Scroll(x, y)
        if self.Debug:
            if wx.Platform == '__WXMSW__':
                self.Editor.Thaw()
            else:
                self.Editor.Refresh()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def launch_wxglade(self, options, wait=False):
        path = self.GetWxGladePath()
        glade = os.path.join(path, 'wxglade.py')
        if wx.Platform == '__WXMSW__':
            glade = "\"%s\"" % glade
        mode = {False: os.P_NOWAIT, True: os.P_WAIT}[wait]
        os.spawnv(mode, sys.executable, ["\"%s\"" % sys.executable] + [glade] + options)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def _editWXGLADE(self):
        wxg_filename = self._getWXGLADEpath()
        open_wxglade = True
        if not self.GetCTRoot().CheckProjectPathPerm():
            dialog = wx.MessageDialog(self.GetCTRoot().AppFrame,
                                      _("You don't have write permissions.\nOpen wxGlade anyway ?"),
                                      _("Open wxGlade"),
                                      wx.YES_NO | wx.ICON_QUESTION)
            open_wxglade = dialog.ShowModal() == wx.ID_YES
            dialog.Destroy()
        if open_wxglade:
            if not os.path.exists(wxg_filename):
                hmi_name = self.BaseParams.getName()
                open(wxg_filename, "w").write("""<?xml version="1.0"?>
    <application path="" name="" class="" option="0" language="python" top_window="%(name)s" encoding="UTF-8" use_gettext="0" overwrite="0" use_new_namespace="1" for_version="2.8" is_template="0">
        <object class="%(class)s" name="%(name)s" base="EditFrame">
            <style>wxDEFAULT_FRAME_STYLE</style>
            <title>frame_1</title>
            <object class="wxBoxSizer" name="sizer_1" base="EditBoxSizer">
                <orient>wxVERTICAL</orient>
            <object class="sizerslot" />
        </object>
        </object>
    </application>
    """ % {"name": hmi_name, "class": "Class_%s" % hmi_name})
            if wx.Platform == '__WXMSW__':
                wxg_filename = "\"%s\"" % wxg_filename
            self.launch_wxglade([wxg_filename])
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GetDefaultTargetName(self):
        if wx.Platform == '__WXMSW__':
            return "Win32"
        else:
            return "Linux"
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def OnTaskBarQuit(self, evt):
                if wx.Platform == '__WXMSW__':
                    Thread(target=self.pyroserver.Quit).start()
                self.RemoveIcon()
                wx.CallAfter(wx.GetApp().ExitMainLoop)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def ShowSplashScreen(self):
        from wx.lib.agw.advancedsplash import AdvancedSplash
        bmp = wx.Image(self.splashPath).ConvertToBitmap()
        self.splash = AdvancedSplash(None, bitmap=bmp)

        # process all events
        # even the events generated by splash themself during showing
        if wx.Platform == '__WXMSW__':
            self.splash.Show()
            self.splash.ProcessEvent(wx.PaintEvent())
        else:
            for i in range(0, 30):
                wx.Yield()
                time.sleep(0.01)
项目:cx_Freeze    作者:anthony-tuininga    | 项目源码 | 文件源码
def add_toolbar(self):
        self.toolbar = NavigationToolbar2Wx(self.canvas)
        self.toolbar.Realize()
        if wx.Platform == '__WXMAC__':
            self.SetToolBar(self.toolbar)
        else:
            tw, th = self.toolbar.GetSize()
            fw, fh = self.canvas.GetSize()
            self.toolbar.SetSize(wx.Size(fw, th))
            self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        self.toolbar.update()
项目:fritzchecksum    作者:mementum    | 项目源码 | 文件源码
def DoSort(self, column, status=None):
        '''Separated from event management to allow it to be used internally and
        externally

        When called a list of column text is gathered on the fly to use it
        during the sorting process.

        This is key to avoid the user keeping external data sync'ed: the data
        is already in the control

        Does additional column count control and allows reordering with current
        state

        The rest from the original

        '''

        colcount = self.GetColumnCount()
        if not colcount:
            return
        if column < 0:
            column = 0
        elif column >= colcount:
            column = colcount - 1

        oldcol = self.col  # reference to last sorted column
        self.col = col = column

        if status is None:
            # invert the last sorting order
            self.sortflags[col] = not self.sortflags[col]
        else:
            self.sortflags[col] = status

        self.sortdata = dict()  # prepare the data holder
        for index in xrange(0, self.GetItemCount()):
            # loop over all items and gather the ItemData and ColumnText
            itemdata = self.GetItemData(index)
            item = self.GetItem(index, col)
            self.sortdata[itemdata] = item.GetText()

        self.SortItems(self.GetColumnSorter())  # Sort
        macusegeneric = "mac.listctrl.always_use_generic"
        if wx.Platform != "__WXMAC__" or \
           wx.SystemOptions.GetOptionInt(macusegeneric) == 1:
            # If needed an possible update the images
            self.UpdateImages(oldcol)

        self.OnSortOrderChanged()  # go to the notification callback
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def GenerateSearchResultsTreeBranch(self, root, infos):
        to_delete = []
        if infos["name"] == "body":
            item_name = "%d:" % infos["data"][1][0]
        else:
            item_name = infos["name"]

        self.SearchResultsTree.SetItemText(root, item_name)
        self.SearchResultsTree.SetPyData(root, infos["data"])
        self.SearchResultsTree.SetItemBackgroundColour(root, wx.WHITE)
        self.SearchResultsTree.SetItemTextColour(root, wx.BLACK)
        if infos["type"] is not None:
            if infos["type"] == ITEM_POU:
                self.SearchResultsTree.SetItemImage(root, self.TreeImageDict[self.ParentWindow.Controler.GetPouType(infos["name"])])
            else:
                self.SearchResultsTree.SetItemImage(root, self.TreeImageDict[infos["type"]])

        text = None
        if infos["text"] is not None:
            text = infos["text"]
            start, end = infos["data"][1:3]
            text_lines = infos["text"].splitlines()
            start_idx = start[1]
            end_idx = reduce(lambda x, y: x + y, map(lambda x: len(x) + 1, text_lines[:end[0] - start[0]]), end[1] + 1)
            style = wx.TextAttr(wx.BLACK, wx.Colour(206, 204, 247))
        elif infos["type"] is not None and infos["matches"] > 1:
            text = _("(%d matches)") % infos["matches"]
            start_idx, end_idx = 0, len(text)
            style = wx.TextAttr(wx.Colour(0, 127, 174))

        if text is not None:
            text_ctrl_style = wx.BORDER_NONE | wx.TE_READONLY | wx.TE_RICH2
            if wx.Platform != '__WXMSW__' or len(text.splitlines()) > 1:
                text_ctrl_style |= wx.TE_MULTILINE
            text_ctrl = wx.TextCtrl(id=-1, parent=self.SearchResultsTree, pos=wx.Point(0, 0),
                                    value=text, style=text_ctrl_style)
            width, height = text_ctrl.GetTextExtent(text)
            text_ctrl.SetClientSize(wx.Size(width + 1, height))
            text_ctrl.SetBackgroundColour(self.SearchResultsTree.GetBackgroundColour())
            text_ctrl.Bind(wx.EVT_LEFT_DOWN, self.GetTextCtrlClickFunction(root))
            text_ctrl.Bind(wx.EVT_LEFT_DCLICK, self.GetTextCtrlDClickFunction(root))
            text_ctrl.SetInsertionPoint(0)
            text_ctrl.SetStyle(start_idx, end_idx, style)
            self.SearchResultsTree.SetItemWindow(root, text_ctrl)

        if wx.VERSION >= (2, 6, 0):
            item, root_cookie = self.SearchResultsTree.GetFirstChild(root)
        else:
            item, root_cookie = self.SearchResultsTree.GetFirstChild(root, 0)
        for child in infos["children"]:
            if item is None:
                item = self.SearchResultsTree.AppendItem(root, "")
                item, root_cookie = self.SearchResultsTree.GetNextChild(root, root_cookie)
            self.GenerateSearchResultsTreeBranch(item, child)
            item, root_cookie = self.SearchResultsTree.GetNextChild(root, root_cookie)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def __init__(self, parent, folder, filter=None, editable=True):
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)

        main_sizer = wx.BoxSizer(wx.VERTICAL)

        self.Tree = wx.TreeCtrl(self,
                                style=(wx.TR_HAS_BUTTONS |
                                       wx.TR_SINGLE |
                                       wx.SUNKEN_BORDER |
                                       wx.TR_HIDE_ROOT |
                                       wx.TR_LINES_AT_ROOT |
                                       wx.TR_EDIT_LABELS))
        if wx.Platform == '__WXMSW__':
            self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnTreeItemExpanded, self.Tree)
            self.Tree.Bind(wx.EVT_LEFT_DOWN, self.OnTreeLeftDown)
        else:
            self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnTreeItemExpanded, self.Tree)
        self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnTreeItemCollapsed, self.Tree)
        self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnTreeBeginLabelEdit, self.Tree)
        self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnTreeEndLabelEdit, self.Tree)
        main_sizer.AddWindow(self.Tree, 1, flag=wx.GROW)

        if filter is not None:
            self.Filter = wx.ComboBox(self, style=wx.CB_READONLY)
            self.Bind(wx.EVT_COMBOBOX, self.OnFilterChanged, self.Filter)
            main_sizer.AddWindow(self.Filter, flag=wx.GROW)
        else:
            self.Filter = None

        self.SetSizer(main_sizer)

        self.Folder = folder
        self.Editable = editable

        self.TreeImageList = wx.ImageList(16, 16)
        self.TreeImageDict = {}
        for item_type, bitmap in [(DRIVE, "tree_drive"),
                                  (FOLDER, "tree_folder"),
                                  (FILE, "tree_file")]:
            self.TreeImageDict[item_type] = self.TreeImageList.Add(GetBitmap(bitmap))
        self.Tree.SetImageList(self.TreeImageList)

        self.Filters = {}
        if self.Filter is not None:
            filter_parts = filter.split("|")
            for idx in xrange(0, len(filter_parts), 2):
                if filter_parts[idx + 1] == "*.*":
                    self.Filters[filter_parts[idx]] = ""
                else:
                    self.Filters[filter_parts[idx]] = filter_parts[idx + 1].replace("*", "")
                self.Filter.Append(filter_parts[idx])
                if idx == 0:
                    self.Filter.SetStringSelection(filter_parts[idx])

            self.CurrentFilter = self.Filters[self.Filter.GetStringSelection()]
        else:
            self.CurrentFilter = ""
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def _init_Editor(self, parent):
        self.Editor = wx.Panel(parent)

        main_sizer = wx.BoxSizer(wx.HORIZONTAL)

        left_sizer = wx.BoxSizer(wx.VERTICAL)
        main_sizer.AddSizer(left_sizer, 1, border=5, flag=wx.GROW | wx.ALL)

        managed_dir_label = wx.StaticText(self.Editor, label=_(self.TagName) + ":")
        left_sizer.AddWindow(managed_dir_label, border=5, flag=wx.GROW | wx.BOTTOM)

        self.ManagedDir = FolderTree(self.Editor, self.Folder, FILTER)
        left_sizer.AddWindow(self.ManagedDir, 1, flag=wx.GROW)

        managed_treectrl = self.ManagedDir.GetTreeCtrl()
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeItemChanged, managed_treectrl)
        if self.EnableDragNDrop:
            self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnTreeBeginDrag, managed_treectrl)

        button_sizer = wx.BoxSizer(wx.VERTICAL)
        main_sizer.AddSizer(button_sizer, border=5,
                            flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL)

        for idx, (name, bitmap, help) in enumerate([
                ("DeleteButton", "remove_element", _("Remove file from left folder")),
                ("LeftCopyButton", "LeftCopy", _("Copy file from right folder to left")),
                ("RightCopyButton", "RightCopy", _("Copy file from left folder to right")),
                ("EditButton", "edit", _("Edit file"))]):
            button = wx.lib.buttons.GenBitmapButton(
                self.Editor,
                bitmap=GetBitmap(bitmap),
                size=wx.Size(28, 28), style=wx.NO_BORDER)
            button.SetToolTipString(help)
            setattr(self, name, button)
            if idx > 0:
                flag = wx.TOP
            else:
                flag = 0
            self.Bind(wx.EVT_BUTTON, getattr(self, "On" + name), button)
            button_sizer.AddWindow(button, border=20, flag=flag)

        right_sizer = wx.BoxSizer(wx.VERTICAL)
        main_sizer.AddSizer(right_sizer, 1, border=5, flag=wx.GROW | wx.ALL)

        if wx.Platform == '__WXMSW__':
            system_dir_label = wx.StaticText(self.Editor, label=_("My Computer:"))
        else:
            system_dir_label = wx.StaticText(self.Editor, label=_("Home Directory:"))
        right_sizer.AddWindow(system_dir_label, border=5, flag=wx.GROW | wx.BOTTOM)

        self.SystemDir = FolderTree(self.Editor, self.HomeDirectory, FILTER, False)
        right_sizer.AddWindow(self.SystemDir, 1, flag=wx.GROW)

        system_treectrl = self.SystemDir.GetTreeCtrl()
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeItemChanged, system_treectrl)

        self.Editor.SetSizer(main_sizer)