problem with array of wxPanel

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.
Eman
Experienced Solver
Experienced Solver
Posts: 68
Joined: Sat Aug 31, 2019 2:11 pm

problem with array of wxPanel

Post by Eman »

Hello,
My Application has 2d array of wxPanel. I drew them in grid sizer. if array size is 8*8, 16*16, 32*32, 64*64, there is no problem to display the grid. But, when the size of array is 256*256, the app takes long time, then display error: Create input context failed: Timeout was reached.
NOTE: I assigned IDs for the wxPanel starting from 1

Any help is highly appreciated.
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: problem with array of wxPanel

Post by New Pagodi »

If you're on windows, there is a limit to the number of windows your allowed to create:
There is a theoretical limit of 65,536 user handles per session. However, the maximum number of user handles that can be opened per session is usually lower, since it is affected by available memory. There is also a default per-process limit of user handles. To change this limit, set the following registry value:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\USERProcessHandleQuota

This value can be set to a number between 200 and 18,000.
link
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: problem with array of wxPanel

Post by doublemax »

Yes, the default value is 10000, so you're way over that limit. Depending on what you actually want to do, you should try a custom drawn panel. Eventually a wxGrid might work, but that depends on the task at hand.
Use the source, Luke!
Eman
Experienced Solver
Experienced Solver
Posts: 68
Joined: Sat Aug 31, 2019 2:11 pm

Re: problem with array of wxPanel

Post by Eman »

I am on Linux(Ubuntu) installed on Mac
256*256 = 65536
should I made changes on the system to accept this.
or any suggestions
because what I need is displaying a grid of squares (256*256) (wxPanels) , and according to specific calculations, the color of some panels is changed.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: problem with array of wxPanel

Post by doublemax »

I am on Linux(Ubuntu) installed on Mac
256*256 = 65536
should I made changes on the system to accept this.
I don't know if similar limits exist on other platforms that Windows.
because what I need is displaying a grid of squares (256*256) (wxPanels) , and according to specific calculations, the color of some panels is changed.
Do you only need to change the color of the panel? Then it's definitely easier to have a custom drawn panel and draw the colored rectangles yourself.
Use the source, Luke!
Eman
Experienced Solver
Experienced Solver
Posts: 68
Joined: Sat Aug 31, 2019 2:11 pm

Re: problem with array of wxPanel

Post by Eman »

doublemax wrote: Sat Oct 03, 2020 2:58 pm Do you only need to change the color of the panel? Then it's definitely easier to have a custom drawn panel and draw the colored rectangles yourself.
Based on calculations, if i=3 and j=5, for example, then in the 2d array of wxPanels, I need to color the wxPanel in position (i,j)
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: problem with array of wxPanel

Post by doublemax »

Check this sample that fills a scrolled window with "colored" cells. By clicking you can toggle the color of each cell between white and black.
Number and size of the cells is set in the MyCanvas constructor.

This should get you started.
Attachments
minimal.cpp
(9.47 KiB) Downloaded 57 times
Use the source, Luke!
Eman
Experienced Solver
Experienced Solver
Posts: 68
Joined: Sat Aug 31, 2019 2:11 pm

Re: problem with array of wxPanel

Post by Eman »

Many thanks. It is helpful
class MyCanvas inherits from wxScrolledWindow, but I do not want a scroll in my App's grid. Could I achieve that?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: problem with array of wxPanel

Post by doublemax »

Eman wrote: Sun Oct 04, 2020 7:06 am Many thanks. It is helpful
class MyCanvas inherits from wxScrolledWindow, but I do not want a scroll in my App's grid. Could I achieve that?
Just comment out the SetScrollbars() call.
Use the source, Luke!
Eman
Experienced Solver
Experienced Solver
Posts: 68
Joined: Sat Aug 31, 2019 2:11 pm

Re: problem with array of wxPanel

Post by Eman »

Thanx for help. Could I use wxGrid (tables), and hide the row and column labels?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: problem with array of wxPanel

Post by doublemax »

