wx/led problems

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Cittamatra
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Nov 16, 2018 8:36 pm

wx/led problems

Post by Cittamatra » Mon Feb 10, 2020 11:17 am

Hi all,

I am trying to get a simple widgets application to work using wx/led.h
The way I'm doing it is to drag a panel onto the wxFrame. Inside the panel, drop a FlexGridSizer, and into that, drop a few LEDs.

The first problem is, the panel wants to cover the entire wxFrame. I can't make it cover just a limited area of the frame. But, If I drag a button onto the wxFrame, the panel seems to behave itself, and covers a small area, as desired. If I remove the button, the panel jumps back, to cover the entire frame area.

The second problem is the LED appearance, or lack-of. When the 'Show Preview' button is pressed, the LEDs appear in the panel/FlexGridSizer area. But, when compiled and run, nothing appears.

I was wondering if anyone could throw any light on this problem? I've attached the simple project.

Thanks,

Paul
LED test v1.zip
(1012.07 KiB) Downloaded 11 times

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2231
Joined: Sun Jan 03, 2010 5:45 pm

Re: wx/led problems

Post by PB » Mon Feb 10, 2020 12:23 pm

Cittamatra wrote:
Mon Feb 10, 2020 11:17 am
The first problem is, the panel wants to cover the entire wxFrame. I can't make it cover just a limited area of the frame.
That is by design, if a wxTopLevelWindow(wxFrame, wxDialog) has exactly one child and no sizer, the child will cover its entire client area.

I just use a wxPanel as the only child of a wxFrame and add the controls as its children. wxFrame has an "odd" background colour by default and IIRC does not even support tabbing between its children.

Cittamatra
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Nov 16, 2018 8:36 pm

Re: wx/led problems

Post by Cittamatra » Mon Feb 10, 2020 4:06 pm

Ok, thanks for that. That is a bit more clear now. I still have problems getting LEDs to appear on the panel though. I actually had one GUI, where 2 LEDs appeared inside a panel/FlexGridSizer, but, when I add more LEDs, they don't appear at runtime. I've tried everything.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3896
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wx/led problems

Post by ONEEYEMAN » Mon Feb 10, 2020 5:31 pm

Hi,
Did you call "Layout()"?
If you did - can you post some code?

Thank you.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2231
Joined: Sun Jan 03, 2010 5:45 pm

Re: wx/led problems

Post by PB » Mon Feb 10, 2020 5:44 pm

I am not familiar with wxLed but I tried to look at the project you attached.

Seems broken to me, led.cpp does not match led.h. For example, the declaration and definition of wxLed ctor is different (3 colors in declaration, 2 in definition), a missing declaration for SwitchOn/Off() methods. Seems that the header file lacks those "PJG" modifications, whatever it is.

I skimmed the frame ctor but I did not see any obvious mistake. However, I do not understand why are using wxFlexGridSizer when all its items are of the same size?

EDIT
Actually, there is at least one issue. Button1 is not a part of a sizer. You must assign it to some. Did you mean to add it to the same sizer as the leds? If so, it must have the same parent as they do (i.e., Panel1)

Cittamatra
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Nov 16, 2018 8:36 pm

Re: wx/led problems

Post by Cittamatra » Tue Feb 11, 2020 9:59 am

PB wrote:
Mon Feb 10, 2020 5:44 pm
Seems broken to me, led.cpp does not match led.h. For example, the declaration and definition of wxLed ctor is different (3 colors in declaration, 2 in definition), a missing declaration for SwitchOn/Off() methods. Seems that the header file lacks those "PJG" modifications, whatever it is.
Yes, I added a dummy colour parameter in the ctor. I forgot to add the dummy to the definition. I'll add it now. I added a dummy because, when I drag an LED onto the frame, it auto-generates three colour parameters:

Led3 = new wxLed(Panel1,wxID_ANY,wxColour(128,128,128),wxColour(0,255,0),wxColour(255,0,0),wxDefaultPosition,wxDefaultSize);

The original LED code only had two colour parameters in the ctor, so it complained.
PB wrote:
Mon Feb 10, 2020 5:44 pm
I skimmed the frame ctor but I did not see any obvious mistake. However, I do not understand why are using wxFlexGridSizer when all its items are of the same size?
There wasn't any particular reason. I was just trying anything to get a row of LEDs to appear inside a panel. I tried all the different sizers.. Either No LEDs appear, or just two appear, and the rest are just empty space.

