2012-07-07 2 views
0

글쎄요, 경험이 풍부한 프로그래머는 아니지만, 특히 멀티미디어 애플리케이션의 경우에는 전체 이미지를 표시하는 이미지 뷰어 프로그램을 사용해야했고, 이미지가 변경되었습니다 사용자가 < 또는 -> 화살표를 누를 때.wxPython으로 연속적인 비트 맵 생성 문제 :

일반적인 아이디어는 특정 폴더 (imgs)에 포함 된 모든 이미지가 표시되는 목록 상자를 만드는 것이 었습니다. 누군가가 두 번 클릭하거나 RETURN을 눌렀을 때 처음에는 이미지를 포함하는 전체 화면 프레임이 생성되었습니다 목록 상자에서 선택되지만 사용자가 화살표를 친 후에 정규 이미지 뷰어 에서처럼 이미지가 연속 순서로 변경됩니다.

초기 15-20 개 이미지가 생성 될 때, 프로그램이 여전히 매우 불쾌하고 매우 원치 않는 중개자로 작동하지만 모든 것이 순조롭게 진행됩니다. 이미지 생성간에 효과가 나타나며 기본적으로 이미지 이전에 생성 된 이미지는 화면에 빠르게 표시되고 그 후에는 오른쪽 이미지가 연속적으로 나타납니다. 첫 번째 발현시에 그 효과는 눈에 띄게 나타납니다. 그러나 잠시 후 그것은 세대간에 더 오래 걸립니다. 사전에 어떤 조언을

def lbclick(self, eve): 
    frm = wx.Frame(None, -1, '') 
    frm.ShowFullScreen(True) 
    self.sel = self.lstb.GetSelection() # getting the selection from the listbox 
    def pressk(eve): 
     keys = eve.GetKeyCode() 
     if keys == wx.WXK_LEFT: 
      self.sel = self.sel - 1 
      if self.sel < 0: 
       self.sel = len(self.chk) - 1 
      imgs() # invocking the function made for displaying fullscreen images when left arrow key is pressed 
     elif keys == wx.WXK_RIGHT: 
      self.sel = self.sel + 1 
      if self.sel > len(self.chk) - 1: 
       self.sel = 0 
      imgs() # doing the same for the right arrow 
     elif keys == wx.WXK_ESCAPE: 
      frm.Destroy()  
     eve.Skip() 
    frm.Bind(wx.EVT_CHAR_HOOK, pressk) 
    def imgs(): # building the function 
     imgsl = self.chk[self.sel] 
     itm = wx.Image(str('imgs/{0}'.format(imgsl)), wx.BITMAP_TYPE_JPEG).ConvertToBitmap() # obtaining the name of the image stored in the list   self.chk 
     mar = itm.Size # Because not all images are landscaped I had to figure a method to rescale them after height dimension, which is common to all images 
     frsz = frm.GetSize() 
     marx = float(mar[0]) 
     mary = float(mar[1]) 
     val = frsz[1]/mary 
     vsize = int(mary * val) 
     hsize = int(marx * val) 
     panl = wx.Panel(frm, -1, size = (hsize, vsize), pos = (frsz[0]/2 - hsize/2, 0)) # making a panel container 
     panl.SetBackgroundColour('#000000') 
     imag = wx.Image(str('imgs/{0}'.format(imgsl)), wx.BITMAP_TYPE_JPEG).Scale(hsize, vsize, quality = wx.IMAGE_QUALITY_NORMAL).ConvertToBitmap() 
     def destr(eve): # unprofessionaly trying to destroy the panel container when a new image is generated hopeing the unvanted effect, with previous generated images will disappear. But it doesn't. 
      keycd = eve.GetKeyCode() 
      if keycd == wx.WXK_LEFT or keycd == wx.WXK_RIGHT: 
       try: 
        panl.Destroy() 
       except: 
        pass 
      eve.Skip() 
     panl.Bind(wx.EVT_CHAR_HOOK, destr) # the end of my futile tries 
     if vsize > hsize: # if the image is portrait instead of landscaped I have to put a black image as a container, otherwise in the background the previous image will remain, even if I use Refresh() on the container (the black bitmap named fundal) 
      intermed = wx.Image('./res/null.jpg', wx.BITMAP_TYPE_JPEG).Scale(frsz[0], frsz[1]).ConvertToBitmap() 
      fundal = wx.StaticBitmap(frm, 101, intermed) 
      stimag = wx.StaticBitmap(fundal, -1, imag, size = (hsize, vsize), pos = (frsz[0]/2 - hsize/2, 0)) 
      fundal.Refresh() 
      stimag.SetToolTip(wx.ToolTip('Esc = exits fullscreen\n<- -> arrows = quick navigation')) 
      def destr(eve): # the same lame attempt to destroy the container in the portarit images situation 
       keycd = eve.GetKeyCode() 
       if keycd == wx.WXK_LEFT or keycd == wx.WXK_RIGHT: 
        try: 
         fundal.Destroy() 
        except: 
         pass 
       eve.Skip() 
      frm.Bind(wx.EVT_CHAR_HOOK, destr) 
     else: # the case when the images are landscape 
      stimag = wx.StaticBitmap(panl, -1, imag) 
      stimag.Refresh() 
      stimag.SetToolTip(wx.ToolTip('Esc = exits fullscreen\n<- -> arrows = quick navigation')) 
    imgs() # invocking the function imgs for the situation when someone does double click 
    frm.Center() 
    frm.Show(True) 

감사 :

여기에 누군가가 목록 상자 항목을 더블 클릭을 수행 할 때 실행되는 코드입니다.

나중에 추가 :

캐치 내가 그것을 이미지의 제비를 가진 DVD에 대한 자동 실행 프리젠 테이션을 할 노력하고있어입니다. 어쨌든 다른 옵션이있는 경우 위의 코드 부분을 제대로 작동시키지 않아도됩니다. 이미 윈도우 이미지 뷰어를 사용하려했지만, 이상하게도 충분히 상대 경로를 인식하지 않고, 나는이

path = os.getcwd() # getting the path of the current working directory 
sel = listbox.GetSelection() # geting the value of the current selection from the list box 
imgname = memlist[sel] # retrieving the name of the images stored in a list, using the listbox selection, that uses as choices the same list 
os.popen(str('rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen {0}/imgsdir/{1}'.format(path, imgname))) # oepning the images up with bloody windows image viewer 

을 수행 할 때 내 프로그램은 하드 디스크에있는 때에 있다면 그것은 이미지 만 열립니다 CD/이미지 드라이브는 아무 것도하지 않습니다.

답변

0

wxPython 데모 패키지에 이미지 뷰어가 포함되어 있습니다. 나는 또한 정말로 간단한 것을 썼다 here. 어느 쪽이든 당신의 여정에서 당신을 도울 것입니다. 나는 당신이 당신의 패널/프레임을 재사용하고 있지 않다는 것을 의심하고, 대신 당신은 제대로 파괴되지 않은 오래된 것들을보고있다.