Beispiel #1
0
    def __init__(self, **kwargs):
        super().__init__(orientation='vertical', **kwargs)
        self.history = []  # directory navigation history
        # If False - do not add a directory to the history -
        # The user moves down the tree.
        self.history_flag = True
        toolbar_label = self.ids.toolbar.children[1].children[0]
        toolbar_label.font_style = "Subtitle1"
        
        self.app = App.get_running_app()
        from kivymd.uix.button import MDFillRoundFlatButton as Button, MDRoundFlatButton

        if self.save_mode:
            action_button = MDRoundFlatButton(
                
                text="Save",
                size_hint=(1,None)
            )
            action_button.bind(on_release=self.select_directory_on_press_button)
            self.add_widget(action_button)

            from kivymd.uix.textfield import MDTextFieldRect,MDTextField
            self.saveFileName = MDTextField(text=str(self.save_mode),mode='fill', multiline=False,font_size='22sp',size_hint=(1,None))

            self.add_widget(self.saveFileName)
Beispiel #2
0
    def click(self):
        image = Image(source='E:\circle-cropped.png',
                      size_hint=(1, 1),
                      allow_stretch=True,
                      size=(200, 200))
        layout = GridLayout(cols=1)
        popupLabel = Label(
            text=
            "Mayank Raj\nEmail:\[email protected]\nphone n.\n6204396601",
            font_size=10)
        p = GridLayout(cols=2)
        k = GridLayout(cols=1)
        k.add_widget(popupLabel)
        p.add_widget(image)
        p.add_widget(k)
        closeButton = MDRoundFlatButton(text="done", size_hint=(.15, 0.1))
        layout.add_widget(p)
        layout.add_widget(closeButton)
        popup = Popup(title='DEVELOPER',
                      content=layout,
                      size_hint=(0.7, 0.5),
                      size=(700, 500),
                      background='E:\monkuyoert.jpg')
        popup.open()

        closeButton.bind(on_press=popup.dismiss)
Beispiel #3
0
def add_btn_to_layout(dropdown_src, layout):
    btn_to_add = MDRoundFlatButton(
        pos_hint={'top': 1})  # pos_hint={'center_x':0, 'center_y':0.5})
    current = dropdown_src.current_item
    first_item = dropdown_src.items[0]
    if current != first_item:
        btn_to_add.text = dropdown_src.current_item
        btn_to_add.bind(
            on_release=lambda x: remove_btn_from_layout(layout, btn_to_add))
        btn_to_add.color = "Primary"
        layout.add_widget(btn_to_add)
Beispiel #4
0
    def __init__(self, **kwargs):
        Screen.__init__(self, **kwargs)
        layout = FloatLayout()
        self.add_widget(layout)
        #add label
        recipeName = MDLabel(font_style="Subtitle2",
                             text=self.name,
                             halign="center",
                             pos_hint={"center_y": .95})
        layout.add_widget(recipeName)

        #load ingredient list
        with open("grocery_store.json") as f:
            recipe_book = json.load(f)
        ingredients_chosen = {}
        for name, ing in recipe_book.items():
            for key in ing:
                if (name == self.name):
                    ingredients_chosen[key] = ing[key]

        #add ingredients list
        listLayout = GridLayout(cols=2,
                                padding=40,
                                row_force_default=True,
                                row_default_height=45)
        for key in ingredients_chosen:
            listLayout.add_widget(MDLabel(text=key))
            checkbox = MDCheckbox(on_active=self.checkbox_clicked)
            listLayout.add_widget(checkbox)
        #add checkboxes
        layout.add_widget(listLayout)
        #add back button
        button = MDRoundFlatButton(text='<',
                                   padding="10dp",
                                   pos_hint={
                                       "center_x": .2,
                                       "center_y": .95
                                   },
                                   font_style="Subtitle1",
                                   text_color=(0, 0, 0),
                                   line_color=(1, 1, 1),
                                   line_width=1)
        layout.add_widget(button)
        button.bind(on_release=self.switch_screen)
