Skip to content
Closed
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
8 changes: 4 additions & 4 deletions cnapy/appdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self):
# more scencolors
self.scen_color_good = QColor(130, 190, 0)
self.scen_color_warn = QColor(255, 200, 0)
self.scen_color_bad = Qt.red
self.scen_color_bad = Qt.GlobalColor.red

font = QFont()
font.setFamily(font.defaultFamily())
Expand Down Expand Up @@ -126,9 +126,9 @@ def flux_value_display(self, vl, vu): # -> str, color, bool
if isclose(vl, vu, abs_tol=self.abs_tol):
if self.modes_coloring:
if vl == 0:
background_color = Qt.red
background_color = Qt.GlobalColor.red
else:
background_color = Qt.green
background_color = Qt.GlobalColor.green
else:
background_color = self.comp_color
as_one = True
Expand Down Expand Up @@ -421,7 +421,7 @@ def __init__(self):
"it under 'Config->Configure cobrapy').\n"+\
"Right now, GLPK is set as alternative solver instead of Gurobi."
)
msgBox.setIcon(QMessageBox.Warning)
msgBox.setIcon(QMessageBox.Icon.Warning)
msgBox.exec()

self.cobra_py_model = CNApyModel()
Expand Down
47 changes: 24 additions & 23 deletions cnapy/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
import nest_asyncio
nest_asyncio.apply()

# ensuring compatibility with high resolution displays
if hasattr(Qt, 'AA_EnableHighDpiScaling'):
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
if hasattr(Qt, 'AA_UseHighDpiPixmaps'):
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
# Ensuring compatibility with high resolution displays. These attributes are
# Qt 5-only, so look them up through ApplicationAttribute for Qt 6 safety.
for attribute_name in ("AA_EnableHighDpiScaling", "AA_UseHighDpiPixmaps"):
attribute = getattr(Qt.ApplicationAttribute, attribute_name, None)
if attribute is not None:
QApplication.setAttribute(attribute, True)

from cnapy.appdata import AppData
from cnapy.gui_elements.main_window import MainWindow
Expand Down Expand Up @@ -82,15 +83,15 @@ def make_dark_palette() -> QPalette:
palette.setColor(QPalette.ColorRole.Button, QColor(66, 66, 66)) # medium‑dark gray

# ---- Text colours ----
palette.setColor(QPalette.ColorRole.WindowText, Qt.white) # normal text
palette.setColor(QPalette.ColorRole.ButtonText, Qt.white) # button labels
palette.setColor(QPalette.ColorRole.Text, Qt.white) # line‑edit / plain‑text
palette.setColor(QPalette.ColorRole.WindowText, Qt.GlobalColor.white) # normal text
palette.setColor(QPalette.ColorRole.ButtonText, Qt.GlobalColor.white) # button labels
palette.setColor(QPalette.ColorRole.Text, Qt.GlobalColor.white) # line‑edit / plain‑text
palette.setColor(QPalette.ColorRole.PlaceholderText,
QColor(150, 150, 150)) # a softer gray for placeholders

# ---- Highlight (selection) colours ----
palette.setColor(QPalette.ColorRole.Highlight, QColor(0, 120, 215))
palette.setColor(QPalette.ColorRole.HighlightedText, Qt.black) # black text on the blue highlight
palette.setColor(QPalette.ColorRole.HighlightedText, Qt.GlobalColor.black) # black text on the blue highlight

# ---- Disabled state (optional) ----
disabled = QColor(120, 120, 120) # lighter than the normal text gray so it is still visible
Expand All @@ -99,7 +100,7 @@ def make_dark_palette() -> QPalette:

# ---- Other states ----
palette.setColor(QPalette.ColorRole.ToolTipBase, QColor(255, 255, 220))
palette.setColor(QPalette.ColorRole.ToolTipText, Qt.black)
palette.setColor(QPalette.ColorRole.ToolTipText, Qt.GlobalColor.black)

