Skip to content
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
19 changes: 19 additions & 0 deletions Assets/icons/svg_bullets.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions Assets/icons/svg_hyperlink.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Assets/icons/svg_redo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Assets/icons/svg_table.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Assets/icons/svg_undo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 17 additions & 15 deletions Models/DraggableContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def setChildWidget(self, childWidget):
self.vLayout.addWidget(childWidget)
self.vLayout.setContentsMargins(0,0,0,0)

def eventFilter(self, obj, event):
def eventFilter(self, obj, e):

# If child widget resized itsself, resize this drag container, not ideal bc child resizes on hover
if isinstance(event, QResizeEvent):
if isinstance(e, QResizeEvent):
self.resize(self.childWidget.size())
return False

Expand All @@ -80,7 +80,7 @@ def popupShow(self, pt: QPoint):
def mousePressEvent(self, e: QMouseEvent):
self.position = QPoint(e.globalX() - self.geometry().x(), e.globalY() - self.geometry().y())

print("DC MOUSE PRESS")
print("Draggable Container MOUSE PRESS")

# Undo related
# self.old_x = e.globalX()
Expand All @@ -93,7 +93,7 @@ def mousePressEvent(self, e: QMouseEvent):
print("NOT EDIT")
return
if not e.buttons() and Qt.LeftButton:
print("DC GOT MOUSE PRESS")
print("Draggable Container GOT MOUSE PRESS")
self.setCursorShape(e.pos())
return True
if e.button() == Qt.RightButton:
Expand All @@ -117,14 +117,17 @@ def leaveEvent(self, e: QMouseEvent):
self.childWidget.setAttribute(Qt.WA_TransparentForMouseEvents, True)
self.setStyleSheet("border: none;")

# Delete this DC if childWidget says it's empty
if hasattr(self.childWidget, "checkEmpty"):
if self.childWidget.checkEmpty():
editorSignalsInstance.widgetRemoved.emit(self)

# ???
if self.childWidget.hasFocus():
self.setFocus()
# Delete this Draggable Container if childWidget says it's empty
# current bug: draggable containers will still exist after creating a
# new textbox but after creating an additional textbox, the dc will remove itself.
if not self.childWidget.hasFocus():
if hasattr(self.childWidget, "checkEmpty"):
if self.childWidget.checkEmpty():
editorSignalsInstance.widgetRemoved.emit(self)

# If mouse leaves draggable container, set focus to the editor
#if self.childWidget.hasFocus():
# self.setFocus()'''

def buildDragContainerMenu(self):

Expand Down Expand Up @@ -217,7 +220,7 @@ def setCursorShape(self, e_pos: QPoint):
self.setCursor(QCursor(Qt.SizeVerCursor))
self.mode = Mode.RESIZEB
else:
self.setCursor(QCursor(Qt. ArrowCursor))
self.setCursor(QCursor(Qt.ArrowCursor))
self.mode = Mode.MOVE

# Determine how to handle the mouse being moved inside the box
Expand Down Expand Up @@ -281,7 +284,7 @@ def mouseMoveEvent(self, e: QMouseEvent):
self.parentWidget().repaint()
self.newGeometry.emit(self.geometry())

# Pass the event to the child widget if this container is focuesd, and childwidget implements the method to receive it
# Pass the e to the child widget if this container is focuesd, and childwidget implements the method to receive it
def widgetAttributeChanged(self, changedWidgetAttribute, value):

cw = self.childWidget
Expand All @@ -306,4 +309,3 @@ def widgetAttributeChanged(self, changedWidgetAttribute, value):

if hasattr(cw, "changeBackgroundColorEvent") and (changedWidgetAttribute == ChangedWidgetAttribute.BackgroundColor):
cw.changeBackgroundColorEvent(value)

130 changes: 118 additions & 12 deletions Modules/BuildUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
from PySide6.QtGui import *
from PySide6.QtWidgets import *

from Models.DraggableContainer import DraggableContainer
from Widgets.Textbox import *

from Modules.EditorSignals import editorSignalsInstance, ChangedWidgetAttribute
from Modules.Undo import UndoHandler
from Widgets.Table import *

from Views.EditorFrameView import *

FONT_SIZES = [7, 8, 9, 10, 11, 12, 13, 14, 18, 24, 36, 48, 64, 72, 96, 144, 288]

#builds the application's UI
def build_ui(editor):
print("Building UI...")


#editor.EditorFrameView = EditorFrameView(editor)
#editor.statusBar = editor.statusBar()
build_window(editor)
build_menubar(editor)
#build_toolbar(editor)
build_toolbar(editor)
#build_test_toolbar(editor)

