0

多数のサムネイル画像を含むアプリケーション用のパネルを作成しています。それらはすべてウィンドウに収まらないため、ScrolledWindow を使用してそれらを保持し、ユーザーがスクロールして表示できるようにしています。

サムネイル画像の生成には時間がかかるため、現在ウィンドウに表示されているサムネイルの画像の作成を優先しようとしています。また、どのサムネイルが表示されているかをキャプチャして、サムネイルのサブセットを追加または削除した場合に、スクロールバーをどこに配置して、以前に表示されていたものをできるだけ多く含めるかを把握したいと考えています。

私が抱えている問題は、子ウィンドウが ScrolledWindow のクライアント領域に再配置される前に EVT_SCROLLWIN がポストされたように見えることです。つまり、スクロールバーが移動する前から表示されているオブジェクトを測定しています。次の方法はありますか: a) ScrolledWindow に強制的に子ウィンドウの位置を更新させる、b) 新しいクライアント ウィンドウのオフセットが現在と比較してどうなるかを確実に判断する、または c) この更新が発生した後にイベント ハンドラーを呼び出す?

問題があれば、このコンピューターで Python 2.7.11 と wxPython 3.0.2.0 を実行しています。

コード セグメントは次のとおりです。

class ThumbsViewer(wx.ScrolledWindow):
    def __init__(self, parent, info, style = wx.BORDER_RAISED | wx.HSCROLL):
        wx.ScrolledWindow.__init__(self, parent = parent, id = wx.ID_ANY, size = wx.DefaultSize, 
                                   pos = wx.DefaultPosition, style = style, name = "ThumbsViewer")

        self.__info__ = info
        self.__bitmapctrls__ = []
        self.__selected__ = []
        self.__lastclicked__ = []

        self.Bind(wx.EVT_SCROLLWIN, self.__OnScroll__)

        # ... Code to generate placeholder thumbnails, arrange buttons, size window, etc. ...


    # ... Various functions to handle clicking on thumbnails, etc. ...


    # EVT_SCROLLWIN Handler - Measure client window positions and determine which are
    #                         visible on the screen.  
    def __OnScroll__(self, event):
        if event:
            event.Skip()

        priority = []
        clientsize = self.GetClientSize()

        for ctrl in self.__bitmapctrls__:
            pos = ctrl.GetPosition()
            size = ctrl.GetSize()

            # Test to see if any part of the thumbnail control falls within the client
            # area...append to the priority list if it does.

            # This appears to be where the problem is - the child window positions
            # have not been updated to reflect the new scrollbar position yet.

            if (((pos[0] >= 0 and pos[0] <= clientsize[0]) or (pos[0] + size[0] >= 0 and pos[0] + size[0] <= clientsize[0]))
                    and ((pos[1] >= 0 and pos[1] <= clientsize[1]) or (pos[1] + size[1] >= 0 and pos[1] + size[1] <= clientsize[1]))): 
                priority.append(ctrl.GetPage())

        self.__info__.SetPriorityPages(priority)
4

1 に答える 1