Beispiel #5
0
    def gotoStreamRow(self,
                      stream,
                      postID,
                      document=None,
                      noBack=False,
                      template=None):
        "Editor/viewer for ONE specific row"
        self.streamEditPanel.clear_widgets()
        self.streamEditPanel.add_widget(
            MDToolbar(title="Table Row in " + stream))

        self.streamEditPanel.add_widget(self.makeBackButton())

        if not noBack:

            def goHere():
                self.gotoStreamRow(stream, postID)

            self.backStack.append(goHere)
            self.backStack = self.backStack[-50:]

        document = document or daemonconfig.userDatabases[
            stream].getDocumentByID(postID, allowOrphans=True)
        if 'type' in document and not document['type'] == 'row':
            raise RuntimeError("Document is not a row")
        document['type'] = 'row'

        title = Label(text=document.get("name", ''), font_size='22sp')

        #Our default template if none exists
        #Give it a name because eventually we may want to have multiple templates.
        #Give it an ID so it can override any existing children of that template.
        #Use only the direct ID of the parent record in cade we want to move it eventually.
        oldTemplate = {
            'type':
            "row.template",
            'leafNode':
            True,
            'parent':
            document['parent'],
            'name':
            'default',
            'id':
            uuid.uuid5(uuid.UUID(document['parent'].split("/")[-1]),
                       ".rowtemplate.default")
        }

        for i in daemonconfig.userDatabases[stream].getDocumentsByType(
                "row.template",
                parent=document['parent'],
                limit=1,
                allowOrphans=True):
            oldTemplate = i

        template = template or oldTemplate

        def post(*a):
            with daemonconfig.userDatabases[stream]:
                #Make sure system knows this is not an old document
                try:
                    del document['time']
                except:
                    pass
                daemonconfig.userDatabases[stream].setDocument(document)

                #If the template has changed, that is how we know we need to save template changes at the same time as data changes
                if not template.get('time', 0) == oldTemplate.get('time', 1):
                    daemonconfig.userDatabases[stream].setDocument(template)
                daemonconfig.userDatabases[stream].commit()
                self.unsavedDataCallback = None

            self.goBack()

        btn1 = Button(text='Save Changes')
        btn1.bind(on_release=post)

        self.streamEditPanel.add_widget(title)

        buttons = BoxLayout(orientation="horizontal",
                            spacing=10,
                            adaptive_height=True)

        if daemonconfig.userDatabases[stream].writePassword:
            self.streamEditPanel.add_widget(buttons)
            buttons.add_widget(btn1)

        def delete(*a):
            def reallyDelete(v):
                if v == postID:
                    with daemonconfig.userDatabases[stream]:
                        daemonconfig.userDatabases[stream].setDocument({
                            'type':
                            'null',
                            'id':
                            postID
                        })
                        daemonconfig.userDatabases[stream].commit()
                    self.gotoStreamPosts(stream)

            self.askQuestion("Delete table row permanently on all nodes?",
                             postID, reallyDelete)

        btn1 = Button(text='Delete')
        btn1.bind(on_release=delete)

        if daemonconfig.userDatabases[stream].writePassword:
            buttons.add_widget(btn1)

        names = {}

        self.streamEditPanel.add_widget(MDToolbar(title="Data Columns:"))

        for i in template:
            if i.startswith('row.'):
                names[i] = ''

        for i in document:
            if i.startswith('row.'):
                if i in template:
                    names[i] = ''
                else:
                    #In the document but not the template, it is an old/obsolete column, show that to user.
                    names[i] = '(removed)'

        for i in names:
            self.streamEditPanel.add_widget(Button(text=i[4:]))
            d = document.get(i, '')
            try:
                d = float(d)
            except:
                pass

            x = MDTextField(text=str(d) + names[i],
                            mode='fill',
                            multiline=False,
                            font_size='22sp')

            def oc(*a, i=i, x=x):
                d = x.text.strip()
                if isinstance(d, str):
                    d = d.strip()
                try:
                    d = float(d or 0)
                except:
                    pass
                document[i] = d

            x.bind(text=oc)
            self.streamEditPanel.add_widget(x)

            if isinstance(d, float) or not d.strip():
                l = BoxLayout(orientation="horizontal",
                              spacing=10,
                              adaptive_height=True)
                b = MDRoundFlatButton(text="--")

                def f(*a, i=i, x=x):
                    d = document.get(i, '')
                    if isinstance(d, str):
                        d = d.strip()
                    try:
                        d = float(d or 0)
                    except:
                        return
                    document[i] = d - 1
                    x.text = str(d - 1)

                b.bind(on_release=f)

                b2 = MDRoundFlatButton(text="++")

                def f(*a, i=i, x=x):
                    d = document.get(i, '')
                    if isinstance(d, str):
                        d = d.strip()
                    try:
                        d = float(d or 0)
                    except:
                        return
                    document[i] = d + 1
                    x.text = str(document[i])

                b2.bind(on_release=f)

                l.add_widget(b)
                l.add_widget(b2)
                self.streamEditPanel.add_widget(l)

        b = MDRoundFlatButton(text="Add Column")

        def f(*a):
            def f2(r):
                if r:
                    template['row.' + r] = ''
                    #Remove time field which marks it as a new record that will get a new timestamp rather than
                    #being ignored when we go to save it, for being old.
                    template.pop('time', None)
                    #Redraw the whole page, it is lightweight, no DB operation needed.
                    self.gotoStreamRow(stream,
                                       postID,
                                       document=document,
                                       noBack=True,
                                       template=template)

            self.askQuestion("Name of new column?", cb=f2)

        b.bind(on_release=f)
        self.streamEditPanel.add_widget(b)

        b = MDRoundFlatButton(text="Del Column")

        def f(*a):
            def f2(r):
                if r:
                    try:
                        del template['row.' + r]
                        template.pop('time', None)
                    except:
                        pass
                    #Redraw the whole page, it is lightweight, no DB operation needed.
                    self.gotoStreamRow(stream,
                                       postID,
                                       document=document,
                                       noBack=True,
                                       template=template)

            self.askQuestion("Column to delete?", cb=f2)

        b.bind(on_release=f)
        self.streamEditPanel.add_widget(b)

        self.screenManager.current = "EditStream"
