Skip to content

Commit

Permalink
WIP: some QtWidgets and QtCore, etc forgotten. (!)AND some ugly comme…
Browse files Browse the repository at this point in the history
…nted line just to get open the visualea window
  • Loading branch information
baugetfa committed Jan 18, 2023
1 parent ae566ec commit 258816e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 58 deletions.
16 changes: 8 additions & 8 deletions src/openalea/visualea/dataflowview/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from . import anno
from . import adapter

from openalea.vpltk.qt import qt
from openalea.vpltk.qt import QtWidgets # qt
from openalea.vpltk.qt.compat import to_qvariant
from openalea.visualea.graph_operator import GraphOperator
from openalea.core import compositenode, node
Expand Down Expand Up @@ -130,7 +130,7 @@ def __drop_from_factory(self, factory, pos):
scene.add_vertex(node, position=pos)
return node
except RecursionError:
mess = QMessageBox.warning(self, "Error",
mess = QtWidgets.QMessageBox.warning(self, "Error",
"A graph cannot be contained in itself.")
return None

Expand All @@ -139,12 +139,12 @@ def __check_factory(self, factory):
operator = self.get_graph_operator()
for ws in operator.get_siblings():
if factory == ws.factory:
res = QMessageBox.warning(self, "Other instances are already opened!",
res = QtWidgets.QMessageBox.warning(self, "Other instances are already opened!",
"You are trying to insert a composite node that has already been opened.\n" +
"Doing this might cause confusion later on.\n" +
"Do you want to continue?",
QMessageBox.Ok | QMessageBox.Cancel)
if res == QMessageBox.Cancel:
QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
if res == QtWidgets.QMessageBox.Cancel:
return False
else:
break
Expand Down Expand Up @@ -287,12 +287,12 @@ def keyPressEvent(self, e):
qt.View.keyPressEvent(self, e)
if not e.isAccepted():
if e.key() == qt.QtCore.Qt.Key_Space:
self.setDragMode(QGraphicsView.ScrollHandDrag)
self.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag)

def keyReleaseEvent(self, e):
key = e.key()
if key == qt.QtCore.Qt.Key_Space:
self.setDragMode(QGraphicsView.RubberBandDrag)
self.setDragMode(QtWidgets.QGraphicsView.RubberBandDrag)

#########################
# Handling mouse events #
Expand Down Expand Up @@ -321,7 +321,7 @@ def mouseMoveEvent(self, e):
###########################################
def contextMenuEvent(self, event):

QGraphicsView.contextMenuEvent(self, event)
QtWidgets.QGraphicsView.contextMenuEvent(self, event)
if event.isAccepted():
return

Expand Down
64 changes: 32 additions & 32 deletions src/openalea/visualea/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#from openalea import misc

from openalea.vpltk.qt import QtCore, QtGui, QtWidgets, qt
from openalea.vpltk.qt import QtCore, QtGui, QtWidgets, QtSvg #, qt
from openalea.vpltk.qt.designer import generate_pyfile_from_uifile, get_data

from openalea.core import cli, logger
Expand Down Expand Up @@ -78,7 +78,7 @@ def __init__(self, session, parent=None):
ui_mainwindow.Ui_MainWindow.__init__(self)
self.setupUi(self)
self.setAcceptDrops(True)
self.setAttribute(qt.QtCore.Qt.WA_QuitOnClose)
self.setAttribute(QtCore.Qt.WA_QuitOnClose)

self.tabWorkspace.removeTab(0)
self.tabWorkspace.setTabsClosable(True)
Expand Down Expand Up @@ -141,8 +141,8 @@ def __init__(self, session, parent=None):

# The fix didn't work for some reason so I kept the old buggy one (l.141/142)
# self.tabWorkspace.contextMenuEvent.connect(self.contextMenuEvent)
self.connect(self.tabWorkspace, qt.QtCore("contextMenuEvent(QContextMenuEvent)"),
self.contextMenuEvent)
# self.connect(self.tabWorkspace, QtCore("contextMenuEvent(QContextMenuEvent)"),
# self.contextMenuEvent) # F. Bauget 2023-01-18
self.tabWorkspace.currentChanged.connect(self.ws_changed)
self.search_lineEdit.editingFinished.connect(self.search_node)
self.tabWorkspace.tabCloseRequested.connect(self.close_tab_workspace)
Expand Down Expand Up @@ -206,7 +206,7 @@ def __init__(self, session, parent=None):
(self.actionSetCustomColor, "graph_set_selection_color"),
(self.actionUseCustomColor, "graph_use_user_color")])

