def __init__(self, parent=None):
        self.old_name = ''
        self.new_name = ''

        self.data_access = DataAccess(engine)
        tags = self.data_access.list_tags()

        super().__init__(tags, parent)

        # Cannot drag a note to a tag
        self.setDragEnabled(False)
class Environment:
    # SQLAlchemy engine
    engine = database.engine

    # SQLAlchemy Base
    Base = database.Base

    # Work Directory
    working_directory = '/'

    # configuration
    configuration = config

    # Database Entities
    Base = database.Base
    Notebook = database.Notebook
    Note = database.Note
    Tag = database.Tag
    Image = database.Image

    # Commands
    cmd_descriptions = []
    cmd_details = {}
    cmd_processors = {}
    cmd_completers = {}

    # Data Access Method
    data_access = DataAccess(engine)
Exemple #3
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.data_access = DataAccess(engine)

        self.load(QUrl.fromLocalFile(os.getcwd() + '/desktop_mode/index.html'))
        self.settings().setUserStyleSheetUrl(QUrl.fromLocalFile(os.getcwd() + '/lib/web/bootstrap/css/bootstrap.min.css'))
Exemple #4
0
 def dropEvent(self, event: QDropEvent):
     if self.dropIndicatorPosition() == 0:
         print('Note:', self.currentItem().text(0))
         print('Notebook:', self.itemAt(event.pos()).text(0))
         notebook_name = self.itemAt(event.pos()).text(0)
         note_title = self.currentItem().text(0)
         data_access = DataAccess(engine)
         if data_access.has_notebook(
                 notebook_name) and data_access.has_note(note_title):
             notebook = data_access.get_notebook_by_name(notebook_name)
             note = data_access.get_note_by_title(note_title)
             data_access.move_note_to_notebook(note, notebook)
             super().dropEvent(event)
Exemple #5
0
 def rename_note(self, old_name, new_name):
     print('Rename Note:', old_name, 'to', new_name)
     data_access = DataAccess(engine)
     if not data_access.has_note(new_name):
         note = data_access.get_note_by_title(old_name)
         note.title = new_name
         data_access.save_note(note)
     else:
         self.editItem(self.currentItem())
Exemple #6
0
 def delete_note(self, note_title):
     print('Delete_Note:', note_title)
     data_access = DataAccess(engine)
     note = data_access.get_note_by_title(note_title)
     data_access.delete_note(note)
     self.currentItem().removeChild(self.currentItem())
Exemple #7
0
class MainFrame(QWidget):
    data_access = DataAccess(engine)
    title_input = None
    notebook_selector = None
    markdown_view = None
    markdown_editor = None
    note = None
    note_editing = None

    def __init__(self, parent=None):
        super().__init__(parent)

        # Base Vertical layout
        v_layout = QVBoxLayout()
        self.setLayout(v_layout)

        # Title Input
        self.title_input = QLineEdit(self)
        self.title_input.setDisabled(True)
        v_layout.addWidget(self.title_input)

        # Notebook Select
        property_h_layout = QHBoxLayout()
        v_layout.addLayout(property_h_layout)

        # Select Notebook Label
        notebook_select_label = QLabel('Select Notebook', self)
        property_h_layout.addWidget(notebook_select_label)

        # Select Notebook Combo Box
        self.notebook_selector = QComboBox(self)
        self.notebook_selector.addItems(
            [notebook.name for notebook in self.data_access.list_notebooks()])
        self.notebook_selector.setDisabled(True)
        property_h_layout.addWidget(self.notebook_selector)

        # Horizontal layout to show and edit note content
        h_layout = QHBoxLayout()
        v_layout.addLayout(h_layout)

        # Markdown View in Horizontal Layout
        self.markdown_view = MarkdownView(self)
        h_layout.addWidget(self.markdown_view)

        # Markdown Editor in Horizontal Layout
        self.markdown_editor = MarkdownEditor(self)
        self.markdown_editor.setVisible(False)
        self.markdown_editor.set_editing_callback(self.editing_callback)
        h_layout.addWidget(self.markdown_editor)

    def enter_editing(self):
        # Enable Title Input
        self.title_input.setEnabled(True)
        self.title_input.setText(self.note_editing.title)

        # Enable and Refresh Notebook Selector
        self.notebook_selector.setEnabled(True)
        self.notebook_selector.clear()
        self.notebook_selector.addItems(
            [notebook.name for notebook in self.data_access.list_notebooks()])
        if self.note:
            self.notebook_selector.setCurrentText(self.note.notebook.name)

        # Show MarkdownEditor
        self.markdown_editor.setVisible(True)
        self.markdown_editor.edit_note(self.note_editing.content)

        # Show Editing Content in MarkdownView
        self.markdown_view.show_note(self.note_editing.content)

    def exit_editing(self):
        # Disable Title Input
        self.title_input.setDisabled(True)
        if self.note:
            self.title_input.setText(self.note.title)
        else:
            self.title_input.setText('')

        # Disable Notebook Selector
        self.notebook_selector.setDisabled(True)

        # Close MarkdownEditor
        self.markdown_editor.setVisible(False)

        # Show Current Note Content in MarkdownView
        if self.note:
            self.markdown_view.show_note(self.note.content)
        else:
            self.markdown_view.show_default_page()

    # Receive Editing Signal from MarkdownEditor
    def editing_callback(self, content):
        self.note_editing.content = content
        self.markdown_view.show_note(content)

    # Receive signals from MainWindow
    def show_note(self, note_title):
        if self.data_access.has_note(note_title):
            self.note = self.data_access.get_note_by_title(note_title)
            self.notebook_selector.setCurrentText(self.note.notebook.name)
            self.markdown_view.show_note(self.note.content)
        else:
            self.markdown_view.show_default_page()

    def new_note(self):
        self.note_editing = Note()
        self.note_editing.title = ''
        self.note_editing.content = ''
        self.enter_editing()

    def edit_note(self):
        self.note_editing = self.note
        self.enter_editing()

    def save_note(self):
        if self.title_input.text() != '' and self.markdown_editor.toPlainText(
        ) != '':
            notebook_name = self.notebook_selector.currentText()
            notebook = self.data_access.get_notebook_by_name(notebook_name)
            self.note = self.note_editing
            self.note.title = self.title_input.text()
            self.note.notebook = notebook
            self.data_access.save_note(self.note)
            self.exit_editing()
            return True
        else:
            return False

    def edit_cancel(self):
        self.exit_editing()