# Application's main layout (grid)
gridLayout = QGridLayout()
Expand All @@ -37,6 +47,9 @@ def build_ui(editor):
leftSideLayout.setContentsMargins(0, 0, 0, 0)
leftSideLayout.setSpacing(0)




# Right side of the app's layout
rightSideLayout = QVBoxLayout()
rightSideContainerWidget = QWidget()
Expand All @@ -46,6 +59,7 @@ def build_ui(editor):
rightSideLayout.setStretch(0, 0)
rightSideLayout.setStretch(1, 1)


# Add appropriate widgets (ideally just view controllers) to their layouts
leftSideLayout.addWidget(editor.notebookTitleView, 0)
leftSideLayout.addWidget(editor.pageView, 1) # Page view has max stretch factor
Expand All @@ -56,6 +70,10 @@ def build_ui(editor):
gridLayout.addWidget(leftSideContainerWidget, 0, 0)
gridLayout.addWidget(rightSideContainerWidget, 0, 1)

addSectionButton = QPushButton("Add Section")
#add functionality e.g. addSectionButton.clcicked.connect(editor.add_section_function)
leftSideLayout.addWidget(addSectionButton)

def build_window(editor):
editor.setWindowTitle("OpenNote")
editor.setWindowIcon(QIcon('./Assets/OpenNoteLogo.png'))
Expand All @@ -67,11 +85,11 @@ def build_menubar(editor):
file = editor.menuBar().addMenu('&File')
plugins = editor.menuBar().addMenu('&Plugins')

new_file = build_action(editor, 'assets/icons/svg_file_open', 'New Notebook...', 'New Notebook', False)
new_file = build_action(editor, 'assets/icons/svg_file_open', 'New Notebook', 'New Notebook', False)
new_file.setShortcut(QKeySequence.StandardKey.New)
new_file.triggered.connect(lambda: new(editor))

open_file = build_action(editor, 'assets/icons/svg_file_open', 'Open Notebook...', 'Open Notebook', False)
open_file = build_action(editor, 'assets/icons/svg_file_open', 'Open Notebook', 'Open Notebook', False)
open_file.setShortcut(QKeySequence.StandardKey.Open)
open_file.triggered.connect(lambda: load(editor))

Expand All @@ -87,35 +105,81 @@ def build_menubar(editor):

def build_toolbar(editor):
toolbar = QToolBar()
toolbar.setIconSize(QSize(15, 15))
toolbar.setIconSize(QSize(16, 16))
toolbar.setMovable(False)
editor.addToolBar(Qt.ToolBarArea.TopToolBarArea, toolbar)

#separates toolbar with a line break
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

toolbar_undo = build_action(toolbar, 'assets/icons/svg_undo', "undo", "undo", False)
#toolbar_undo.triggered.connect(editor.frameView.triggerUndo)


redo = build_action(toolbar, 'assets/icons/svg_redo', "redo", "redo", False)



font = QFontComboBox()
font.currentFontChanged.connect(lambda x: editorSignalsInstance.widgetAttributeChanged.emit(ChangedWidgetAttribute.Font, font.currentFont()))
font.currentFontChanged.connect(lambda: editorSignalsInstance.widgetAttributeChanged.emit(ChangedWidgetAttribute.Font, font.currentFont()))

size = QComboBox()
size.addItems([str(fs) for fs in FONT_SIZES])
size.currentIndexChanged.connect(lambda x: editorSignalsInstance.widgetAttributeChanged.emit(ChangedWidgetAttribute.FontSize, int(size.currentText())))

fontColor = build_action(toolbar, 'assets/icons/svg_font_color', "Font Color", "Font Color", False)
fontColor.triggered.connect(lambda x: openGetColorDialog(purpose = "font"))

bgColor = build_action(toolbar, 'assets/icons/svg_font_bucket', "Text Box Color", "Text Box Color", False)
bgColor.triggered.connect(lambda x: openGetColorDialog(purpose = "background"))
bgColor.triggered.connect(lambda: openGetColorDialog(purpose = "background"))



fontColor = build_action(toolbar, 'assets/icons/svg_font_color', "Font Color", "Font Color", False)
fontColor.triggered.connect(lambda: openGetColorDialog(purpose = "font"))

bold = build_action(toolbar, 'assets/icons/bold', "Bold", "Bold", True)
bold.triggered.connect(lambda x: editorSignalsInstance.widgetAttributeChanged.emit(ChangedWidgetAttribute.FontBold, None))
bold.toggled.connect(lambda: editorSignalsInstance.widgetAttributeChanged.emit(ChangedWidgetAttribute.FontBold, None))
#bold.triggered.connect(editor.frameView.add_table_action)

