Python论坛  - 讨论区

标题:[python-chinese] wx.ScrolledWindow的scroll事件如何才能激发?

2008年01月09日 星期三 16:37

MaLi mali98765在gmail.com
星期三 一月 9 16:37:22 HKT 2008

EVT_SCROLLWIN Õâ¸öÓÃÏÂÀ´²»ÐУ¬²»ÖªÎªÉ¶£¬»¹ÊÇÐèÒª¶ÔscrollwinµÄ¸÷¸öʼþ½øÐе¥¶À´¦Àí£¬
ÏÂÃæÊǸÕÕÛÌÚ³öÀ´µÄ1¸öʾÀý£¬¿ÉÒÔ¶ÔͼƬ½øÐÐscroll£¬Óõ½µÄÏà¹ØʼþÊÇ£º
EVT_SCROLLWIN_THUMBRELEASE
EVT_SCROLLWIN_THUMBTRACK
EVT_SCROLLWIN_PAGEDOWN
EVT_SCROLLWIN_PAGEUP

#########################################################################
# -*- encoding: utf-8 -*-
import wx

class drawtmp(wx.ScrolledWindow):
    def __init__(self,parent):
        wx.ScrolledWindow.__init__(self, parent,style=wx.HSCROLL+wx.VSCROLL)
        self.SetScrollbars(1, 1, 1600, 1400)
        self.FitInside()
        img = wx.Image('d:\IMG_2899.JPG',type=wx.BITMAP_TYPE_ANY)
        self.photo = img.ConvertToBitmap()

        #»æͼÏà¶Ô×ø±ê
        self.posx = 0
        self.posy = 0

        self.InitBuffer()

        self.Bind(wx.EVT_PAINT,self.Onpaint)
        self.Bind(wx.EVT_SIZE,self.OnSize)
        self.Bind(wx.EVT_SCROLLWIN_THUMBRELEASE,self.scrollrelease)
        self.Bind(wx.EVT_SCROLLWIN_THUMBTRACK, self.scrolldrag)
        self.Bind(wx.EVT_SCROLLWIN_PAGEDOWN,self.Scrolldown)
        self.Bind(wx.EVT_SCROLLWIN_PAGEUP,self.Scrollup)

    def OnSize(self,evt):
        self.InitBuffer()

    def Onpaint(self,evt):
        dc = wx.BufferedPaintDC(self,self.buffer)

    # ²¶×½¶Ôscrollbar ½øÐÐÍÏÒ·µÄ¶¯×÷
    def scrolldrag(self,evt):
        scrollpos = evt.GetOrientation()
        #ÅжÏÔÚHorizon scroll£¬Ð޸ĻæͼÆðʼx×ø±ê
        if scrollpos == 4:  self.posx = evt.GetPosition()
        #ÅжÏÔÚVertical scroll£¬Ð޸ĻæͼÆðʼy×ø±ê
        if scrollpos == 8:  self.posy = evt.GetPosition()
        self.InitBuffer()

    #²¶×½ÍÏÒ·scrollbarºóÊͷŶ¯×÷
    def scrollrelease(self,evt):
        scrollpos = evt.GetOrientation()
        #±ØÐë½øÐÐSetScrollPos,²ÅÄܺÍEVT_SCROLLWIN_THUMBTRACKʼþºó×ø±ê±£³ÖÒ»Ö£»
        #¸ù¾Ýscroll·½Ïò·Ö±ðÉèÖÃ
        if scrollpos == 4:  self.SetScrollPos(4,self.posx)
        if scrollpos == 8:  self.SetScrollPos(8,self.posy)
        self.SetScrollPos(self.posx,self.posy)
        self.InitBuffer()

    # ÉèÖÃscrollµÄpageup¶¯×÷£¬×ø±êֵΪ¼õÉÙ
    def Scrollup(self,evt):
        scrollpos = evt.GetOrientation()
        if scrollpos == 4:  self.posx = self.posx - 50
        if scrollpos == 8:  self.posy = self.posy - 50
        self.Scroll(self.posx, self.posy)
        self.InitBuffer()

    # ÉèÖÃscrollµÄpagedown¶¯×÷£¬×ø±êֵΪÔö¼Ó
    def Scrolldown(self,evt):
        scrollpos = evt.GetOrientation()
        if scrollpos == 4:  self.posx = self.posx + 50
        if scrollpos == 8:  self.posy = self.posy + 50
        self.Scroll(self.posx, self.posy)
        self.InitBuffer()

    def InitBuffer(self):
        w,h = self.GetVirtualSize()
        self.buffer = wx.EmptyBitmap(w,h)
        #ÔÚÕâÀï²ÉÓà ClientDC £¬¶ø²»ÊÇ WindowDC
        dc = wx.BufferedDC(wx.ClientDC(self),self.buffer)
        #ÔÚscrolledwindowÏ»æͼÍƼöµÄÅäÖã¬ÔÚ´ËÀýÖвâÊÔϺÃÏñÎÞɶÓô¦
        self.DoPrepareDC(dc)
        self.DrawGraph(dc,self.posx,self.posy)

    def DrawGraph(self,dc,posx,posy):
        brush = wx.Brush('sky blue')
        dc.SetBackground(brush)
        dc.Clear()
        #×¢ÒâʹÓüõ×ø±ê»æͼ,²ÅÄÜÕýȷˢд°¿ÚͼƬ
        dc.DrawBitmap(self.photo,-posx,-posy,True)
        dc.DrawLine(10-posx,10-posy,100-posx,200-posy)


class SketchFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, "Sketch Frame", size=(800,600))
        self.sketch = drawtmp(self)
        self.Show(1)

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = SketchFrame(None)
    app.MainLoop()



ÔÚ07-12-28£¬clfff. peter <clfff.peter在gmail.com> дµÀ£º
>
> ÊÔÊÔ EVT_SCROLLWIN
>
> ÔÚ07-12-26£¬MaLi <mali98765在gmail.com> дµÀ£º
> >
> > *±í8.7 ¹ö¶¯ÌõµÄʼþ*
> >
> > EVT_SCROLL£ºµ±Èκιö¶¯Ê¼þ±»´¥·¢Ê±·¢Éú¡£
> >
> > EVT_SCROLL_BOTTOM£ºµ±Óû§Òƶ¯¹ö¶¯Ìõµ½ËüµÄ·¶Î§µÄ×îÄ©¶Ëʱ´¥·¢£¨µ×±ß»òÓұߣ¬ÒÀÀµÓÚ·½Ïò£©¡£
> >
> > EVT_SCROLL_ENDSCROLL£ºÔÚ΢ÈíµÄWindowsÖУ¬Èκιö¶¯»á»°µÄ½áÊø¶¼½«´¥·¢¸Ãʼþ£¬²»¹ÜÊÇÒòÊó±êÍ϶¯»ò°´¼ü°´Ï¡£
> >
> > EVT_SCROLL_LINEDOWN£ºµ±Óû§ÏòϹö¶¯Ò»ÐÐʱ´¥·¢¡£
> >
> > EVT_SCROLL_LINEUP£ºµ±Óû§ÏòÉϹö¶¯Ò»ÐÐʱ´¥·¢¡£
> >
> > EVT_SCROLL_PAGEDOWN£ºµ±Óû§ÏòϹö¶¯Ò»Ò³Ê±´¥·¢¡£
> >
> > EVT_SCROLL_PAGEUP£ºµ±Óû§ÏòÉϹö¶¯Ò»Ò³Ê±´¥·¢¡£
> >
> > EVT_SCROLL_THUMBRELEASE £ºÓû§Ê¹ÓÃÊó±êÍ϶¯¹ö¶¯Ìõ¹ö¶¯²»³¬¹ýÒ»Ò³µÄ·¶Î§£¬²¢ÊÍ·ÅÊó±êºó£¬´¥·¢¸Ãʼþ¡£
> >
> > EVT_SCROLL_THUMBTRACK£º¹ö¶¯ÌõÔÚÒ»Ò³ÄÚ±»Í϶¯Ê±²»¶ÏµÄ´¥·¢¡£
> >
> > EVT_SCROLL_TOP£ºµ±Óû§Òƶ¯¹ö¶¯Ìõµ½ËüµÄ·¶Î§µÄ×îʼ¶Ëʱ´¥·¢£¬¿ÉÄÜÊǶ¥¶Ë»ò×ó±ß£¬ÒÀÀµÓÚ·½Ïò¶ø¶¨¡£
> >
> > class drawtmp(wx.ScrolledWindow):
> >     def __init__(self,parent):
> >         wx.ScrolledWindow.__init__(self, parent,style= wx.HSCROLL)
> >         self.SetScrollbars(1, 1, 1600, 1400)
> >         self.FitInside()
> >         self.Scroll(10, 10)
> >         self.Bind(wx.EVT_SCROLL,self.OnScroll)
> >
> >     def OnScroll(self,evt):
> >         print "on scrolling"
> >
> > windows»·¾³Ï£¬ÉÏÃæµÄÕ⼸¸öʼþÈ«¶¼ÊÔ¹ýÁË£¬Êó±êÍÏÀ­£¬¹öÖᣬһµã¶¼Ã»¼¤·¢µÄÒâ˼£¬ÄѵÀÊÇ·½·¨´íÁË£¿
> >
> >
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20080109/74f39660/attachment-0001.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2024

    京ICP备05028076号