Skip to content

Commit

Permalink
transitioned RNAlysis to Qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyTeichman committed Sep 6, 2024
1 parent 92f81d6 commit 9beae2b
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 536 deletions.
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
testpaths = tests/
python_files = *.py
python_functions = test_*
qt_api=pyqt5
qt_api=pyqt6
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ joblib>=1.4.2
tqdm>=4.65
appdirs>=1.4.0
typing_extensions>=4.5
PyQt5>=5.15.9
qdarkstyle
PyQt6>=6.7
qdarkstyle>=3
defusedxml>=0.7.1
aiohttp>=3.8.4, <3.10
aiodns>=3.0.0
Expand All @@ -26,5 +26,5 @@ tenacity>=8.2.3
mslex>=1.1.0
nest-asyncio>=1.6.0
kmedoids>=0.5.1
polars[async,numpy,pyarrow,pandas]>=1.5.0
polars[async,numpy,pyarrow,pandas]>=1.6.0,<1.7
pandas[performance,parquet]
216 changes: 115 additions & 101 deletions rnalysis/gui/gui.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions rnalysis/gui/gui_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import matplotlib
import matplotlib_venn
import upsetplot
from PyQt5 import QtCore, QtGui
from PyQt6 import QtCore, QtGui
from matplotlib import pyplot as plt
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg, NavigationToolbar2QT

Expand Down Expand Up @@ -473,6 +473,6 @@ def get_icon(name: str):
return icon
elif name == 'blank':
pixmap = QtGui.QPixmap(32, 32)
pixmap.fill(QtCore.Qt.transparent)
pixmap.fill(QtCore.Qt.GlobalColor.transparent)
return QtGui.QIcon(pixmap)
return None
24 changes: 12 additions & 12 deletions rnalysis/gui/gui_quickstart.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt6 import QtCore, QtWidgets, QtGui

from rnalysis.utils import settings, io

Expand Down Expand Up @@ -134,9 +134,9 @@ def __init__(self, parent=None):

self.currentIdChanged.connect(self.play_tutorial)

self.setWizardStyle(QtWidgets.QWizard.ModernStyle)
self.setWizardStyle(QtWidgets.QWizard.WizardStyle.ModernStyle)
self.setWindowTitle('Welcome to RNAlysis!')
self.setPixmap(self.LogoPixmap,
self.setPixmap(self.WizardPixmap.LogoPixmap,
QtGui.QPixmap(Path.cwd().parent.parent.joinpath('docs/source/favicon.ico').as_posix()))
self.setField('dont_show_again', not settings.get_show_tutorial_settings())

Expand Down Expand Up @@ -223,22 +223,22 @@ def __init__(self, video_path: Path, parent=None):
self.layout = QtWidgets.QGridLayout(self)
self.label = QtWidgets.QLabel(self)
self.video = QtGui.QMovie(full_video_path)
self.video.setCacheMode(self.video.CacheAll)
self.video.setCacheMode(self.video.CacheMode.CacheAll)
self.label.setMovie(self.video)

self.play_button = QtWidgets.QToolButton()
self.play_button.clicked.connect(self.change_play_state)

self.stop_button = QtWidgets.QToolButton()
self.stop_button.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaStop))
self.stop_button.setIcon(self.style().standardIcon(QtWidgets.QStyle.StandardPixmap.SP_MediaStop))
self.stop_button.clicked.connect(self.stop)

self.speed_button = QtWidgets.QToolButton()
self.speed_button.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaSeekForward))
self.speed_button.setIcon(self.style().standardIcon(QtWidgets.QStyle.StandardPixmap.SP_MediaSeekForward))
self.speed_button.setCheckable(True)
self.speed_button.clicked.connect(self.change_speed)

self.position_slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
self.position_slider = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
self.position_slider.setRange(0, self.video.frameCount())
self.position_slider.valueChanged.connect(self.set_frame)
self.position_slider.setTracking(False)
Expand All @@ -256,7 +256,7 @@ def __init__(self, video_path: Path, parent=None):
pixmap = QtGui.QPixmap(full_video_path)
size = pixmap.size()

size.scale(750, 750, QtCore.Qt.KeepAspectRatio)
size.scale(750, 750, QtCore.Qt.AspectRatioMode.KeepAspectRatio)
self.video.setScaledSize(size)

self.layout.addWidget(self.label, 0, 0, 4, 8)
Expand All @@ -279,19 +279,19 @@ def change_play_state(self):

def update_play_button(self):
if self.paused:
self.play_button.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaPlay))
self.play_button.setIcon(self.style().standardIcon(QtWidgets.QStyle.StandardPixmap.SP_MediaPlay))
else:
self.play_button.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaPause))
self.play_button.setIcon(self.style().standardIcon(QtWidgets.QStyle.StandardPixmap.SP_MediaPause))
QtWidgets.QApplication.processEvents()

def mousePressEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
if event.button() == QtCore.Qt.MouseButton.LeftButton:
self.press_pos = event.pos()

