wxPython GUI-wide settings - python-2.7

I have both a fundamental and technical wxpython question regarding GUI settings that are common to, and accessed by, many aspects of a single GUI.
In the interest of saving time I haven't cut/paste huge swathes of example code but I will explain it in words. I don't think I lose any clarity by doing so but shout if I do.
I have a wxpython GUI whose main feature is a notebook featuring many pages, the majority of which are data plots. Each page is defined according to unique class and while each class is different, they all access the same underlying data and are therefore fundamentally connected. Given this connection, there are some settings within the GUI that are common to all pages within the notebook. For example, the definition of the colour or shape of points on the various plots. Such settings may be used to define how the data is displayed e.g. car data may be red squares while bus data may be blue triangles.
Given that the plots on each notebook page are defined in separate classes, I could just repeat these definitions in each class. However, this feels like code duplication and since the colour/symbol definitions should be common across all plots, it feels like these definitions should be at the top GUI window level not at the notebook page level.
I have tried placing attributes within the top level window and I can access them from within a notebook page class using something along the lines of:
self.GetGrandParent(self).mySymbols
Where GetGrandParent is a crude way to work up the hierarchy of page /notebook / panel etc up to the main window. There may actually be more levels to traverse than just two.
My question is, is there a better way or more pythonic way to define GUI wide settings or attributes, once, at the top level (eg main frame) but access them from lower levels (eg notebook pages)?

Related

Style transfer on large image. (in chunks?)

I am looking into various style transfer models and I noted that they all have limited resolution (when running on Pixel 3, for example, I couldn't go beyond 1,024x1,024, OOM otherwise).
I've noticed a few apps (eg this app) which appear to be doing style transfer for up to ~10MP images, these apps also show progress bar which I guess means that they don't just call a single tensorflow "run" method for entire image as otherwise they won't know how much was processed.
I would guess they are using some sort of tiling, but naively splitting the image into 256x256 produces inconsistent style (not just on the borders).
As this seems like an obvious problem I tried to find any publications about this, but I couldn't find any. Am I missing something?
Thanks!
I would guess people split the model into multiple ones (for VGG it is easy to do manually, eg. via layers) and then use model_summary Keras function (or benchmarks) to estimate relative time it takes for each step and thus guide progress bar. Such separation probably also saves memory as tensorflow lite might not be clever enough to reuse memory storing intermediate activations from lower layers once they are not needed.

How to draw connections between items in a QTreeView

I wonder how to draw the lines connecting the items in a QTreeView as illustrated in the picture under Tree Model. My program will run on different platforms and thus use different styles. Can I guarantee that the items are drawn as desired?
I feel, using style sheets might be problematic because certain styles do not print such lines and using a delagate might lead me into issues of double drawing.
There's an example in the documentation here showing exactly what you want to achieve using style sheets.
Please note that when you use style sheets QStyleSheetStyle kicks in, irregardless from the QStyle your application is using at the moment. So if you decide to go this way you will override the look and feel of your control the same way, irregardless from the target platform.
If that is a problem, you may consider to use style sheets only for certain platforms. As an example:
#ifdef Q_OS_MAC
myControl->setStyleSheet(":/my_stylesheet_for_mac.qss");
#endif
Back to the example in the documentation, it uses a few images containing all the various lines (vertical, horizontal, branch, etc) and the ::branch subcontrol and its states to determine which image to use.
The result is something like this:
.
Obviously, you must change the code to show the vline picture instead of the arrows.
As a side node, I may suggest to consider why you want to do this if you are using native styles. If your application has a native look and feel, you should not alter it in any way. That is, if the target platform doesn't render lines to connect tree view items, then you shouldn't add those.
However, if your application is not required to look native across all the target platforms, you may consider using the same style (e.g. Fusion) and deliver the same user experience no matter what the platform is.

What's the difference between core data, essential data and sample data in hybris?

In the hybris wiki trails, there is mention of core data vs. essential data vs. sample data. What is the difference between these three types of data?
Ordinarily, I would assume that sample data is illustrative gobbledygook data created to populate the example apparel and electronics storefronts. However, the wiki trails suggest that core data is for non-store specific data and the sample data is for store specific data.
On the same page, the wiki states that core data contains cockpit and catalog definitions, email templates, CMS layout, and site definitions (countries and user groups impex are included in this as well). This seems rather store specific to me. Does anyone have an explanation for this?
Yes, I have an explanation. Actually a lot of this is down to arbitrary decisions I made on separating data between acceleratorcore and acceleratorsampledata extensions as part of the Accelerator in 4.5 (later these had y- prefix added).
Essential and Project Data are two sets of data that are used within hybris' init/update process. These steps are controlled for each extension via particular Annotations on classes and methods.
Core vs Sample data is more about if I thought the impex file, or lines, were specific to the sample store or were more general. You will notice your CoreSystemSetup has both essential and projectdata steps.
Lots of work has happened in various continents since then, so, like much of hybris now, its a bit of a mess.
There are a few fun bugs related to hybris making certain things part of essentialdata. But these are in the platform not something I can fix without complaining to various people etc.
To confuse matters further, there is the yacceleratorinitialdata extension. This extension was a way I hoped to make projects easier, by giving some impex skeletons for new sites and stores. This would be generated for you during modulegen. It has rotted heavily though since release, now very out of date.
For a better explanation, take a look at this answer from answers.sap.com.
Hybris imports two types of data on initialization and update processes; first is essentialdata and other one is projectdata.
Essentialdata is the coredata setup which is mandatory and will import when you run initialization or update.
sampledata is your projectdata and it is not mandatory it will import when you select project while updating the system.

What Mac/iOS/Portable library can I use for formatting information to print onto label paper?

I'm looking for an open source (or cheap commercial) library that handles the difficulty of formatting information for standard label paper (say Avery 5160) for example. I would like to use the library in a Mac and iPhone app. I saw this similar question for a dedicated label printer, but I am looking for a Mac compatible library that will work with label paper loaded into any printer:
What options are available to developers for printing to a dedicated label printer?
Alternatively, I'm interested in suggestions about my best strategy for doing it myself... I'm not up for figuring out the intricacies of many different paper formats - I would probably target just one kind of US Letter label paper and one kind of A4 label paper. Which are the most popular?
Having written a (closed source) Mac codebase that actually does this, I can tell you that it's not the most difficult thing in the world. My codebase only supports Avery labels. I have a resource file in the app with geometry info for each kind of label (number of rows, columns, margin sizes, gutter sizes, etc.). I use this to layout a grids of properly sized subviews of the main print view, where each subview is one label. Each subview is responsible for modifying the layout of its information to fit its size. Conceivably this could be done using Cocoa Autolayout now (my code predates Autolayout).
You can download a CSV version of my label dimensions file here.
EDIT: I might also mention that you'll need to do some significant extra work for a solution that works on both Mac and iOS. The printing APIs are quite different between the two platforms. Even if you use a custom view to do printing on iOS, UIView and NSView aren't exactly the same. Still, with some careful planning, you should be able to come up with something that at least shares common core code on both platforms.

How do I append a large amount of rich content (images, formatting) quickly to a control without using tons of CPU?

I am using wxWidgets and Visual C++ to create functionality similar to using Unix "tail -f" with rich formatting (colors, fonts, images) in a GUI. I am targeting both wxMSW and wxMAC.
The obvious answer is to use wxTextCtrl with wxTE_RICH, using calls to wxTextCtrl::SetDefaultStyle() and wxTextCtrl::WriteText().
However, on my 3ghz workstation, compiled in release mode, I am unable to keep tailing a log that grows on average of 1 ms per line, eventually falling behind. For each line, I am incurring:
Two calls to SetDefaultStyle()
Two calls two WriteText()
A call to Freeze() and Thaw() the widget
When running this, my CPU goes to 100% on one core using wxMSW after filling up roughly 20,000 lines. The program is visibly slower once it reaches a certain threshold, falling further behind.
I am open to using other controls (wxListCtrl, wxRichTextCtrl, etc).
Have you considered limiting the amount of lines in the view? When we had a similar issue, we just made sure never more than 10,000 lines are in the view. If more lines come in at the bottom we remove lines at the top. This was not using WxWidgets, it was using a native Cocoa UI on Mac, but the issue is the same. If a styled text view (with colors, formatting and pretty printing) grows to large, appending more data at the bottom becomes pretty slow.
Sounds like the control you are using is simply not built for the amount of data you are throwing at it. I would consider building a custom control. Here's some things you could take into account:
When a new line comes in, you don't need to re-render the previous lines... they don't change and the layout won't change due to the new data.
Try to only keep the visible portion plus a few screens of look-back in memory at a time. This would make it a little lighter... but you will have to do your own scroll management if you want the user to be able to scroll back further than your look-back and make it all appear to be seamless.
Don't necessarily update one line at a time. When there is new data, grab it all and update. If you get 10 lines really quickly, and you update the screen all at once, you might save on some of the overhead of doing it line by line.
Hope this helps.
Derive from wxVListBox. From the docs:
wxVListBox is a listbox-like control with the following two main differences from a regular listbox: it can have an arbitrarily huge number of items because it doesn't store them itself but uses OnDrawItem() callback to draw them (so it is a Virtual listbox) and its items can have variable height as determined by OnMeasureItem() (so it is also a listbox with the lines of Variable height).