embedding grid in panel in wxpython - python

What is the proper way to embedd grid (wx.grid.Grid) into the panel? I tried the following code and got bizarre frame:
wx.Frame.__init__(self,wx.GetApp().TopWindow,size=(600,800),title='Material Properties')
self.GridPanel=wx.Panel(self,-1)
grid=wx.grid.Grid(self.GridPanel,-1)
grid.CreateGrid(10,10)
I cannot see an easy way to create a grid which can also have buttons as well as menubar and other related widgets. Is there any example which shows GUI of how to implement wx.grid to achieve some sort of spreadsheet which has tabs on it for manipulation. I seem to be lost on this.
I want to create two different grid and also want to add some buttons and additional functionalites to the frame containing the table. Is there any better way to do that in wxpython?

I wrote about grids quite a while ago on my blog. You might find the following articles helpful for putting a Grid onto a Panel:
http://www.blog.pythonlibrary.org/2010/04/04/wxpython-grid-tips-and-tricks/
http://www.blog.pythonlibrary.org/2010/03/18/wxpython-an-introduction-to-grids/
Once you have that figured out, you can easily put the panel into a Notebook. If you want to add buttons, create the buttons and then add them to the sizer (see second example). Adding a Toolbar to the frame is covered in the wxPython demo, but I covered it here too:
http://www.blog.pythonlibrary.org/2008/07/02/wxpython-working-with-menus-toolbars-and-accelerators/

Related

Grouping multiple buttons with absolute positioning in a layout

Is it possible to group buttons that are arbitrarily positionned with PyQt ?
There is the context :
I would like to code a visual programm to control a research system with specific geometry, through Python.
I expect this kind of result :
In this program, the buttons of "buttons group 3" are positionned is a specific geometry that does not fit in a grid. Those buttons are clickable and a click on them change their color.
I would like those buttons to be grouped together, in something like a layout, because it seems to be that it is coherent in order to change positions and sizes of layouts and window if needed.
I'm coding that with PYQT5,... but I cannot figure in PyQt5 how to code this group of buttons with specific geometry ?
Is it possible to group buttons that are arbitrarily positionned with PyQt ?
Thanks in advance for your advice, I feel I'm missing something in PyQt concept.

Exporting data and graphs from a python GUI into a single file

I have made a GUI with qt designer and python. In this GUI i have multiple tabs. In some tabs i display a matplotlib widget and in some tabs i display a textedit. After pressing a button lines will be plotted in the matplotlib widgets and in the textedit some data will be displayed. How can i get these matplotlib graphs and the data from the textedits into one file after pressing an 'export' button?
The question doesn't specify many constraints, but if one big honking image is sufficient, you can take snapshots of the relevant widgets using Qt5 or Qt4 and just tile them into gigantic image:
After calling QWidget::grab or Pixmap::grabWidget, find the most reasonable layout for all the widgets and calculate the total size. Then create one gigantic QPixmap and render them via QPainter::drawPixmap to the appropriate coordinates into the combined image.
Of course, this seems pretty ugly and questionable to me, but I'm not one to second-guess what you want to do either... just know that I realize this is kind of icky.

Best way to dynamically display several images as a list or table in Qt?

I would like to dynamically add and display images in a list or a table, probably with a scroll bar in Qt. However, I do not know what is the best choice to do so.
Qt provides an example called FlowLayout. Newly added widgets get automatically arranged in grid-like manner. When the window gets resized, the arrangement of the grid is updated to accommodate the new layout dimensions.
In Qt, it serves as an example how to implement your own layout class derived from QLayout. Find useful documentation here:
http://doc.qt.io/qt-5/qtwidgets-layouts-flowlayout-example.html
Copy-paste the class and use it for example like this:
FlowLayout *flowLayout = new FlowLayout(this);
flowLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
for (int i=0;i<1000;i++)
flowLayout->addWidget(new MyWidget(i));

Adding many scrolledpanels to one scrolledPanel in wxPython

Level: Beginner
I am developing a GUI with wxPython on Windows 7 OS. Python version is 2.7 ad wxPython version is 3. My GUI looks as shown in the image below:
I would like to take some time to explain what I am trying to achieve. As you mayhave noticed from the first image that there are 4 different scrolled panels in my GUI named as panel-1 to panel-4. A vertical BoxSizer is applied to each scrolled panel. Each scrolled panel in return contains a boxsizer and a horizontal wx.StaticLine. The reason for using horizontal line was to make it is easier for the user to read the values for a particular serial number. (It will be easy for an user to read all the values in different panels for a particular serial number.) Finally all these four scrolled panels are added to a horizontal BoxSizer named as panelSizer. Currently the scrolled panels are scrolling individually. One important thing is that all the scrolled panels will every time contain same number of components/elements.
Problem:
I need a way so that I can add all these scrolled panels to one sizer or a panel in such a way that there is only one scroll bar at right side and when I scroll this scrollbar all the scrolled panels (panel-1 to panel-4) should scroll simultaneously. I would like to have something like this:
I think this option is better from the GUI perspective. I have tried couple of things like, I created a new scrolled panel named as main panel, and applied the BoxSizer named as panelSizer (it contains all the panel from panel-1 to panel-4) using SetSizer() function, but the scroll bar doesn't appears, even the individual scroll bars doesn't appear! Also, I have checked that there are enough components in the panels so that scroll bars appears. I tried to change the four scrolled panels to simple panels and then add to the panelSizer and then applied the sizer to the main panel but nothing solved the problem..
Can anyone suggest what is wrong with my approach? Any suggestion. Thank you for your time.
Well I found the solution myself so here it goes.
I have to disable scrolling on the panels-1 to panel-4. This can be done by not using SetupScrolling() method on them. Also, the scrolling should be enabled on the mainPanel like this:
mainPanel.SetupScrolling()
For an example: Consider that you have two scrolled panels named as panel1 and panel2. Now if you want to add these two scrolled panels to an other scrolled panel named as mainPanel, then you first create these two scrolled panels and then disable scrolling on them then add these two panels two a sizer, then apply this sizer to the mainPanel.
Code example:
mainPanel = wx.lib.scrolledpanel.ScrolledPanel(self, -1,style=wx.SIMPLE_BORDER)
mainPanel.SetupScrolling()
panel1 = wx.lib.scrolledpanel.ScrolledPanel(mainPanel, -1, style=wx.SIMPLE_BORDER)
panel2 = wx.lib.scrolledpanel.ScrolledPanel(mainPanel, -1, style=wx.SIMPLE_BORDER)
panelSizer = wx.BoxSizer(wx.HORIZONTAL)
panelSizer.Add(panel1)
panelSizer.Add(panel2)
mainPanel.SetSizer(panelSizer)

Python, matplotlib, wxpython - Anyway to move an canvas from one frame to another?

So I don't really have any code to show as it's a very large script I have currently. Having said that I will try and add a simple example shortly.
Basically lets say I have two frames in wxpython, each containing a single panel with a matplotlib canvas. Lets call these canvases graph1 and graph2.
So I know how to plot directly into graph1, using standard methods.
I was wondering if there is any way I could change the location of graph1 into that of graph2, i.e. move the plot to the second frame (window).
Basically I am trying to implement a full screen option for the user, which upon clicking a graph will maximise it into the second frame. I am hoping I can do this just by changing the references rather than re-drawing etc. as I want it to keep the original state of the graph when it maximises.

Categories