Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make code clear and like python style #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
146 changes: 10 additions & 136 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,151 +14,25 @@
#
# ///////////////////////////////////////////////////////////////

import sys
import os
import platform
import sys

from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QApplication

# IMPORT / GUI AND MODULES AND WIDGETS
# ///////////////////////////////////////////////////////////////
from modules import *
from widgets import *
os.environ["QT_FONT_DPI"] = "96" # FIX Problem for High DPI and Scale above 100%
from modules import App

os.environ["QT_FONT_DPI"] = "96" # FIX Problem for High DPI and Scale above 100%

# SET AS GLOBAL WIDGETS
# ///////////////////////////////////////////////////////////////
widgets = None

class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)

# SET AS GLOBAL WIDGETS
# ///////////////////////////////////////////////////////////////
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
global widgets
widgets = self.ui

# USE CUSTOM TITLE BAR | USE AS "False" FOR MAC OR LINUX
# ///////////////////////////////////////////////////////////////
Settings.ENABLE_CUSTOM_TITLE_BAR = True

# APP NAME
# ///////////////////////////////////////////////////////////////
title = "PyDracula - Modern GUI"
description = "PyDracula APP - Theme with colors based on Dracula for Python."
# APPLY TEXTS
self.setWindowTitle(title)
widgets.titleRightInfo.setText(description)

# TOGGLE MENU
# ///////////////////////////////////////////////////////////////
widgets.toggleButton.clicked.connect(lambda: UIFunctions.toggleMenu(self, True))

# SET UI DEFINITIONS
# ///////////////////////////////////////////////////////////////
UIFunctions.uiDefinitions(self)

# QTableWidget PARAMETERS
# ///////////////////////////////////////////////////////////////
widgets.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

# BUTTONS CLICK
# ///////////////////////////////////////////////////////////////

# LEFT MENUS
widgets.btn_home.clicked.connect(self.buttonClick)
widgets.btn_widgets.clicked.connect(self.buttonClick)
widgets.btn_new.clicked.connect(self.buttonClick)
widgets.btn_save.clicked.connect(self.buttonClick)

# EXTRA LEFT BOX
def openCloseLeftBox():
UIFunctions.toggleLeftBox(self, True)
widgets.toggleLeftBox.clicked.connect(openCloseLeftBox)
widgets.extraCloseColumnBtn.clicked.connect(openCloseLeftBox)

# EXTRA RIGHT BOX
def openCloseRightBox():
UIFunctions.toggleRightBox(self, True)
widgets.settingsTopBtn.clicked.connect(openCloseRightBox)

# SHOW APP
# ///////////////////////////////////////////////////////////////
self.show()

# SET CUSTOM THEME
# ///////////////////////////////////////////////////////////////
useCustomTheme = False
themeFile = "themes\py_dracula_light.qss"

# SET THEME AND HACKS
if useCustomTheme:
# LOAD AND APPLY STYLE
UIFunctions.theme(self, themeFile, True)

# SET HACKS
AppFunctions.setThemeHack(self)

# SET HOME PAGE AND SELECT MENU
# ///////////////////////////////////////////////////////////////
widgets.stackedWidget.setCurrentWidget(widgets.home)
widgets.btn_home.setStyleSheet(UIFunctions.selectMenu(widgets.btn_home.styleSheet()))


# BUTTONS CLICK
# Post here your functions for clicked buttons
# ///////////////////////////////////////////////////////////////
def buttonClick(self):
# GET BUTTON CLICKED
btn = self.sender()
btnName = btn.objectName()

# SHOW HOME PAGE
if btnName == "btn_home":
widgets.stackedWidget.setCurrentWidget(widgets.home)
UIFunctions.resetStyle(self, btnName)
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))

# SHOW WIDGETS PAGE
if btnName == "btn_widgets":
widgets.stackedWidget.setCurrentWidget(widgets.widgets)
UIFunctions.resetStyle(self, btnName)
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))

# SHOW NEW PAGE
if btnName == "btn_new":
widgets.stackedWidget.setCurrentWidget(widgets.new_page) # SET PAGE
UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU

if btnName == "btn_save":
print("Save BTN clicked!")