def mouseReleaseEvent(self, event):
# ensure that the left button was pressed *and* released within the
# geometry of the widget; if so, emit the signal;
if self.press_pos is not None and event.button() == QtCore.Qt.LeftButton and event.pos() in self.rect():
if self.press_pos is not None and event.button() == QtCore.Qt.MouseButton.LeftButton and event.pos() in self.rect():
self.clicked.emit()
self.press_pos = None

Expand Down
2 changes: 1 addition & 1 deletion rnalysis/gui/gui_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ def get_stylesheet():
QSplitter::handle:hover { background-color: #788D9C; }
"""
else:
other_stylesheet = qdarkstyle.load_stylesheet(qt_api='pyqt5', palette=palette)
other_stylesheet = qdarkstyle.load_stylesheet(qt_api='pyqt6', palette=palette)
return param_stylesheet + '\n' + other_stylesheet
50 changes: 25 additions & 25 deletions rnalysis/gui/gui_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import numpy as np
import polars as pl
import polars.selectors as cs
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt6 import QtCore, QtWidgets, QtGui
from joblib import Parallel, parallel_backend
from tqdm.auto import tqdm
from typing_extensions import get_origin, get_args
Expand Down Expand Up @@ -93,13 +93,13 @@ def value(self):
return picked_cols

def _update_window_size(self):
self.dialog_table.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
# self.dialog_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.dialog_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.dialog_table.setSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Minimum)
# self.dialog_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
self.dialog_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
self.dialog_table.resizeRowsToContents()
self.dialog_table.resizeColumnsToContents()
self.dialog_table.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
self.dialog_table.horizontalHeader().setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
self.dialog_table.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeMode.ResizeToContents)
self.dialog_table.horizontalHeader().setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeMode.Stretch)

screen_height = QtWidgets.QApplication.primaryScreen().size().height()

Expand Down Expand Up @@ -303,7 +303,7 @@ def __init__(self, message: str = "No prompt available", parent=None):
super().__init__(parent)
self.message = message
self.layout = QtWidgets.QVBoxLayout(self)
self.button_box = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok)
self.button_box = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.StandardButton.Ok)
self.path = PathLineEdit(parent=self)

self.init_ui()
Expand Down Expand Up @@ -480,7 +480,7 @@ def create_colormap_pixmap(map_name: str):
fig.canvas.draw()
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
image = QtGui.QImage(data, data.shape[1], data.shape[0], QtGui.QImage.Format_RGB888)
image = QtGui.QImage(data, data.shape[1], data.shape[0], QtGui.QImage.Format.Format_RGB888)
pixmap = QtGui.QPixmap.fromImage(image)
plt.close(fig)

Expand Down Expand Up @@ -530,7 +530,7 @@ def init_ui(self):

def copy_to_clipboard(self):
cb = QtWidgets.QApplication.clipboard()
cb.clear(mode=cb.Clipboard)
cb.clear(mode=QtGui.QClipboard.Mode.Clipboard)
cb.setText(self.text_edit.toPlainText())
self.copied_label.setText('Copied to clipboard')

Expand Down Expand Up @@ -570,7 +570,7 @@ def paintEvent(self, event):
self.setMinimumHeight((radius + self.BORDER) * 2)

painter = QtGui.QPainter(self)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
painter.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing)
painter.translate(center)
painter.setBrush(QtGui.QColor("#cccccc"))

Expand All @@ -584,7 +584,7 @@ def paintEvent(self, event):
if not self.isChecked():
sw_rect.moveLeft(-width)
painter.drawRoundedRect(sw_rect, radius, radius)
painter.drawText(sw_rect, QtCore.Qt.AlignCenter, label)
painter.drawText(sw_rect, QtCore.Qt.AlignmentFlag.AlignCenter, label)


class ToggleSwitch(QtWidgets.QWidget):
Expand Down Expand Up @@ -664,7 +664,7 @@ class HelpButton(QtWidgets.QToolButton):

def __init__(self, parent=None):
super().__init__(parent)
self.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MessageBoxQuestion))
self.setIcon(self.style().standardIcon(QtWidgets.QStyle.StandardPixmap.SP_MessageBoxQuestion))
self.param_name = ''
self.desc = ''

Expand All @@ -679,7 +679,7 @@ def set_param_help(self, param_name: str, desc: str):

def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
super().mouseReleaseEvent(event)
help_event = QtGui.QHelpEvent(QtCore.QEvent.Type.ToolTip, event.pos(), event.globalPos())
help_event = QtGui.QHelpEvent(QtCore.QEvent.Type.ToolTip, event.pos(), event.globalPosition().toPoint())
self.event(help_event)


Expand Down Expand Up @@ -752,7 +752,7 @@ def __init__(self, items: Sequence, icons: Sequence = None, parent=None):
self.items = []
self.list_items = []
self.list = QtWidgets.QListWidget(self)
self.list.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
self.list.setSelectionMode(QtWidgets.QAbstractItemView.SelectionMode.MultiSelection)
self.layout.addWidget(self.list, 1, 1, 4, 1)

self.select_all_button = QtWidgets.QPushButton('Select all', self)
Expand Down Expand Up @@ -831,8 +831,8 @@ def delete_selected(self):
def delete_all(self):
accepted = QtWidgets.QMessageBox.question(self, f"{self.delete_text.capitalize()} all items?",
f"Are you sure you want to {self.delete_text} all items?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
if accepted == QtWidgets.QMessageBox.Yes:
QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.No)
if accepted == QtWidgets.QMessageBox.StandardButton.Yes:
for n_item in reversed(range(len(self.items))):
self.itemDeleted.emit(n_item)
self.delete_all_quietly()
Expand Down Expand Up @@ -1055,7 +1055,7 @@ class MinMaxDialog(QtWidgets.QDialog):

def __init__(self, parent=None):
super().__init__(parent)
self.setWindowFlag(QtCore.Qt.WindowMinMaxButtonsHint)
self.setWindowFlag(QtCore.Qt.WindowType.WindowMinMaxButtonsHint)


class TrueFalseBoth(QtWidgets.QWidget):
Expand Down Expand Up @@ -1796,7 +1796,7 @@ def __init__(self, parent=None):
@QtCore.pyqtSlot(str)
def append_text(self, text: str):

self.moveCursor(QtGui.QTextCursor.End)
self.moveCursor(QtGui.QTextCursor.MoveOperation.End)
if text == '\n':
return
text = text.replace("<", "&lt;").replace(">", "&gt;")
Expand All @@ -1805,8 +1805,8 @@ def append_text(self, text: str):
self.carriage = False
diff = self.document().characterCount() - self.prev_coord
cursor = self.textCursor()
cursor.movePosition(QtGui.QTextCursor.PreviousCharacter, QtGui.QTextCursor.MoveAnchor, n=diff)
cursor.movePosition(QtGui.QTextCursor.End, QtGui.QTextCursor.KeepAnchor)
cursor.movePosition(QtGui.QTextCursor.MoveOperation.PreviousCharacter, QtGui.QTextCursor.MoveMode.MoveAnchor, n=diff)
cursor.movePosition(QtGui.QTextCursor.MoveOperation.End, QtGui.QTextCursor.MoveMode.KeepAnchor)
cursor.removeSelectedText()

if text.endswith('\r'):
Expand Down Expand Up @@ -2180,7 +2180,7 @@ def __init__(self, *args, **kwargs):

def contextMenu(self, value: str):
self.context_menu = QtWidgets.QMenu(self)
copy_action = QtWidgets.QAction(f'Copy "{value}"')
copy_action = QtGui.QAction(f'Copy "{value}"')
copy_action.triggered.connect(functools.partial(QtWidgets.QApplication.clipboard().setText, value))
self.context_menu.addAction(copy_action)

Expand All @@ -2189,7 +2189,7 @@ def contextMenu(self, value: str):

self.db_actions = []
for name in settings.get_databases_settings():
action = QtWidgets.QAction(f'Search "{value}" on {name}')
action = QtGui.QAction(f'Search "{value}" on {name}')
self.db_actions.append(action)
open_url_partial = functools.partial(QtGui.QDesktopServices.openUrl,
QtCore.QUrl(f'{databases[name]}{value}'))
Expand Down Expand Up @@ -2225,7 +2225,7 @@ def __init__(self, *args, **kwargs):

def contextMenu(self, value: str):
self.context_menu = QtWidgets.QMenu(self)
copy_action = QtWidgets.QAction(f'Copy "{value}"')
copy_action = QtGui.QAction(f'Copy "{value}"')
copy_action.triggered.connect(functools.partial(QtWidgets.QApplication.clipboard().setText, value))
self.context_menu.addAction(copy_action)

Expand All @@ -2234,7 +2234,7 @@ def contextMenu(self, value: str):

self.db_actions = []
for name in settings.get_databases_settings():
action = QtWidgets.QAction(f'Search "{value}" on {name}')
action = QtGui.QAction(f'Search "{value}" on {name}')
self.db_actions.append(action)
open_url_partial = functools.partial(QtGui.QDesktopServices.openUrl,
QtCore.QUrl(f'{databases[name]}{value}'))
Expand Down Expand Up @@ -2268,7 +2268,7 @@ def __init__(self, *args, **kwargs):

def contextMenu(self, value: str):
self.context_menu = QtWidgets.QMenu(self)
copy_action = QtWidgets.QAction(f'Copy "{value}"')
copy_action = QtGui.QAction(f'Copy "{value}"')
copy_action.triggered.connect(functools.partial(QtWidgets.QApplication.clipboard().setText, value))
self.context_menu.addAction(copy_action)

Expand Down
Loading

0 comments on commit 9beae2b

Please sign in to comment.