Skip to content

Commit

Permalink
Migration to pyqt4
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielelanaro committed Jan 5, 2015
1 parent 13883e6 commit 9d8e0aa
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 72 deletions.
14 changes: 14 additions & 0 deletions chemlab/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
import sys

# Setup pyqt API
import sip
try:
sip.setapi('QDate', 2)
sip.setapi('QDateTime', 2)
sip.setapi('QString', 2)
sip.setapi('QtextStream', 2)
sip.setapi('Qtime', 2)
sip.setapi('QUrl', 2)
sip.setapi('QVariant', 2)
except ValueError, e:
raise RuntimeError('Could not set API version (%s): did you import PyQt4 directly?' % e)

44 changes: 0 additions & 44 deletions chemlab/contrib/gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,50 +105,6 @@ def rdffunc(args):
grid()
show()


# from PySide.QtUiTools import QUiLoader
# from PySide.QtCore import QFile
# from PySide.QtGui import QWidget, QApplication

# import matplotlib
# matplotlib.use('Qt4Agg')
# matplotlib.rcParams['backend.qt4'] = 'PySide'
# import pylab

# from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
# from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
# from matplotlib.figure import Figure
# import sys

# class App(QApplication):
# def __init__(self):
# QApplication.__init__(self, sys.argv)
# self.loader = loader = QUiLoader()
# pref = '/home/gabriele/workspace/chemlab/chemlab/contrib/'
# file = QFile(pref + "energyplot.ui")
# file.open(QFile.ReadOnly)
# self.mainwin = mainwin = loader.load(file)
# file.close()
# pltcontainer = mainwin.findChild(QWidget, "plotplaceholder")
# fig = Figure(figsize=(600,600), dpi=72, facecolor=(1,1,1), edgecolor=(0,0,0))
# self.ax = ax = fig.add_subplot(111)
# # generate the canvas to display the plot
# self.canvas = canvas = FigureCanvas(fig)
# ly = pltcontainer.layout()
# ly.addWidget(canvas)
# #canvas.setParent(self.mainwin)
# tb = NavigationToolbar(canvas, self.mainwin)

# ly.addWidget(tb)
# self.mainwin.show()

# def plot(self, *a, **kw):
# self.ax.plot(*a, **kw)
# self.canvas.draw()

# def set_statusbar(self, msg):
# self.mainwin.statusBar().showMessage(msg)


if __name__ == '__main__':
main(['pressure'])
1 change: 1 addition & 0 deletions chemlab/graphics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

from .qtviewer import QtViewer
from .qchemlabwidget import QChemlabWidget
from .qttrajectory import QtTrajectoryViewer, format_time
Expand Down
12 changes: 6 additions & 6 deletions chemlab/graphics/qchemlabwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from PIL import Image as pil_Image

from PySide import QtCore, QtGui
from PySide.QtCore import Qt
from PySide.QtOpenGL import QGLWidget
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import Qt
from PyQt4.QtOpenGL import QGLWidget

from OpenGL.GL import *
from OpenGL.GL.framebufferobjects import *
Expand All @@ -19,8 +19,8 @@
DEFAULT_FRAMEBUFFER = 0

class QChemlabWidget(QGLWidget):
'''Extensible and modular OpenGL widget developed using the Qt (PySide)
Framework. This widget can be used in other PySide programs.
'''Extensible and modular OpenGL widget developed using the Qt (PyQt4)
Framework. This widget can be used in other PyQt4 programs.
The widget by itself doesn't draw anything, it delegates the
writing task to external components called 'renderers' that expose
Expand Down Expand Up @@ -49,7 +49,7 @@ class QChemlabWidget(QGLWidget):
widget.uis.append(TextUI(widget, 200, 200, 'Hello, world!'))
.. warning:: At this point there is only one ui element available.
PySide provides a lot of UI elements so there's the
PyQt4 provides a lot of UI elements so there's the
possibility that UI elements will be converted into renderers.
QChemlabWidget has its own mouse gestures:
Expand Down
8 changes: 4 additions & 4 deletions chemlab/graphics/qttrajectory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from PySide.QtGui import QMainWindow, QApplication, QDockWidget
from PySide import QtGui, QtCore
from PySide.QtCore import Qt
from PyQt4.QtGui import QMainWindow, QApplication, QDockWidget
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt

import os

Expand Down Expand Up @@ -243,7 +243,7 @@ def set_time(self, t):


class QtTrajectoryViewer(QMainWindow):
"""Bases: `PySide.QtGui.QMainWindow`
"""Bases: `PyQt4.QtGui.QMainWindow`
Interface for viewing trajectory.
Expand Down
12 changes: 6 additions & 6 deletions chemlab/graphics/qtviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import time

