Opening a new window

Hi-

I'm working with this code (very slowly) and it works so far except when I go to add the new image it opens it in a new frame, why is this? is there some kind of update call that i can make to the original?

thanks

import wx
from time import time
import os
from fileLocator import *

app = wx.App(redirect=False)

class Frame(wx.Frame):
  
  """ main frame """
  
  def __init__(self):

    wx.Frame.__init__(self, None, title="myGuts", size=(1125,675), style=wx.DEFAULT_FRAME_STYLE)
    self.panel = wx.Panel(self, wx.ID_ANY)
    
    self.panel.SetBackgroundColour('black')

    shooter = wx.Button(self.panel, -1, "shoot", pos=(300,500))
    addImageButton = wx.Button(self.panel, -1, "add image", pos=(300,520))
    quitButton = wx.Button(self.panel, -1, "quit", pos=(300,540))
    
    self.Bind(wx.EVT_BUTTON, self.OnShoot, shooter)
    self.Bind(wx.EVT_BUTTON, self.OnCloseWindow, quitButton)
    self.Bind(wx.EVT_BUTTON, self.OnAddImage, addImageButton)
    
    toolbar = self.CreateToolBar()
    self.CreateStatusBar()
    
  def OnShoot(self, event):
    
    mainShooter = ScreenShooter()
    currentFileTime = (str(mainShooter.returnedTime()) + '.png')
    AddShot = AddImage(currentFileTime)
    AddShot.Show()
    
  def OnAddImage(self, event):
    
    AddShot = AddImage("moo.png")
    AddShot.Show()
    
  def OnCloseWindow(self, event):
    
    """ ask the user if they really want to quit """
    
    dial = wx.MessageDialog(None, 'Are you sure to quit?', 'Question',
    wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
    ret = dial.ShowModal()
    if ret == wx.ID_YES:
      self.Destroy()
    else:
      event.Veto()
    
class MyGuts(wx.App):
  
  """ this just instantiates the main frame and centers the window.. no arguments """
  
  def OnInit(self):
  
    self.frame = Frame()
    self.frame.CentreOnScreen()
    self.frame.Show()
    
    return True

class ScreenShooter():
  
  """ takes a screengrab of the screen (on a osx system) and saves to disc with a unix timestamp """
  
  def __init__(self):
    self.fileLocation = fileLocation()
    self.currentTimeFile = time()
    os.system(('screencapture -x ' + str(self.currentTimeFile) + '.png ') + self.fileLocation())
    
  def returnedTime(self):
    return self.currentTimeFile
    
class AddImage(Frame):
  
  """ this add an image based on the timestamp file passed to __init__ """
  
  def __init__(self, timeStampFile):
    
    Frame.__init__(self)
    
    image = wx.Image('boo.png', wx.BITMAP_TYPE_PNG)
    
    w, h = image.GetWidth(), image.GetHeight()
    
    scaledImage = image.Scale(w*.1, h*.1)
    
    scaledConvertedImage = scaledImage.ConvertToBitmap()
    
    self.bmp = wx.StaticBitmap(self.panel, bitmap=scaledConvertedImage, pos=(10, 10))

def main():
  app = MyGuts()
  app.MainLoop()
  
if __name__ == '__main__':
  main()

Dom wrote:

Hi-

I'm working with this code (very slowly) and it works so far except when I go to add the new image it opens it in a new frame, why is this?

Because you call "AddShot = AddImage("moo.png")" so you are creating a new instance of AddImage, and AddImage is a class that derives from your Frame class.

is there some kind of update call that i can make to the original?

Save a reference to the original and then use it to update the static bitmap that it is already showing. Don't create anything new.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!