# PRINT BTN NAME
print(f'Button "{btnName}" pressed!')


# RESIZE EVENTS
# ///////////////////////////////////////////////////////////////
def resizeEvent(self, event):
# Update Size Grips
UIFunctions.resize_grips(self)

# MOUSE CLICK EVENTS
# ///////////////////////////////////////////////////////////////
def mousePressEvent(self, event):
# SET DRAG POS WINDOW
self.dragPos = event.globalPos()

# PRINT MOUSE EVENTS
if event.buttons() == Qt.LeftButton:
print('Mouse click: LEFT CLICK')
if event.buttons() == Qt.RightButton:
print('Mouse click: RIGHT CLICK')

if __name__ == "__main__":
app = QApplication(sys.argv)
app.setWindowIcon(QIcon("icon.ico"))
window = MainWindow()
sys.exit(app.exec_())
window = App()
window.launch()
sys.exit(app.exec())
126 changes: 115 additions & 11 deletions modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,122 @@
# https://doc.qt.io/qtforpython/licenses.html
#
# ///////////////////////////////////////////////////////////////
from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *

# GUI FILE
from . ui_main import Ui_MainWindow
from PySide6.QtWidgets import QHeaderView

# APP SETTINGS
from . app_settings import Settings
from modules.app_settings import Settings
from modules.ui_main import Ui_MainWindow
from modules.ui_beautify import UiBeautify
from modules.ui_functions import UIFunctions
from modules.app_functions import AppFunctions

# IMPORT FUNCTIONS
from . ui_functions import *

# APP FUNCTIONS
from . app_functions import *
class App(UiBeautify):

def __init__(self):
super().__init__()

def launch(self):
self.setupUi(self)

# USE CUSTOM TITLE BAR | USE AS "False" FOR MAC OR LINUX
# ///////////////////////////////////////////////////////////////
Settings.ENABLE_CUSTOM_TITLE_BAR = True

# APP NAME
# ///////////////////////////////////////////////////////////////
title = "PyDracula - Modern GUI"
description = "PyDracula APP - Theme with colors based on Dracula for Python."

# APPLY TEXTS
self.setWindowTitle(title)
self.titleRightInfo.setText(description)
self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
self.connect_event()

# show app ui
self.show()

# SET CUSTOM THEME
# ///////////////////////////////////////////////////////////////
useCustomTheme = False
themeFile = "themes/py_dracula_light.qss"

# SET THEME AND HACKS
if useCustomTheme:
# LOAD AND APPLY STYLE
UIFunctions.theme(self, themeFile, True)

# SET HACKS
AppFunctions.setThemeHack(self)

# SET HOME PAGE AND SELECT MENU
# ///////////////////////////////////////////////////////////////
self.stackedWidget.setCurrentWidget(self.home)
self.btn_home.setStyleSheet(UIFunctions.selectMenu(self.btn_home.styleSheet()))

def connect_event(self):
# TOGGLE MENU
# ///////////////////////////////////////////////////////////////
self.toggleButton.clicked.connect(lambda: UIFunctions.ex_toggleMenu(self, True))

# SET UI DEFINITIONS
# ///////////////////////////////////////////////////////////////
UIFunctions.uiDefinitions(self)

# LEFT MENUS
self.btn_home.clicked.connect(self.buttonClick)
self.btn_widgets.clicked.connect(self.buttonClick)
self.btn_new.clicked.connect(self.buttonClick)
self.btn_save.clicked.connect(self.buttonClick)

# EXTRA LEFT BOX
def openCloseLeftBox():
UIFunctions.ex_toggleLeftBox(self, True)

self.toggleLeftBox.clicked.connect(openCloseLeftBox)
self.extraCloseColumnBtn.clicked.connect(openCloseLeftBox)

# EXTRA RIGHT BOX
def openCloseRightBox():
UIFunctions.ex_toggleRightBox(self, True)

self.settingsTopBtn.clicked.connect(openCloseRightBox)

# RESIZE EVENTS
# ///////////////////////////////////////////////////////////////
def resizeEvent(self, event):
# Update Size Grips
UIFunctions.resize_grips(self)