import sys
from PySide.QtGui import QMainWindow, QApplication
from PySide.QtCore import QTimer, Qt
from PySide import QtCore, QtGui
from PySide.QtOpenGL import *
from PyQt4.QtGui import QMainWindow, QApplication
from PyQt4.QtCore import QTimer, Qt
from PyQt4 import QtCore, QtGui
from PyQt4.QtOpenGL import *

from .qchemlabwidget import QChemlabWidget

Expand All @@ -31,7 +31,7 @@ def draw(self):


class QtViewer(QMainWindow):
"""Bases: `PySide.QtGui.QMainWindow`
"""Bases: `PyQt4.QtGui.QMainWindow`
View objects in space.
Expand Down Expand Up @@ -68,7 +68,7 @@ def __init__(self):

# Pre-initializing an OpenGL context can let us use opengl
# functions without having to show the window first...
context = QGLContext(QGLFormat())
context = QGLContext(QGLFormat(), None)
widget = QChemlabWidget(context, self)
context.makeCurrent()
self.setCentralWidget(widget)
Expand Down
2 changes: 1 addition & 1 deletion chemlab/graphics/uis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from OpenGL.GL import *
from PySide.QtGui import QFont, QPainter
from PyQt4.QtGui import QFont, QPainter
from .shaders import compileShader, compileProgram
from OpenGL.arrays import vbo
import os
Expand Down
2 changes: 1 addition & 1 deletion chemlab/mviewer/QIPythonWidget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import atexit

from PySide.QtCore import QTimer
from PyQt4.QtCore import QTimer

from IPython.kernel.zmq.kernelapp import IPKernelApp
from IPython.lib.kernel import find_connection_file
Expand Down
2 changes: 1 addition & 1 deletion chemlab/mviewer/api/appeareance.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Function to popup an interactive dialog
def _interactive_color_dialog(callback):
from PySide.QtGui import QColorDialog
from PyQt4.QtGui import QColorDialog

dialog = QColorDialog()

Expand Down
4 changes: 2 additions & 2 deletions chemlab/mviewer/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def trajectory(start=None, stop=None, step=None):
'''
import numpy as np
from PySide import QtGui
from PyQt4 import QtGui

times = np.array(current_frame_times()) / 1000

Expand Down Expand Up @@ -69,7 +69,7 @@ def frames(skip=1):
You can use the option *skip* to take every i :sup:`th` frame.
'''
from PySide import QtGui
from PyQt4 import QtGui

for i in range(0, viewer.traj_controls.max_index, skip):
viewer.traj_controls.goto_frame(i)
Expand Down
6 changes: 3 additions & 3 deletions chemlab/mviewer/qtmolecularviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import numpy as np
import os

from PySide import QtGui
from PySide.QtCore import Qt, QSize
from PySide import QtCore
from PyQt4 import QtGui
from PyQt4.QtCore import Qt, QSize
from PyQt4 import QtCore

from ..graphics.qtviewer import QtViewer
from ..graphics import colors
Expand Down
13 changes: 13 additions & 0 deletions chemlab/mviewer/representations/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# Setup pyqt API
import sip
try:
sip.setapi('QDate', 2)
sip.setapi('QDateTime', 2)
sip.setapi('QString', 2)
sip.setapi('QtextStream', 2)
sip.setapi('Qtime', 2)
sip.setapi('QUrl', 2)
sip.setapi('QVariant', 2)
except ValueError, e:
raise RuntimeError('Could not set API version (%s): did you import PyQt4 directly?' % e)

from ballandstick import BallAndStickRepresentation
2 changes: 1 addition & 1 deletion chemlab/mviewer/representations/ballandstick.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ...db import ChemlabDB
from ...graphics.postprocessing import GlowEffect

from PySide import QtCore
from PyQt4 import QtCore

cdb = ChemlabDB()
vdw_radii = cdb.get('data', 'vdwdict')
Expand Down
2 changes: 1 addition & 1 deletion chemlab/mviewer/representations/obsarray.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from chemlab.graphics.events import BoundEvent
from ..events import BoundEvent

class obsarray(object):
def __init__(self, arr):
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def __getitem__(self, index):
def __mul__(self, other):
return Mock()

MOCK_MODULES = ['PySide.QtGui', 'PySide.QtCore', 'PySide',
'PySide.QtOpenGL',
MOCK_MODULES = ['PyQt4.QtGui', 'PyQt4.QtCore', 'PyQt4',
'PyQt4.QtOpenGL',
'chemlab.molsim.cforces2', 'h5py',
'chemlab.libs.pyxdr',
'Cython.Distutils', 'numpy', 'numpy.linalg',
Expand Down

0 comments on commit 9d8e0aa

Please sign in to comment.