PyGauge(wxPython Phoenyx)不会随Frame一起扩展 [英] PyGauge (wxPython Phoenyx) does not expand with Frame

查看:191
本文介绍了PyGauge(wxPython Phoenyx)不会随Frame一起扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在wx.pyGauge中添加几对或标记以指示最小,最大自定义限制.
这是代码:

I wanted to add a couple or marks into a wx.pyGauge to indicate min, max custom limits.
This is the code:

import wx
from wx.lib.agw.pygauge import PyGauge as PG
#
#
class AFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.gauge = GaugeBar(self)
        p1 = wx.Panel(self)
        p2 = wx.Panel(self)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(p1, 1, wx.EXPAND)
        self.sizer.Add(self.gauge, 0, wx.EXPAND)
        self.sizer.Add(p2, 1, wx.EXPAND)
        self.SetSizer(self.sizer)

        self.Fit()
        self.SetSize((400, 100))


class GaugeBar(PG):
    def __init__(self, parent, size=(-1, 20)):
        self.range_width = 14
        self.limit_min, self.limit_max = (3, 8)
        #
        PG.__init__(self, parent, -1, self.range_width, size, style=wx.GA_HORIZONTAL)
        #
        self.SetBackgroundColour('yellow')
        self.SetForegroundColour('red')
        #
        self.Bind(wx.EVT_PAINT, self.onPaint)
    #
    def onPaint(self, evt):
        dc = wx.PaintDC(self)
        dc.Clear()
        PG.OnPaint(self, evt)
        #
        w, h = dc.GetSize()
        #
        xmin = self.limit_min * w / self.range_width
        xmax = self.limit_max * w / self.range_width
        #
        dc.DrawText('|', xmin, -8)
        dc.DrawText('|', xmin, 10)
        dc.DrawText('|', xmax, -8)
        dc.DrawText('|', xmax, 10)

#
if __name__ == '__main__':

    app = wx.App()
    a_frame = AFrame(None)
    a_frame.gauge.SetValue(10)
    a_frame.Show()
    app.MainLoop()

压力表正确显示,带有两个红色标记和蓝色压力表级别.

The gauge appears correctly with the two red marks and the blue gauge level.

但是,当我水平延伸框架时,仪表液位指示器或红色标记都不会刷新以反映新的比例.

However, when I extend horizontally the frame, neither the gauge level indicator or the red marks are refreshed to reflect the new proportions.

有趣的是,如果我关闭并垂直延伸框架,它会因压力表和标记在正确的位置而得到刷新.

Interestingly, if I close and extend vertically the frame, it gets refreshed with the gauge and marks in the correct positions.

我做错了什么?这是一个错误吗?

What I am doing wrong ? Is this a bug ?

推荐答案

在Windows上,默认情况下,仅窗口的新显示区域会按调整大小绘制,其余部分则从更新区域中裁剪出来.因此,尽管您的onPaint被调用,但是窗口的现有部分将从绘图区域中排除.避免这种情况的最简单方法是在创建小部件时使用wx.FULL_REPAINT_ON_RESIZE样式,但是在某些情况下,您可能需要处理一些额外的闪烁.

On Windows, by default, only the newly exposed areas of a window are painted on resizes and the rest is clipped out of the update region. So although your onPaint is being called, the existing parts of the window are excluded from the drawing region. The easiest way to avoid this is to use the wx.FULL_REPAINT_ON_RESIZE style when creating the widget, however you may then need to deal with some extra flicker in some cases.

这篇关于PyGauge(wxPython Phoenyx)不会随Frame一起扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