Esempio n. 1
0
 def create_db(self):
     storage.create_database([Person, Age])
Esempio n. 2
0
    def __init__(self):
        wx.Frame.__init__(self, None, title="Maitenotas")
        # ask for user password
        user_password = ""
        if app_data.get_new_database():
            # create db and set new password
            dlg_pass1 = wx.TextEntryDialog(self, text_labels.DEFINE_PASSWORD,
                                           text_labels.NEW_DIARY)
            if dlg_pass1.ShowModal() == wx.ID_OK:
                password1=dlg_pass1.GetValue()
                dlg_pass1.Destroy()

                # ask password confirmation
                dlg = wx.TextEntryDialog(self, text_labels.CONFIRM_PASSWORD,text_labels.NEW_DIARY)
                if dlg.ShowModal() == wx.ID_OK:
                    password2=dlg.GetValue()
                    dlg.Destroy()
                    if password1 == password2:
                        user_password = password1
                    else:
                        wx.MessageBox(text_labels.PASSWORDS_DO_NOT_MATCH, "Error" ,
                                      wx.OK | wx.ICON_ERROR)
                        self.Close()
                else:
                    dlg.Destroy()
                    self.Close()
            else:
                dlg_pass1.Destroy()
                self.Close()

            # get name of first book
            dlg_first_book_name = wx.TextEntryDialog(self, text_labels.DIARY_NAME,
                                                  text_labels.INITIAL_NAME)
            name_of_first_book=""
            if dlg_first_book_name.ShowModal() == wx.ID_OK:
                name_of_first_book=dlg_first_book_name.GetValue()
                dlg_first_book_name.Destroy()
            else:
                dlg_first_book_name.Destroy()
                self.Close()

        else:
            # ask for password for existing database
            dlg_pass = wx.TextEntryDialog(self, text_labels.ENTER_PASSWORD, text_labels.OPENING_DIARY)

            if dlg_pass.ShowModal() == wx.ID_OK:
                user_password=dlg_pass.GetValue()
                dlg_pass.Destroy()
            else:
                dlg_pass.Destroy()
                self.Close()

        # verify database connection
        app_data.set_user_key(generate_user_key(user_password))
        if app_data.get_new_database():
            database_access = create_database(app_data.get_user_key(), user_password)
            if database_access is False:
                wx.MessageBox(text_labels.ERROR_READING_DATA, "Error" ,wx.OK | wx.ICON_ERROR)
                self.Close()
            # create first book
            book_id = create_book(app_data.get_user_key(), name_of_first_book)
            # create example data to start, since the book is new the parentId leaf is ZERO
            journal_name = text_labels.LEAF_ONE_OF + name_of_first_book
            journal_text = text_labels.SAMPLE_TEXT_1 + name_of_first_book
            create_journal(app_data.get_user_key(), book_id, 0, journal_name, journal_text)
            journal_name = text_labels.LEAF_TWO_OF + name_of_first_book
            journal_text = text_labels.SAMPLE_TEXT_2 + name_of_first_book
            create_journal(app_data.get_user_key(), book_id, 0, journal_name, journal_text)
        else:
            database_access = verify_database_password(app_data.get_user_key(), user_password)
            if database_access is False:
                wx.MessageBox(text_labels.INVALID_PASSWORD, "Error" ,wx.OK | wx.ICON_ERROR)
                self.Close()

        # create GUI Main panel and sub panels
        panel = MainPanel(self)
        box_sizer = wx.BoxSizer(wx.HORIZONTAL)

        self.tree_panel = TreePanel(panel)
        box_sizer.Add(self.tree_panel, 1, wx.EXPAND | wx.ALL, 1)
        text_panel = TextPanel(panel)
        box_sizer.Add(text_panel, 2, wx.EXPAND | wx.ALL, 1)
        panel.SetSizer(box_sizer)

        # keep a reference to the text control inside the tree panel
        # and inside the main panel also to access it later
        self.text_control = text_panel.get_text_control()
        self.tree_panel.set_text_control(self.text_control)

        # Show main panel
        self.Show()
        self.Maximize(True)

        # menus
        menubar = wx.MenuBar()

        # application menu
        application_menu = wx.Menu()
        wx_pythonid_exit=app_data.get_next_wx_python_id()
        wx_id_about=app_data.get_next_wx_python_id()

        menu_item_about = wx.MenuItem(application_menu, wx_id_about, text_labels.TEXT_ABOUT)
        application_menu.Append(menu_item_about)
        self.Bind(wx.EVT_MENU, show_about_screen, id=wx_id_about)
        menu_item_exit = wx.MenuItem(application_menu, wx_pythonid_exit, text_labels.TEXT_QUIT)
        application_menu.Append(menu_item_exit)
        self.Bind(wx.EVT_MENU, self.quit_application, id=wx_pythonid_exit)

        # tree menu
        tree_menu = wx.Menu()
        wx_python_d1=app_data.get_next_wx_python_id()
        wx_python_d2=app_data.get_next_wx_python_id()
        wx_python_d3=app_data.get_next_wx_python_id()
        menu_item_add_leaf = wx.MenuItem(tree_menu, wx_python_d1, text_labels.TEXT_ADD_LEAF)
        menu_item_remove_leaf = wx.MenuItem(tree_menu, wx_python_d2, text_labels.TEXT_REMOVE_LEAF)
        menu_item_rename_leaf = wx.MenuItem(tree_menu, wx_python_d3, text_labels.TEXT_RENAME_LEAF)
        tree_menu.Append(menu_item_add_leaf)
        tree_menu.Append(menu_item_remove_leaf)
        tree_menu.Append(menu_item_rename_leaf)

        self.Bind(wx.EVT_MENU, self.add_leaf, id=wx_python_d1)
        self.Bind(wx.EVT_MENU, self.remove_leaf, id=wx_python_d2)
        self.Bind(wx.EVT_MENU, self.rename_leaf, id=wx_python_d3)

        menubar.Append(application_menu, text_labels.TEXT_APPLICATION)
        menubar.Append(tree_menu, text_labels.TEXT_TREE)
        self.SetMenuBar(menubar)

        # window close event
        self.Bind(wx.EVT_CLOSE, self.close_window)
Esempio n. 3
0
 def create_db_just_person(self):
     storage.create_database(Person)
Esempio n. 4
0
    power = request.json.get('power_type')
    battery = request.json.get('power_level')

    storage.record_client_data(name, power, battery, request.json['sensors'])

    return jsonify({'result': 'OK'})


@app.route('/api/clients', methods=['GET'])
def get_all_clients():
    obj = storage.get_all_clients()
    return jsonify(obj)


@app.route('/api/client/<client>', methods=['GET'])
def get_client_data(client):
    obj = storage.get_client_data(client)
    return jsonify(obj)


@app.route('/api/client/history/<client>/<sensor>', methods=['GET'])
def get_client_history(client, sensor):
    obj = storage.get_client_history(client, sensor)
    return jsonify(obj)


storage.create_database()

if __name__ == '__main__':
    app.run('0.0.0.0', 5555)