2012-07-18 4 views
0

파이썬 스크립트에 2 개의 프레임이 있습니다. 첫 번째 매개 변수가 최소화되면 두 번째 매개 변수가 표시됩니다. 두 번째를 닫은 후에 원래의 것을 최소화 된 상태로 복원하는 방법은 무엇입니까? 작동 할 수wxpython/python에서 최소화 된 창/프레임을 복원하는 방법

import wx 
import wx.media 
import os 

class MainWindow(wx.Frame): 

    def __init__(self,parent,id): 
     wx.Frame.__init__(self,parent,id,'Music Player',size=(900,600), style=wx.MINIMIZE_BOX|wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX|wx.CLIP_CHILDREN) 
     wx.Frame.CenterOnScreen(self) 
     panel=wx.Panel(self) 
     panel2=wx.Panel(panel,-1, (0,0), (160,600)) 
     ##wx.Frame.Maximize(self) 
     panel.SetBackgroundColour('grey') 
     panel2.SetBackgroundColour('black') 

     ##MENU AND STATUS BAR 
     status=self.CreateStatusBar() 
     menubar=wx.MenuBar() 
     file_menu=wx.Menu() 
     help_menu=wx.Menu() 

     ID_FILE_NEW = 1 
     ID_FILE_LOAD = 2 
     ID_FILE_EXIT = 3 

     file_menu.Append(ID_FILE_NEW,"New Window","This will open a new window") 
     file_menu.Append(ID_FILE_LOAD,"Load...", "This will let you choose a song to load") 
     file_menu.Append(ID_FILE_EXIT,"Exit","This will exit the program") 

     menubar.Append(file_menu,"File") 
     self.SetMenuBar(menubar) 

     self.Bind(wx.EVT_MENU, self.newWin, None, 1) 
     self.Bind(wx.EVT_MENU, self.Load, None, 2)   
     self.Bind(wx.EVT_MENU, self.Close, None, 3) 

##  heading = wx.StaticText(panel, -1, "Music Player",pos=(345,10)) 
     font1 = wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD) 
     font2 = wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD) 
##  heading.SetFont(font1) 

     try: 
      self.mc = wx.media.MediaCtrl(self) 
     except NotImplementedError: 
      raise 

     loadButton = wx.Button(panel2, -1, "Load File", pos=(30,10)) 
     self.Bind(wx.EVT_BUTTON, self.Load, loadButton) 

     playButton = wx.Button(panel2, -1, "Play", pos=(30,50)) 
     self.Bind(wx.EVT_BUTTON, self.Play, playButton) 

     pauseButton = wx.Button(panel2, -1, "Pause", pos=(30,90)) 
     self.Bind(wx.EVT_BUTTON, self.Pause, pauseButton) 

     stopButton = wx.Button(panel2, -1, "Stop", pos=(30,130)) 
     self.Bind(wx.EVT_BUTTON, self.Stop, stopButton) 

     self.playbackSlider = wx.Slider(panel, size=(400,45), pos=(310,50)) 
     self.playbackSlider.SetRange(0,self.mc.Length()) 
     self.Bind(wx.EVT_SLIDER, self.onSeek, self.playbackSlider) 
     self.playbackSlider.SetBackgroundColour('grey') 

     self.volumeCtrl = wx.Slider(panel, value=50, minValue=0, maxValue=100, style=wx.SL_VERTICAL|wx.SL_INVERSE, pos=(180,40)) 
     self.volumeCtrl.Bind(wx.EVT_SLIDER, self.onSetVolume) 

     self.timer = wx.Timer(self) 
     self.Bind(wx.EVT_TIMER, self.onTimer) 
     self.timer.Start(100) 

     self.Bind(wx.EVT_ICONIZE, self.newWin2)   

     self.st_file = wx.StaticText(self, -1, "**Nothing** Please click the \"Load File\" Button", pos=(310,10)) 
     playing = wx.StaticText(self, -1, "Now Playing: ", pos=(165,10)) 
     playing.SetFont(font2) 
     self.st_file.SetFont(font1) 
     playing.SetBackgroundColour('grey') 
     self.st_file.SetBackgroundColour('grey') 
     playing.SetForegroundColour('white') 
     self.st_file.SetForegroundColour('white') 

    def newWin2(self, event): 
     if self.IsIconized() == True: 
      self.new = NewWindow(parent=None, id=-1) 
      self.new.Show() 

    def newWin(self, event): 
      self.new = NewWindow(parent=None, id=-1) 
      self.new.Show() 

    def Close(self, event): 
     box=wx.MessageDialog(None, 'Are you sure you want to exit?', 'Exit program?', wx.YES_NO) 
     answer=box.ShowModal() 
     if answer==wx.ID_YES: 
      self.Destroy() 

    def Load(self, event): 
     dlg = wx.FileDialog(self, "Choose a media file", "songs", "", "*.*", wx.OPEN) 
     if dlg.ShowModal() == wx.ID_OK: 
      path = dlg.GetPath() 
      self.doLoadFile(path) 
     dlg.Destroy() 

    def doLoadFile(self, path): 
     if not self.mc.Load(path): 
      wx.MessageBox("Unable to load %s: Unsupported format?" % path, "ERROR", wx.ICON_ERROR | wx.OK) 

     else: 
      folder, filename = os.path.split(path) 
      self.st_file.SetLabel('%s' % filename) 
      self.mc.SetBestFittingSize() 
      self.mc.Play() 

    def Play(self, event): 
     self.mc.Play() 
     self.playbackSlider.SetRange(0,self.mc.Length()) 

    def Pause(self, event): 
     self.mc.Pause() 

    def Stop(self, event): 
     self.mc.Stop() 

    def onSetVolume(self, event): 
     self.currentVolume = self.volumeCtrl.GetValue() 
     self.mc.SetVolume(float(self.currentVolume)/100) 

    def onTimer(self, event): 
     offset = self.mc.Tell() 
     self.playbackSlider.SetValue(offset) 

    def onSeek(self, event): 
     offset = self.playbackSlider.GetValue() 
     self.mc.Seek(offset) 