palette.setColor(QPalette.ColorRole.Link, QColor(86, 156, 214)) # a light‑blue link colour
palette.setColor(QPalette.ColorRole.LinkVisited, QColor(150, 150, 255))
Expand All @@ -113,26 +114,26 @@ def make_light_palette():

# ---- Base colours (backgrounds) ----
# Window background (main window, dialogs, etc.)
palette.setColor(QPalette.Window, QColor(240, 240, 240)) # light gray
palette.setColor(QPalette.ColorRole.Window, QColor(240, 240, 240)) # light gray
# General widget background (e.g. QLineEdit, QTextEdit)
palette.setColor(QPalette.Base, QColor(255, 255, 255)) # white
palette.setColor(QPalette.ColorRole.Base, QColor(255, 255, 255)) # white
# Button background
palette.setColor(QPalette.Button, QColor(230, 230, 230))
palette.setColor(QPalette.ColorRole.Button, QColor(230, 230, 230))

# ---- Text colours ----
palette.setColor(QPalette.WindowText, Qt.black)
palette.setColor(QPalette.ButtonText, Qt.black)
palette.setColor(QPalette.Text, Qt.black)
palette.setColor(QPalette.PlaceholderText, QColor(120, 120, 120))
palette.setColor(QPalette.ColorRole.WindowText, Qt.GlobalColor.black)
palette.setColor(QPalette.ColorRole.ButtonText, Qt.GlobalColor.black)
palette.setColor(QPalette.ColorRole.Text, Qt.GlobalColor.black)
palette.setColor(QPalette.ColorRole.PlaceholderText, QColor(120, 120, 120))

# ---- Highlight (selection) colours ----
palette.setColor(QPalette.Highlight, QColor(0, 120, 215)) # classic Windows blue
palette.setColor(QPalette.HighlightedText, Qt.white)
palette.setColor(QPalette.ColorRole.Highlight, QColor(0, 120, 215)) # classic Windows blue
palette.setColor(QPalette.ColorRole.HighlightedText, Qt.GlobalColor.white)

# ---- Disabled state (optional) ----
disabled = QColor(150, 150, 150)
palette.setColor(QPalette.Disabled, QPalette.Text, disabled)
palette.setColor(QPalette.Disabled, QPalette.ButtonText, disabled)
palette.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.Text, disabled)
palette.setColor(QPalette.ColorGroup.Disabled, QPalette.ColorRole.ButtonText, disabled)

return palette

Expand Down Expand Up @@ -182,7 +183,7 @@ def __init__(
self.qapp.aboutToQuit.connect(
self.window.centralWidget().shutdown_kernel
)
sys.exit(self.qapp.exec_())
sys.exit(self.qapp.exec())

def first_start_up_message(self):
msgBox = QMessageBox()
Expand All @@ -194,7 +195,7 @@ def first_start_up_message(self):
"Also, should CNApy's font size be too small or too large, you can change\n"
"it under 'Config->Configure CNApy...'."
)
msgBox.setIcon(QMessageBox.Information)
msgBox.setIcon(QMessageBox.Icon.Information)
msgBox.exec()

self.window.show_config_dialog(first_start=True)
Expand Down
2 changes: 1 addition & 1 deletion cnapy/core_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def except_likely_community_model_error() -> None:
msgBox = QMessageBox()
msgBox.setWindowTitle("Error")
msgBox.setText(community_error_text)
msgBox.setIcon(QMessageBox.Warning)
msgBox.setIcon(QMessageBox.Icon.Warning)
msgBox.exec()


Expand Down
8 changes: 4 additions & 4 deletions cnapy/gui_elements/about_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ def __init__(self, appdata: AppData):
"Version: {version}\
\n\nCNApy is an integrated environment for metabolic modeling.\
\nFor more information visit us at:".format(version=appdata.version))
self.text1.setAlignment(Qt.AlignCenter)
self.text1.setAlignment(Qt.AlignmentFlag.AlignCenter)

self.url1 = QLabel(
"<a href=\"https://github.com/cnapy-org/CNApy\"> https://github.com/cnapy-org/CNApy </a>")
self.url1.setOpenExternalLinks(True)
self.url1.setAlignment(Qt.AlignCenter)
self.url1.setAlignment(Qt.AlignmentFlag.AlignCenter)

self.text2 = QLabel(
"<br>If you use CNApy in your scientific work, please consider to cite CNApy's publication:<br>"
"Thiele et al. (2022). CNApy: a CellNetAnalyzer GUI in Python for analyzing and designing metabolic networks. "
"<i>Bioinformatics</i> 38, 1467-1469:"
)
self.text2.setAlignment(Qt.AlignCenter)
self.text2.setAlignment(Qt.AlignmentFlag.AlignCenter)

self.url2 = QLabel(
"<a href=\"https://doi.org/10.1093/bioinformatics/btab828\"> https://doi.org/10.1093/bioinformatics/btab828 </a>")
self.url2.setOpenExternalLinks(True)
self.url2.setAlignment(Qt.AlignCenter)
self.url2.setAlignment(Qt.AlignmentFlag.AlignCenter)


self.button = QPushButton("Close")
Expand Down
4 changes: 2 additions & 2 deletions cnapy/gui_elements/annotation_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, parent):
check_button = QPushButton("identifiers.org check")
check_button.setIcon(QIcon.fromTheme("list-add"))
policy = QSizePolicy()
policy.ShrinkFlag = True
policy.PolicyFlag.ShrinkFlag = True
check_button.setSizePolicy(policy)
check_button.clicked.connect(self.check_in_identifiers_org)
lh.addWidget(check_button)
Expand All @@ -31,7 +31,7 @@ def __init__(self, parent):
self.annotation = QTableWidget(0, 2)
self.annotation.setHorizontalHeaderLabels(
["key", "value"])
self.annotation.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.annotation.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
lh2.addWidget(self.annotation)

lh3 = QVBoxLayout()
Expand Down
4 changes: 2 additions & 2 deletions cnapy/gui_elements/box_position_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def set_position(self):
msgBox = QMessageBox()
msgBox.setWindowTitle("X position error")
msgBox.setText("The X value you typed in is no valid number, hence, the new box position could not be set.")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setIcon(QMessageBox.Icon.Warning)
msgBox.exec()
return

Expand All @@ -68,7 +68,7 @@ def set_position(self):
msgBox = QMessageBox()
msgBox.setWindowTitle("Y position error")
msgBox.setText("The Y value you typed in is no valid number, hence, the new box position could not be set.")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setIcon(QMessageBox.Icon.Warning)
msgBox.exec()
return

Expand Down
14 changes: 7 additions & 7 deletions cnapy/gui_elements/central_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from qtconsole.inprocess import QtInProcessKernelManager
from qtconsole.rich_jupyter_widget import RichJupyterWidget
from qtpy.QtCore import Qt, Signal, Slot, QSignalBlocker
from qtpy.QtGui import QColor, QBrush
from qtpy.QtGui import QAction, QColor, QBrush
from qtpy.QtWidgets import (QCheckBox, QDialog, QHBoxLayout, QLabel, QLineEdit, QPushButton, QSplitter,
QTabWidget, QVBoxLayout, QWidget, QAction, QApplication, QComboBox, QFrame)
QTabWidget, QVBoxLayout, QWidget, QApplication, QComboBox, QFrame)

from cnapy.appdata import AppData, CnaMap, ModelItemType, parse_scenario
from cnapy.gui_elements.map_view import MapView
Expand Down Expand Up @@ -47,8 +47,8 @@ def __init__(self, parent):
self.search_annotations.setChecked(False)
searchbar_layout.addWidget(self.search_annotations)
line = QFrame()
line.setFrameShape(QFrame.VLine)
line.setFrameShadow(QFrame.Sunken)
line.setFrameShape(QFrame.Shape.VLine)
line.setFrameShadow(QFrame.Shadow.Sunken)
searchbar_layout.addWidget(line)
searchbar_layout.addSpacing(10)
self.model_item_history = QComboBox()
Expand Down Expand Up @@ -120,7 +120,7 @@ def __init__(self, parent):
self.mode_navigator = ModeNavigator(self.appdata, self)
self.splitter2.addWidget(self.mode_navigator)
self.splitter2.addWidget(self.console)
self.splitter2.setOrientation(Qt.Vertical)
self.splitter2.setOrientation(Qt.Orientation.Vertical)
self.splitter.addWidget(self.splitter2)
self.splitter.addWidget(self.tabs)
self.console.show()
Expand Down Expand Up @@ -354,7 +354,7 @@ def update_selected(self):
map_idx = self.map_tabs.currentIndex()

with_annotations = self.search_annotations.isChecked() and self.search_annotations.isEnabled()
QApplication.setOverrideCursor(Qt.BusyCursor)
QApplication.setOverrideCursor(Qt.CursorShape.BusyCursor)
QApplication.processEvents() # to put the change above into effect
if idx == ModelTabIndex.Reactions:
found_ids = self.reaction_list.update_selected(string, with_annotations)
Expand Down Expand Up @@ -723,7 +723,7 @@ def add_model_item_to_history(self, item_id: str, item_name: str, item_type: Mod
if index >= 0:
index = self.model_item_history.removeItem(index)
self.model_item_history.insertItem(0, item_id + " (" + ModelItemType(item_type).name + ")", item_data)
self.model_item_history.setItemData(0, item_name, Qt.ToolTipRole)
self.model_item_history.setItemData(0, item_name, Qt.ItemDataRole.ToolTipRole)
self.model_item_history.setCurrentIndex(0)

def update_item_in_history(self, previous_id: str, new_id: str, new_name: str, item_type: ModelItemType):
Expand Down
40 changes: 20 additions & 20 deletions cnapy/gui_elements/config_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, main_window, first_start: bool):
self.scen_color_btn = QPushButton()
self.scen_color_btn.setFixedWidth(100)
palette = self.scen_color_btn.palette()
palette.setColor(QPalette.Button, self.appdata.scen_color)
palette.setColor(QPalette.ColorRole.Button, self.appdata.scen_color)
self.scen_color_btn.setPalette(palette)
h2.addWidget(self.scen_color_btn)
self.layout.addItem(h2)
Expand All @@ -57,7 +57,7 @@ def __init__(self, main_window, first_start: bool):
self.comp_color_btn = QPushButton()
self.comp_color_btn.setFixedWidth(100)
palette = self.comp_color_btn.palette()
palette.setColor(QPalette.Button, self.appdata.comp_color)
palette.setColor(QPalette.ColorRole.Button, self.appdata.comp_color)
self.comp_color_btn.setPalette(palette)
h3.addWidget(self.comp_color_btn)
self.layout.addItem(h3)
Expand All @@ -69,7 +69,7 @@ def __init__(self, main_window, first_start: bool):
self.spec1_color_btn = QPushButton()
self.spec1_color_btn.setFixedWidth(100)
palette = self.spec1_color_btn.palette()
palette.setColor(QPalette.Button, self.appdata.special_color_1)
palette.setColor(QPalette.ColorRole.Button, self.appdata.special_color_1)
self.spec1_color_btn.setPalette(palette)
h4.addWidget(self.spec1_color_btn)
self.layout.addItem(h4)
Expand All @@ -81,7 +81,7 @@ def __init__(self, main_window, first_start: bool):
self.spec2_color_btn = QPushButton()
self.spec2_color_btn.setFixedWidth(100)
palette = self.spec2_color_btn.palette()
palette.setColor(QPalette.Button, self.appdata.special_color_2)
palette.setColor(QPalette.ColorRole.Button, self.appdata.special_color_2)
self.spec2_color_btn.setPalette(palette)
h5.addWidget(self.spec2_color_btn)
self.layout.addItem(h5)
Expand All @@ -93,7 +93,7 @@ def __init__(self, main_window, first_start: bool):
self.default_color_btn = QPushButton()
self.default_color_btn.setFixedWidth(100)
palette = self.default_color_btn.palette()
palette.setColor(QPalette.Button, self.appdata.default_color)
palette.setColor(QPalette.ColorRole.Button, self.appdata.default_color)
self.default_color_btn.setPalette(palette)
h6.addWidget(self.default_color_btn)
self.layout.addItem(h6)
Expand Down Expand Up @@ -185,52 +185,52 @@ def choose_results_cache_directory(self):

def choose_scen_color(self):
palette = self.scen_color_btn.palette()
initial = palette.color(QPalette.Button)
initial = palette.color(QPalette.ColorRole.Button)

dialog = QColorDialog(self)
color: str = dialog.getColor(initial)
if color.isValid():
palette.setColor(QPalette.Button, color)
palette.setColor(QPalette.ColorRole.Button, color)
self.scen_color_btn.setPalette(palette)

def choose_comp_color(self):
palette = self.comp_color_btn.palette()
initial = palette.color(QPalette.Button)
initial = palette.color(QPalette.ColorRole.Button)

dialog = QColorDialog(self)
color: str = dialog.getColor(initial)
if color.isValid():
palette.setColor(QPalette.Button, color)
palette.setColor(QPalette.ColorRole.Button, color)
self.comp_color_btn.setPalette(palette)

def choose_spec1_color(self):
palette = self.spec1_color_btn.palette()
initial = palette.color(QPalette.Button)
initial = palette.color(QPalette.ColorRole.Button)

dialog = QColorDialog(self)
color: str = dialog.getColor(initial)
if color.isValid():
palette.setColor(QPalette.Button, color)
palette.setColor(QPalette.ColorRole.Button, color)
self.spec1_color_btn.setPalette(palette)

def choose_spec2_color(self):
palette = self.spec2_color_btn.palette()
initial = palette.color(QPalette.Button)
initial = palette.color(QPalette.ColorRole.Button)

dialog = QColorDialog(self)
color: str = dialog.getColor(initial)
if color.isValid():
palette.setColor(QPalette.Button, color)
palette.setColor(QPalette.ColorRole.Button, color)
self.spec2_color_btn.setPalette(palette)

def choose_default_color(self):
palette = self.default_color_btn.palette()
initial = palette.color(QPalette.Button)
initial = palette.color(QPalette.ColorRole.Button)

dialog = QColorDialog(self)
color: str = dialog.getColor(initial)
if color.isValid():
palette.setColor(QPalette.Button, color)
palette.setColor(QPalette.ColorRole.Button, color)
self.default_color_btn.setPalette(palette)

def apply(self):
Expand All @@ -251,19 +251,19 @@ def apply(self):
self.appdata.last_scen_directory = self.work_directory.text()

palette = self.scen_color_btn.palette()
self.appdata.scen_color = palette.color(QPalette.Button)
self.appdata.scen_color = palette.color(QPalette.ColorRole.Button)

palette = self.comp_color_btn.palette()
self.appdata.comp_color = palette.color(QPalette.Button)
self.appdata.comp_color = palette.color(QPalette.ColorRole.Button)

palette = self.spec1_color_btn.palette()
self.appdata.special_color_1 = palette.color(QPalette.Button)
self.appdata.special_color_1 = palette.color(QPalette.ColorRole.Button)

palette = self.spec2_color_btn.palette()
self.appdata.special_color_2 = palette.color(QPalette.Button)
self.appdata.special_color_2 = palette.color(QPalette.ColorRole.Button)

palette = self.default_color_btn.palette()
self.appdata.default_color = palette.color(QPalette.Button)
self.appdata.default_color = palette.color(QPalette.ColorRole.Button)

self.appdata.box_width = int(self.box_width.text())
self.appdata.rounding = int(self.rounding.text())
Expand Down
2 changes: 1 addition & 1 deletion cnapy/gui_elements/download_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ def download(self, download_all=False):
msgBox.setText(
"Projects were downloaded successfully in the working directory."
)
msgBox.setIcon(QMessageBox.Information)
msgBox.setIcon(QMessageBox.Icon.Information)
msgBox.exec()
Loading
Loading