#bold.toggled.connect(lambda x: editor.selected.setFontWeight(700 if x else 500))

italic = build_action(toolbar, 'assets/icons/italic.svg', "Italic", "Italic", True)
italic.triggered.connect(lambda x: editorSignalsInstance.widgetAttributeChanged.emit(ChangedWidgetAttribute.FontItalic, None))
italic.toggled.connect(lambda: editorSignalsInstance.widgetAttributeChanged.emit(ChangedWidgetAttribute.FontItalic, None))

underline = build_action(toolbar, 'assets/icons/underline.svg', "Underline", "Underline", True)
underline.triggered.connect(lambda x: editorSignalsInstance.widgetAttributeChanged.emit(ChangedWidgetAttribute.FontUnderline, None))
underline.toggled.connect(lambda: editorSignalsInstance.widgetAttributeChanged.emit(ChangedWidgetAttribute.FontUnderline, None))

table = build_action(toolbar, 'assets/icons/svg_table', "Create Table", "Create Table", False)
table.triggered.connect(editor.frameView.toolbar_table)
hyperlink = build_action(toolbar, 'assets/icons/svg_hyperlink', "Hyperlink", "Hyperlink", False)
hyperlink.triggered.connect(editor.frameView.toolbar_hyperlink)
bullets = build_action(toolbar, 'assets/icons/svg_bullets', "Hyperlink", "Hyperlink", False)



editor.action1 = QAction('Action 1', editor)
#editor.action1.triggered.connect(EditorFrameView.slot_action1)
toolbar.addAction(editor.action1)
editor.action2 = QAction('Action 2', editor)
#editor.action2.triggered.connect(TextboxWidget.slot_action2)
#editor.action2.triggered.connect(show_popup)
toolbar.addAction(editor.action2)
#editor.button = QPushButton("Click Me", editor)
#editor.button.clicked.connect(editor.slot_button_click)


#toolbar.addActions([undo, redo])
toolbar.addSeparator()
toolbar.addWidget(font)
toolbar.addWidget(size)
toolbar.addSeparator()
toolbar.addActions([bgColor, fontColor, bold, italic, underline])
toolbar.addSeparator()
toolbar.addActions([table, hyperlink, bullets])

def toggle_bold(self):
self.is_bold = not self.is_bold

font =self.text_edit

def openGetColorDialog(purpose):
color = QColorDialog.getColor()
Expand All @@ -128,4 +192,46 @@ def openGetColorDialog(purpose):
def build_action(parent, icon_path, action_name, set_status_tip, set_checkable):
action = QAction(QIcon(icon_path), action_name, parent)
action.setStatusTip(set_status_tip)
action.setCheckable(set_checkable)
return action

def build_test_toolbar(self):
editorFrameViewInstance = EditorFrameView(self)

toolbar = QToolBar(self)
self.addToolBar(toolbar)

exitAct = QAction(QIcon('assets/icons/underline.svg'), 'Exit', self)
exitAct.setShortcut('Ctrl+Q')
exitAct.triggered.connect(QApplication.instance().quit)

self.toolbar = self.addToolBar('Exit')
self.toolbar.addAction(exitAct)

#font_change
font_combo = QFontComboBox(self)
toolbar.addWidget(font_combo)

bold = build_action(toolbar, 'assets/icons/bold', "Bold", "Bold", True)
bold.setShortcut('Ctrl+B')
bold.triggered.connect(lambda: editorSignalsInstance.widgetAttributeChanged.connect(self.widgetAttributeChangedEvent))


toolbar.addAction(bold)

undo_action = QAction("Undo", self)
undo_action.triggered.connect(self.frameView.triggerUndo)

toolbar.addAction(undo_action)



def change_font(self):
selected_font = self.sender().parent().widgetForAction(self.sender()).currentFont()

self.text_edit.setFont(selected_font)

def widgetAttributeChangedEvent(self, draggableContainer):
editorSignalsInstance.widgetAttributeChanged.emit(draggableContainer)


6 changes: 3 additions & 3 deletions Modules/Load.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

from Modules.Save import Autosaver

import pyautogui
from PySide6.QtWidgets import *
from PySide6.QtCore import *
from PySide6.QtGui import *
Expand All @@ -13,8 +13,8 @@
def new(editor):
print("RAN NEW")
destroy(editor)

editor.notebook = NotebookModel('Untitled')
p_name = pyautogui.prompt("Enter Notebook Name")
editor.notebook = NotebookModel(p_name)
editor.notebookTitleView.setText(editor.notebook.title)
editor.selected = None
editor.autosaver = Autosaver(editor)
Expand Down
Loading