Exemple #8
0
    def __init__(self, parent=None):
        self.data_access = DataAccess(engine)
        notebooks = self.data_access.list_notebooks()

        super().__init__(notebooks, parent)
Exemple #9
0
class NotebookTreeView(SuperTreeView):
    def __init__(self, parent=None):
        self.data_access = DataAccess(engine)
        notebooks = self.data_access.list_notebooks()

        super().__init__(notebooks, parent)

    # Refresh Data
    def refresh_data(self):
        notebooks = self.data_access.list_notebooks()
        super().refresh_data(notebooks)

    # Rename Notebook
    def rename_root_item(self, old_name, new_name):
        print('Rename Notebook', old_name, 'to', new_name)
        if not self.data_access.has_notebook(new_name):
            if self.data_access.has_notebook(old_name):
                notebook = self.data_access.get_notebook_by_name(old_name)
                notebook.name = new_name
                self.data_access.save_notebook(notebook)
            else:
                self.data_access.add_notebook(new_name)
        else:
            self.editItem(self.currentItem())

    # Delete Notebook
    def delete_root_item(self, notebook_name):
        if self.data_access.has_notebook(notebook_name):
            notebook = self.data_access.get_notebook_by_name(notebook_name)
            self.data_access.delete_notebook(notebook)
            self.currentItem().removeChild(self.currentItem())
            print('Delete Notebook', notebook_name)
Exemple #10
0
from django.http import HttpResponse
from lib.database import engine
from lib.data_access import DataAccess
from markdown import markdown
from django.views.decorators.csrf import csrf_exempt
import json

data_access = DataAccess(engine)


def to_dict(obj):
    return list(
        map(
            lambda x: {
                'id': x.id,
                'name': x.name,
                'notes': list(map(lambda y: y.title, x.note))
            }, obj))


def list_notebooks(request):
    notebooks = data_access.list_notebooks()
    notebooks_json = to_dict(notebooks)
    return HttpResponse(json.dumps(notebooks_json))


def list_tags(request):
    tags = data_access.list_tags()
    tags_json = to_dict(tags)
    return HttpResponse(json.dumps(tags_json))
class TagTreeView(SuperTreeView):
    def __init__(self, parent=None):
        self.old_name = ''
        self.new_name = ''

        self.data_access = DataAccess(engine)
        tags = self.data_access.list_tags()

        super().__init__(tags, parent)

        # Cannot drag a note to a tag
        self.setDragEnabled(False)

    # Refresh Data
    def refresh_data(self):
        tags = self.data_access.list_tags()
        super().refresh_data(tags)

    # Rename Tag
    def rename_root_item(self, old_name, new_name):
        print('Rename Tag', old_name, 'to', new_name)
        if not self.data_access.has_tag(new_name):
            if self.data_access.has_tag(old_name):
                tag = self.data_access.get_tag_by_name(old_name)
                tag.name = new_name
                self.data_access.save_tag(tag)
            else:
                self.data_access.add_tag(new_name)
        else:
            self.editItem(self.currentItem())

    # Delete Tag
    def delete_root_item(self, tag_name):
        if self.data_access.has_tag(tag_name):
            tag = self.data_access.get_tag_by_name(tag_name)
            self.data_access.delete_tag(tag)
            self.currentItem().removeChild(self.currentItem())
            print('Delete Tag', tag_name)