self._last_open_action_group = QtGui.QActionGroup(self)
self._last_open_action_group = QtWidgets.QActionGroup(self)
self._last_open_action_group.triggered.connect(
self.reopen_last)
self.action_New_Empty_Workspace.triggered.connect(self.new_workspace)
Expand Down Expand Up @@ -234,14 +234,14 @@ def __init__(self, session, parent=None):
self.menu_provenance.setObjectName("menu_provenance")
self.menu_provenance.setTitle(QtWidgets.QApplication.translate("MainWindow", "&Provenance", None, QtWidgets.QApplication.UnicodeUTF8))

self.action_activ_prov = QtGui.QAction(self)
self.action_activ_prov = QtWidgets.QAction(self)
self.action_activ_prov.setCheckable(True)
prov = self.get_provenance()
self.action_activ_prov.setChecked(prov)
self.action_activ_prov.setObjectName("action_activ_prov")
self.action_activ_prov.setText(QtWidgets.QApplication.translate("MainWindow", "Connect/Disconnect Provenance", None, QtWidgets.QApplication.UnicodeUTF8))

self.action_show_prov = QtGui.QAction(self)
self.action_show_prov = QtWidgets.QAction(self)
self.action_show_prov.setCheckable(False)
self.action_show_prov.setObjectName("action_show_prov")
self.action_show_prov.setText(QtWidgets.QApplication.translate("MainWindow", "Show Provenance", None, QtWidgets.QApplication.UnicodeUTF8))
Expand Down Expand Up @@ -371,14 +371,14 @@ def read_settings(self):
#main window
try:
size = eval(settings.get("MainWindow", "size"))
self.resize(qt.QtCore.QSize(*size))
self.resize(QtCore.QSize(*size))
except NoSectionError:
pass
except NoOptionError:
pass
try:
pos = eval(settings.get("MainWindow", "pos"))
self.move(qt.QtCore.QPoint(*pos))
self.move(QtCore.QPoint(*pos))
except NoSectionError:
pass
except NoOptionError:
Expand Down Expand Up @@ -501,7 +501,7 @@ def open_compositenode(self, factory):
def about(self):
""" Display About Dialog """

