5
$\begingroup$

I have created a grid, and also made a list of control objects(ex:inputfields, buttons, etc..). Then, I lay the list in my grid. There is no problem. However, the final layout takes a lot of time. I timed each operation and realized that the final grid layout is the one that takes up a huge chunk of time. Is there a better way of controlling the execution time of the graphics grid.

mygrid = ConstantArray["", {100, 100}]; mybutton1 = Button["Example", ImageSize -> {40, 50}]; myinput2 = InputField[x]; updatedlist = {}; updatedlist = ReplacePart[mygrid, {1, 2} -> mybutton1]; updatedlist = ReplacePart[updatedlist, {2, 3} -> myinput2]; Panel[GraphicsGrid[updatedlist, ImageSize -> {30, 40}, ContentSelectable -> True]]

The above code takes a lot of time to execute. I used the Timing function of mathematica to figure out which part took the long time to execute and it was the Panel[GraphicsGrid[updatedlist, ImageSize -> {30, 40}, ContentSelectable -> True]] part that was the longest. Because of this, my entire application has slowed down. Can I finetune my code to improve the performance? Look forward to hearing your inputs!

Based on the comments blow, I tried to use a grid for the updatedlist above, but the problem is, how can I set the ImageSize of the Gridwhich is an option for the GraphicsGrid and not Grid?

Thanks in advance,Anuk

$\endgroup$
1
  • $\begingroup$ you might want to mark your additional question in a more prominent fashion, e.g. using a bold heading like EDIT or such. See the Grid help for defining the ImageSize for items. $\endgroup$
    – Yves Klett
    Commented Feb 21, 2013 at 18:09

1 Answer 1

5
$\begingroup$

The reason for the slow response is that GraphicsGrid needs to convert $100\times 100 = 10000$ cells into graphics. For an interactive interface, you should use Grid instead of GraphicsGrid. If you do need graphics in the grid, they can be put into the cells of the Grid. You don't need to convert the entire layout into Graphics.

$\endgroup$
6
  • $\begingroup$ My idea is to have a customized layout that can dynamically change itself itself depending on the requirements of the user interface which is why I am using Graphicsgrid which provides a lot of options for ImageSize. For sake of testing I did do this, I put my list in Grid and placed it in GraphicsGrid. Even though the execution time is faster, the control buttons are way off in the layout the with their sides being cut, improperly displayed, etc. Converting the entire layout gives accurate graphical versions of control objects but takes up a lot of time. $\endgroup$
    – Anuk
    Commented Jan 30, 2013 at 6:38
  • 1
    $\begingroup$ @Anuk Sounds like you are having trouble correctly displaying your elements using Grid, and have gotten around this by the hack of pushing everything through GraphicsGrid instead. You should work on getting it to work properly in Grid. You could post a question with the problems you where facing there. $\endgroup$
    – jVincent
    Commented Jan 30, 2013 at 12:52
  • $\begingroup$ @jVincent, I tried to place the list containing the control objects such as popupmenu, input boxes in a grid. But the problem here is that I have to set the individual Itemsize of the control object.Can I set the ImageSize of the Grid? $\endgroup$
    – Anuk
    Commented Feb 21, 2013 at 16:02
  • $\begingroup$ @Anuk You could use scaled itemsizes and wrap the grid in a pane that has a fixed imagesize eg. Pane[Grid[{{1, 2}, {3, 4}}, ItemSize -> Scaled[0.5]], ImageSize -> 200] $\endgroup$
    – jVincent
    Commented Feb 21, 2013 at 23:10
  • $\begingroup$ @jVincent, even the ItemSize works, the control objects are not displayed properly at all times for different dimensions. Is there a magical number that scales to actual ImageSize of the control object that we specify? $\endgroup$
    – Anuk
    Commented Feb 22, 2013 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.