PB wrote:
Mon Feb 10, 2020 5:44 pm
EDIT
Actually, there is at least one issue. Button1 is not a part of a sizer. You must assign it to some. Did you mean to add it to the same sizer as the leds? If so, it must have the same parent as they do (i.e., Panel1)
I just placed Button1 inside wxFrame. I added Button1 separately from the LEDs/FlexGridSizer/Panel1. I added it because, having an extra object in the wxFrame stops the panel from defaulting its size over the entire wxFrame.

I found this updated LED widget, viewtopic.php?t=15679
This is exactly what I'd like to implement. A row of LEDs. Does anyone know how to port a new widget into wxWidgets?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3896
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wx/led problems

Post by ONEEYEMAN » Tue Feb 11, 2020 3:22 pm

Hi,
You should post to the wx-dev ML and ask the question if it will be taken.
If it is OK - clone the wxWidgets master from the GitHub following direction here.
Then make changes and use git diff to create a patch.
Open a ticket on the trac.wxwidgets.org and wait for it to be accepted.

Or create a for of the main wxWidgets repository.
Clone your fork.
Create a branch and make you changes.
Then push you changes to your own fork and create a "pull request".

Thank you.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2231
Joined: Sun Jan 03, 2010 5:45 pm

Re: wx/led problems

Post by PB » Tue Feb 11, 2020 6:01 pm

The code you linked is ... well, let's say interesting.

First time I saw a mutex used like this in a paint event handler. :o

Colors and bitmaps specified as char* is also an unusual choice... The use of goto is just an icing on a cake.

Anyway, I obtained a buildable version of wxLed from Code::Blocks source tree, as described here
http://forums.codeblocks.org/index.php? ... #msg124876

It seems as if wxLed was not designed with sizers in mind and does not override best size etc. methods. It seems to work just fine when adding it to a sizer with a fixed min size flag (or set its min size manually).
leds.png
leds.png (2.59 KiB) Viewed 194 times

Code: Select all

#include <wx/wx.h>

#include "led.h"

class MyFrame : public wxFrame
{
public:
    MyFrame() : wxFrame(NULL, wxID_ANY, "Test")
    {
        wxPanel* mainPanel = new wxPanel(this);
        wxBoxSizer* mainPanelSizer = new wxBoxSizer(wxVERTICAL);        
        wxBoxSizer* ledSizer = new wxBoxSizer(wxHORIZONTAL);
        
        ledSizer->Add(CreateLed(mainPanel, *wxRED), wxSizerFlags().Border().FixedMinSize());
        ledSizer->Add(CreateLed(mainPanel, *wxBLUE), wxSizerFlags().Border().FixedMinSize());
        ledSizer->Add(CreateLed(mainPanel, *wxGREEN), wxSizerFlags().Border().FixedMinSize());
        mainPanelSizer->Add(ledSizer);
        
        mainPanelSizer->Add(new wxButton(mainPanel, wxID_ANY, "This is a button"), wxSizerFlags().Expand().DoubleBorder());        
        
        mainPanel->SetSizer(mainPanelSizer);
    }
private:    
    wxLed* CreateLed(wxWindow* parent, const wxColour& onClr, bool on = true)
    {
        wxLed* led = new wxLed(parent, wxID_ANY, *wxLIGHT_GREY, onClr, *wxBLACK);        
        if ( on )
            led->SwitchOn();
        else
            led->SwitchOff();        
        return led;
    }
};

class MyApp : public wxApp
{
public:
    bool OnInit() override
    {
        (new MyFrame())->Show();        
        return true;
    }
}; wxIMPLEMENT_APP(MyApp);

Perhaps wxLed was designed to work with wxLedPanel, see http://svn.code.sf.net/p/codeblocks/cod ... tems/wxled

Anyway, try adding wxFIXED_MINSIZE sizer flag to your wxLeds and maybe all will be good.


I am attaching the buildable wxLed sources I got as described above, but I repeat, I find it horrible.
Attachments
led.zip
(2.64 KiB) Downloaded 6 times

Post Reply