|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
more gradient issues for panel backgrounds
I know this comes up from time to time. I am trying to have a gradient as
the background of a panel and have managed to come to *some* success, but it is not all the way there yet. So I have two questions: 1) Would it be possible for wxPython to have a good approach for doing gradients, one that automatically dealt with the issues I will describe in the next point? I think this would be valuable. Gradients are "just" aesthetic, but aesthetics matter, I feel, and they are fairly highly associated these days with professional-looking software. Having to do some of the tricks that have been discussed on this group lately strikes me as unfortunate (I know, you can't have everything, but I am just throwing this out there). 2) Until that time, here is my issue. I have enclosed a runnable sample. What I've done is placed a few controls (using sizers) on a gradient background, and, since wxStaticText forces you to see the background and thus breaks the gradient there, I have drawn on text directly with the DC. I had been having problems with the gradient being broken after a resizing of the frame, but that seems to be fixed by calling .Refresh() after each resize. However, as you will see if you try it, after each resize, the DC-drawn text sometimes just isn't there (in this example you have to resize the frame for it to appear), it flickers quite noticeably, sometimes disappears, or becomes darker and kind of ugly. It's not acceptable. Anyone know how I can stop this behavior? My point (2) here is really not a great solution. There are other problems with gradients. is that buttons on a gradient have an extra pixel or so grey border around the edges, which is not pleasant. I know Andrea's nice ButtonPanel is useful for dealing with that, but, if AFAIK that only works with buttons that are specially made of transparent PNGs and not the standard wxButton. Another is that wxCheckBoxes are like wxStaticText and will show the frame's background as their background, and not the gradient they look ugly on a gradient. So, again, it would be nice if there were a built-in way to deal with these things, so that any standard widget from wxPython could sit on the gradient background nicely. Code follows. Thanks, Che # #Boa:Frame:Frame1 import wx def create(parent): return Frame1(parent) [wxID_FRAME1, wxID_FRAME1BUTTN1, wxID_FRAME1CHICE1, wxID_FRAME1PANEL1, wxID_FRAME1STATICTEXT1, wxID_FRAME1TEXTCTRL1, ] = [wx.NewId() for _init_ctrls in range(6)] class Frame1(wx.Frame): def _init_coll_boxSizer1_Items(self, parent): # generated method, don't edit parent.AddSpacer(wx.Size(25, 25), border=0, flag=0) parent.AddWindow(self.staticText1, 0, border=5, flag=wx.ALL) parent.AddSpacer(wx.Size(25, 25), border=0, flag=0) parent.AddWindow(self.choice1, 0, border=5, flag=wx.ALL) parent.AddSpacer(wx.Size(25, 25), border=0, flag=0) parent.AddWindow(self.textCtrl1, 0, border=5, flag=wx.ALL) parent.AddSpacer(wx.Size(8, 8), border=0, flag=0) parent.AddWindow(self.button1, 0, border=5, flag=wx.ALL) def _init_sizers(self): # generated method, don't edit self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL) (self.boxSizer1) self.panel1.SetSizer(self.boxSizer1) def _init_ctrls(self, prnt): # generated method, don't edit wx.Frameinit__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(276, 281), size=wx.Size(402, 489), style=wx.NFULL_REPAINTN_RESIZE | wx.DEFAULT_FRAME_STYLE, title='Frame1') self.SetClientSize(wx.Size(394, 455)) self.Bind(wx.EVT_PAINT, Frame1Paint) self.Bind(wx.EVT_SIZE, Frame1Size) self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self, pos=wx.Point(0, 0), size=wx.Size(394, 455), style=wx.NFULL_REPAINTN_RESIZE | wx.TAB_TRAVERSAL) self.panel1.Bind(wx.EVT_ERASE_BACKGRUND, Panel1EraseBackground) self.choice1 = wx.Choice(choices=[], id=wxID_FRAME1CHICE1, name='choice1', parent=self.panel1, pos=wx.Point(5, 78), size=wx.Size(130, 21), style=0) self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='textCtrl1', parent=self.panel1, pos=wx.Point(5, 134), size=wx.Size(100, 21), style=0, value='textCtrl1') self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1, label=u'Notice how background is showing in this staticText?', name='staticText1', parent=self.panel1, pos=wx.Point(5, 30), size=wx.Size(272, 13), style=0) self.button1 = wx.Button(id=wxID_FRAME1BUTTN1, label='button1', name='button1', parent=self.panel1, pos=wx.Point(5, 173), size=wx.Size(75, 23), style=0) self._init_sizers() def __init__(self, parent): self._init_ctrls(parent) def Panel1EraseBackground(self, event): event.GetDC().GradientFillLinear(self.GetClientRec t(), "white", "green", wx.NRTH ) def Frame1Paint(self, event): wx.PaintDC(self) dc = wx.ClientDC(self.panel1) dc.SetFont(wx.Font(12, wx.DEFAULT, wx.NRMAL, wx.NRMAL)) dc.SetPen(wx.Pen(wx.NamedColour('black'), 20)) dc.DrawText("This text is drawn on with DC",5,6) dc.SetFont(wx.Font(10, wx.DEFAULT, wx.NRMAL, wx.NRMAL)) dc.SetPen(wx.Pen(wx.NamedColour('black'), 18)) dc.DrawText("This text is also drawn on with DC",5,55) dc.SetFont(wx.Font(10, wx.DEFAULT, wx.NRMAL, wx.NRMAL)) dc.SetPen(wx.Pen(wx.NamedColour('red'), 18)) dc.DrawText("This text is also drawn on with DC",5,98) event.Skip() def Frame1Size(self, event): self.Refresh() event.Skip() if __name__ == '__main__': app = wx.PySimpleApp() frame = create(None) frame.Show() app.MainLoop() |
![]() |
| Viewing: Web Development Archives > Mailing Lists > Python > more gradient issues for panel backgrounds |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|