Sortable Kivy List - python

I'm creating a Kivy/Python app that generates a formatted report. The report itself is generated with pandas dataframes and then written to Excel. I'd like to add something to the UI that would allow users to apply custom sorting to the report.
So, for instance, if the dataframe has a "Category" field with values "Cat1", "Cat2", "Cat3", I'd like to add a feature where a user could organize those categories in a custom order.
What I'm envisioning is a list of items on the Kivy UI that a user could re-sort by dragging and dropping the items? Or, even just a simple list with an up/down arrow would suffice. I believe this is generally called a listbox, but I can't seem to find that widget in Kivy. Currently, I'm managing sorting by just having an external mapping document, but I'd like to integrate this into the app functionality instead.
Note: I'm not looking for detailed code or anything--just some ideas on what modules/widgets/approach might work here.
Any thoughts would be greatly appreciated!
Thanks

Store the data inside a list property.
Create a table out of a grid layout, on which you would like to show the content of the data list. The headers of the table would be buttons that do some sorting on the list. Each time the list changes, an on_data callback will be triggered. Use the callback to redraw the table rows.

Related

How to give each row of a MDDataTable a specific color working with kivymd?

I'm developing an app which fetches some numeric data from an api and manifests it in a MDDataTable(I'm using Kivymd). I need to give each row different color based on its numeric values. Is it doable in Kivymd and this specific class(MDDataTable)?If yes, how?
I appreciate your answers. thanks.
I just found a way to do that. But it may causes serious problems to your app. Each MDDataTable object has a data_table attribute. This attribute has a sub-attribute named data, which contains all cells of data in your table. Each cell is saved as a dictionary containing multiple items as its properties, which among them, "background_color_cell" is the one I was looking for. So all I had to do was to iterate over the data dictionary and change the background color.

Iterating over controls in wxPython in order to save session data

I have a GUI written in wxPython (with boa constructor).
I would like to save a user's session to a file, to be loaded the next time the application starts.
I would like to avoid saving each value 'by hand' by iterating over the controls and saving their values to a dictionary.
Is there a way to get a hold of all the wxIDs used in the application, and their corresponding widgets?
You don't need the IDs at all, just start from the top level window and recursively enumerate all the children using wxWindow::GetChildren() method. Then, for each child, you will need to dynamically determine its type (this is simpler if you only use controls of a few types) and save its value. You may also find it useful to specify the names (not labels) for your controls when creating them to have a more convenient unique identifier for each of them than a numeric ID.
IMHO you are going at this wrong. The state of a user's session is best not stored in the values of the controls. The state should be stored in a 'model'. The 'view' should query the model when it needs to display the state of the model, and when it wants to save the state to a file. http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller.
This makes lots of things easier, even trivial, including your problem.
I would look at the PersistenceManager mechanism in wx.lib.agw. Here are the original docs for it: http://xoomer.virgilio.it/infinity77/AGW_Docs/persist.persistencemanager.PersistenceManager.html
And here are the newer docs:
https://docs.wxpython.org/wx.lib.agw.persist.persistencemanager.PersistenceManager.html#wx.lib.agw.persist.persistencemanager.PersistenceManager
Alternatively, you can probably use the frame or panel's GetChildren() method to grab all the widgets and pull the values from them, but I think the PersistenceManager would make more sense.

How to filter by multiple lists in OpenERP?

How would you go about filtering one list based on a selection from a different list on the same page?
I'm trying to implement an interface similar to Warehouse Dashboard where multiple lists are on the same page but I need to filter each list based on a selection in the above list(s).
Thank you.
AFAIK, this is not possible. You should try to customize existing views and/or develop your own widget. Take a look at this question on how to start.
Moin you can fiter the listview when it display. But after display you can't filter the data on the bases of the other listview's selection.

Using custom role in QTreeView instead of DisplayRole

A simple question, (hopefully with a simple answer).
QTreeView will pass Qt.DisplayRole to the model's data function when fetching rows for display, by default.
But say I wanted to pass 'MyAwesomeTreeDisplayRole' instead of Qt.DisplayRole, what would I need to do?
I can't seem to find anything about where the view decides to use displayrole or how to override it.
Just before you ask why I want to do such awful things..
Basically, my QAbstractItemModel is intended to be usable both for a treeview (1 column) and a tableview (multiple columns, based on parent).
Using the same DisplayRole for both types of views doesn't really work, since then I'm forced to return the same data for both. This results in me only seeing the first column in the treeview when I want to return a concatenation of a couple of columns.
I think the simplest way would be to just use custom roles (TreeDisplayRole and TableDisplayRole).
Thanks in advance.
I don't know, how to do it in python, but you have to create your own delegate to render items data. Delegate is actually the object, that requests any data from indices and renders it
Note, that in common case QTreeView is able to show multiple columns, you should only have columnCount set incorrectly for top-level index
I've used QTreeView to view a simple table with many columns - it works well - you can adjust the column count by sending it the columnCountChanged signal. So I'm not sure you need to do what you are asking.
But I've used ItemDelegates too: use my_treeview.setItemDelegate() to point the treeview to your item delegate. If this subclasses QStyledItemDelegate then it doesn't need to do much work - it can mostly just pass it all through to super.
The user roles then are just agreed between your custom ItemDelegate and your ItemModel and can be anything you like as long as they are >= than QtCore.Qt.UserRole.
(Edit: Sorry, I put this in as a new answer but it's really just an elaboration on what Lol4t0 said - apart from the columnCountChanged thing)

Looking for a wxpython widget that would let user's fill in data like they would in a table

I want to have a table like display on one of panels where the user can fill in data into pre-made columns. I'm not sure what widget will give me this functionality. I want users to be able to edit elements they have already added, and to easily add another element. Any suggestions?
Look at Grid or ListCtrl to create the columns. I think Grid is a better choice for editing as you can add TextCtrls or the like to the columns.
Try out CSheet, it is much better and customizable than the standard wxGrid and has similar interface.
Try ListCtrl with TextEditMixin - it's pretty neat and offers keyboard navigation to move between cells.

Categories

Resources