Unix下DirPickerCtrl的最大路径长度

2024-09-30 14:20:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是wxpython3.0.2.0、python2.7.13,我使用的是FreeBSD,所以我有一个Unix系统。你知道吗

我的问题是关于wx.DirPickerCtrl文件你知道吗

dir_picker_style = wx.DIRP_DIR_MUST_EXIST | wx.DIRP_USE_TEXTCTRL
dir_picker = wx.DirPickerCtrl(self, wx.ID_ANY, path=path, message="test",
                              style=dir_picker_style)

如果我的路径超过32个字符(包括反斜杠),那么

value = dir_picker.TextCtrl.Value

值是一个空字符串(u“”),我必须用

dir_picker.GetChildren()[0].SetValue(dir_picker.Path)

一切正常。但是我的同事使用Windows,对于他们来说,一个超过32个字符的路径也可以正常工作。你知道吗

有人知道这个虫子吗?有人知道为什么会这样吗?你知道吗

谢谢你的时间!你知道吗


下面是一个可运行的示例:

#!/usr/bin/env python
import wx
class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(250,250))
        dir_picker_style = wx.DIRP_DIR_MUST_EXIST | wx.DIRP_USE_TEXTCTRL

        path1 = "more/than/"
        path2 = "more/than/thirtytwo/characters/more"

        dir_picker = wx.DirPickerCtrl(self, wx.ID_ANY,
                                      path=path1,
                                      style=dir_picker_style,
                                      pos=(100,50))

        statictext1 = wx.StaticText(self, label =
                                          "dir_picker.TextCtrl.Value: ",
                                          pos=(100,90))
        control1 = wx.TextCtrl(self, style=wx.TE_READONLY, pos=(100,130))
        control1.SetValue(dir_picker.TextCtrl.Value)
        control1.Enable(False)

        statictext2 = wx.StaticText(self, 
                                    label = "dir_picker.GetPath(): ",
                                    pos=(100,170))
        control2 = wx.TextCtrl(self, style=wx.TE_READONLY|wx.GROW,
                               pos=(100,200))
        control2.SetValue(dir_picker.GetPath())
        control2.Enable(False)

        self.Show(True)

app = wx.App(False)
frame = MyFrame(None, 'DirPicker')
app.MainLoop()

当我使用path1时,它将显示在每个textctrl中,但当我使用path2时,它只显示在最后一个textctrl中。(但是当我双击窗口时,path2也会出现在第一个textctrl中。对我来说,这真是一种奇怪的行为。你知道吗


Tags: pathposselftitlevaluestylemoredir
1条回答
网友
1楼 · 发布于 2024-09-30 14:20:32

我无法使用wxpython3.0.2.0classic、python2.7和xubuntu16.04复制您的问题。当我尝试访问TextCtrl.Value时,会得到一个AttributeError。你知道吗

我尝试改用文档化的API,它调用GetPath(),它可以很好地处理长文件夹名:

import wx

class MyPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        self.picker = wx.DirPickerCtrl(self)
        self.picker.Bind(wx.EVT_DIRPICKER_CHANGED, self.onPicked)

    def onPicked(self, event):
        print self.picker.GetPath()


class MyFrame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, title='Pickers')
        panel = MyPanel(self)
        self.Show()

if __name__ == '__main__':
    app = wx.App(False)
    frame = MyFrame()
    app.MainLoop()

相关问题 更多 >