def __init__(self, config, albumpath, title, x, y, w, h): ListView.__init__(self, title, x, y, w, h) ButtonView.__init__(self, align="center") self.AddButton("↑", "Go up") self.AddButton("↓", "Go down") self.AddButton("c", "Clean name") self.AddButton("e", "Edit name") #self.AddButton("␣", "Toggle") #self.AddButton("↵", "Commit") #self.AddButton("␛", "Cancel") # elements are a tuple (original path, new path) self.cfg = config self.fs = Filesystem(self.cfg.music.path) self.albumpath = albumpath self.nameinput = FileNameInput() self.numberinput = TextInput() self.cdnuminput = TextInput() dialogh = 2 + 3 self.dialog = Dialog("Rename Song", self.x, self.y + 1, self.w, dialogh) self.dialog.AddInput("Song name:", self.nameinput, "Correct name only") self.dialog.AddInput("Song number:", self.numberinput, "Song number only") self.dialog.AddInput("CD number:", self.cdnuminput, "CD number or nothing") self.dialogmode = False
def __init__(self, config, database, title, x, y, w, h): ListView.__init__(self, title, x, y, w, h) MusicDBTags.__init__(self, config, database) self.UpdateView() self.dialog = Dialog("Edit Mood", self.x, self.y + 1, self.w, self.h - 1) self.dialogmode = False self.nameinput = TextInput() self.iconinput = TextInput() self.colorinput = TextInput() self.posxinput = TextInput() self.posyinput = TextInput() self.varselector = BoolInput() self.dialog.AddInput("Name:", self.nameinput, "Visibly for user") self.dialog.AddInput("Icon:", self.iconinput, "Unicode char") self.dialog.AddInput("U+FE0E:", self.varselector, "Do not replace with emoji") self.dialog.AddInput("Color:", self.colorinput, "In HTML notation (#RRGGBB)") self.dialog.AddInput("X:", self.posxinput, "X coordinate on grid (positive integer)") self.dialog.AddInput("Y:", self.posyinput, "X coordinate on grid (positive integer)") self.moodgridcrossref = None
def __init__(self, config, database, title, x, y, w, h): ListView.__init__(self, title, x, y, w, h) MusicDBTags.__init__(self, config, database) self.UpdateView() self.dialog = Dialog("Edit Genre", self.x, self.y+1, self.w, self.h-1) self.dialogmode = False self.nameinput = TextInput() self.posxinput = TextInput() self.dialog.AddInput("Name:", self.nameinput, "Visibly for user") self.dialog.AddInput("Position:", self.posxinput, "Position in WebUI list (positive integer)")
def __init__(self, title=None, x=0, y=0, w=0, h=0): ListView.__init__(self, title, x, y, w, h) ButtonView.__init__(self, align="center") self.elements = [] # ListView works on this list. It contains a tuple (label, control, hint) self.maxlabellength = 0 self.maxhintlength = 0 self.AddButton("↑", "Go up") self.AddButton("↓", "Go down") self.AddButton("↵", "Commit") self.AddButton("␣", "Toggle") self.AddButton("␛", "Cancel")
def __init__(self, config, database, genreview, title, x, y, w, h): ListView.__init__(self, title, x, y, w, h) MusicDBTags.__init__(self, config, database) if type(genreview) != GenreView: raise TypeError("genreview must be of type GenreView!") self.genreview = genreview self.UpdateView() self.dialog = Dialog("Edit Subgenre", self.x, self.y+1, self.w, self.h-1) self.dialogmode = False self.nameinput = TextInput() self.dialog.AddInput("Name:", self.nameinput, "Visibly for user")
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()
def Draw(self): if self.dialogmode == True: pass else: ListView.Draw(self) x = self.x + 1 y = self.y + self.h - 1 w = self.w - 2 ButtonView.Draw(self, x, y, w)
def Draw(self): if self.dialogmode == True: pass else: self.allsongnamesvalid = True # Will be updated by ListView.Draw() call ListView.Draw(self) x = self.x + 1 y = self.y + self.h - 1 w = self.w - 2 ButtonView.Draw(self, x, y, w)
def SetData(self, artists, albums, songs): artistdata = [("artist", path) for path in artists] albumdata = [("album", path) for path in albums ] songdata = [("song", path) for path in songs ] data = [] data.extend(artistdata) data.extend(albumdata ) data.extend(songdata ) ListView.SetData(self, data)
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)
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)
def Draw(self): # Only draw the list view when not in dialog mode if self.dialogmode == False: ListView.Draw(self)
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
def __init__(self, title, x=0, y=0, w=0, h=0): ListView.__init__(self, title, x, y, w, h)
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)