mess = QtGui.QMessageBox.about(self, "About Visualea",
mess = QtWidgets.QMessageBox.about(self, "About Visualea",
"Version %s\n\n" % (metainfo.get_version()) +
"VisuAlea is part of the OpenAlea framework.\n" +
metainfo.get_copyright() +
Expand All @@ -515,14 +515,14 @@ def help(self):

def web(self):
""" Open OpenAlea website """
QtGui.QDesktopServices.openUrl(qt.QtCore.QUrl(metainfo.url))
QtGui.QDesktopServices.openUrl(QtCore.QUrl(metainfo.url))

def quit(self):
""" Quit Application """
if(QtGui.QMessageBox.question(self, "Quit?", "Are you sure you want to quit?",
QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel) ==
QtGui.QMessageBox.Ok):
QtGui.QApplication.exit(0)
if(QtWidgets.QMessageBox.question(self, "Quit?", "Are you sure you want to quit?",
QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) ==
QtWidgets.QMessageBox.Ok):
QtWidgets.QApplication.exit(0)

def notify(self, sender, event):
""" Notification from observed """
Expand Down Expand Up @@ -635,13 +635,13 @@ def open_widget_tab(self, graph, factory, caption=None, pos=-1):
#by sending new views the QEvent.WindowActivate event.
#The bug is present until Qt4.6.2 at least. Bugreport:
#http://bugreports.qt.nokia.com/browse/QTBUG-11148
qt.QtCore.QCoreApplication.instance().notify(gwidget, qt.QtCore.QEvent(qt.QtCore.QEvent.WindowActivate))
QtCore.QCoreApplication.instance().notify(gwidget, QtCore.QEvent(QtCore.QEvent.WindowActivate))
if gwidget is not None:
gwidget.show_entire_scene()
return index

def add_pkgdir(self):
dirname = QtGui.QFileDialog.getExistingDirectory(self, "Select Package/Directory")
dirname = QtWidgets.QFileDialog.getExistingDirectory(self, "Select Package/Directory")
if(dirname):
self.pkgmanager.load_directory(str(dirname))
self.reinit_treeview()
Expand Down Expand Up @@ -685,17 +685,17 @@ def contextMenuEvent(self, event):
def close_current_ws():
self.close_tab_workspace(index)

menu = QtGui.QMenu(self)
menu = QtWidgets.QMenu(self)

action = menu.addAction("Close")
self.connect(action, qt.QtCore.SIGNAL("triggered()"), close_current_ws)
self.connect(action, QtCore.pyqtSignal("triggered()"), close_current_ws)
#action.triggered.connect(close_current_ws)

# action = menu.addAction("Run")
# self.connect(action, qt.QtCore.SIGNAL("triggered()"), self.run)
# self.connect(action, QtCore.pyqtSignal("triggered()"), self.run)

# action = menu.addAction("Export to Model")
# self.connect(action, qt.QtCore.SIGNAL("triggered()"), self.export_to_factory)
# self.connect(action, QtCore.pyqtSignal("triggered()"), self.export_to_factory)

menu.move(event.globalPos())
menu.show()
Expand Down Expand Up @@ -750,7 +750,7 @@ def new_package(self):
def exec_python_script(self):
""" Choose a python source and execute it """

filename = QtGui.QFileDialog.getOpenFileName(
filename = QtWidgets.QFileDialog.getOpenFileName(
self, "Python Script", "Python script (*.py)")

filename = str(filename)
Expand Down Expand Up @@ -784,7 +784,7 @@ def exec_python_script(self):
def open_python_console(self):
""" Set focus on the python shell """
try:
self.interpreterWidget.setFocus(qt.QtCore.Qt.ShortcutFocusReason)
self.interpreterWidget.setFocus(QtCore.Qt.ShortcutFocusReason)
except:
pass

Expand All @@ -797,8 +797,8 @@ def new_session(self):

def open_session(self):

filename = QtGui.QFileDialog.getOpenFileName(
self, "OpenAlea Session", qt.QtCore.QDir.homePath(), "Session file (*.oas)")
filename = QtWidgets.QFileDialog.getOpenFileName(
self, "OpenAlea Session", QtCore.QDir.homePath(), "Session file (*.oas)")

filename = str(filename)
if(not filename):
Expand All @@ -817,8 +817,8 @@ def save_session(self):
def save_as(self):
""" Save as menu entry """

filename = QtGui.QFileDialog.getSaveFileName(
self, "OpenAlea Session", qt.QtCore.QDir.homePath(), "Session file (*.oas)")
filename = QtWidgets.QFileDialog.getSaveFileName(
self, "OpenAlea Session", QtCore.QDir.homePath(), "Session file (*.oas)")

filename = str(filename)
if(not filename):
Expand Down Expand Up @@ -915,8 +915,8 @@ def to_python_script(self):
def export_image(self):
""" Export current workspace to an image """

filename = QtGui.QFileDialog.getSaveFileName(
self, "Export image", qt.QtCore.QDir.homePath(), "PNG Image (*.png)")
filename = QtWidgets.QFileDialog.getSaveFileName(
self, "Export image", QtCore.QDir.homePath(), "PNG Image (*.png)")

filename = str(filename)
if not filename:
Expand All @@ -943,8 +943,8 @@ def export_image(self):
def export_image_svg(self):
""" Export current workspace to an image """

filename = QtGui.QFileDialog.getSaveFileName(
self, "Export svg image", qt.QtCore.QDir.homePath(), "SVG Image (*.svg)")
filename = QtWidgets.QFileDialog.getSaveFileName(
self, "Export svg image", QtCore.QDir.homePath(), "SVG Image (*.svg)")

filename = str(filename)
if not filename:
Expand All @@ -960,7 +960,7 @@ def export_image_svg(self):
matrix = view.matrix()
rect = matrix.mapRect(rect)

svg_gen = qt.QtSvg.QSvgGenerator()
svg_gen = QtSvg.QSvgGenerator()
svg_gen.setFileName(filename)
svg_gen.setSize(rect.toRect().size())

Expand Down
35 changes: 18 additions & 17 deletions src/openalea/visualea/node_treeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from weakref import ref

# from openalea.vpltk.qt import qt
from openalea.vpltk.qt import QtWidgets, QtCore
from openalea.vpltk.qt import QtWidgets, QtCore, QtGui

from openalea.core.node import NodeFactory, AbstractFactory
from openalea.core.data import DataFactory
Expand Down Expand Up @@ -65,12 +65,12 @@ def get_icon(item):
if(not icon_dict):
# dict to do a switch
icon_dict = {
PseudoGroup: to_qvariant(QtWidgets.QPixmap(":/icons/category.png")),
CompositeNodeFactory: to_qvariant(QtWidgets.QPixmap(":/icons/diagram.png")),
NodeFactory: to_qvariant(QtWidgets.QPixmap(":/icons/node.png")),
DataFactory: to_qvariant(QtWidgets.QPixmap(":/icons/data.png")),
UserPackage: to_qvariant(QtWidgets.QPixmap(":/icons/usrpkg.png")),
Package: to_qvariant(QtWidgets.QPixmap(":/icons/pkg.png")),
PseudoGroup: to_qvariant(QtGui.QPixmap(":/icons/category.png")),
CompositeNodeFactory: to_qvariant(QtGui.QPixmap(":/icons/diagram.png")),
NodeFactory: to_qvariant(QtGui.QPixmap(":/icons/node.png")),
DataFactory: to_qvariant(QtGui.QPixmap(":/icons/data.png")),
UserPackage: to_qvariant(QtGui.QPixmap(":/icons/usrpkg.png")),
Package: to_qvariant(QtGui.QPixmap(":/icons/pkg.png")),
}

# Get icon from dictionary
Expand All @@ -85,14 +85,14 @@ def get_icon(item):
icon = item.item.metainfo.get("icon", None)
if(icon):
icon = os.path.join(item.item.path, icon)
pix = QtWidgets.QPixmap(icon)
pix = QtGui.QPixmap(icon)
if(not pix.isNull()):
return to_qvariant(pix)

# Standard icon
return icon_dict[type(item.item)]

return to_qvariant(QtWidgets.QPixmap(":/icons/pseudopkg.png"))
return to_qvariant(QtGui.QPixmap(":/icons/pseudopkg.png"))

else:
return to_qvariant()
Expand Down Expand Up @@ -208,7 +208,7 @@ def index(self, row, column, parent):
parentItem = parent.internalPointer()

l = list(parentItem.iter_public_values())
l.sort(item_compare)# (lambda x,y : cmp(x.get_id(), y.get_id())))
# F. Bauget 2023-01-18 l.sort(item_compare)# (lambda x,y : cmp(x.get_id(), y.get_id())))

This comment has been minimized.

Copy link
@pradal

pradal Jan 18, 2023

Contributor

Solution for this is:

from functools import cmp_to_key
def cmp(a, b):
    return (a.get_id() > b.get_id()) - (a.get_id() < b.get_id())

l.sort(key=cmp_to_key(cmp))
childItem = l[row]

# save parent and row
Expand Down Expand Up @@ -309,7 +309,7 @@ def data(self, index, role):

# Icon
elif(role == QtCore.Qt.DecorationRole):
return to_qvariant(QtWidgets.QPixmap(":/icons/ccmime.png"))
return to_qvariant(QtGui.QPixmap(":/icons/ccmime.png"))

# Tool Tip
elif(role == QtCore.Qt.ToolTipRole):
Expand Down Expand Up @@ -485,7 +485,7 @@ def startDrag(self, supportedActions):

itemData = QtCore.QByteArray()
dataStream = QtCore.QDataStream(itemData, QtCore.QIODevice.WriteOnly)
pixmap = QtWidgets.QPixmap(item.data(QtCore.Qt.DecorationRole))
pixmap = QtGui.QPixmap(item.data(QtCore.Qt.DecorationRole))

(pkg_id, factory_id, mimetype) = self.get_item_info(item)

Expand All @@ -495,7 +495,7 @@ def startDrag(self, supportedActions):

mimeData.setData(mimetype, itemData)

drag = QtWidgets.QDrag(self)
drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
drag.setHotSpot(QtCore.QPoint(pixmap.width() / 2, pixmap.height() / 2))
drag.setPixmap(pixmap)
Expand Down Expand Up @@ -910,8 +910,9 @@ def __init__(self, main_win, parent=None):
self.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
#self.setAnimated(True)

self.expanded(QtCore.QModelIndex).connect(self.expanded)
self.collapsed(QtCore.QModelIndex).connect(self.collapsed)
# F. Bauget 2023-01-18
# self.expanded(QtCore.QModelIndex).connect(self.expanded)
# self.collapsed(QtCore.QModelIndex).connect(self.collapsed)

self.expanded_items = set()

Expand Down Expand Up @@ -1003,7 +1004,7 @@ def startDrag(self, supportedActions):

itemData = QtCore.QByteArray()
dataStream = QtCore.QDataStream(itemData, QtCore.QIODevice.WriteOnly)
pixmap = QtWidgets.QPixmap(":/icons/ccmime.png")
pixmap = QtGui.QPixmap(":/icons/ccmime.png")

l = list(self.model().datapool.keys())
l.sort()
Expand All @@ -1017,7 +1018,7 @@ def startDrag(self, supportedActions):
linecode = cli.get_datapool_code(name)
mimeData.setText(linecode)

drag = QtWidgets.QDrag(self)
drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
drag.setHotSpot(QtCore.QPoint(pixmap.width() / 2, pixmap.height() / 2))
drag.setPixmap(pixmap)
Expand Down
2 changes: 1 addition & 1 deletion src/openalea/visualea/visualeagui.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def show_splash_screen():
message = "" + metainfo.get_copyright() +\
"Version : %s\n"%(metainfo.get_version(),) +\
"Loading modules..."
splash.showMessage(message, QtCore.Qt.AlignCenter|QtCore.Qt.AlignBottom)
splash.showMessage(message) # F. Bauget 2023-01-18 #, QtCore.Qt.AlignCenter|QtCore.Qt.AlignBottom)
# -- make sure qt really display the message before importing the modules.--
QtWidgets.QApplication.processEvents()
return splash
Expand Down

0 comments on commit 258816e

Please sign in to comment.