Eman wrote: Mon Oct 05, 2020 9:51 pm Thanx for help. Could I use wxGrid (tables), and hide the row and column labels?
Theoretically, yes. But i doubt this would make your life easier. Of course it all depends on what the final goal is.
Use the source, Luke!
Eman
Experienced Solver
Experienced Solver
Posts: 68
Joined: Sat Aug 31, 2019 2:11 pm

Re: problem with array of wxPanel

Post by Eman »

I have int **grid that contains 0 and 1

if grid[0][0] is 0 I want to color the wxGrid [0][0] with white
if grid[3][4] is 1 I want to color the wxGrid [3][4] with black

I do not need wxGrid cells to be clickable
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: problem with array of wxPanel

Post by doublemax »

You'll need a custom wxGridCellRenderer for that. Check the "grid" sample that comes with wxWidgets and search for "MyGridCellRenderer".
Use the source, Luke!
Eman
Experienced Solver
Experienced Solver
Posts: 68
Joined: Sat Aug 31, 2019 2:11 pm

Re: problem with array of wxPanel

Post by Eman »

Can I add empty label or any object that does not consume memory in wxGridSizer of size 256*256
This is my app:
main.cpp

Code: Select all

#include <wx/wx.h>
#include "GUI.h"



// application class
class myApp : public wxApp
{
public:
	// function called at the application initialization
	virtual bool OnInit();

};

IMPLEMENT_APP(myApp);

bool myApp::OnInit()
{
	GUI *gui = new GUI(wxT("My App"));
    gui->Show(true);

    return true;
}
GUI.h

Code: Select all

#include <wx/wx.h>
#include <wx/grid.h>


#ifndef GUI_H
#define GUI_H

class GUI : public wxFrame
{
private:
	wxGridSizer *gridMap;
	int **grid;
	const wxWindowID sButtonId = 5000; // start button id
	const wxWindowID gButtonId = 6000; // goal button id
public:
	GUI(const wxString& title);
	~GUI();
};

#endif // GUI_H
GUI.cpp

Code: Select all

#include "GUI.h"

GUI::GUI(const wxString& title)
        : wxFrame(NULL, -1, title, wxPoint(-1, -1), wxSize(900, 900))
{
  wxPanel *panel = new wxPanel(this, -1);

  wxBoxSizer *vboxMap = new wxBoxSizer(wxVERTICAL);
  wxBoxSizer *vboxControls = new wxBoxSizer(wxVERTICAL);
  wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);

  int row = 256;
  int col = 256;
  
  grid = new int*[row];
  for(int i=0 ; i<row ; i++)
	  grid[i] = new int[col];
  for(int i=0; i<row ; i++)
	  for(int j=0; j<col ;j++)
		  grid[i][j] = 0;
		  
	grid [2][2] = 1;
	grid [3][3] =1;
	
	gridMap = new wxGridSizer(row,col,0,0);
	  for(int i=0; i<row ; i++)
		  for(int j=0; j<col ;j++)
			  gridMap->Add(); // Adding wxPanel will consume memory
	  
	
  vboxMap->Add(gridMap);
  
  wxButton *startButton = new wxButton(panel, sButtonId, wxT("Set Start"));
  //startButton->Connect(sButtonId, wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(GUI::OnButtonClicked),NULL,this);
  
  wxButton *goalButton = new wxButton(panel, gButtonId, wxT("Set Goal"));
 // goalButton->Connect(gButtonId, wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(GUI::OnButtonClicked),NULL,this);
  
 
  vboxControls->Add(startButton);
  vboxControls->Add(goalButton);

  
  hbox->Add(vboxMap, 1, wxEXPAND);
  hbox->Add(vboxControls, 0, wxALIGN_RIGHT, 10);
  
  panel->SetSizer(hbox);

  Centre();
}

GUI::~GUI() 
{
}


User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: problem with array of wxPanel

Post by doublemax »

Can I add empty label or any object that does not consume memory in wxGridSizer of size 256*256
If you want to set individual colors to it, no.

So now you're discarding everything i said so far and try to use wxPanels again?

Please explain to me why my first suggestion with demo code does not work for you.
Use the source, Luke!
Post Reply