Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/xdot/qt_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-

from python_qt_binding import QT_BINDING_VERSION
g_PYQT_MAJOR_VERSION = int(QT_BINDING_VERSION.split('.')[0])
def get_qt_version():
global g_PYQT_MAJOR_VERSION
return g_PYQT_MAJOR_VERSION


# monkey patch
import types
import functools
from python_qt_binding.QtGui import QMouseEvent
def mouseevent_wrapper(func):
global g_PYQT_MAJOR_VERSION
if g_PYQT_MAJOR_VERSION == 5:
@functools.wraps(func)
def wrapper(self, event):
def _posF(self):
return self.localPos()
event.posF = types.MethodType(_posF, event)
return func(self, event)
return wrapper
else:
return func

def wheelevent_wrapper(func):
global g_PYQT_MAJOR_VERSION
if g_PYQT_MAJOR_VERSION == 5:
@functools.wraps(func)
def wrapper(self, event):
def _delta(self):
return self.angleDelta().y()
event.delta = types.MethodType(_delta, event)
return func(self, event)
return wrapper
else:
return func
74 changes: 60 additions & 14 deletions src/xdot/xdot_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,26 @@

#from PySide.QtCore import *
#from PySide.QtGui import *
from PyQt4 import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *

#from PyQt4 import *
#from PyQt4.QtCore import *
#from PyQt4.QtGui import *
#from PyQt5 import *
#from PyQt5.QtCore import *
#from PyQt5.QtGui import *
#from PyQt5.QtWidgets import *
from python_qt_binding.QtGui import QPalette, QColor, QFont, QFontMetrics, QPen, QBrush, QPolygonF, QPainterPath, QPainter, QKeySequence, QIcon, QMouseEvent
from python_qt_binding.QtCore import Qt, QPoint, QPointF, QTimer, QSettings, QVariant, QSize, QFileInfo

from qt_utils import get_qt_version, mouseevent_wrapper, wheelevent_wrapper
g_PYQT_MAJOR_VERSION = get_qt_version()
if g_PYQT_MAJOR_VERSION == 4:
from python_qt_binding.QtGui import QWidget, QMainWindow, QApplication, QAction, QFileDialog
from python_qt_binding.QtCore import QString, SIGNAL
elif g_PYQT_MAJOR_VERSION == 5:
from python_qt_binding.QtWidgets import QWidget, QMainWindow, QApplication, QAction, QFileDialog
QString = type("")
from python_qt_binding import QtCore
SIGNAL = QtCore.Signal #XXX should be fixed
#from python_qt_binding import *
#from python_qt_binding.QtCore import *
#from python_qt_binding.QtGui import *
Expand Down Expand Up @@ -1131,8 +1147,11 @@ def __init__(self, dot_widget):
self.timeout_id = None

def start(self):
self.timeout_id = QTimer();
self.dot_widget.connect(self.timeout_id, SIGNAL('timeout()'), self.tick)
self.timeout_id = QTimer()
if get_qt_version() == 4:
self.dot_widget.connect(self.timeout_id, SIGNAL('timeout()'), self.tick)
else:
self.timeout_id.timeout.connect(self.tick)
self.timeout_id.start(int(self.step * 1000))

def stop(self):
Expand Down Expand Up @@ -1338,6 +1357,9 @@ class DotWidget(QWidget):
"""Qt widget that draws dot graphs."""

filter = 'dot'
if get_qt_version() == 5:
sig_clicked = QtCore.Signal(unicode, QMouseEvent)
sig_rightclicked = QtCore.Signal(unicode, QMouseEvent)

