Save load in gui application - python-2.7

I try to make custom savefile for my GUI application.
In saving method I have something like this to save enabled status of all checkboxes.
enabledparams = [checkbox.isEnabled() for checkbox in self.tabParameters.findChildren(QtGui.QCheckBox)]
In loading method I should do this in backward sense, so to make enabled status from the saved
enabledparams
How to do this effectively in pythonic sense with minimum of code?
I have more of these cases for checked state of the boxes and also for a lot of spinboxes and textboxes.
Thank you in advance

the QSettings module of Qt would be useful to you. It provides functionality to save and load application settings.

Related

Qt/QML: Delay window rendering until data is available

I am building an application using Qt/QML. The QML of my main window is very complex and depends on lots of data which must be loaded via HTTP and then be processed by a C++ backend before it is ready to be displayed.
The C++ backend provides a signal which is fired when the data is ready. Until then, I want the window to be empty except for a simple loading indicator being displayed. Of course, I could use a simple overlay which hides my actual interface until the data is available, but this would mean that the QML code of my actual user interface is already loaded and tries to access the not-yet-available data, which is causing a lot of errors, so I would need to add dozens of dummy values and NOTIFY signals for each single property which might not yet be available.
What is the best way to completely deactivate a portion of QML code and to enable it as soon as a signal is triggered?
My personal experience is to not give data to your view components, don't bind them. For example, set your text value to an empty string or don't set it, set your image component source to an empty string or don't set it at first. When your signal comes in with data ready, you assign the data to the views at that time.

ListView in android for dynamic data

how to refresh List View dynamic data content in android?
I tried loading dynamic data for the List View in android application but no luck .Any advice how to accomplish this?
Call notifyDataSetChanged() on your Adapter object once you've modified the data in that adapter.
Some additional specifics on how/when to call notifyDataSetChanged() can be viewed in this Google I/O video.
Or else Look at this link.it may helpful.
Dynamic ListView in Android app
Or else
The right thing to do is to call notifyDataSetChanged() on your Adapter.
Troubleshooting
If calling notifyDataSetChanged() doesn't work all the layout methods won't help either. Believe me the list view was properly updated. If you fail to find the difference you need to check where the data in your adapter comes from.
If this is just a collection you're keeping in memory check that you actually deleted the item from the collection before calling the notifyDataSetChanged().
If you're working with a database or service backend you'll have to call the method to retrieve the information again (or manipulate the in memory data) before calling the notifyDataSetChanged().
The thing is this notifyDataSetChanged only works if the dataset has changed. So that is the place to look if you don't find changes coming through. Debug if needed.
UI Thread
It is true that this has to be called from the UI thread. Other answers have examples on how to achieve this. However this is only required if you're working on this information from outside the UI thread. That is from a service or a non UI thread. In simple cases you'll be updating your data from a button click or another activity/fragment. So still within the UI thread. No need to always pop that runOnUiTrhead in.
More Information
Another nice post about the power of list Views is found here:http://www.vogella.com/articles/AndroidListView/article.html

ActiveX Property Persistance

I have a question about an ActiveX Control I am developing. I have hashed my way through most problems but I am stuck at a real road block. This ActiveX is being imorted into other software so I have to have a good implementation of the Property Pages. I have managed to get some persistant properties working with one issue. When I make a change in the property page it is updated and persists as long as the application that is development app that is using it is open but it reverts back when I reload the app. I have narrowed this down to the fact that the development app doesnt realize the ActiveX has changed and therfore doesnt save. If i make a unrelated change and save the program all is good and the values persist as expected. I have tried everything and cant seem t get the application that imports my ActiveX to realize when it has changed via the property page. I am wondering if anyone has some work arounds for this type of problem. It seems to me if I could force the DoPropExchange() it would work but I dont know how to call this explicitly.
Thanks in advance
Matt
Thanks for the input. I did have the SetModifiedFlag() but it wasnt working. After poking at it I solved that problem but now I am redirecting my question. I had removed the property above in question from the idl files dispinterface in order to prevent the application that loads the activex from displaying the property in its "Connection List"(3rd party application specific"). It appears that the app loads all the interface into this list but this is not good as some properties should be persistant and only modifiable through the proppages. I tried all the flags like hidden and local but still were displayed in the list. When I removed it from the dispinterface it was how I wanted it but would not signal the IsModified. My new question is in there another way to define properties for an instance like this or is it possible to have a secondary interface(I have not tested if the application would see this interface because I am not sure how I would go about defining this inteface)or to have a property only between the proppage and control. Or is there another way to signal the dirty. The OnMemberVariable of the control was properly executing I know from testing it just seems SetModifiedFlag() doesnt do anything if the property is not in the dispinterface
Thanks Again
You need to mark your control as "modified", so that its host could detect it and re-save persistent properties. In this case IPersistXxx::IsDirty implemented by your control would indicate dirty state.
MFC based control has COleControl::SetModifiedFlag for this purpose:
Call this function whenever a change occurs that would affect your control's persistent state. For example, if the value of a persistent property changes, call this function with bModified TRUE.
Update: To hide a property from property browser you can use nonbrowsable attribute.
Use the [nonbrowsable] attribute to tag an interface or dispinterface member that should not be displayed in a properties browser.

How to save a session in a Qt application?

I made this tool in Qt Creator where i have to enter some data in spin boxes and combo boxes. Each of these boxes have a default value when I open my tool. But I would like to implement a function to save the session of the application, i.e. if i modify some values in the boxes i can save them and when I open my application again my modifications are there. And also when I am done with that data I can restore the defaults.
Any idea as to how to do this?
Use QSettings , it's usage is explained in the page

Why is CMFCMenuBar not utilizing the accelerator table?

In a doc/view project using VS2008, a MFCMenuBar seems to load the correct MENU resource (IDR_MAINFRAME) from the project, since adding and removing menu items is reflected in the menu's UI. It even appends the accelerators to the default menu items (e.g. Ctrl+O to the Open... item). However, the accelerator table (IDR_MAINFRAME) doesn't seem to be connected to the menu. Changing the default Ctrl+O for Open... to something like Ctrl+7 doesn't work. The Ctrl+O is still appended to the Open... menu item, and Ctrl+O still invokes the Open... handler. There is only one accelerator table in the resource file, so I have no idea where the CMFCMenuBar is getting its accelerator information.
At this point, I've been able to get the accelerators to work by manually loading the IDR_MAINFRAME accelerator table and translating messages myself. But the CMFCMenuBar is still appending the default accelerators.
Can anyone explain what is going on here? How can I force the MFCMenuBar to utilize my accelerator table and either not append the accelerators or append the correct accelerators?
Having just spent far too much time wrestling with this problem I thought I'd post the solution that appears to work for me.
I call :
theApp.GetKeyboardManager()->ResetAll();
after the MDI framework stuff has been loaded from the registry (I've created a specific function called PostLoadFrame() which I call immediately after calling LoadFrame() which is where the registry seems to get read).
This function call ignores any accelerators loaded from the registry (which is fine for me because I don't allow customisation of them anyway) and uses the accelerators in your resource file instead.
Like I said, it seems to be working for me in my application. If you do allow customisation of the accelerator keys, then it looks like it's possible to merge your resource file and the registry stored values with other functions in CKeyboardManager, but it's a bit more complicated.
I hope that helps somebody somewhere save some of the time I've lost!!
Apparently some CMFCMenuBar settings are persisted to the registry (HKCU I think.) Try clearing your application's registry settings and see if the correct accelerators are shown.
See this MSDN thread for some related CMFCMenuBar troubleshooting.