Skip to content

Commit

Permalink
Add pre-commit config (#70)
Browse files Browse the repository at this point in the history
* Add pre-commit config

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
haiiliin and pre-commit-ci[bot] committed Jul 23, 2023
1 parent 7842311 commit cbb9be2
Show file tree
Hide file tree
Showing 24 changed files with 229 additions and 196 deletions.
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args:
- --line-length=120
- --include='(pyqtribbon/.*\.py|tests/.*\.py|docs/source/conf\.py)'

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args:
- --profile=black
5 changes: 2 additions & 3 deletions docs/source/_examples/build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os


for file in os.listdir(os.path.dirname(__file__)):
if file.endswith('.py') and not file.startswith('build'):
os.system(f'python {file}')
if file.endswith(".py") and not file.startswith("build"):
os.system(f"python {file}")
58 changes: 30 additions & 28 deletions docs/source/_examples/category.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
import sys

from qtpy import QtGui
from qtpy.QtWidgets import QApplication
from qtpy.QtGui import QIcon
from qtpy.QtWidgets import QApplication

from pyqtribbon import RibbonBar, RibbonCategoryStyle
from pyqtribbon.screenshotwindow import RibbonScreenShotWindow

if __name__ == '__main__':
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setFont(QtGui.QFont("Times New Roman", 8))
window = RibbonScreenShotWindow('category.png')
window = RibbonScreenShotWindow("category.png")

# Ribbon bar
ribbonbar = RibbonBar()
window.setMenuBar(ribbonbar)

# Categories
category1 = ribbonbar.addCategory('Category 1')
panel1 = category1.addPanel('Panel 1')
panel1.addLargeButton('Large Button 1', QIcon('python.png'))

category2 = ribbonbar.addContextCategory('Category 2')
panel12 = category2.addPanel('Panel 2')
panel12.addLargeButton('Large Button 2', QIcon('python.png'))

categories = ribbonbar.addCategoriesBy({
'Category 6': {
"style": RibbonCategoryStyle.Normal,
"panels": {
"Panel 1": {
"showPanelOptionButton": True,
"widgets": {
"Button 1": {
"type": "Button",
"arguments": {
"icon": QIcon("python.png"),
"text": "Button",
"tooltip": "This is a tooltip",
}
category1 = ribbonbar.addCategory("Category 1")
panel1 = category1.addPanel("Panel 1")
panel1.addLargeButton("Large Button 1", QIcon("python.png"))

category2 = ribbonbar.addContextCategory("Category 2")
panel12 = category2.addPanel("Panel 2")
panel12.addLargeButton("Large Button 2", QIcon("python.png"))

categories = ribbonbar.addCategoriesBy(
{
"Category 6": {
"style": RibbonCategoryStyle.Normal,
"panels": {
"Panel 1": {
"showPanelOptionButton": True,
"widgets": {
"Button 1": {
"type": "Button",
"arguments": {
"icon": QIcon("python.png"),
"text": "Button",
"tooltip": "This is a tooltip",
},
},
},
}
},
},
}
}
})
ribbonbar.setCurrentCategory(categories['Category 6'])
)
ribbonbar.setCurrentCategory(categories["Category 6"])

# Show the window
window.resize(1000, 250)
Expand Down
12 changes: 6 additions & 6 deletions docs/source/_examples/panel.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import sys

from qtpy import QtGui
from qtpy.QtWidgets import QApplication, QToolButton, QMenu, QLabel, QLineEdit
from qtpy.QtGui import QIcon
from qtpy.QtCore import Qt
from qtpy.QtGui import QIcon
from qtpy.QtWidgets import QApplication, QLabel, QLineEdit, QMenu, QToolButton

from pyqtribbon import RibbonBar
from pyqtribbon.screenshotwindow import RibbonScreenShotWindow

if __name__ == '__main__':
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setFont(QtGui.QFont("Times New Roman", 8))
window = RibbonScreenShotWindow('panel.png')
window = RibbonScreenShotWindow("panel.png")

# Ribbon bar
ribbonbar = RibbonBar()
Expand Down Expand Up @@ -42,9 +42,9 @@

gallery = panel.addGallery(minimumWidth=500, popupHideOnClick=True)
for i in range(100):
gallery.addToggleButton(f'item {i+1}', QIcon("python.png"))
gallery.addToggleButton(f"item {i+1}", QIcon("python.png"))
popupMenu = gallery.popupMenu()
submenu = popupMenu.addMenu(QIcon("python.png"), 'Submenu')
submenu = popupMenu.addMenu(QIcon("python.png"), "Submenu")
submenu.addAction(QIcon("python.png"), "Action 4")
popupMenu.addAction(QIcon("python.png"), "Action 1")
popupMenu.addAction(QIcon("python.png"), "Action 2")
Expand Down
10 changes: 5 additions & 5 deletions docs/source/_examples/ribbonbar-customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
from pyqtribbon import RibbonBar
from pyqtribbon.screenshotwindow import RibbonScreenShotWindow

if __name__ == '__main__':
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setFont(QtGui.QFont("Times New Roman", 8))
window = RibbonScreenShotWindow('ribbonbar-customize.png')
window = RibbonScreenShotWindow("ribbonbar-customize.png")

# Ribbon bar
ribbonbar = RibbonBar()
window.setMenuBar(ribbonbar)

# Title of the ribbon
ribbonbar.setTitle('This is my custom title')
ribbonbar.setTitle("This is my custom title")

# Quick Access Bar
qbutton = QToolButton()
qbutton.setText('Quick Button')
qbutton.setText("Quick Button")
ribbonbar.addQuickAccessButton(qbutton)

# Right toolbar
rbutton = QToolButton()
rbutton.setText('Right Button')
rbutton.setText("Right Button")
ribbonbar.addRightToolButton(rbutton)

# Show the window
Expand Down
6 changes: 3 additions & 3 deletions docs/source/_examples/ribbonbar.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import sys

from qtpy import QtWidgets, QtGui
from qtpy import QtGui, QtWidgets

from pyqtribbon import RibbonBar
from pyqtribbon.screenshotwindow import RibbonScreenShotWindow

if __name__ == '__main__':
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
app.setFont(QtGui.QFont("Times New Roman", 8))
window = RibbonScreenShotWindow('ribbonbar.png')
window = RibbonScreenShotWindow("ribbonbar.png")

# Ribbon bar
ribbonbar = RibbonBar()
Expand Down
6 changes: 3 additions & 3 deletions docs/source/_examples/tutorial-ribbonbar.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys

from PyQt5.QtWidgets import QApplication, QLabel, QWidget, QVBoxLayout
from PyQt5.QtGui import QIcon, QFont
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont, QIcon
from PyQt5.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget

from pyqtribbon import RibbonBar
from pyqtribbon.screenshotwindow import RibbonScreenShotWindow
Expand All @@ -13,7 +13,7 @@
app.setFont(QFont("Times New Roman", 8))

# Central widget
window = RibbonScreenShotWindow('tutorial-ribbonbar.png')
window = RibbonScreenShotWindow("tutorial-ribbonbar.png")
window.setWindowIcon(QIcon(DataFile("icons/python.png")))
centralWidget = QWidget()
window.setCentralWidget(centralWidget)
Expand Down
89 changes: 45 additions & 44 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
import inspect
import os
import sys

import pyqtribbon

sys.path.insert(0, os.path.abspath('../../'))
sys.path.insert(0, os.path.abspath("../../"))

# -- Project information -----------------------------------------------------

project = 'pyqtribbon'
copyright = '2022, WANG Hailin'
author = 'WANG Hailin'
project = "pyqtribbon"
copyright = "2022, WANG Hailin"
author = "WANG Hailin"

# The full version, including alpha/beta/rc tags
release = version = pyqtribbon.__version__
Expand All @@ -33,43 +34,43 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'hoverxref.extension',
'sphinx.ext.autosummary',
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.linkcode',
'sphinx.ext.napoleon',
'sphinx.ext.githubpages',
'sphinx_copybutton',
'sphinx_codeautolink',
'sphinx_toolbox.more_autodoc.overloads',
'sphinx_qt_documentation',
'sphinxcontrib.apidoc',
"hoverxref.extension",
"sphinx.ext.autosummary",
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.linkcode",
"sphinx.ext.napoleon",
"sphinx.ext.githubpages",
"sphinx_copybutton",
"sphinx_codeautolink",
"sphinx_toolbox.more_autodoc.overloads",
"sphinx_qt_documentation",
"sphinxcontrib.apidoc",
]

qt_documentation = 'Qt5'
autodoc_typehints_format = 'short'
qt_documentation = "Qt5"
autodoc_typehints_format = "short"
numpydoc_show_inherited_class_members = False

# sphinx.ext.intersphinx configuration
intersphinx_mapping = {
'jinjia2': ('https://jinja.palletsprojects.com/en/3.0.x/', None),
'matplotlib': ('https://matplotlib.org/stable/', None),
'numpy': ('https://numpy.org/doc/stable/', None),
'pandas': ('https://pandas.pydata.org/pandas-docs/stable/', None),
'pytest': ('https://pytest.org/en/stable/', None),
'python': ('https://docs.python.org/3/', None),
'readthedocs': ('https://docs.readthedocs.io/en/stable/', None),
'scipy': ('https://docs.scipy.org/doc/scipy/', None),
"jinjia2": ("https://jinja.palletsprojects.com/en/3.0.x/", None),
"matplotlib": ("https://matplotlib.org/stable/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
"pytest": ("https://pytest.org/en/stable/", None),
"python": ("https://docs.python.org/3/", None),
"readthedocs": ("https://docs.readthedocs.io/en/stable/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
}

# Hoverxref configuration
hoverxref_auto_ref = True
hoverxref_domains = ["py"]
hoverxref_roles = [
'numref',
'confval',
'setting',
"numref",
"confval",
"setting",
"option",
"doc", # Documentation pages
"term", # Glossary terms
Expand All @@ -89,10 +90,10 @@
"numref": "tooltip",
}
hoverxref_intersphinx = [
'numpy',
'pytest',
'python',
'readthedocs',
"numpy",
"pytest",
"python",
"readthedocs",
]

# sphinxcontrib-apidoc configuration
Expand All @@ -104,7 +105,7 @@
apidoc_extra_args = ["-d 1"]

# sphinx.ext.autodoc configuration
autoclass_content = 'both'
autoclass_content = "both"


# linkcode source
Expand All @@ -126,21 +127,21 @@ def linkcode_resolve(domain: str, info: dict):
-------
source url of the object
"""
if domain != 'py':
if domain != "py":
return None

modname = info['module']
fullname = info['fullname']
modname = info["module"]
fullname = info["fullname"]

filename = modname.replace('.', '/')
baseurl = f'https://github.com/haiiliin/pyqtribbon/blob/main/{filename}.py'
filename = modname.replace(".", "/")
baseurl = f"https://github.com/haiiliin/pyqtribbon/blob/main/{filename}.py"

submod = sys.modules.get(modname)
if submod is None:
return baseurl

obj = submod
for part in fullname.split('.'):
for part in fullname.split("."):
try:
obj = getattr(obj, part)
except Exception:
Expand All @@ -150,11 +151,11 @@ def linkcode_resolve(domain: str, info: dict):
except Exception:
return baseurl

return baseurl + f'#L{lineno}-L{lineno + len(source) - 1}'
return baseurl + f"#L{lineno}-L{lineno + len(source) - 1}"


# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -167,9 +168,9 @@ def linkcode_resolve(domain: str, info: dict):
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

0 comments on commit cbb9be2

Please sign in to comment.