class NewWindow(wx.Frame): 

    def __init__(self,parent,id): 
     wx.Frame.__init__(self, parent, id, 'New Window', size=(130,150), pos=(0,0), style=wx.MINIMIZE_BOX|wx.CLOSE_BOX) 
     self.SetBackgroundColour('grey') 

     playButton = wx.Button(self, -1, "Play", pos=(5,10)) 
     self.Bind(wx.EVT_BUTTON, self.Play, playButton) 

     pauseButton = wx.Button(self, -1, "Pause", pos=(5,40)) 
     self.Bind(wx.EVT_BUTTON, self.Pause, pauseButton) 

     stopButton = wx.Button(self, -1, "Stop", pos=(5,70)) 
     self.Bind(wx.EVT_BUTTON, self.Stop, stopButton) 

     closeButton = wx.Button(self, -1, "Close", pos=(5,120)) 
     self.Bind(wx.EVT_BUTTON, self.Close, closeButton) 

    def Play(self, event): 
     self.mc.Play() 
     self.playbackSlider.SetRange(0,self.mc.Length()) 

    def Pause(self, event): 
     self.mc.Pause() 

    def Stop(self, event): 
     self.mc.Stop() 

    def onSetVolume(self, event): 
     self.currentVolume = self.volumeCtrl.GetValue() 
     self.mc.SetVolume(float(self.currentVolume)/100) 

    def Close(self, event): 
     self.Destroy() 
     ################## I WANT TO ADD WHATEVER I NEED TO HERE TO RESTORE THE MINIMIZED FRAME AFTER THE CLOSE BUTTON IS PRESSED. 

##RUN## 

if __name__=='__main__': 
     app=wx.PySimpleApp() 
     frame=MainWindow(parent=None,id=-1) 
     frame.Show() 
     app.MainLoop() 

답변

1
the_app.SetTopWindow(wxFrameObject) 
wxFrameObject.Maximize() 

은 ... 우리가

+0

"the_app"라고 할 때 정확히 무엇을 언급하고 있습니까? 다른 모든 것들이 의미가 있습니다. – Worm

+0

wx.App 객체 ...이 코드는 우리 프로젝트에서 다른 것들로 묶여서 독립 실행 형이 될 수도 있습니다. –

+0

참고로 코드 힌트가있는 IDE는 이런 유형의 문제에 도움이 될 수 있습니다 또한 wx.Frame (정말 wx.TopLevelWindow 또는 someat) (나는 이클립스를 사용한다)의 메소드 인 Maximize에 대해서 알려줄 것이다. 또한 wx.STAY_ON_TOP 스타일로 프레임을 초기화하고 싶을 수도있다. –

1
당신은 할 myFrameObject.Raise()를 사용한다

그것의 최소화 나올 사용 이잖아 : 여기

지금까지 내 코드입니다 상태. wx.STAY_ON_TOP 플래그는 최소화되지 않은 다른 모든 프레임 위에 프레임을 유지하기위한 플래그이지만 프레임을 최소화 한 경우 아무 것도 수행하지 않습니다.

관련 문제