[wxPython] Tooltip mit Image

Code-Stücke können hier veröffentlicht werden.
Benutzeravatar
snakeseven
User
Beiträge: 405
Registriert: Freitag 7. Oktober 2005, 14:37
Wohnort: Berlin
Kontaktdaten:

[wxPython] Tooltip mit Image

Beitragvon snakeseven » Dienstag 12. Februar 2008, 14:25

Hi,
hier wieder eine meiner kleinen Übungen zum Verständnis von wxPython. Manch einer kann das vieleicht gebrauchen?

Gruß, Seven


Code: Alles auswählen

''' a window with an jpg-image pops up when entering a panel
'''

import wx
from time import sleep



class MainFrame(wx.Frame):
   
    def __init__(self): 
        wx.Frame.__init__(self, None, -1, title = "Main Frame", size = wx.Size(200, 150))
       
        # the main panel
        whitepanel = wx.Panel(self, size = (200, 150))
        whitepanel.SetBackgroundColour(wx.Colour(255, 255, 255, 255))
       
        # the 2nd panel
        redpanel = wx.Panel(whitepanel, pos = (45, 22), size = (100, 70))
        redpanel.SetBackgroundColour(wx.Colour(255, 0, 0, 255))
       
        # the bindings for entering and leaving the 2nd panel
        redpanel.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterPanel)
        redpanel.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeavePanel)

       
        self.Show()
       
       
       
       
    def OnEnterPanel(self, event):
        global PW
       
        # the delay time before the window pops up
        sleep(0.25)
       
        # the position of the main frame
        winpos = self.GetPosition()
       
        # x-, y- position of the mouse
        mousex = wx.MouseEvent.GetX(event) + winpos[0]
        mousey = wx.MouseEvent.GetY(event) + winpos[1] + 100

        # call the popup window
        PW = Popupwindow(mousex, mousey)
       



    def OnLeavePanel(self, event):
       
        # destroy the popup window on leaving the red panel
        PW.Destroy()




class Popupwindow(wx.MiniFrame):   
   
    def __init__(self, mx, my): 
       
        # get the image and convert it to bitmap
        jpg = wx.Image('''path_to_your_image'''+ 'image.jpg', wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
       
        # get the width and height of the image
        wd = jpg.GetWidth();  ht = jpg.GetHeight()
       
        # wx.MiniFrame: a window without border and title bar.        wx.MINIMIZE_BOX: the window should not be placed in the task bar
        wx.MiniFrame.__init__(self, None, -1, pos = (mx, my), size = wx.Size(wd+150, ht+50), style = wx.MINIMIZE_BOX)
       
        # paints the popup window light yellow
        self.SetBackgroundColour(wx.Colour(252, 254, 214, 255))
       
        # place the image
        wx.StaticBitmap(self, -1, jpg, (10, 20), (wd, ht))
       
        # place the text
        wx.StaticText(self, -1, " Dies ist Zeile 1\n\n Dies ist Zeile 2\n\n Dies ist Zeile3\n\n Dies ist Zeile 4", (wd+40, 40))
       
       
        self.Show()
       
       
       
       
class MyApp(wx.App):
   
    def OnInit(self):
        MF = MainFrame()
        return True
   
   
   
app = MyApp(0)
app.MainLoop()

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder