Does Qt5 accept Numpy float64? - c++

I'm making a QTableView based on a QStandardItemModel. I add data in the following fashion:
def addTableXYData(self,row):
label = 'Point '+str(row)
data = [label, self.x[row-1], self.y[row-1]]
for index, item in enumerate(data):
self.tableModel.setData(self.tableModel.index(row-1,index), item)
self.tableModel.layoutChanged.emit()
The strings for the label show up fine in the table, however it doesn't show the numbers. The numbers come from clicking points on a Matplotlib Qt Canvas, and are naturally numpy.float64 dtypes.
Is Qt5 capable of handling numpy.float64 datatypes? Or must I change it in to something else? I assume it may have something to do with PyQt5 using bindings to the C++ language, and maybe that can't handle it?
I've tried reading the docs on QVariant but it doesn't seem to tell me that I can't use floats.
Edit Instead of down-voting me without saying anything how about laying some wisdom on me and helping me out?

It turns out that PyQt5 does not possess the capability of sending numpy datatype classes to Qt5. It does native python classes like int(), float() etc. but not numpy.int32() etc. I assumed that would have been built-in functionality but, there ya go. The more you know.

Related

python tkinter radiobutton state

How do you get the state of a Button (clicked or unclicked)? This is a button state and not a question about variables set by the button. How do I tell if an object in a Frame is selected using i.winfo_class() to identify a Radiobutton.
i.e.
for i in a.winfo_children():
if i.winfo_class() == "Radiobutton":
i.get()
Radiobuttons have no get attribute so this will never work, but the logic is the same. I've looked through documentation without success.
The only solution is to get the value of the associated variable and compare it to the value of the radiobutton. If they are the same, that radiobutton is selected.
Found the solution. ttk.Radiobutton has more functionality than the tkinter.Radiobutton.
Please make note there there are major issues with all methods and values dereferences by Radiobuttons even now. Sometimes you get a pointer, sometimes you get a string and need to dereference yourself. This makes Radiobuttons a more difficult Widget to deal with than most of the others I've been working with. There are many documents on this and they are fixing this, but it is something to note.
For my purposes, tkinter.Radiobutton has no instate which means there is no simple way to check if it is clicked. I was getting pointer after pointer and dereferencing was far too tedious and complex to code for a dynamic gui.
The code I've ended up with is as follows:
for i in a.winfo_children():
if i.winfo_class() == "TRadiobutton" and i.instate(['selected']) is True:
return i.cget('value')
Also make note that TRadioButton string is used instead of RadioButton, the object type returned is not the same between ttk and tkinter implementations of Radiobutton.

Kivy: set ListProperty from kv language

I am using Kivy to build a simple app that would load different images in different tabs of a tabbed panel. The different Panel items should all behave similarly, but with different images, so I created a widget class. I am trying to initialize my app using the kv language like in many examples.
Currently, I am unable to make it work, because I cannot find how to pass the file names in a list from the kv language part to the widget instance. I am able to work with other Properties, but the ListProperty has me stumped.
Here is a snippet from my code:
Builder.load_string("""
<MyMainClass>:
#stuff
TabbedPanelItem:
MyClassLayout:
filenames: ['pic1.jpg', 'pic2.jpg', 'pic3.jpg', 'pic4.jpg']
#other TabbedPanelItems like the one above,
#with different strings in the list
""")
def MyMainClass(TabbedPanel):
pass
def MyClassLayout(FloatLayout):
filenames = ListProperty([])
#rest of my class
Things I already tried:
Use different parentheses in assigning the list in the kv language part: I tried () and {}, as well as with no parentheses.
Initialize the ListProperty differently: I tried putting some string in it already.
Send different lists: I tried sending numbers instead of strings.
The result is always that the filenames list in my widget is always at the default value. That would be [] in the snippet above, or whatever I set in its declaration in my class.
Would someone please point out what it is I am doing wrong?
Thanks.
I managed to fix this.
The issue was that I was trying to read the lists in the constructor. However, they receive their value from the kv lang part after the widget object has finished its constructor.
As a fix, I call the method that reads the list like so:
Clock.schedule_once(self.late_init, 0.02)
I hope people find this and it helps them.

How to use tango within Qtcreator

I have just started using Qt creator. I have created a simple form in QT4 designer and I used python for it. It is a simple form with two fields and a button. These two fields populate values from the device that I have defined in my jive.I am using the following statement in python to read the values from the device:
taurus.Attribute('device_name/instance_name/attribute_name').getDisplayValue()
This statement fetches the value of the attribute and I am appending this value to the text fields I have on the form.I have an "import taurus" statement in my python code.I am trying to do the similar thing in C++ but I am not sure on how we can read the values from the device defined in jive. So could you let me know how this can be achieved.
This question is really framework-specific. There isn't many Tango users on StackOverflow. Have a look at the QTango documentation on QTWatcher and QTWriter.
Here is a basic example where the attribute value from your device is linked to a ProgressBar:
QProgressBar *pbar = new QProgressBar(this);
QTWatcher *pbarWatcher = new QTWatcher(this);
pbarWatcher­->attach(pbar, SLOT(setValue(int)));
// configure maximum and minimum values when available
pbarWatcher­->setAutoConfSlot(QTWatcher::Min, SLOT(setMinimum(int)));
pbarWatcher-­>setAutoConfSlot(QTWatcher::Max, SLOT(setMaximum(int)));
pbarWatcher­->setSource("$1/short_scalar_ro");

