Skip to content

Commit

Permalink
Feat: Apply initial branding (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnFrueh authored Jul 14, 2024
1 parent a44a691 commit d01366d
Show file tree
Hide file tree
Showing 35 changed files with 206 additions and 100 deletions.
33 changes: 24 additions & 9 deletions modo_kit_central/mkc/database.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List
import sqlite3

from .prefs import Paths, AuthorData
from .prefs import Paths, AuthorData, QueryData


def search_kits(search_text: str) -> List[int]:
Expand All @@ -14,12 +14,13 @@ def search_kits(search_text: str) -> List[int]:
search_terms = [s.strip() for s in search_text.split(",")]

# Generate the search query for all terms.
query = "SELECT * FROM kits WHERE 1=1"
query = QueryData.SelectKits
params = []

for term in search_terms:
query += " AND (name LIKE ? OR author LIKE ? OR search LIKE ? OR Description LIKE ?)"
params.extend([f"%{term}%"] * 4)
query += QueryData.SearchTerm
# For every '?' in the query, add the search term to the params.
params.extend([f"%{term}%"] * QueryData.SearchTerm.count("?"))

with sqlite3.connect(Paths.DATABASE) as connection:
cursor = connection.cursor()
Expand All @@ -37,7 +38,7 @@ def get_kits() -> List[tuple]:
"""
with sqlite3.connect(Paths.DATABASE) as connection:
cursor = connection.cursor()
cursor.execute("SELECT * FROM kits")
cursor.execute(QueryData.SelectKits)
return cursor.fetchall()


Expand All @@ -50,10 +51,24 @@ def get_author(author: str) -> AuthorData:
Returns:
author_data: The author's data class.
"""
search_params = [f"%{author}%"]

with sqlite3.connect(Paths.DATABASE) as connection:
cursor = connection.cursor()
cursor.execute(
"SELECT * FROM authors WHERE name=?",
(author,)
)
cursor.execute(QueryData.SelectAuthor, search_params)
return AuthorData(*cursor.fetchone())


def get_author_kits(author: str) -> List[tuple]:
"""Gets all kits from the database by the given author.
Args:
author: The author's name to get data for.
Returns:
kits: A list of all kits by the author.
"""
with sqlite3.connect(Paths.DATABASE) as connection:
cursor = connection.cursor()
cursor.execute(QueryData.SelectKitsByAuthor, [author])
return cursor.fetchall()
25 changes: 16 additions & 9 deletions modo_kit_central/mkc/gui.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
try:
from PySide6.QtCore import Qt
from PySide6.QtGui import QCloseEvent
from PySide6.QtWidgets import QMainWindow, QTabWidget, QWidget, QVBoxLayout, QTabBar
from PySide6.QtGui import QCloseEvent, QPixmap
from PySide6.QtWidgets import QMainWindow, QTabWidget, QWidget, QVBoxLayout, QTabBar, QLabel
except ImportError:
# Fallback to PySide2 if PySide6 is not available
from PySide2.QtCore import Qt
from PySide2.QtGui import QCloseEvent
from PySide2.QtWidgets import QMainWindow, QTabWidget, QWidget, QVBoxLayout, QTabBar
from PySide2.QtGui import QCloseEvent, QPixmap
from PySide2.QtWidgets import QMainWindow, QTabWidget, QWidget, QVBoxLayout, QTabBar, QLabel

# Kit imports
from .prefs import Text, KEYS, DATA
from .widgets import KitTab
from .prefs import Text, KEYS, DATA, Paths
from .widgets import KitsTab, Banner


class KitCentralWindow(QMainWindow):
Expand All @@ -31,14 +31,19 @@ def _build_window(self) -> None:
self.setStyleSheet(DATA.CSS)
self.setWindowTitle(Text.title)
self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint)
self.resize(450, 300)
self.icon = QPixmap(Paths.ICON.as_posix())
self.setWindowIcon(self.icon)
self.setFixedWidth(512)
self.resize(512, 400)

def _build_ui(self) -> None:
"""Builds the UI for the Kit Central."""
self.base_widget = QWidget(self)
self.base_layout = QVBoxLayout(self.base_widget)
self.base_layout.setContentsMargins(2, 2, 2, 2)
self.base_layout.setContentsMargins(0, 0, 0, 0)
self.base_layout.setSpacing(0)
self.base_widget.setLayout(self.base_layout)
self.base_layout.addWidget(Banner(Paths.BANNERS / "mkc.png"))
self.setCentralWidget(self.base_widget)

def _build_tabs(self) -> None:
Expand All @@ -50,10 +55,12 @@ def _build_tabs(self) -> None:
self.tabs.setObjectName("Tabs")
self.base_layout.addWidget(self.tabs)
# Add the core tab
self.tab_kits = KitTab()
self.tab_kits = KitsTab()
self.tabs.addTab(self.tab_kits, KEYS.KITS)
# Remove the close button from these core tab
self.tabs.tabBar().setTabButton(0, QTabBar.RightSide, None)
# Remove close button on macOS
self.tabs.tabBar().setTabButton(0, QTabBar.LeftSide, None)

def closeEvent(self, event: QCloseEvent) -> None:
"""PySide method: Handle closing the UI
Expand Down
14 changes: 13 additions & 1 deletion modo_kit_central/mkc/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ class DATA:
class Paths:
KIT_ROOT = Path(__file__).parent.parent.absolute()
RESOURCES = KIT_ROOT / "resources"
CSS_IMAGES = RESOURCES / "images"
DATABASE = RESOURCES / "kits.db"
IMAGES = RESOURCES / "images"
ICON = IMAGES / "icon.png"
IMAGES_CSS = IMAGES / "css"
BANNERS = IMAGES / "banners"


class Text:
Expand Down Expand Up @@ -72,3 +75,12 @@ class AuthorData:
def __post_init__(self):
"""Convert the links json string to a dictionary."""
self.links = json.loads(self.links) if self.links else {}


@dataclass
class QueryData:
"""Dataclass for the query data."""
SelectKits: str = "SELECT * FROM kits WHERE TRUE"
SearchTerm: str = " AND (name LIKE ? OR author LIKE ? OR search LIKE ? OR Description LIKE ?)"
SelectAuthor: str = "SELECT * FROM authors WHERE name LIKE ?"
SelectKitsByAuthor: str = "SELECT * FROM kits WHERE author = ?"
2 changes: 1 addition & 1 deletion modo_kit_central/mkc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def set_absolute_images(css_data: str) -> str:
Args:
css_data: The CSS data to update.
"""
return css_data.replace("url(", f"url({Paths.CSS_IMAGES.as_posix()}/")
return css_data.replace("url(", f"url({Paths.IMAGES_CSS.as_posix()}/")


def load_stylesheet() -> None:
Expand Down
Loading

0 comments on commit d01366d

Please sign in to comment.