def __init__(self, parent=None):
super(DotWidget, self).__init__(parent)
Expand Down Expand Up @@ -1634,9 +1656,15 @@ def mouseReleaseEvent(self, event):
x, y = event.x(), event.y()
url = self.get_url(x, y)
if url is not None:
self.emit(SIGNAL("clicked"), unicode(url.url), event)
if get_qt_version() == 4:
self.emit(SIGNAL("clicked"), unicode(url.url), event)
else:
self.sig_clicked.emit(unicode(url.url), event)
else:
self.emit(SIGNAL("clicked"), 'none', event)
if get_qt_version() == 4:
self.emit(SIGNAL("clicked"), 'none', event)
else:
self.sig_clicked.emit(unicode('none'), event)
jump = self.get_jump(x, y)
if jump is not None:
self.animate_to(jump.x, jump.y)
Expand All @@ -1647,9 +1675,15 @@ def mouseReleaseEvent(self, event):
x, y = event.x(), event.y()
url = self.get_url(x, y)
if url is not None:
self.emit(SIGNAL("right_clicked"), unicode(url.url), event)
if get_qt_version() == 4:
self.emit(SIGNAL("right_clicked"), unicode(url.url), event)
else:
self.sig_rightclicked.emit(unicode(url.url), event)
else:
self.emit(SIGNAL("right_clicked"), 'none', event)
if get_qt_version():
self.emit(SIGNAL("right_clicked"), 'none', event)
else:
self.sig_rightclicked.emit(unicode('none'), event)
jump = self.get_jump(x, y)
if jump is not None:
self.animate_to(jump.x, jump.y)
Expand All @@ -1661,6 +1695,7 @@ def mouseReleaseEvent(self, event):
def on_area_scroll_event(self, area, event):
return False

@wheelevent_wrapper
def wheelEvent(self, event):
if event.delta() > 0:
self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT,
Expand All @@ -1669,6 +1704,7 @@ def wheelEvent(self, event):
self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT,
pos=(event.x(), event.y()))

@mouseevent_wrapper
def mouseMoveEvent(self, event):
self.drag_action.on_motion_notify(event)
self.setFocus()
Expand Down Expand Up @@ -1704,7 +1740,6 @@ def get_jump(self, x, y):


#--------------------------------------------------------------------------------------------------------------------------------------------------------------------
#class DotWindow(gtk.Window):
class DotWindow(QMainWindow):

def __init__(self):
Expand Down Expand Up @@ -1736,7 +1771,10 @@ def __init__(self):

self.file_menu = self.menuBar().addMenu("&File")
self.file_menu_actions = (file_open_action, file_reload_action)
self.connect(self.file_menu, SIGNAL("aboutToShow()"), self.update_file_menu)
if get_qt_version() == 4:
self.connect(self.file_menu, SIGNAL("aboutToShow()"), self.update_file_menu)
else:
self.file_menu.triggered.connect(self.update_file_menu)

file_toolbar = self.addToolBar("File")
file_toolbar.setObjectName("FileToolBar")
Expand Down Expand Up @@ -1769,7 +1807,10 @@ def create_action(self, text, slot=None, shortcut=None, icon=None,
action.setToolTip(tip)
action.setStatusTip(tip)
if slot is not None:
self.connect(action, SIGNAL(signal), slot)
if get_qt_version() == 4:
self.connect(action, SIGNAL(signal), slot)
else:
action.triggered.connect(slot)
if checkable:
action.setCheckable(True)
return action
Expand Down Expand Up @@ -1848,7 +1889,12 @@ def update_file_menu(self):
for i, fname in enumerate(recent_files):
action = QAction(QIcon(":/icon.png"), "&%d %s" % (i + 1, QFileInfo(fname).fileName()), self)
action.setData(QVariant(fname))
self.connect(action, SIGNAL("triggered()"), self.open_file)
if get_qt_version() == 4:
self.connect(action, SIGNAL("triggered()"), self.open_file)
elif get_qt_version() == 5:
action.triggered.connect(self.open_file)
else:
print("WARN: not supported qt version")
self.file_menu.addAction(action)
self.file_menu.addSeparator()
self.file_menu.addAction(self.file_menu_actions[-1])
Expand Down