Qt - Set global precision for all tables and models in a program

I will preface this question by mentioning I'm honestly not even sure what I'm trying to do is possible. I've worked with Qt for a while now and never tried to do anything like this, and I've found next to nothing online about how to accomplish my goal, so it may well not be something that Qt can do. I figured it still couldn't hurt to ask in case I'm overlooking something.
I am working on a very large project (~200 files/classes in all) in Qt Creator 3.0.1 (based on Qt 5.2.1). Within this program we have a lot of tables that display numeric data, using probably a dozen or so different model classes fr different tables.
Today my project lead requested that a feature be added to our settings (which we store using the QSettings class) to allow our users to set the decimal precision of any numeric data that is displayed in a table anywhere in the program. I know how to do this using std::setPrecision() and calling QSettings::value().toInt() to get the stored precision. However, it seems like that would have to be done explicitly every time a value is returned by a Model class's data() function, which would literally mean adding that function call hundreds of different places in our code. This seems extremely bulky and tedious, and also very prone to causing bugs, since with so many places in the code that would need it, it would be very easy to accidentally overlook places where it should be used. Also, this would be rather tedious in the future if we end up adding new dialogs with table displays and new models, since those new ones would also need that function called every time a number is needed.
It seems like a very simple, efficient, and elegant way to solve this issue would be if Qt had a way to store a global precision for not just one dialog or one model class, but for the entire project. That way, instead of needing to use setPrecision() every time a number is displayed in a dialog, the program would already know how many places after the decimal to show. It seems like using this as some kind of meta-variable for the program as a whole would save tons of time and effort changing everything over now and adding things in the future. However like I said above, I do not know if it is even possible in Qt to specify for a whole program something like precision in display dialogs. If anyone has any ideas how to do something like this, or any other way to specify precision in models without needing to refer to precision each time a value is added to a display, I'd really appreciate any help. Thanks!
Your models should not care about the format of displayed data. What you can do is to inherit from QStyledItemDelegate and override displayText method.
The method can look something like:
QString BaseItemDelegate::displayText(const QVariant &value,
const QLocale &locale) const
{
if (value.type() == QVariant::Double) {
//here you can retrieve precision of displayed double
//from some settings object
return QLocale().toString(value.toDouble(), 'f', 2);
}
return QStyledItemDelegate::displayText(value, locale);
}
Then you can attach this delegate to your views (QAbstractItemView::setItemDelegate()). Of course you must make your models to return double instead of preformatted strings.

How to use Openlayer refresh strategy with django-olwidget?

I would like to have "realtime" like map.
My main question is:
How to use django-olwidget with openlayers OpenLayers.Strategy.Refresh?
Do I need to start back "from scratch" to use manually openlayers?
With django-olwidget, the data is on the web page so the args which define data-source, protocol.
My "second" question is about which format should I choose...
geoJSON? kml? other?
Can those formats contain openlayers point specific "style" specifications like:
{'graphic_name': 'square', 'point_radius': 10, 'fill_color': "#ABBAAB', 'stroke_color':'#BAABBA'}.
I already overriden the default map template olwidget/multi_layer_map.html to access my map object in JS. I think it should be rather simple to apply a js function on each data layers before passing it to the map.
Thanx in advance.
PS: I'm french speaker.
PS2: I asked this question as a feature request on github: https://github.com/yourcelf/olwidget/issues/89
If you're going to use regularly-refreshing data (without refreshing the page) and serialization formats like geoJSON and KML, django-olwidget won't help you very much out of the box. You might find it easier just to use OpenLayers from scratch.
But if you really wanted to use django-olwidget, here's what I would do:
Subclass olwidget.InfoLayer to create a new vector layer type that uses a network-native format like geoJSON or KML to acquire its data.
Add a corresponding python subclass to be able to use it with Django forms or whatever the use case is. You'll probably need to specify things like the URL from which the map will poll its data.
This is a lot of work beyond writing for OpenLayers directly. The advantages would be that you would get easy Django form integration with the same map.
As to which serialization format to use: I'm partial to JSON flavors over XML flavors such as KML, but it really doesn't matter much -- Django and OpenLayers both speak both fluently.
About the styling,you should take a look at the StyleMap[1] where you can set style properties according to attributes.
For the main question, I’m sorry I don’t know django-olwidget…
1 - http://openlayers.org/dev/examples/stylemap.html