Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use static method of class #80

Closed
remram44 opened this issue Jul 11, 2014 · 2 comments
Closed

Can't use static method of class #80

remram44 opened this issue Jul 11, 2014 · 2 comments

Comments

@remram44
Copy link

I ran into this trying to use PyQt4.QtGui.QMessageBox.information().

This doesn't work:

@pyimport PyQt4.QtGui as QtGui
QtGui.QMessageBox[:information](...)

But this does:

pyimport("PyQt4.QtGui")["QMessageBox"][:information](...)

(amazing job btw, this was my only issue running this PyQt code)

Some details:

julia> QtGui
__anon__

julia> QtGui.QMessageBox
fn (generic function with 1 method)

julia> QtGui.QMessageBox[:information]
ERROR: no method getindex(Function,Symbol)

julia> pyimport("PyQt4.QtGui")
PyObject <module 'PyQt4.QtGui' from '/usr/lib/python2.7/dist-packages/PyQt4/QtGui.so'>

julia> pyimport("PyQt4.QtGui")[:QMessageBox]
fn (generic function with 1 method)

julia> pyimport("PyQt4.QtGui")["QMessageBox"]
PyObject <class 'PyQt4.QtGui.QMessageBox'>

julia> pyimport("PyQt4.QtGui")["QMessageBox"][:information]
fn (generic function with 1 method)
@stevengj
Copy link
Member

The basic problem here is that arbitrary Julia objects are not callable (JuliaLang/julia#2403). So, when PyCall performs an automatic type conversion (as it does for QtGui.QMessageBox), it has to decide whether to convert an object to a Function (which makes it easy to call, but you can't do anything else with it), or leave it as a PyObject (which lets you do anything you want, but then you need to use pycall(...) to call it).

For type constructors, it seemed like what you wanted to do most of the time was to construct instances of the type by calling the constructor, so I defaulted to converting to a Function. But this means that, in order to access static members, you need to explicitly request the raw PyObject instead.

Here, you can do that by QtGui.pymember("QMessageBox"), with which you can then do QtGui.pymember("QMessageBox")[:information](...). Or call pyimport as you mentioned.

I couldn't think of a better syntax, but suggestions are welcome.

@remram44
Copy link
Author

I didn't think this was something you could fix without more support from Julia.

... you can then do QtGui.pymember("QMessageBox")[:information](...)

Nice! This is good enough for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants