Skip to content

Commit

Permalink
refactor: migrate code to pyqt6
Browse files Browse the repository at this point in the history
  • Loading branch information
centaurialpha committed Aug 25, 2022
1 parent d28b199 commit 9c3c7d5
Show file tree
Hide file tree
Showing 31 changed files with 547 additions and 14,239 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
.coverage*
pireal.egg-*
venv/
.venv/
.tox/
11 changes: 7 additions & 4 deletions bin/pireal
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
import os
import sys

project_base_dir = os.path.abspath(os.path.dirname(os.path.dirname(
os.path.realpath(sys.argv[0]))))
project_base_dir = os.path.abspath(
os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))
)
if project_base_dir not in sys.path:
sys.path.insert(0, project_base_dir)

from pireal.core import cliparser # noqa
from pireal import __version__
from pireal import __version__ # noqa
from pireal.dirs import create_app_dirs # noqa

# Parse CLI
Expand All @@ -39,8 +40,10 @@ if args.version:
create_app_dirs()

from pireal.core import logger # noqa
from pireal import resources # noqa

# from pireal import resources # noqa
from pireal import main # noqa

# Set up logger
logger.set_up(verbose=args.verbose)

Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ include_package_data = True
scripts =
bin/pireal
install_requires =
PyQt5==5.15.2
# PyQt5==5.15.2
PyQt6

[options.packages.find]
where = src
Expand Down
19 changes: 11 additions & 8 deletions src/pireal/core/pfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

import os

from PyQt5.QtCore import QObject
from PyQt5.QtCore import pyqtSignal as Signal
from PyQt5.QtCore import QFile
from PyQt5.QtCore import QTextStream
from PyQt5.QtCore import QTextCodec
from PyQt5.QtCore import QIODevice
from PyQt6.QtCore import QObject
from PyQt6.QtCore import pyqtSignal as Signal
from PyQt6.QtCore import QFile
from PyQt6.QtCore import QTextStream

# from PyQt6.QtCore import QTextCodec
from PyQt6.QtCore import QIODevice


class File(QObject):
Expand Down Expand Up @@ -52,11 +53,13 @@ def save(self, data, path=None):
self.is_new = False

_file = QFile(self.filename)
if not _file.open(QIODevice.WriteOnly | QIODevice.Truncate):
if not _file.open(
QIODevice.OpenModeFlag.WriteOnly | QIODevice.OpenModeFlag.Truncate
):
raise Exception(_file.errorString())

stream = QTextStream(_file)
stream.setCodec(QTextCodec.codecForLocale())
# stream.setCodec(QTextCodec.codecForLocale())
stream << data
stream.flush()
_file.close()
Expand Down
15 changes: 12 additions & 3 deletions src/pireal/dirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import platform
from pathlib import Path

from PyQt5.QtCore import QStandardPaths
from PyQt6.QtCore import QStandardPaths


_ROOT_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -45,7 +45,11 @@ def _data_dir() -> Path:
else:
# In windows and mac, use standard paths provided by Qt
pireal_data_dir = (
Path(QStandardPaths.writableLocation(QStandardPaths.GenericDataLocation))
Path(
QStandardPaths.writableLocation(
QStandardPaths.StandardLocation.GenericDataLocation
)
)
/ pireal_dir_name
)

Expand All @@ -56,7 +60,12 @@ def _get_databases_location() -> Path:
"""Return the path used for store the user databases"""

db_dir = (
Path(QStandardPaths.writableLocation(QStandardPaths.HomeLocation)) / "PirealDBs"
Path(
QStandardPaths.writableLocation(
QStandardPaths.StandardLocation.HomeLocation
)
)
/ "PirealDBs"
)

return db_dir
Expand Down
44 changes: 24 additions & 20 deletions src/pireal/gui/central_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
import logging
from collections import defaultdict

from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QStackedWidget
from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtWidgets import QShortcut
from PyQt6.QtWidgets import QWidget
from PyQt6.QtWidgets import QVBoxLayout
from PyQt6.QtWidgets import QStackedWidget
from PyQt6.QtWidgets import QFileDialog
from PyQt6.QtWidgets import QMessageBox
from PyQt6.QtGui import QShortcut

from PyQt5.QtGui import QKeySequence
from PyQt5.QtCore import Qt
from PyQt5.QtCore import QSettings
from PyQt6.QtGui import QKeySequence
from PyQt6.QtCore import Qt
from PyQt6.QtCore import QSettings


from pireal import settings
Expand Down Expand Up @@ -66,14 +66,14 @@ def __init__(self):

self.created = False

qsettings = QSettings(str(DATA_SETTINGS), QSettings.IniFormat)
qsettings = QSettings(str(DATA_SETTINGS), QSettings.Format.IniFormat)
# Acá cacheo la última carpeta accedida
self._last_open_folder = qsettings.value("last_open_folder", type=str)
self._recent_dbs = qsettings.value("recent_databases", type=list)

Pireal.load_service("central", self)

esc_short = QShortcut(QKeySequence(Qt.Key_Escape), self)
esc_short = QShortcut(QKeySequence(Qt.Key.Key_Escape), self)
esc_short.activated.connect(self._hide_search)

def _hide_search(self):
Expand Down Expand Up @@ -290,11 +290,13 @@ def close_database(self):
self,
tr.TR_MSG_SAVE_CHANGES,
tr.TR_MSG_SAVE_CHANGES_BODY,
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
QMessageBox.StandardButton.Yes
| QMessageBox.StandardButton.No
| QMessageBox.StandardButton.Cancel,
)
if ret == QMessageBox.Cancel:
if ret == QMessageBox.StandardButton.Cancel:
return
if ret == QMessageBox.Yes:
if ret == QMessageBox.StandardButton.Yes:
self.save_database()

# Check if editor is modified
Expand All @@ -308,11 +310,13 @@ def close_database(self):
self,
tr.TR_MSG_FILE_MODIFIED,
tr.TR_MSG_FILE_MODIFIED_BODY.format(weditor.name),
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
QMessageBox.StandardButton.Yes
| QMessageBox.StandardButton.No
| QMessageBox.StandardButton.Cancel,
)
if ret == QMessageBox.Cancel:
if ret == QMessageBox.StandardButton.Cancel:
return
if ret == QMessageBox.Yes:
if ret == QMessageBox.StandardButton.Yes:
self.save_query(weditor)

self.stacked.removeWidget(db)
Expand Down Expand Up @@ -434,7 +438,7 @@ def show_settings(self):
"""Show settings dialog on stacked"""

settings_dialog = preferences.SettingsDialog(self)
settings_dialog.exec_()
settings_dialog.exec()

def widget(self, index):
"""Returns the widget at the given index"""
Expand Down Expand Up @@ -527,9 +531,9 @@ def delete_tuple(self):
self,
tr.TR_MSG_REMOVE_TUPLES,
tr.TR_MSG_REMOVE_TUPLES_BODY,
QMessageBox.Yes | QMessageBox.Cancel,
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.Cancel,
)
if r == QMessageBox.Cancel:
if r == QMessageBox.StandardButton.Cancel:
return
tw = self.get_active_db().table_widget
tw.delete_tuple()
Expand Down
20 changes: 10 additions & 10 deletions src/pireal/gui/database_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import csv
import logging

from PyQt5.QtWidgets import QSplitter
from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtWidgets import QMessageBox
from PyQt6.QtWidgets import QSplitter
from PyQt6.QtWidgets import QFileDialog
from PyQt6.QtWidgets import QMessageBox

from PyQt5.QtCore import Qt
from PyQt5.QtCore import QSettings
from PyQt5.QtCore import pyqtSlot as Slot
from PyQt6.QtCore import Qt
from PyQt6.QtCore import QSettings
from PyQt6.QtCore import pyqtSlot as Slot

from pireal.gui import (
table_widget,
Expand All @@ -46,15 +46,15 @@


class DatabaseContainer(QSplitter):
def __init__(self, orientation=Qt.Horizontal):
def __init__(self, orientation=Qt.Orientation.Horizontal):
QSplitter.__init__(self, orientation)
self.pfile = None

self.lateral_widget = lateral_widget.LateralWidget()
self.table_widget = table_widget.TableWidget()
self.query_container = query_container.QueryContainer(self)

self._vsplitter = QSplitter(Qt.Vertical)
self._vsplitter = QSplitter(Qt.Orientation.Vertical)
self._vsplitter.addWidget(self.table_widget)
self._vsplitter.addWidget(self.query_container)
self.addWidget(self.lateral_widget)
Expand Down Expand Up @@ -235,7 +235,7 @@ def execute_selection(self):

def showEvent(self, event):
QSplitter.showEvent(self, event)
qsettings = QSettings(str(DATA_SETTINGS), QSettings.IniFormat)
qsettings = QSettings(str(DATA_SETTINGS), QSettings.Format.IniFormat)
vsizes = qsettings.value("vsplitter_sizes", None)
if vsizes is not None:
self._vsplitter.restoreState(vsizes)
Expand All @@ -252,7 +252,7 @@ def showEvent(self, event):
def save_sizes(self):
"""Save sizes of Splitters"""

qsettings = QSettings(str(DATA_SETTINGS), QSettings.IniFormat)
qsettings = QSettings(str(DATA_SETTINGS), QSettings.Format.IniFormat)
qsettings.setValue("vsplitter_sizes", self._vsplitter.saveState())
qsettings.setValue("hsplitter_sizes", self.saveState())
# FIXME: save sizes of query container
20 changes: 10 additions & 10 deletions src/pireal/gui/dialogs/about_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from datetime import datetime

from PyQt5.QtWidgets import (
from PyQt6.QtWidgets import (
QDialog,
QVBoxLayout,
QLabel,
Expand All @@ -28,8 +28,8 @@
QSizePolicy,
QPushButton,
)
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import Qt
from PyQt6.QtGui import QPixmap
from PyQt6.QtCore import Qt
from pireal import __version__, gui
from pireal import translations as tr

Expand All @@ -42,20 +42,20 @@ def __init__(self, parent=None):
# Banner
banner = QLabel()
banner.setPixmap(QPixmap(":img/icon"))
banner.setAlignment(Qt.AlignHCenter)
banner.setAlignment(Qt.AlignmentFlag.AlignHCenter)
vbox.addWidget(banner)

# Version
lbl_version = QLabel("{0}".format(__version__))
lbl_version.setAlignment(Qt.AlignHCenter)
lbl_version.setAlignment(Qt.AlignmentFlag.AlignHCenter)
font = lbl_version.font()
font.setPointSize(10)
lbl_version.setFont(font)
vbox.addWidget(lbl_version)

# Description
description = QLabel(tr.TR_DIALOG_ABOUT_PIREAL_BODY)
description.setAlignment(Qt.AlignHCenter)
description.setAlignment(Qt.AlignmentFlag.AlignHCenter)
font = description.font()
font.setPointSize(13)
description.setFont(font)
Expand All @@ -67,15 +67,15 @@ def __init__(self, parent=None):
font = abuelo_agui_lbl.font()
font.setPointSize(8)
abuelo_agui_lbl.setFont(font)
abuelo_agui_lbl.setAlignment(Qt.AlignHCenter)
abuelo_agui_lbl.setAlignment(Qt.AlignmentFlag.AlignHCenter)
vbox.addWidget(abuelo_agui_lbl)

# Copyright
copy = QLabel(
"<br>Copyright © 2015-{year} - "
"Gabriel 'gabo' Acosta".format(year=datetime.today().year)
)
copy.setAlignment(Qt.AlignHCenter)
copy.setAlignment(Qt.AlignmentFlag.AlignHCenter)
font = copy.font()
font.setPointSize(9)
copy.setFont(font)
Expand All @@ -85,7 +85,7 @@ def __init__(self, parent=None):
lbl_license_source = QLabel(
tr.TR_DIALOG_ABOUT_PIREAL_COPY.format(gui.__license__, gui.__source_code__)
)
lbl_license_source.setAlignment(Qt.AlignHCenter)
lbl_license_source.setAlignment(Qt.AlignmentFlag.AlignHCenter)
lbl_license_source.setOpenExternalLinks(True)
font = lbl_license_source.font()
font.setPointSize(13)
Expand All @@ -94,7 +94,7 @@ def __init__(self, parent=None):

# Buttons
hbox = QHBoxLayout()
hbox.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding))
hbox.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Policy.Expanding))
btn_ok = QPushButton("Ok")
hbox.addWidget(btn_ok)
vbox.addLayout(hbox)
Expand Down
20 changes: 10 additions & 10 deletions src/pireal/gui/dialogs/edit_relation_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
# You should have received a copy of the GNU General Public License
# along with Pireal; If not, see <http://www.gnu.org/licenses/>.

from PyQt5.QtWidgets import QDialog
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QHBoxLayout
from PyQt5.QtWidgets import QPlainTextEdit
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QStyle
from PyQt5.QtWidgets import QMessageBox
from PyQt6.QtWidgets import QDialog
from PyQt6.QtWidgets import QVBoxLayout
from PyQt6.QtWidgets import QHBoxLayout
from PyQt6.QtWidgets import QPlainTextEdit
from PyQt6.QtWidgets import QLabel
from PyQt6.QtWidgets import QPushButton
from PyQt6.QtWidgets import QStyle
from PyQt6.QtWidgets import QMessageBox

from PyQt5.QtGui import QFont
from PyQt6.QtGui import QFont

from PyQt5.QtCore import pyqtSignal
from PyQt6.QtCore import pyqtSignal

from pireal.gui.main_window import Pireal
from pireal.settings import CONFIG
Expand Down
Loading

0 comments on commit 9c3c7d5

Please sign in to comment.