class NotebookTest(unittest.TestCase):
    def setUp(self):
        print('创建测试用的Notebook……')
        self.notebook = Notebook()

    def test_load(self):
        print('测试Notebook数据的读取')
        minute_nb = '{"cells":[{"cell_type":"markdown","source":"1"},{"cell_type":"code","source":"2"}]}'
        print(minute_nb)
        content = {
            'markdown': [{
                'cell_type': 'markdown',
                'source': '1'
            }],
            'code': [{
                'cell_type': 'code',
                'source': '2'
            }]
        }
        self.notebook.load(minute_nb)
        self.assertEqual(self.notebook.content, content)
        self.assertEqual(self.notebook.code, [{
            'cell_type': 'code',
            'source': '2'
        }])
        self.assertEqual(self.notebook.markdown, [{
            'cell_type': 'markdown',
            'source': '1'
        }])
Example #2
0
    def handle_signup(self):
        username = self.get_text("ثبت نام", "ایمیل:")
        if not username:
            reply = QMessageBox.question(
                self, 'پیام', "ایمیل خالی است. دوباره امتحان میکنید؟",
                QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.handle_login()
            else:
                return

        password = self.get_text("ثبت نام", "رمز:")
        if not password:
            reply = QMessageBox.question(
                self, 'پیام', "رمز خالی است. دوباره امتحان میکنید؟",
                QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.handle_login()
            else:
                return

        ret = self.network.signup_user(username, password)
        if not ret[0]:
            QMessageBox.about(self, 'پیام', 'ثبت نام ناموفق بود')
            return

        # successful signup means we should create a notebook
        QMessageBox.about(self, 'پیام', 'ثبت نام موفق بود')
        self.notebook = Notebook(username=username)
        self.handle_login(create_new=True)
Example #3
0
 def convert(input_file_path, formater):
     output_file_path = formater.construct_output_path(input_file_path)
     if not os.path.exists(output_file_path) or formater.overwrite:
         nb = Notebook()
         nb.read(input_file_path)
         if not formater.dry_run:
             formater.output(nb, output_file_path)
         print "Created file: {}".format(output_file_path)
Example #4
0
 def __init__(self):
     self.notebook = Notebook()
     self.choices = {
         "1": self.show_notes,
         "2": self.search,
         "3": self.add_note,
         "4": self.modify_Note,
         "5": self.quit
     }
Example #5
0
 def __init__(self):
     self.notebook = Notebook()
     #dictionary - also called object in python and JS
     self.choices = {
         "1": self.show_notes,
         "2": self.search_notes,
         "3": self.add_note,
         "4": self.modify_note,
         "5": self.quit
     }
Example #6
0
    def json_to_notebook(nb):
        nb = json.loads(nb)
        notebook = Notebook(nb[0])

        for s in nb[1]:
            print(s[0])
            notebook.add_section(Section(s[0]))
            for n in s[1]:
                print(n)
                notebook.sections[-1].add_note(Note(n[0], n[1]))
        return notebook
Example #7
0
 def __init__(self):
     """
     1. Initialize the Notebook instance
     2. Define the mapping for the menu and operations (methods) to be performed
     """
     self.notebook = Notebook()
     self.choices = {
                     "1": self.show_notes,
                     "2": self.search_notes,
                     "3": self.add_note,
                     "4": self.modify_note,
                     "5": self.modify_tags,
                     "6": self.quit
                     }
Example #8
0
class menu:
    ''' Display a menu with options to be chosen'''
    def __init__(self):
        self.notebook = Notebook()
        self.choices = {
            "1": self.show_notes,
            "2": self.search,
            "3": self.add_note,
            "4": self.modify_Note,
            "5": self.quit
        }

    def display_menu(self):
        print("""
        Notebook menu
        1. Show all Notes
        2. Search Notes
        3. Add Note
        4. Modify Note
        5. Quit
        """)

    def run(self):
        ''' Display the menu and respond to choices'''
        while True:
            self.display_menu()
            choice = input("Enter an option\n")
            action = self.choices.get(choice)
            if action:
                action()
            else:
                print("{0} is not valid".format(choice))

    def show_notes(self, notes=None):
        if not notes:
            notes = self.notebook.notes
        for note in notes:
            print("{0}: {1}\n{2}".format(note.id, note.tags, note.memo))

    def search(self):
        filter = input("Search for:")
        notes = self.notebook.search(filter)
        self.show_notes()

    def add_note(self):
        memo = input("Add Info to your note :")
        self.notebook.new_Note(memo)
        print("Your note's been added")

    def modify_Note(self):
        id = input("Enter your id to modify your Note")
        memo = input("Enter your note")
        tags = input("Enter tags")
        if memo:
            self.notebook.modify_Note(id, memo)
        if tags:
            self.notebook.modify_tags(id, tags)

    def quit(self):
        print("Exiting the program")
Example #9
0
 def __init__(self):
     self.notebook = Notebook()
     self.choices = {
         1: self.add,
         2: self.show,
         3: self.edit,
         4: self.search,
         5: self.exit
     }
Example #10
0
class Menu:

    def __init__(self):
        self.notebook = Notebook()
        self.choices = {
            1: self.add,
            2: self.show,
            3: self.edit,
            4: self.search,
            5: self.exit
        }

    @staticmethod
    def display():
        print("""
1 - Add a new Note
2 - Show All Notes
3 - Edit a Note
4 - Search by title
5 - Exit""")

    def run(self):
        while True:
            self.display()
            choose = int(input("Choose an option: "))
            action = self.choices.get(choose)
            if action:
                action()

    def add(self):
        title = input("Enter Your title: ")
        tags = input("Enter your tags: ")
        self.notebook.add(title, tags)

    def show(self):
        for note in self.notebook.notes:
            print("title: {0} | tags: {1}".format(note.title, note.tags))

    def edit(self):
        note_id = int(input("Enter an id: "))
        title = input("Enter a new title: ")
        if title:
            self.notebook.edit_title(note_id, title)
        tags = input("Enter new tags: ")
        self.notebook.edit_tags(note_id, tags)

    def search(self):
        query = input("Enter your query: ")
        notes = self.notebook.search(query)
        for note in notes:
            print("id: {0} | title: {1} | tags: {2}".format(note.id, note.title, note.tags))

    @staticmethod
    def exit():
        sys.exit(0)


# if __name__ == '__main__':
#     Menu().run()
Example #11
0
    def __init__(self):

        Gtk.Window.__init__(self)

        self.set_title("TimeControl")
        self.set_icon_from_file(
            os.path.join(BASE_PATH, "img", "timecontrol.png"))
        self.set_resizable(True)
        self.set_size_request(640, 480)
        self.set_border_width(2)
        self.set_position(Gtk.WindowPosition.CENTER)

        self.menuBar = MenuBar()
        self.info = Info()
        self.notebook = Notebook()

        panel = Gtk.Paned(orientation=Gtk.Orientation.HORIZONTAL)
        panel.pack1(self.notebook, resize=True, shrink=False)
        panel.pack2(self.info, resize=False, shrink=True)

        vbox = Gtk.VBox()
        vbox.pack_start(self.menuBar, False, False, 0)
        vbox.pack_start(panel, True, True, 0)

        self.add(vbox)

        self.show_all()

        self.connect("delete-event", self.__salir)
        self.menuBar.connect("adduser", self.__newUser)
        self.menuBar.connect("viewuser", self.__viewUser)

        self._current_user = ''
        self._current_dict = OrderedDict()

        self.notebook.hide()  # Se hace visible cuando se cargan los datos
        self.info.frame.hide()  # Se hace visible cuando se cargan los datos
        self.info.saldo.hide()  # Se hace visible cuando se cargan los datos

        self.notebook.connect('switch_page', self.__switch_page)
        self.notebook.connect('updateuser', self.__update)
Example #12
0
class Menu:
    """
    Display Menu options to user via Command Line to perform the Notebook operations
    """

    def __init__(self):
        """
        1. Initialize the Notebook instance
        2. Define the mapping for the menu and operations (methods) to be performed
        """
        self.notebook = Notebook()
        self.choices = {
                        "1": self.show_notes,
                        "2": self.search_notes,
                        "3": self.add_note,
                        "4": self.modify_note,
                        "5": self.modify_tags,
                        "6": self.quit
                        }

    # Static Method as it only used for display purpose and data operations performed.
    @staticmethod
    def display_menu():
        """
        Menu to be displayed to the user
        :return:
        """
        print("""
        
    Notebook Menu
    
    1. Show all Notes
    2. Search Notes
    3. Add Note
    4. Modify Note
    5. Modify Tags
    6. Quit
    
    """)

    def run(self):
        """
        Display the user menu and obtain the user input for the required operation
        :return:
        """
        self.display_menu()
        # Obtain user input
        choice = input("Enter an option: ")
        action = self.choices.get(choice)
        if action:
            action()
        else:
            print("{} is not a valid choice, please select a valid choice")

        # Call the menu again to continue additional operations
        self.run()

    def show_notes(self, notes=None, filter_key=False):
        """
        Display all the notes linked to the Notebook
        :return: ID, memo, tags
        """
        if not notes and not filter_key:
            notes = self.notebook.Notes
        elif not notes and filter_key:
            print("No Notes can be found with the keyword provided")

        for note in notes:
            print("{}: {}/{}".format(note.id, note.memo, note.tags))

    def search_notes(self):
        """
        Input search keyword from input
        Search for a user input keyword from the notes and associated tags
        :return: list of notes with the keyword
        """
        keyword = input("Enter a keyword to search: ")
        results = self.notebook.search(keyword)
        self.show_notes(results, True)

    def add_note(self):
        """
        adds note to an existing notebook
        :return: Add a note to notebook
        """
        memo = input("Enter the new note: ")
        self.notebook.new_note(memo)
        print("New Note has been added")

    def modify_note(self):
        """
        Modify note for a given note with an ID provided by the user
        :return: Modify note of a existing Notebook
        """
        note_id = input("Enter the note id: ")
        memo = input("Enter the modified note: ")
        result = self.notebook.modify_note(int(note_id), memo)
        if result:
            print("Note {} is modified".format(note_id))
        else:
            print("Note ID does not exist, please provide another id")

    def modify_tags(self):
        """
        Modify tags for a given note with an ID provided by the user
        :return: Modify tags of a existing Notebook
        """
        note_id = input("Enter the note id: ")
        tags = input("Enter the modified tag(s): ")
        result = self.notebook.modify_tag(int(note_id), tags)
        if result:
            print("Tag {} is modified".format(note_id))
        else:
            print("Note ID does not exist, please provide another id")

    @staticmethod
    def quit():
        print("Thank you for using the Notebook app")
        sys.exit(0)
Example #13
0
class MainWidget(QWidget):
    def __init__(self):
        self.layout = None
        self.notebook = None
        self.network = Network()
        self.show_login_page()

    @staticmethod
    def quit_app():
        exit()

    def show_login_page(self):
        QWidget.__init__(self)

        # login button
        login = QPushButton("ورود")
        login.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        login.setStyleSheet("background-color: rgb(228, 210, 86)")

        # sign up button
        signup = QPushButton("ثبت نام")
        signup.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        signup.setStyleSheet("background-color: rgb(228, 210, 86)")

        # exit button
        ex = QPushButton("خروج")
        ex.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        ex.setStyleSheet("background-color: rgb(228, 210, 86)")

        # set layout
        self.layout = QGridLayout()
        self.layout.setRowStretch(0, 10)
        self.layout.setRowStretch(1, 10)
        self.layout.setRowStretch(2, 5)
        self.layout.addWidget(login, 0, 2)
        self.layout.addWidget(signup, 1, 2)
        self.layout.addWidget(ex, 2, 0)
        self.layout.setSpacing(100)
        self.setLayout(self.layout)

        p = self.palette()
        p.setColor(self.backgroundRole(), QColor(78, 143, 171))
        self.setPalette(p)

        # Connecting the signal
        login.clicked.connect(self.handle_login)
        signup.clicked.connect(self.handle_signup)
        ex.clicked.connect(self.quit_app)

    def get_text(self, widget_name, widget_text):
        text, pressed = QInputDialog.getText(self, widget_name, widget_text,
                                             QLineEdit.Normal, "")
        if pressed and text != '':
            return text
        return None

    def handle_login(self, create_new=False):
        username = self.get_text("ورود", "ایمیل:")
        if not username:
            reply = QMessageBox.question(
                self, 'پیام', "ایمیل خالی است. دوباره امتحان میکنید؟",
                QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.handle_login()
            else:
                return

        password = self.get_text("ورود", "رمز:")
        if not password:
            reply = QMessageBox.question(
                self, 'پیام', "رمز خالی است. دوباره امتحان میکنید؟",
                QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.handle_login()
            else:
                return

        ret = self.network.login_user(username, password)
        QMessageBox.about(self, 'پیام', ret[1])
        if not ret[0]:
            return

        # login means that this user has already a notebook in server
        if create_new:
            self.network.create_notebook(self.notebook)
        else:
            self.notebook = self.network.download_notebook(username=username)
        self.show_main_menu()

    def handle_signup(self):
        username = self.get_text("ثبت نام", "ایمیل:")
        if not username:
            reply = QMessageBox.question(
                self, 'پیام', "ایمیل خالی است. دوباره امتحان میکنید؟",
                QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.handle_login()
            else:
                return

        password = self.get_text("ثبت نام", "رمز:")
        if not password:
            reply = QMessageBox.question(
                self, 'پیام', "رمز خالی است. دوباره امتحان میکنید؟",
                QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.handle_login()
            else:
                return

        ret = self.network.signup_user(username, password)
        if not ret[0]:
            QMessageBox.about(self, 'پیام', 'ثبت نام ناموفق بود')
            return

        # successful signup means we should create a notebook
        QMessageBox.about(self, 'پیام', 'ثبت نام موفق بود')
        self.notebook = Notebook(username=username)
        self.handle_login(create_new=True)

    def show_main_menu(self):
        # new note button
        new_note = QPushButton("ایجاد یادداشت جدید")
        new_note.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        new_note.setStyleSheet("background-color: rgb(228, 210, 86)")

        # new group button
        new_group = QPushButton("ایجاد دسته جدید")
        new_group.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        new_group.setStyleSheet("background-color: rgb(228, 210, 86)")

        # view group
        view_groups = QPushButton("مشاهده دسته های قبلی")
        view_groups.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        view_groups.setStyleSheet("background-color: rgb(228, 210, 86)")

        exit_page = QPushButton("خروج")
        exit_page.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        exit_page.setStyleSheet("background-color: rgb(228, 210, 86)")

        # set layout
        self.clear_layout(self.layout)

        self.layout.setRowStretch(0, 10)
        self.layout.setRowStretch(1, 10)
        self.layout.setRowStretch(2, 10)
        self.layout.setRowStretch(3, 5)
        self.layout.addWidget(new_note, 0, 2)
        self.layout.addWidget(new_group, 1, 2)
        self.layout.addWidget(view_groups, 2, 2)
        self.layout.addWidget(exit_page, 3, 0)
        self.layout.setSpacing(100)

        new_note.clicked.connect(lambda: self.show_note_menu(None, None))
        new_group.clicked.connect(self.handle_add_section)
        view_groups.clicked.connect(self.show_sections_list)
        exit_page.clicked.connect(self.quit_app)

    def handle_add_section(self):
        section_name = self.get_text("بخش جدید", "نام بخش:")
        if not section_name:
            reply = QMessageBox.question(
                self, 'پیام', "نام بخش خالی است. دوباره امتحان میکنید؟",
                QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.handle_add_section()
            else:
                return

        self.notebook.add_section(Section(section_name))
        self.network.update_notebook(self.notebook)

    def get_note_and_section_name(self, section_name):
        note_name = self.get_text("یادداشت جدید", "نام یادداشت:")
        if not note_name:
            reply = QMessageBox.question(
                self, 'پیام', "نام خالی است. دوباره امتحان میکنید؟",
                QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.get_note_and_section_name()
            else:
                return

        if section_name is None:
            section_name = self.get_text("بخش", "نام بخش:")
            if not note_name:
                reply = QMessageBox.question(
                    self, 'پیام', "نام بخش خالی است. دوباره امتحان میکنید؟",
                    QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
                if reply == QMessageBox.Yes:
                    self.get_note_and_section_name()
                else:
                    return

        section = None
        for s in self.notebook.sections:
            if s.name == section_name:
                section = s

        if section is None:
            section = Section(section_name)
            self.notebook.add_section(section)

        note = Note(note_name, "")
        section.add_note(note)
        return note, section_name

    def show_note_menu(self, note, section_name, is_editable=False):
        if note is None and section_name is None:
            note, section_name = self.get_note_and_section_name(None)
        elif note is None:
            note, section_name = self.get_note_and_section_name(section_name)

        # reminder button
        remind_note = QPushButton("یادآوری")
        remind_note.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        remind_note.setStyleSheet("background-color: rgb(228, 210, 86)")

        # edit button
        edit_note = QPushButton("ویرایش")
        edit_note.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        edit_note.setStyleSheet("background-color: rgb(228, 210, 86)")

        # save button
        save_note = QPushButton("ثبت")
        save_note.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        save_note.setStyleSheet("background-color: rgb(228, 210, 86)")

        # delete button
        delete_note = QPushButton("حذف")
        delete_note.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        delete_note.setStyleSheet("background-color: rgb(228, 210, 86)")

        layout_topbar = QHBoxLayout()
        layout_topbar.addWidget(remind_note)
        layout_topbar.addWidget(edit_note)
        layout_topbar.addWidget(save_note)
        layout_topbar.addWidget(delete_note)
        layout_topbar.setSpacing(50)

        wid = QWidget()
        wid.setLayout(layout_topbar)

        text_box = QPlainTextEdit(self)
        text_box.setEnabled(is_editable)

        if isinstance(note, Note):
            text_box.setPlainText(note.data)

        self.clear_layout(self.layout)

        self.layout.setRowStretch(0, 5)
        self.layout.setRowStretch(1, 20)
        self.layout.addWidget(wid, 0, 2)
        self.layout.addWidget(text_box, 1, 2)
        self.layout.setSpacing(100)

        remind_note.clicked.connect(lambda: self.set_note_reminder(note))
        save_note.clicked.connect(lambda: self.handle_save_note(
            note, section_name, text_box.toPlainText()))
        delete_note.clicked.connect(
            lambda: self.handle_delete_note(section_name, note.name))
        edit_note.clicked.connect(
            lambda: self.set_editable(note, section_name))

    def set_editable(self, note, section_name):
        self.show_note_menu(note, section_name, True)

    def handle_save_note(self, note, section_name, data):
        note.data = data
        self.show_notes_list(section_name)
        self.network.update_notebook(self.notebook)

    def set_note_reminder(self, note):
        date = self.get_text("یادآوری", "(yyyy mm dd hh mm ss):")
        if not date:
            reply = QMessageBox.question(self, 'پیام',
                                         "زمان خالی! دوباره امتحان میکنید؟",
                                         QMessageBox.Yes | QMessageBox.No,
                                         QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.set_note_reminder()
            else:
                return

        year, month, day, hour, minute, second = date.split()

        dt = datetime.datetime(int(year), int(month), int(day), int(hour),
                               int(minute), int(second))
        ret = self.network.set_timer(self.notebook.username, note.name,
                                     time.mktime(dt.timetuple()))
        QMessageBox.about(self, 'Reminder', ret[1])

    def show_sections_list(self):
        # quit button
        exit_page = QPushButton("خروج")
        exit_page.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        exit_page.setStyleSheet("background-color: rgb(228, 210, 86)")

        # delete button
        delete_section = QPushButton("حذف")
        delete_section.setSizePolicy(QSizePolicy.Preferred,
                                     QSizePolicy.Preferred)
        delete_section.setStyleSheet("background-color: rgb(228, 210, 86)")

        layout_topbar = QVBoxLayout()
        for s in self.notebook.sections:
            btn = QPushButton(s.name)
            btn.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
            btn.setStyleSheet("background-color: rgb(228, 210, 86)")
            layout_topbar.addWidget(btn)
            btn.clicked.connect(partial(self.show_notes_list, s.name))
        layout_topbar.setSpacing(50)

        wid = QWidget()
        wid.setLayout(layout_topbar)

        self.clear_layout(self.layout)
        self.layout.setRowStretch(0, 20)
        self.layout.setRowStretch(1, 5)
        self.layout.setRowStretch(2, 5)
        self.layout.addWidget(wid, 0, 2)
        self.layout.addWidget(exit_page, 2, 0)
        self.layout.addWidget(delete_section, 2, 3)
        self.layout.setSpacing(20)

        # set action for each button
        delete_section.clicked.connect(self.handle_delete_section)
        exit_page.clicked.connect(self.show_main_menu)

    def handle_delete_section(self):
        section_name = self.get_text("پاک کردن بخش", "نام بخش:")
        if not section_name:
            reply = QMessageBox.question(
                self, 'پیام', "نام بخش خالی است. دوباره امتحان میکنید؟",
                QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.handle_delete_section()
            else:
                return

        ret = self.notebook.remove_section(section_name)
        if ret:
            self.network.update_notebook(self.notebook)
        else:
            QMessageBox.about(self, 'پیام', 'بخش وجود ندارد')

        self.show_sections_list()

    def show_notes_list(self, section_name):
        print(section_name)
        # section name
        section_label = QPushButton(section_name)
        section_label.setSizePolicy(QSizePolicy.Preferred,
                                    QSizePolicy.Preferred)
        section_label.setStyleSheet("background-color: rgb(228, 210, 86)")

        # quit button
        new_note = QPushButton("ایجاد یادداشت جدید")
        new_note.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        new_note.setStyleSheet("background-color: rgb(228, 210, 86)")

        # delete button
        exit_button = QPushButton("خروج")
        exit_button.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        exit_button.setStyleSheet("background-color: rgb(228, 210, 86)")

        for s in self.notebook.sections:
            if s.name == section_name:
                section = s
                break

        layout_topbar = QVBoxLayout()
        for note in section.notes:
            btn = QPushButton(note.name)
            btn.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
            btn.setStyleSheet("background-color: rgb(228, 210, 86)")
            layout_topbar.addWidget(btn)
            btn.clicked.connect(
                partial(self.show_note_menu, note, section_name))
        layout_topbar.setSpacing(20)

        wid = QWidget()
        wid.setLayout(layout_topbar)

        self.clear_layout(self.layout)

        self.layout.setRowStretch(0, 1)
        self.layout.setRowStretch(1, 6)
        self.layout.setRowStretch(2, 2)
        self.layout.setRowStretch(3, 2)
        self.layout.addWidget(wid, 1, 2)
        self.layout.addWidget(new_note, 3, 0)
        self.layout.addWidget(exit_button, 3, 3)
        self.layout.addWidget(section_label, 0, 2)
        self.layout.setSpacing(50)

        # set action for each node
        new_note.clicked.connect(
            lambda: self.show_note_menu(None, section_name))
        exit_button.clicked.connect(self.show_sections_list)

    def handle_delete_note(self, section_name, note_name):
        if note_name is None:
            note_name = self.get_text("پاک کردن یادداشت", "نام یادداشت:")
            if not note_name:
                reply = QMessageBox.question(
                    self, 'پیام',
                    "نام یادداشت خالی است. دوباره امتحان میکنید؟",
                    QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
                if reply == QMessageBox.Yes:
                    self.handle_delete_note(section_name, note_name)
                else:
                    return

        for s in self.notebook.sections:
            if s.name == section_name:
                s.del_note(note_name)
                break

        self.network.update_notebook(self.notebook)
        self.show_notes_list(section_name)

    def clear_layout(self, layout):
        if layout is not None:
            while layout.count():
                item = layout.takeAt(0)
                widget = item.widget()
                if widget is not None:
                    widget.deleteLater()
                else:
                    self.clear_layout(item.layout())
Example #14
0
class TimeControl(Gtk.Window):
    def __init__(self):

        Gtk.Window.__init__(self)

        self.set_title("TimeControl")
        self.set_icon_from_file(
            os.path.join(BASE_PATH, "img", "timecontrol.png"))
        self.set_resizable(True)
        self.set_size_request(640, 480)
        self.set_border_width(2)
        self.set_position(Gtk.WindowPosition.CENTER)

        self.menuBar = MenuBar()
        self.info = Info()
        self.notebook = Notebook()

        panel = Gtk.Paned(orientation=Gtk.Orientation.HORIZONTAL)
        panel.pack1(self.notebook, resize=True, shrink=False)
        panel.pack2(self.info, resize=False, shrink=True)

        vbox = Gtk.VBox()
        vbox.pack_start(self.menuBar, False, False, 0)
        vbox.pack_start(panel, True, True, 0)

        self.add(vbox)

        self.show_all()

        self.connect("delete-event", self.__salir)
        self.menuBar.connect("adduser", self.__newUser)
        self.menuBar.connect("viewuser", self.__viewUser)

        self._current_user = ''
        self._current_dict = OrderedDict()

        self.notebook.hide()  # Se hace visible cuando se cargan los datos
        self.info.frame.hide()  # Se hace visible cuando se cargan los datos
        self.info.saldo.hide()  # Se hace visible cuando se cargan los datos

        self.notebook.connect('switch_page', self.__switch_page)
        self.notebook.connect('updateuser', self.__update)

    def __update(self, widget, _dict):
        self.info.update(_dict)

    def __switch_page(self, widget, widget_child, indice):
        self.info.switch_page_and_set_user(self._current_user, indice,
                                           self._current_dict)

    def __viewUser(self, widget, name):
        self._current_user = name
        self._current_dict = getDataUser(self._current_user)
        self.notebook.set_data(self._current_user, self._current_dict)
        self.info.switch_page_and_set_user(self._current_user, 0,
                                           self._current_dict)
        self.notebook.show_all()  # Se hace visible cuando se cargan los datos
        self.info.show_all()  # Se hace visible cuando se cargan los datos

    def __newUser(self, widget, name):
        if adduser(name):
            self.menuBar.adduser(name)
        else:
            dialog = Gtk.Dialog(parent=self.get_toplevel(),
                                flags=Gtk.DialogFlags.MODAL,
                                buttons=["OK", Gtk.ResponseType.OK])
            dialog.set_border_width(15)
            label = Gtk.Label("Este Funcionario ya Existe")
            dialog.vbox.pack_start(label, True, True, 5)
            dialog.vbox.show_all()
            dialog.run()
            dialog.destroy()
        self.__viewUser(None, name)

    def __salir(self, widget=None, senial=None):
        Gtk.main_quit()
        sys.exit(0)
Example #15
0
class Menu:
    def __init__(self):
        self.notebook = Notebook()
        self.notebook.new_note('Example note',
                               ['Example tag 1', 'Example tag 2'])

    def run(self):
        self.showMenu()
        self.waitForInput()

    def showMenu(self):
        print()
        print('Notebook Menu')
        print('-------------')
        print('Choose action:')
        print('1 - Show all notes')
        print('2 - Search notes')
        print('3 - Add a note')
        print('4 - Modify a note')
        print('5 - Quit')

    def waitForInput(self):
        option = input('Action: ')
        if option == '1':
            self.showNotes()
        elif option == '2':
            self.searchNote()
        elif option == '3':
            self.addNote()
        elif option == '4':
            self.modifyNote()
        elif option != '5':
            print('Please choose a valid action.')
            self.waitForInput()

    def printNotes(self, notes):
        first = True
        for note in notes:
            if not first:
                print()
            first = False
            note.print()

    def showNotes(self):
        print()
        print('All notes')
        print('---------')
        if len(self.notebook.notes) == 0:
            print('There are no notes.')
        else:
            self.printNotes(self.notebook.notes)
        self.run()

    def searchNote(self):
        print()
        print('Search for a note')
        print('-----------------')
        text = input('Search for: ')
        result = self.notebook.search(text)
        if len(result) == 0:
            print("No notes found.")
        else:
            print()
            print('Results')
            print('-------')
            self.printNotes(self.notebook.search(text))
        self.run()

    def addNote(self):
        print()
        print('Add a note')
        print('----------')
        memo = input('Enter a note: ')
        self.saveNoteDialog(Note(memo))

    def saveNoteDialog(self, note):
        print()
        print('Save note?')
        print('----------')
        self.printNotes([note])
        print()
        print('Choose action:')
        print('1 - Save')
        print('2 - Edit')
        print('3 - Add a tag')
        print('4 - Remove a tag')
        self.waitForNoteSaveInput(note)

    def waitForNoteSaveInput(self, note):
        action = input('Action: ')
        if action == '1':
            self.notebook.notes.append(note)
            print('Note saved.')
            self.run()
        elif action == '2':
            self.editNote(note)
        elif action == '3':
            self.addNoteTag(note)
        elif action == '4':
            self.removeNoteTag(note)
        else:
            print('Please choose a valid action.')
            self.waitForNoteSaveInput(note)

    def editNote(self, note):
        print()
        print('Edit a note')
        print('-----------')
        text = input('New note: ')
        note.setMemo(text)
        self.saveNoteDialog(note)

    def addNoteTag(self, note):
        print()
        print('Add note tag')
        print('------------')
        tag = input('Tag: ')
        note.addTag(tag)
        self.saveNoteDialog(note)

    def removeNoteTag(self, note):
        print()
        print('Remove note tag')
        print('---------------')
        tag = input('Tag: ')
        note.removeTag(tag)
        self.saveNoteDialog(note)

    def modifyNote(self):
        print()
        print('Modify a note')
        print('-------------')
        self.waitForNoteModifyInput()

    def waitForNoteModifyInput(self):
        note_id = input('Note id: ')
        note = self.notebook.remove_note(uuid.UUID(note_id))
        if note == False:
            print('Note not found.')
            self.waitForNoteModifyInput()
        else:
            self.saveNoteDialog(note)
 def setUp(self):
     print('创建测试用的Notebook……')
     self.notebook = Notebook()
Example #17
0
def notebook(parentWindow, **kwds):
    from Notebook import Notebook
    return Notebook(parentWindow, **kwds)
Example #18
0
class Menu:
    def __init__(self):
        self.notebook = Notebook()
        #dictionary - also called object in python and JS
        self.choices = {
            "1": self.show_notes,
            "2": self.search_notes,
            "3": self.add_note,
            "4": self.modify_note,
            "5": self.quit
        }

    def displayMenu(self):
        #to indent in the same way as type here, use """
        print("""
           Notebook Menu

            1. Show all notes
            2. Search notes
            3. Add note
            4. Modify note
            5. Quit
            """)

    def run(self):
        #run forever
        while True:
            self.displayMenu()
            choice = input("Enter an option:")
            action = self.choices.get(choice)
            if action:
                action()
            else:
                print("{0} is not a valid choice".format(choice))

    def quit(self):
        print("Thank you for using the notebook.")
        sys.exit(0)

    def show_notes(self, notes=None):
        if not notes:
            notes = self.notebook.getNotes()
        for note in notes:
            self.notebook.print_note(note.getId())

    def search_notes(self):
        filter = input("search for:")
        notes = self.notebook.search(filter)
        show_notes(notes)

    def add_note(self):
        memo = input("Enter a memo:")
        self.notebook.new_note(memo)
        print("Your note has been added")

    def modify_note(self):
        noteId = int(input("Enter the note ID"))
        memo = input("Enter a memo:")
        tags = input("Enter tags:")
        if memo:
            self.notebook.modify_memo(noteId, memo)
        if tags:
            self.notebook.modify_tags(noteId, tags)
Example #19
0
from Notebook import Notebook
from Note import Note
from Section import Section
from Network import Network
import time

if __name__ == '__main__':
    nt = Notebook('a')
    nt.add_section(Section('مشکلات'))
    nt.add_section(Section('مستقلات'))
    nt.sections[0].add_note(Note('مناسب', 'مهارت های ابتدایی'))
    nt.sections[1].add_note(Note('تعهد', 'به زمانه های پلید'))

    net = Network("http://127.0.0.1:8000/noteserver/")
    net.login_user('a', 'aa')
    res = net.set_timer("*****@*****.**", "testi", time.time() + 50)
Example #20
0
class Menu:
    def __init__(self):
        self.notebook = Notebook()
        self.choices = {
            "1": self.show_notes,
            "2": self.search_notes,
            "3": self.add_note,
            "4": self.modify_note,
            "5": self.quit
        }

    def display_menu(self):
        print("""
        Notebook Menu

        1. Show all Notes
        2. Search Notes
        3. Add Note
        4. Modify Note
        5. Quit
        """)

    def run(self):
        while True:
            self.display_menu()
            choice = input("Enter an option: ")
            action = self.choices.get(choice)
            if action:
                try:
                    action()
                except:
                    print("Something went wrong. Please try again.")
            else:
                print("{0} is not a valid choice".format(choice))

    def show_notes(self, notes=None):
        if not notes:
            notes = self.notebook.notes

        for note in notes:
            print("{0}: {1}\n{2}".format(note.id, note.memo, note.tags))

    def search_notes(self):
        filter = input("Search for: ")
        notes = self.notebook.search(filter)
        self.show_notes(notes)

    def add_note(self):
        memo = input("Enter a memo: ")
        self.notebook.new_note(memo)
        print("Your note has been added.")

    def modify_note(self):
        id = int(input("Enter a note id: "))
        memo = input("Enter a memo: ")
        tags = input("Enter tags: ")
        if memo:
            self.notebook.modify_memo(id, memo)

        if tags:
            self.notebook.modify_tags(id, tags)

    def quit(self):
        print("Thank you for using the notebook.")
        sys.exit(0)
Example #21
0
 def __init__(self):
     self.__id = None
     self.__name = None
     self.__board = Board()
     self.__notebook = Notebook()
Example #22
0
# main program
print("\n-> Create Object Backpack")
item_list = Backpack(owner="Bintang", capacity=3)
item_list.detail()

print("\n-> Backpack.remove()")
item_list.remove()

print("\n-> Backpack.add() menambahkan Object Eraser")
item_list.add(Eraser(owner="Bintang"))

print("\n-> Backpack.add() menambahkan Object Pen")
item_list.add(Pen(owner="Agastya"))

print("\n-> Backpack.add() menambahkan Object Notebook")
item_list.add(Notebook(owner="Bintang"))

print("\n-> Backpack.add() menambahkan Object Ruler")
item_list.add(Ruler(owner="Agastya"))

print("\n-> Backpack.remove(4) pada index = 4")
item_list.remove(4)

print("\n-> Backpack.remove(1) pada index = 1")
item_list.remove(1)

print("\n-> Backpack.add() menambahkan Object Pencil")
item_list.add(Pencil(owner="Bintang"))

print("\n-> Backpack.detail()")
item_list.detail()
Example #23
0
 def __init__(self):
     self.notebook = Notebook()
     self.notebook.new_note('Example note',
                            ['Example tag 1', 'Example tag 2'])
from Computador import Computador
from Desktop import Desktop
from Notebook import Notebook
print()

print('--------------- Desktop ---------------')

D = Desktop('Lenovo', 'Branco', '2500', '650w')
print(D.getInformacoes)

print()

print('--------------- Notebook ---------------')
N = Notebook('Samsung', 'Prata', '7000', '700w')
print(N.getInformacoes)


from Computador import Computador
from Desktop import Desktop
from Notebook import Notebook

print('Computador')
c1 = Computador("HP", 'Preto', 2900)
c1.cadastrar()
c1.getInformacoes()

print('Desktop')

d1 = Desktop('Dell', 'Branco', 4700, 650)
d1.getInformacoes()

print('Notebook')

n1 = Notebook('Lenovo', "Rosa", '3250', '2:00')
n1.getInformacoes()