Beispiel #6
0
    def gotoTableView(self, stream, parent='', search=''):
        "Data records can be attatched to a post."
        self.currentPageNewRecordHandler = None
        self.streamEditPanel.clear_widgets()
        s = daemonconfig.userDatabases[stream]
        parentDoc = daemonconfig.userDatabases[stream].getDocumentByID(
            parent, allowOrphans=True)
        if not parentDoc:
            logging.error("nonexistent parent document")
            return
        themeColor = getColor(parentDoc)
        self.streamEditPanel.add_widget(self.makeBackButton())

        postWidget = self.makePostWidget(stream,
                                         parentDoc,
                                         indexAssumption=False)
        self.streamEditPanel.add_widget(postWidget)
        t = (MDToolbar(title="Data Table View"))

        if themeColor:
            t.md_bg_color = themeColor
            t.specific_text_color = getFGForColor(themeColor)

        self.streamEditPanel.add_widget(t)

        topbar = BoxLayout(orientation="horizontal",
                           spacing=10,
                           adaptive_height=True)

        searchBar = BoxLayout(orientation="horizontal",
                              spacing=10,
                              adaptive_height=True)

        searchQuery = MDTextField(size_hint=(0.68, None),
                                  multiline=False,
                                  text=search)
        searchButton = MDRoundFlatButton(text="Search")
        searchBar.add_widget(searchQuery)
        searchBar.add_widget(searchButton)

        def doSearch(*a):
            self.currentPageNewRecordHandler = None
            self.gotoTableView(stream, parent, searchQuery.text.strip())

        searchButton.bind(on_release=doSearch)

        def goHere():
            self.currentPageNewRecordHandler = None
            self.gotoTableView(stream, parent, search)

        self.backStack.append(goHere)
        self.backStack = self.backStack[-50:]

        newEntryBar = BoxLayout(orientation="horizontal",
                                spacing=10,
                                adaptive_height=True)

        newRowName = MDTextField(size_hint=(0.68, None),
                                 multiline=False,
                                 text=search)

        def write(*a):
            for i in newRowName.text:
                if i in "[]{}:,./\\":
                    return

            if newRowName.text.strip():
                id = uuid.uuid5(
                    uuid.UUID(parent),
                    newRowName.text.strip().lower().replace(' ', ""))
                #That name already exists, jump to it
                if daemonconfig.userDatabases[stream].getDocumentByID(
                        id, allowOrphans=True):
                    self.currentPageNewRecordHandler = None
                    self.gotoStreamRow(stream, id)
                    return
            else:
                id = str(uuid.uuid4())

            x = daemonconfig.userDatabases[stream].getDocumentsByType(
                "row.template", parent=parent, limit=1, allowOrphans=True)
            newDoc = {
                'parent': parent,
                'id': id,
                'name': newRowName.text.strip() or id,
                'type': 'row',
                'leafNode': True
            }

            #Use the previously created or modified row as the template
            for i in x:
                for j in i:
                    if j.startswith('row.'):
                        newDoc[j] = ''

            self.currentPageNewRecordHandler = None
            self.gotoStreamRow(stream, id, newDoc)

        btn1 = Button(text='New Entry')

        btn1.bind(on_press=write)
        newEntryBar.add_widget(newRowName)
        newEntryBar.add_widget(btn1)

        if s.writePassword:
            topbar.add_widget(newEntryBar)

        self.streamEditPanel.add_widget(topbar)

        if not search:
            p = s.getDocumentsByType("row",
                                     limit=1000,
                                     parent=parent,
                                     allowOrphans=True)
        else:
            p = s.searchDocuments(search, "row", limit=1000, parent=parent)

        t = MDToolbar(title="Data Rows")

        if themeColor:
            t.md_bg_color = themeColor
            t.specific_text_color = getFGForColor(themeColor)

        self.streamEditPanel.add_widget(t)
        self.streamEditPanel.add_widget(searchBar)

        for i in p:
            self.streamEditPanel.add_widget(self.makeRowWidget(stream, i))
        self.screenManager.current = "EditStream"

        def onNewRecord(db, r, sig):
            if db is daemonconfig.userDatabases[stream]:
                if r.get('parent', '') == parentDoc.get(
                        'parent', '') and r['type'] == "post":
                    if not self.unsavedDataCallback:
                        self.gotoStreamPost(stream, postID, noBack=True)

                elif parentDoc['id'] in r.get("parent", ''):
                    postWidget.body.text = renderPostTemplate(
                        daemonconfig.userDatabases[stream], parentDoc['id'],
                        parentDoc.get("body", ''))[0]

        self.currentPageNewRecordHandler = onNewRecord