コード例 #1
0
ファイル: dialog.py プロジェクト: whiteblue3/musicdb
    def HandleKey(self, key):
        """
        This method must be called whenever a key was pressed and this dialog is "active".
        It expects the key name returned by :meth:`lib.clui.text.Text.GetKey`.

        If the key is ``"up"`` the element above the current selected element gets selected.
        If the key is ``"down"`` the one below will be selected.
        This will be done by passing the *up* and *down* key to the ``HandleKey`` method of the base class.

        Any other key gets passed to the :meth:`~onAction` method of this class.

        After handling an key, the :meth:`~Draw` method gets called to refresh the view.

        Args:
            key (str): Key name that shall be handled

        Returns:
            *Nothing*
        """
        if key == "up" or key == "down":
            ListView.HandleKey(self, key)

        else:
            if self.elements:
                self.onAction(self.elements[self.linemarker], key)
            self.Draw()
コード例 #2
0
    def HandleKey(self, key):
        if self.dialogmode == True:
            if key == "enter":  # Commit dialog inputs
                self.dialogmode = False
                self.Draw() # show list view instead of dialog

                # Get data from dialog
                name = self.nameinput.GetData()
                posx = self.posxinput.GetData()
                oldname = self.dialog.oldname

                try:
                    posx = int(posx)
                    assert posx >= 0
                except:
                    posx = None # do not update an invalid position

                # Update database with new data
                if oldname == None:
                    self.CreateGenre(name)
                    tagname = name
                    newname = None
                else:
                    tagname = oldname
                    # Was the tag renamed?
                    if oldname != name:
                        newname = name
                    else:
                        newname = None

                self.ModifyGenre(tagname, newname, newposx=posx)
                self.UpdateView()
                self.Draw()


            elif key == "escape":
                self.dialogmode     = False
                self.dialog.oldname = None  # prevent errors by leaving a clean state
                self.Draw() # show list view instead of dialog
                # reject changes

            else:
                self.dialog.HandleKey(key)
        else:
            if key == "a":
                # Add new tag
                self.nameinput.SetData("")
                self.posxinput.SetData("")
                self.dialog.oldname = None    # new tag has no old name
                self.dialog.Draw()
                self.dialogmode = True
            else:
                ListView.HandleKey(self, key)
コード例 #3
0
    def HandleKey(self, key):
        if self.dialogmode == True:
            if key == "enter":  # Commit dialog inputs
                self.dialogmode = False
                self.Draw() # show list view instead of dialog

                # Get data from dialog
                name       = self.nameinput.GetData()
                oldname    = self.dialog.oldname
                parentname = self.dialog.parentname

                # Update database with new data
                if oldname == None:
                    self.CreateSubgenre(name, parentname)
                    tagname = name
                    newname = None
                else:
                    tagname = oldname
                    # Was the tag renamed?
                    if oldname != name:
                        newname = name
                    else:
                        newname = None

                self.ModifySubgenre(tagname, newname)
                self.UpdateView()
                self.Draw()


            elif key == "escape":
                self.dialogmode        = False
                self.dialog.oldname    = None  # prevent errors by leaving a clean state
                self.dialog.parentname = None
                self.Draw() # show list view instead of dialog
                # reject changes

            else:
                self.dialog.HandleKey(key)
        else:
            if key == "a":
                # Add new tag
                self.nameinput.SetData("")

                parent     = self.genreview.GetSelectedData()
                parentname = parent["name"]

                self.dialog.oldname    = None    # new tag has no old name
                self.dialog.parentname = parentname
                self.dialog.Draw()
                self.dialogmode = True
            else:
                ListView.HandleKey(self, key)
コード例 #4
0
ファイル: add.py プロジェクト: whiteblue3/musicdb
    def HandleKey(self, key):
        if self.dialogmode == True:
            if key == "enter":  # Commit dialog inputs
                songname = self.nameinput.GetData()
                songnumber = self.numberinput.GetData()
                cdnumber = self.cdnuminput.GetData()

                element = self.dialog.oldelement
                path = element[
                    1]  # the editable path is 1, 0 is the original path
                directory = self.fs.GetDirectory(path)
                extension = self.fs.GetFileExtension(path)

                if len(songnumber) == 1:
                    songnumber = "0" + songnumber
                if cdnumber:
                    songnumber = cdnumber + "-" + songnumber

                newpath = os.path.join(
                    directory, songnumber + " " + songname + "." + extension)
                self.SetSelectedData((element[0], newpath))

                self.dialogmode = False
                self.Draw()  # show list view instead of dialog

            elif key == "escape":
                self.dialogmode = False
                self.dialog.oldname = None  # prevent errors by leaving a clean state
                self.Draw()  # show list view instead of dialog
                # reject changes

            else:
                self.dialog.HandleKey(key)

        else:
            if key == "up" or key == "down":
                ListView.HandleKey(self, key)

            elif key == "c":
                self.CleanFileNames()

            elif key == "e":  # edit name
                element = self.GetSelectedData()
                editpath = element[1]
                filename = self.fs.GetFileName(editpath)
                seg = self.FileNameSegments(filename)
                songnumber = filename[seg["number"]:seg["gap"]].strip()
                songname = filename[seg["name"]:].strip()

                if "-" in songnumber:
                    cdnumber = songnumber.split("-")[0].strip()
                    songnumber = songnumber.split("-")[1].strip()
                else:
                    cdnumber = ""

                self.nameinput.SetData(songname)
                self.numberinput.SetData(songnumber)
                self.cdnuminput.SetData(cdnumber)

                self.dialog.oldelement = element
                self.dialog.Draw()
                self.dialogmode = True
コード例 #5
0
    def HandleKey(self, key):
        if self.dialogmode == True:
            if key == "enter":  # Commit dialog inputs
                self.dialogmode = False
                self.Draw()  # show list view instead of dialog

                # Get data from dialog
                name = self.nameinput.GetData()
                icon = self.iconinput.GetData()
                posx = self.posxinput.GetData()
                posy = self.posyinput.GetData()

                try:
                    posx = int(posx)
                    assert posx >= 0
                except:
                    posx = None  # do not update an invalid position
                try:
                    posy = int(posy)
                    assert posy >= 0
                except:
                    posy = None  # do not update an invalid position

                if self.varselector.GetData() == True:
                    icon += b"\xef\xb8\x8e".decode()
                color = self.colorinput.GetData()

                if len(color) != 7 or color[0] != "#":
                    color = None
                oldname = self.dialog.oldname

                # Update database with new data
                if oldname == None:
                    self.CreateMood(name)
                    tagname = name
                    newname = None
                else:
                    tagname = oldname
                    # Was the tag renamed?
                    if oldname != name:
                        newname = name
                    else:
                        newname = None

                self.ModifyMood(tagname, newname, icon, color, posx, posy)
                self.UpdateView()
                self.Draw()
                # Synchronize new state with mood grid
                self.moodgridcrossref.UpdateView()
                self.moodgridcrossref.Draw()

            elif key == "escape":
                self.dialogmode = False
                self.dialog.oldname = None  # prevent errors by leaving a clean state
                self.Draw()  # show list view instead of dialog
                # reject changes

            else:
                self.dialog.HandleKey(key)
        else:
            if key == "a":
                # Add new tag
                self.nameinput.SetData("")
                self.iconinput.SetData("")
                self.varselector.SetData(False)
                self.colorinput.SetData("")
                self.dialog.oldname = None  # new tag has no old name
                self.dialog.Draw()
                self.dialogmode = True
            else:
                ListView.HandleKey(self, key)