from wxPython.wx import *

############################################
# DEFINITIONS DES IDENTIFIANTS D'EVENEMENTS
############################################
ID_MENU_OPEN = 1001
ID_MENU_QUIT = 1002
ID_MENU_ABOUT = 1003

############################################
# CLASSE PRINCIPALE
############################################
class ViewerFrame(wxFrame):
  def __init__(self, parent, ID, title):
    wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, wxSize(640, 480))

    # icône de la fenêtre
    self.SetIcon(wxIcon("mainIcon.ico", wxBITMAP_TYPE_ICO));

    # menu help
    menuHelp = wxMenu()
    menuHelp.Append(ID_MENU_ABOUT, "&About...\tCtrl-A", "About this program")

    # menu file
    menuFile = wxMenu()
    menuFile.Append(ID_MENU_OPEN, "&Open...\tCtrl-O", "Open a bitmap picture")
    menuFile.Append(ID_MENU_QUIT, "E&xit\tAlt-X", "Quit this program")

    # barre de menus
    menuBar = wxMenuBar()
    menuBar.Append(menuFile, "&File")
    menuBar.Append(menuHelp, "&Help")
    self.SetMenuBar(menuBar)

    # événements
    EVT_MENU(self, ID_MENU_OPEN, self.OnOpen)
    EVT_MENU(self, ID_MENU_QUIT, self.OnQuit)
    EVT_MENU(self, ID_MENU_ABOUT, self.OnAbout)

    # barre de statut
    self.CreateStatusBar(2)
    self.SetStatusText("BMP Viewer", 0)
    self.SetStatusText("<No Bitmap>", 1)

    # panneau défilant
    self.scrollPane = wxScrolledWindow(self , -1, wxDefaultPosition, wxDefaultSize, wxHSCROLL | wxVSCROLL);
    self.bitmap = wxStaticBitmap(self.scrollPane, -1, wxBitmap("gfxsign.bmp"));

  def OnOpen(self, event):
    # ouverture d'un fichier
    dialog = wxFileDialog(self, "Choose a bitmap", "", "", "BMP files (*.bmp)|*.bmp", wxOPEN)
    if dialog.ShowModal() == wxID_OK:
      self.SetStatusText(dialog.GetFilename(), 1);
      bmp = wxBitmap(dialog.GetFilename(), wxBITMAP_TYPE_BMP)
      self.scrollPane.SetScrollbars(5, 5, bmp.GetWidth() / 5, bmp.GetHeight() / 5)
      self.bitmap.SetBitmap(bmp)

  def OnQuit(self, event):
    # fermeture
    self.Close(true)

  def OnAbout(self, event):
    # A propos...
    wxMessageBox("Bitmap Viewer\n(C)2002 Romain Guy - 05/16/2002", "About...",
                 wxOK | wxICON_INFORMATION, self);

############################################
# APPLICATION
############################################
class ViewerApp(wxApp):
  def OnInit(self):
    frame = ViewerFrame(NULL, -1, "BMP Viewer")
    frame.CenterOnScreen()
    frame.Show(true)
    self.SetTopWindow(frame)
    return true

app = ViewerApp(0)
app.MainLoop()