# BUTTONS CLICK
# Post here your functions for clicked buttons
# ///////////////////////////////////////////////////////////////
def buttonClick(self):
# GET BUTTON CLICKED
btn = self.sender()
btnName = btn.objectName()

# SHOW HOME PAGE
if btnName == "btn_home":
self.stackedWidget.setCurrentWidget(self.home)
UIFunctions.resetStyle(self, btnName)
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))

# SHOW WIDGETS PAGE
if btnName == "btn_widgets":
self.stackedWidget.setCurrentWidget(self.widgets)
UIFunctions.resetStyle(self, btnName)
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))

# SHOW NEW PAGE
if btnName == "btn_new":
self.stackedWidget.setCurrentWidget(self.new_page) # SET PAGE
UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU

if btnName == "btn_save":
print("Save BTN clicked!")

# PRINT BTN NAME
print(f'Button "{btnName}" pressed!')
29 changes: 18 additions & 11 deletions modules/app_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@

# MAIN FILE
# ///////////////////////////////////////////////////////////////
from main import *
from modules import (
UiBeautify,
Settings
)


# WITH ACCESS TO MAIN WINDOW WIDGETS
# ///////////////////////////////////////////////////////////////
class AppFunctions(MainWindow):
class AppFunctions(UiBeautify):

def setThemeHack(self):
Settings.BTN_LEFT_BOX_COLOR = "background-color: #495474;"
Settings.BTN_RIGHT_BOX_COLOR = "background-color: #495474;"
Expand All @@ -30,12 +35,14 @@ def setThemeHack(self):
"""

# SET MANUAL STYLES
self.ui.lineEdit.setStyleSheet("background-color: #6272a4;")
self.ui.pushButton.setStyleSheet("background-color: #6272a4;")
self.ui.plainTextEdit.setStyleSheet("background-color: #6272a4;")
self.ui.tableWidget.setStyleSheet("QScrollBar:vertical { background: #6272a4; } QScrollBar:horizontal { background: #6272a4; }")
self.ui.scrollArea.setStyleSheet("QScrollBar:vertical { background: #6272a4; } QScrollBar:horizontal { background: #6272a4; }")
self.ui.comboBox.setStyleSheet("background-color: #6272a4;")
self.ui.horizontalScrollBar.setStyleSheet("background-color: #6272a4;")
self.ui.verticalScrollBar.setStyleSheet("background-color: #6272a4;")
self.ui.commandLinkButton.setStyleSheet("color: #ff79c6;")
self.lineEdit.setStyleSheet("background-color: #6272a4;")
self.pushButton.setStyleSheet("background-color: #6272a4;")
self.plainTextEdit.setStyleSheet("background-color: #6272a4;")
self.tableWidget.setStyleSheet(
"QScrollBar:vertical { background: #6272a4; } QScrollBar:horizontal { background: #6272a4; }")
self.scrollArea.setStyleSheet(
"QScrollBar:vertical { background: #6272a4; } QScrollBar:horizontal { background: #6272a4; }")
self.comboBox.setStyleSheet("background-color: #6272a4;")
self.horizontalScrollBar.setStyleSheet("background-color: #6272a4;")
self.verticalScrollBar.setStyleSheet("background-color: #6272a4;")
self.commandLinkButton.setStyleSheet("color: #ff79c6;")
2 changes: 1 addition & 1 deletion modules/app_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Settings():
class Settings(object):
# APP SETTINGS
# ///////////////////////////////////////////////////////////////
ENABLE_CUSTOM_TITLE_BAR = True
Expand Down
4 changes: 4 additions & 0 deletions modules/resources_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from PySide6 import QtCore


qt_resource_data = b"\
\x00\x00\x07b\
\x89\
Expand Down Expand Up @@ -34141,10 +34142,13 @@
\x00\x00\x01v+M\xdd\xa0\
"


def qInitResources():
QtCore.qRegisterResourceData(0x03, qt_resource_struct, qt_resource_name, qt_resource_data)


def qCleanupResources():
QtCore.qUnregisterResourceData(0x03, qt_resource_struct, qt_resource_name, qt_resource_data)


qInitResources()
Loading