The biggest diffence from Python is that object attributes/members are accessed witho[:attribute]rather thano.attribute
using PyCall
@pyimport PyQt4
@pyimport PyQt4.QtGui as Qt
@pyimport sys
app = Qt.QApplication(sys.argv)
## from gtk_doevent, tk_doevent pattern
qt_doevent(::Int32) = qt_doevent()
function qt_doevent()
app[:processEvents]()
end
global timeout
timeout = Base.TimeoutAsyncWork(qt_doevent)
Base.start_timer(timeout,int64(20),int64(20))
## test it with a Qt example
w = Qt.QWidget()
w[:setWindowTitle]("Example")
lcd = Qt.QLCDNumber(w)
sld = Qt.QSlider(w)
btn = Qt.QPushButton(w); btn[:setText]("click me")
vbox = Qt.QVBoxLayout()
map(u -> vbox[:addWidget](u), (lcd, sld, btn))
w[:setLayout](vbox)
## connect valueChanged signal of sld with display slot of lcd
sld[:valueChanged][:connect](lcd[:display])
## connect a callback to clicked event
btn[:clicked][:connect](x -> print("clicked"))
w[:show]()
No, the callback is not executed. It couldn't because the instruction that connects the callback raises an error too.
julia> btn[:clicked][:connect](x -> print("clicked"))
ERROR: error compiling anonymous: unsupported or misplaced expression & in function anonymous
Yes, I'm using a fairly recent version (actually I just rebuilt it) and (this error comes first than the one at "btn[:clicked][:connect](x -> print("clicked"))"):
julia> sld[:valueChanged][:connect]
# methods for generic function fn
fn(args...)
julia> lcd[:display]
# methods for generic function fn
fn(args...)
julia> sld[:valueChanged][:connect](lcd[:display])
ERROR: error compiling anonymous: unsupported or misplaced expression & in function anonymous
How about sld[:valueChanged][:connect](lcd["display"]) (which passes the lcd.display Python object directly, rather than converting it to a Julia function and then back to Python)? Or how about PyObject(lcd[:display]) (which only exercises the Julia function -> Python code)?
Ah, a little better
julia> sld[:valueChanged][:connect](lcd["display"])
julia> PyObject(lcd[:display])
ERROR: error compiling anonymous: unsupported or misplaced expression & in function anonymous
Also try running (via include(....)) the .julia/PyCall/test/test.jl script to see if PyCall's self-tests pass.
Okay, it looks like the problem is the & in the function argument of:
function pyjlwrap_type(name::String, init::Function)
pyjlwrap_init()
PyTypeObject(name,
sizeof(Py_jlWrap) + sizeof(PyPtr), # must be > base type
t::PyTypeObject -> begin
t.tp_base = ccall(:jl_value_ptr, Ptr{Void},
(Ptr{PyTypeObject},),
&(jlWrapType::PyTypeObject))
init(t)
end)
end
(This code is just using the jl_value_ptr function as an identity function in order to get the address of the struct data, since & can't be used outside of ccall; it should become unnecessary once #2818 is merged.)
Can you try:
type Foo; bar::Int; end
foo = Foo(1)
ccall(:jl_value_ptr, Ptr{Void}, (Ptr{Foo},), &(foo::Foo))
? It works fine for me on MacOS and GNU/Linux.
Can you try:
type Foo; bar::Int; end
foo = Foo(1)
ccall(:jl_value_ptr, Ptr{Void}, (Ptr{Foo},), &(foo::Foo))
? It works fine for me on MacOS and GNU/Linux.
You found it. Same error
julia> ccall(:jl_value_ptr, Ptr{Void}, (Ptr{Foo},), &(foo::Foo))
ERROR: error compiling anonymous: unsupported or misplaced expression & in function anonymous
You found it. Same error
julia> ccall(:jl_value_ptr, Ptr{Void}, (Ptr{Foo},), &(foo::Foo))
ERROR: error compiling anonymous: unsupported or misplaced expression & in function anonymous
Can you please file a Julia issue for this? I don't see why this should fail on Windows only, so it seems like a Julia bug.