저는 파이썬 프로그램에 약간의 문제가있었습니다. 기본적으로 매우 단순한 파일 관리자입니다.버튼을 눌렀을 때 wxpython 새로 고침 창이 나타납니다
나는 폴더 간 이동 (사용자가 폴더를 클릭하면 프로그램이 표시 내용을 새로 고침하고 폴더의 내용을 표시)을 시도하고 있습니다.
내가 겪고있는 문제는 디스플레이를 새로 고치고 클릭 할 때 새 폴더와 파일로 채우는 버튼이있는 것 같습니다.
다음은 현재 사용중인 코드이며 Linux에 있습니다.
import wx
import fileBrowser
class interface(wx.Frame):
def __init__(self, parent, id):
'''(object, int) --> None
Set up wx python in a frame and displays it and contents defined in this function on the screen.'''
wx.Frame.__init__(self, parent, id, "Bronto", size = (800, 600))
panel = wx.Panel(self)
self.createPanels()
contents = fileBrowser.print_items("/")
wx.StaticText(panel, -1, "/", (50, 10))
col = 50
row = 50
for items in contents:
name = items
col, row = self.makeIcons(panel, (800, 600), name, col, row)
def makeIcons(self, panel, param, name, col, row):
'''(object, object) --> None
Place a button on the window that uses an image as its icon.'''
pic = wx.Image("folder.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.button = wx.BitmapButton(panel, -1, pic, pos = (col, row))
wx.StaticText(panel, -1, name, (col + 10, row + 40))
self.Bind(wx.EVT_BUTTON, self.displayContents, self.button)
self.button.SetDefault()
if(col < 600):
return col + 90, row
else:
col = 50
return col, row + 80
def createPanels(self):
'''(object) --> None
Create and place both menu and status bars on the window.'''
status = self.CreateStatusBar()
menubar = wx.MenuBar()
File = wx.Menu()
Edit = wx.Menu()
menubar.Append(File,"File")
menubar.Append(Edit, "Edit")
new = wx.MenuItem(File, 101, '&New\tCtrl+N', 'Creates a new document')
File.AppendItem(new)
self.Bind(wx.EVT_MENU, self.NewApplication, id=101)
self.SetMenuBar(menubar)
def NewApplication(self, event):
app = wx.PySimpleApp()
frame = interface(parent = None, id =1)
frame.Show()
app.MainLoop()
def displayContents(self, event):
'''(event) --> None
Display the contents of the folder clicked on'''
#self.panel.Destroy();
#self.panel = wx.Panel(self)
self.Refresh(True)
contents = fileBrowser.print_items("/home")
col = 50
row = 50
for items in contents:
name = items
wx.Yield()
col, row = self.makeIcons(panel, (800, 600), name, col, row)
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = interface(parent = None, id =1)
frame.Show()
app.MainLoop()
그리고 여기에는 fileBrower 프로그램이다 (나는 폴더 만 보는 순간,하지만 난 나중에 변경됩니다)
import os
import os.path
def print_items(d):
'''(str) -> NoneType
Print the list of files and directories in directory d, recursively,
prefixing each with indentation.'''
icons = []
#print out the names of files and subdirectories
for filename in os.listdir(d):
subitem = os.path.join(d, filename)
if os.path.isdir(subitem):
print filename
icons.append(filename)
return icons
@pthonm을 : 나는 당신이 제시 한 코드를 추가하지만 것 나던 새로운 것들로 그것을 업데이 트하는 (비록 그것은 창을 지우지)
편집 : 좋아, 나는 거의 일하고있다. self.Refresh (True)를 사용하여 내용을 표시 할 수 있지만 self.panel.Destroy() 메서드를 사용하지 않으면 작동합니다. 그래서, 버튼과 텍스트를 없애는 방법에 대한 제안 (displayContents 메소드가 내가 추가 한 것을 보시오)?
EDIT2 : 제대로 작동합니다. 내가 한 것은 displayContents 메서드에 추가 한 것입니다. 이것은 아마 이런 일을하는 가장 좋은 방법은 아닙니다.
def displayContents(self, event):
'''(event) --> None
Display the contents of the folder clicked on'''
self.panel.Destroy();
self.panel = wx.Panel(self)
self.createPanels()
self.Update()
wx.StaticText(self.panel, -1, location, (50, 10))
contents = fileBrowser.print_items("/home/gum/Documents")
col = 50
row = 50
for directory,name in contents.iteritems():
col, row = self.makeIcons(self.panel, (800, 600), name, col, row)
당신은이 단순한 파일 관리자와 같이 매우 어렵고 복잡하다고 생각합니다. 거기에 기존의 디자인 패턴과 당신을 위해 더 나은, 규칙에 따라 프로그램. 다음은 코드가있는 예제, 파일 관리자를 코딩하는 방법입니다. "http://zetcode.com/wxpython/skeletons/"이 코드를 연구하고 처음부터 다시 작성하십시오. 내 추천서 ..! – fecub