problem with array of wxPanel
problem with array of wxPanel
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.
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.
-
- Super wx Problem Solver
- Posts: 466
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: problem with array of wxPanel
If you're on windows, there is a limit to the number of windows your allowed to create:
linkThere 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.
Re: problem with array of wxPanel
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!
Re: problem with array of wxPanel
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.
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.
Re: problem with array of wxPanel
I don't know if similar limits exist on other platforms that Windows.I am on Linux(Ubuntu) installed on Mac
256*256 = 65536
should I made changes on the system to accept this.
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.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.
Use the source, Luke!
Re: problem with array of wxPanel
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)
Re: problem with array of wxPanel
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.
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!
Re: problem with array of wxPanel
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?
class MyCanvas inherits from wxScrolledWindow, but I do not want a scroll in my App's grid. Could I achieve that?
Re: problem with array of wxPanel
Thanx for help. Could I use wxGrid (tables), and hide the row and column labels?
Re: problem with array of wxPanel
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!
Re: problem with array of wxPanel
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
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
Re: problem with array of wxPanel
You'll need a custom wxGridCellRenderer for that. Check the "grid" sample that comes with wxWidgets and search for "MyGridCellRenderer".
Use the source, Luke!
Re: problem with array of wxPanel
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
GUI.h
GUI.cpp
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;
}
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
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()
{
}
Re: problem with array of wxPanel
If you want to set individual colors to it, no.Can I add empty label or any object that does not consume memory in wxGridSizer of size 256*256
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!