Skip to content

Commit

Permalink
Add PySide2 support to pygui (#649)
Browse files Browse the repository at this point in the history
* Add PySide2 support to pygui

* change pyside2 to :qt5 and add :qt_pyside2

* refactor codes
  • Loading branch information
cherichy authored and stevengj committed Feb 27, 2019
1 parent 79d5141 commit 4b5fc97
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/gui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ pygui_works(gui::Symbol) = gui == :default ||
(gui == :gtk && pyexists("gtk")) ||
(gui == :gtk3 && pyexists("gi")) ||
(gui == :tk && pyexists(tkinter_name())) ||
((gui == :qt5 || gui == :qt_pyqt5) && pyexists("PyQt5")) ||
(gui == :qt_pyqt4 && pyexists("PyQt4")) ||
(gui == :qt_pyqt5 && pyexists("PyQt5")) ||
(gui == :qt_pyside && pyexists("PySide")) ||
(gui == :qt_pyside2 && pyexists("PySide2")) ||
(gui == :qt4 && (pyexists("PyQt4") || pyexists("PySide"))) ||
(gui == :qt && (pyexists("PyQt5") || pyexists("PyQt4") || pyexists("PySide"))))
(gui == :qt5 && (pyexists("PyQt5") || pyexists("PySide2"))) ||
(gui == :qt && (pyexists("PyQt5") || pyexists("PyQt4") || pyexists("PySide") || pyexists("PySide2"))))

# get or set the default GUI; doesn't affect running GUI
"""
Expand All @@ -53,7 +55,7 @@ end
function pygui(g::Symbol)
global gui
if g != gui::Symbol
if !(g in (:wx,:gtk,:gtk3,:tk,:qt,:qt4,:qt5,:qt_pyqt5,:qt_pyqt4,:qt_pyside,:default))
if !(g in (:wx,:gtk,:gtk3,:tk,:qt,:qt4,:qt5,:qt_pyqt5,:qt_pyqt4,:qt_pyside,:qt_pyside2,:default))
throw(ArgumentError("invalid gui $g"))
elseif !pygui_works(g)
error("Python GUI toolkit for $g is not installed.")
Expand Down Expand Up @@ -155,7 +157,7 @@ qt_eventloop(QtModule::AbstractString, sec::Real=50e-3) =
qt_eventloop(pyimport("$QtModule.QtCore"), sec)

function qt_eventloop(sec::Real=50e-3)
for QtModule in ("PyQt5", "PyQt4", "PySide")
for QtModule in ("PyQt5", "PyQt4", "PySide", "PySide2")
try
return qt_eventloop(QtModule, sec)
catch
Expand Down Expand Up @@ -227,18 +229,26 @@ function pygui_start(gui::Symbol=pygui(), sec::Real=50e-3)
eventloops[gui] = gtk_eventloop("gi.repository.Gtk", sec)
elseif gui == :tk
eventloops[gui] = Tk_eventloop(sec)
elseif gui == :qt_pyqt5 || gui == :qt5
eventloops[gui] = qt_eventloop("PyQt5", sec)
elseif gui == :qt_pyqt4
eventloops[gui] = qt_eventloop("PyQt4", sec)
elseif gui == :qt_pyqt5
eventloops[gui] = qt_eventloop("PyQt5", sec)
elseif gui == :qt_pyside
eventloops[gui] = qt_eventloop("PySide", sec)
elseif gui == :qt_pyside2
eventloops[gui] = qt_eventloop("PySide2", sec)
elseif gui == :qt4
try
eventloops[gui] = qt_eventloop("PyQt4", sec)
catch
eventloops[gui] = qt_eventloop("PySide", sec)
end
elseif gui == :qt5
try
eventloops[gui] = qt_eventloop("PyQt5", sec)
catch
eventloops[gui] = qt_eventloop("PySide2", sec)
end
elseif gui == :qt
eventloops[gui] = qt_eventloop(sec)
else
Expand Down

0 comments on commit 4b5fc97

Please sign in to comment.