Beispiel #1
0
    def __init__(self, parent, bind: Bind, dirty=False):
        KeystoneEditFrame.__init__(self, parent)

        self.BindFileEditor = parent
        while (self.BindFileEditor.__class__.__name__ != "EditBindFile"):
            self.BindFileEditor = self.BindFileEditor.master
            if (self.BindFileEditor == None):
                break
        self.Editor = None

        self.columnconfigure(0, weight=0)
        self.columnconfigure(1, weight=1)
        self.rowconfigure(0, weight=0)
        self.rowconfigure(1, weight=0)
        self._showingEdit = True
        self.Button = KeystoneButton(self,
                                     text="...",
                                     width=6,
                                     command=self.OnEdit)
        self.Button.grid(row=0, column=0, sticky="nsew")
        self.Repr = tk.StringVar()
        self.Label = KeystoneLabel(self, textvariable=self.Repr)
        self.Repr.set(bind.__repr__())
        self.Label.grid(row=0, column=1, sticky="nsew")

        self.OnSetDirty.append(self.SetEdited)
        self.OnSetClean.append(self.SetEdited)
        self.BindFileEditor.OnSetClean.append(self.SetClean)
        if (dirty):
            self.SetDirty()
    def __init__(self, parent, link: Keylink, keychain: Keychain):

        KeystoneEditFrame.__init__(self, parent)
        self.Keychain = keychain
        self.RootPath = os.path.dirname(keychain.RootPath)
        if (link == None):
            #new link
            filePath = self.Keychain.GetNewFileName()
            self.Link = keychain.Newlink(filePath)
        else:
            self.Link = link

        #layout grid and frames
        self.columnconfigure(0, weight=0)
        self.columnconfigure(1, weight=1)
        self.rowconfigure(0, weight=0)

        self.FileName = tk.StringVar()
        self.NameEdit = KeystoneEntry(self, textvariable=self.FileName)
        self.NameLabel = KeystoneLabel(self, textvariable=self.FileName)
        name = GetDirPathFromRoot(self.RootPath, self.Link.FilePath)
        self.FileName.set(name)
        self.FileName.trace("w", self.OnSetDirty)
        self.NameLabel.grid(row=0, column=1, sticky='nsew')

        self.Button = KeystoneButton(self,
                                     text="...",
                                     width=3,
                                     command=self.OnEdit)
        self.Button.grid(row=0, column=0, sticky="nsew")

        self.Editing = False
Beispiel #3
0
    def __init__(self, parent, macro: Macro = None):

        tk.Toplevel.__init__(self, parent)
        self.attributes("-topmost", 1)

        self.title("Create a Macro")
        icon = GetResourcePath('.\\Resources\\keystone.ico')
        if (icon != None):
            self.iconbitmap(icon)
        self.protocol("WM_DELETE_WINDOW", self.OnClose)
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        frame = KeystoneFrame(self)
        frame.columnconfigure(0, weight=0)
        frame.columnconfigure(1, weight=1, minsize='205')
        frame.rowconfigure(0, weight=1)
        frame.rowconfigure(1, weight=0)

        if (macro == None):
            macro = Macro("Name", [SlashCommand(repr="powexec_name power")])
        self.Editor = EditMacro(frame, macro)
        self.Editor.grid(column = 1, row = 0, rowspan=2, sticky='nsew')
        self.Close = KeystoneButton(frame)
        self.Close.configure(text="Close",  command=self.OnClose)
        self.Close.Color('red', 'black')
        self.Close.grid(column=0, row=1, sticky='nsew')
        self.Copy = KeystoneButton(frame, text="Copy to Clipboard", command=self.OnCopy)
        self.Copy.Color('green', 'black')
        self.Copy.grid(column=0, row=0, sticky='nsew')
        frame.grid(column=0, row=0, sticky='nsew')
Beispiel #4
0
    def __init__(self, parent, text, *args, **kwargs):

        KeystoneFrame.__init__(self, parent, *args, **kwargs)

        #setup grid
        self.columnconfigure(1, weight=1)
        self.rowconfigure(0, weight=1)
        self.rowconfigure(1)

        parts = text.split("\n", 1)
        self.ShortText = parts[0]
        if (len(parts) > 1):
            self.LongText = "\n".join(parts)
        else:
            self.LongText = None

        self.ShortLabel = KeystoneLabel(self, text=self.ShortText)
        self.ShortLabel.grid(row=0, column=0, sticky='nsew')
        self.LongLabel = None
        self.Button = None
        self.ButtonText = None
        if (self.LongText != None):
            self.LongLabel = KeystoneLabel(self, text=self.LongText)
            self.ButtonText = tk.StringVar(value=self.MORE)
            self.Button = KeystoneButton(self,
                                         textvariable=self.ButtonText,
                                         command=self.ToggleText)
            self.Button.grid(row=1, column=0, sticky='sw')
Beispiel #5
0
    def __init__(self,
                 parent,
                 resultCallback,
                 bind: Bind = None,
                 lockKey=False,
                 title=None,
                 dirty=False):

        tk.Toplevel.__init__(self, parent)
        self.attributes("-topmost", 1)

        if (title == None):
            if (bind == None):
                title = 'New Bind'
                dirty = True
            else:
                title = bind.GetKeyWithChord()

        self.Title = title
        self.ResultCallback = resultCallback

        self.title(title)
        icon = GetResourcePath('.\\Resources\\keystone.ico')
        if (icon != None):
            self.iconbitmap(icon)
        self.protocol("WM_DELETE_WINDOW", self.OnCancel)
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        frame = KeystoneEditFrame(self)
        frame.columnconfigure(0, weight=0)
        frame.columnconfigure(1, weight=1, minsize='205')
        frame.rowconfigure(0, weight=1)
        frame.rowconfigure(1, weight=0)

        if (bind == None):
            self.Editor = BindEditor(frame,
                                     Bind(repr=DEFAULT_BIND),
                                     lockKey=lockKey,
                                     dirty=dirty)
        else:
            self.Editor = BindEditor(frame, bind, lockKey=lockKey, dirty=dirty)
        self.Editor.grid(column=1, row=0, rowspan=2, sticky='nsew')
        self.Cancel = KeystoneButton(frame, text="OK", command=self.OnOk)
        self.Cancel.configure(text="Cancel", command=self.OnCancel)
        self.Cancel.Color('red', 'black')
        self.Cancel.grid(column=0, row=1, sticky='nsew')
        self.OK = KeystoneButton(frame, text="OK", command=self.OnOk)
        self.OK.Color('green', 'black')
        self.OK.grid(column=0, row=0, sticky='nsew')
        frame.grid(column=0, row=0, sticky='nsew')
Beispiel #6
0
    def __init__(self,
                 parent,
                 showControls=False,
                 showControlsOnFocus=True,
                 selectMode=False):
        KeystoneEditFrame.__init__(self, parent)

        self.MovingObject = None
        self.Items = None
        self.Constructor = None
        self.DefaultArgs = None

        self.columnconfigure(0, weight=0)
        self.columnconfigure(0, weight=0)
        self.columnconfigure(2, weight=1)
        self.rowconfigure(0, weight=1)

        #control were items are inserted
        self.RootItemRow = 1
        self.ItemColumn = 2

        #setup show controls vars
        self.ShowControls = tk.BooleanVar()
        self.ShowControls.set(showControls)
        self.ShowControls.trace("w", self.OnShowControls)

        self.ShowControlsOnFocus = tk.BooleanVar()
        self.ShowControlsOnFocus.set(showControlsOnFocus)

        self.SelectMode = tk.BooleanVar()
        self.SelectMode.set(selectMode)
        self.SelectMode.trace("w", self.OnSelectMode)

        self.SelectAll = KeystoneButton(self,
                                        text="Select All",
                                        command=self.OnSelectAll)
        self.DeselectAll = KeystoneButton(self,
                                          text="Deselect All",
                                          command=self.OnDeselectAll)
Beispiel #7
0
class EditMacroWindow(tk.Toplevel):

    def OnCopy(self, *args):
        macro = self.Editor.Get()
        self.clipboard_clear()
        command = macro.__repr__()
        self.clipboard_append(macro.__repr__())

        messagebox.showinfo("Copy to City of Heroes",  
            "The command:\n\n" +
            "%s\n\n" % str(command) +
            "has been copied to  the clipboard.\n\n" +
            "Paste and execute this command in the game to create the macro")

    def OnClose(self, *args):
        self.destroy()


    def __init__(self, parent, macro: Macro = None):

        tk.Toplevel.__init__(self, parent)
        self.attributes("-topmost", 1)

        self.title("Create a Macro")
        icon = GetResourcePath('.\\Resources\\keystone.ico')
        if (icon != None):
            self.iconbitmap(icon)
        self.protocol("WM_DELETE_WINDOW", self.OnClose)
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        frame = KeystoneFrame(self)
        frame.columnconfigure(0, weight=0)
        frame.columnconfigure(1, weight=1, minsize='205')
        frame.rowconfigure(0, weight=1)
        frame.rowconfigure(1, weight=0)

        if (macro == None):
            macro = Macro("Name", [SlashCommand(repr="powexec_name power")])
        self.Editor = EditMacro(frame, macro)
        self.Editor.grid(column = 1, row = 0, rowspan=2, sticky='nsew')
        self.Close = KeystoneButton(frame)
        self.Close.configure(text="Close",  command=self.OnClose)
        self.Close.Color('red', 'black')
        self.Close.grid(column=0, row=1, sticky='nsew')
        self.Copy = KeystoneButton(frame, text="Copy to Clipboard", command=self.OnCopy)
        self.Copy.Color('green', 'black')
        self.Copy.grid(column=0, row=0, sticky='nsew')
        frame.grid(column=0, row=0, sticky='nsew')
Beispiel #8
0
class EditBindFile(KeystoneEditFrame):
    def ShowSaveButtons(self, *args):
        if (self.LoadedFile == None):
            return
        self.SaveButton.grid(row=0, column=1, sticky='nse')
        if (self.FilePath != None):
            self.CancelButton.grid(row=0, column=2, sticky='nse')

    def HideSaveButtons(self, *args):
        self.SaveButton.grid_forget()
        self.CancelButton.grid_forget()

    def Load(self, bindFile):
        self.LoadedFile = bindFile.Clone()
        self.Loading = True
        try:
            if (self.LoadedFile.Binds != None):

                binds = []
                if (self.List.get()):
                    binds = self.LoadedFile.Binds
                else:
                    #load in expeded order
                    chords = ['']
                    for chord, altname, desc in CHORD_KEYS:
                        dummy = altname
                        dummy = desc
                        chords.append(chord)
                    for key, altname, desc in KEY_NAMES:
                        dummy = altname
                        dummy = desc
                        for chord in chords:
                            keyBinds = self.LoadedFile.GetBindForKey(
                                key, chord)
                            if (len(keyBinds) > 0):
                                binds.append(keyBinds[0])
                    #load anything in the file we didn't match at the end
                    for bind in self.LoadedFile.Binds:
                        loaded = [
                            b for b in binds if (bind.GetKeyWithChord(
                                defaultNames=True) == b.GetKeyWithChord(
                                    defaultNames=True))
                        ]
                        if (len(loaded) == 0):
                            binds.append(bind)

                self.view.Load(BindListItem, binds, Bind(repr=DEFAULT_BIND))

        finally:
            self.Loading = False
        self.FilePath = self.LoadedFile.FilePath
        if (self.FilePath == None):
            self.PathLabel.configure(text="")
        else:
            self.PathLabel.configure(text=self.FilePath)
            if (os.path.exists(self.FilePath)):
                self.SetClean(self)
            else:
                self.SetDirty(self)
        self.OnLinkedFilesFound()

    def NewBindCallback(self, result, bind, moving=None):

        self.Editor = None
        if (result):
            insertIndex = None
            replaceItem = None
            newKey = bind.Key
            newChord = bind.Chord
            if (self.view.Items == None):
                self.view.Items = []

            #find place in list
            index = -1
            itemsInList = [
                (idx, str.upper(FormatKeyWithChord(bind.Key, bind.Chord)))
                for idx, bind in [(idx, item.Item.Get())
                                  for idx, item in enumerate(self.view.Items)]
            ]
            newKeyWithChord = str.upper(FormatKeyWithChord(newKey, newChord))
            chords = ['']
            for chord, altname, desc in CHORD_KEYS:
                dummy = altname
                dummy = desc
                chords.append(chord)
            for key, altname, desc in KEY_NAMES:
                dummy = altname
                dummy = desc
                for chord in chords:
                    keyWithChord = str.upper(FormatKeyWithChord(key, chord))
                    match = [(idx, listedKeyWithChord)
                             for idx, listedKeyWithChord in itemsInList
                             if listedKeyWithChord == keyWithChord]
                    if (len(match) > 0):
                        #this key is in binds
                        index = match[0][0]
                        #we are overwriting it
                        matchKeyWithChord = match[0][1]
                        if (matchKeyWithChord == newKeyWithChord):
                            replaceItem = self.view.Items[index]
                            insertIndex = index
                            break
                    if (keyWithChord == newKeyWithChord):
                        #this is our spot
                        insertIndex = index + 1
                        break
                if (insertIndex != None):
                    break

            if (replaceItem != None):
                response = messagebox.askokcancel(
                    "Existing Bind",
                    "Overwrite the existing bind for %s\n\n%s\n\nwith the new bind\n\n%s?"
                    % (newKeyWithChord, replaceItem.Item.Get(), bind))
                if (response):
                    self.view.Remove(replaceItem)
                else:
                    if (moving == None):
                        title = 'New Bind'
                        self.Editor = EditBindWindow(self,
                                                     self.NewBindCallback,
                                                     bind,
                                                     title=title,
                                                     dirty=True)
                    else:
                        title = moving.Item.Get().GetKeyWithChord()
                        moving.Item.Button.Color(FOREGROUND, BACKGROUND)
                        moving.Item.Editor = EditBindWindow(
                            moving.Item,
                            moving.Item.EditorCallback,
                            bind,
                            title=title,
                            dirty=True)
                    return

            if (moving != None):
                #remapping rather than inserting new
                movingIndex = self.view.GetIndex(moving)
                if (movingIndex >= 0):
                    self.view.Remove(moving)
                    if (movingIndex < insertIndex):
                        insertIndex = insertIndex - 1

            self.view.Insert(
                insertIndex,
                FrameListViewItem(self.view, BindListItem, bind, True))
            if (bind.IsLoadFileBind()):
                self.OnLinkedFilesFound(binds=[bind])

    def OnNewBind(self, *args):
        if (self.Editor == None):
            self.Editor = EditBindWindow(self, self.NewBindCallback)

    def Get(self) -> BindFile:
        binds = None
        if (self.view.Items != None):
            binds = [
                bind for bind in [item.Item.Get() for item in self.view.Items]
                if bind.Commands != None
            ]
        return BindFile(binds=binds, filePath=self.FilePath)

    def OnSave(self, *args):
        if ((self.FilePath == None) or (self.FilePath == '')):
            filePath = self.PromptForFilePath()
            if (filePath == ''):
                return
        else:
            filePath = self.FilePath

        model = self.Get()
        self.DoWork(target=self._write, args=(
            model,
            filePath,
        ))
        self.FilePath = filePath
        self.SetClean(self)
        if (self.OnSaveCallback != None):
            self.OnSaveCallback(self)

    def OnCancel(self, *args):
        self.Load(self.LoadedFile)

    def _read(self, filePath):
        self._readFile = ReadBindsFromFile(filePath)

    def _write(self, model, filePath):
        model.WriteBindsToFile(filePath)

    def OnLinkedFilesFound(self, binds=None, *args):
        if (binds == None):
            binds = self.Get().GetLoadFileBinds()
        for bind in binds:
            for command in bind.GetLoadFileCommands():
                targetPath = command.GetTargetFile()
                TriggerOpenLinkedFileCallback(targetPath, bind, source=self)

    def Open(self, fileName=None):
        if (fileName == None):
            options = {}
            if (self.LoadedFile != None):
                filePath = self.LoadedFile.FilePath
            else:
                filePath = None
            if (filePath != None):
                options['initialfile'] = filePath
                options['initialdir'] = os.path.dirname(filePath)
            options['title'] = "Open Keybind File"
            options['filetypes'] = (("Text Files", "*.txt"), ("All Files",
                                                              "*.*"))
            options['defaultextension'] = "txt"
            options['multiple'] = False
            fileName = filedialog.askopenfilename(**options)
        if (fileName != ''):
            self.DoWork(target=self._read, args=(fileName, ))
            self.Load(self._readFile)
            self._readFile = None

    def New(self, defaults: bool = False):
        file = NewBindFile(defaults)
        self.Load(file)
        self.SetDirty(self)

    def PromptForFilePath(self) -> str:
        if (self.LoadedFile == None):
            return ''
        options = {}
        options['initialfile'] = "keybinds.txt"
        options['title'] = "Save Keybind File As"
        options['filetypes'] = (("Text Files", "*.txt"), ("All Files", "*.*"))
        options['defaultextension'] = "txt"
        filePath = filedialog.asksaveasfilename(**options)

        return filePath

    def Save(self, promptForPath: bool = False):
        if (promptForPath):
            filePath = self.PromptForFilePath()
            if (filePath == ''):
                return
        self.OnSave()

    def OnOkSelect(self, *args):
        close = True
        if (self.OnSelectCallback != None):
            selected = [b.Get() for b in self.view.GetSelected()]
            if (len(selected) > 0):
                close = self.OnSelectCallback(selected)
        if (close):
            self.SetSelectMode(False)

    def OnCancelSelect(self, *args):
        self.SetSelectMode(False)

    def AddUploadBind(self, *args):
        if (self.FilePath == None):
            return
        path = os.path.abspath(self.FilePath)
        bind = None
        dirty = False
        #find current biind
        loadBinds = [
            bind for bind in [item.Item.Get() for item in self.view.Items]
            if bind.IsLoadFileBind()
        ]
        for loadBind in loadBinds:
            loadCommands = loadBind.GetLoadFileCommands()
            for command in loadCommands:
                boundPath = command.GetTargetFile()
                if (boundPath == path):
                    bind = loadBind
                    break
            if (bind != None):
                break

        if (bind == None):
            bind = Bind(repr=DEFAULT_LOAD_BIND % path)
            dirty = True

        if (self.Editor == None):
            self.Editor = EditBindWindow(self,
                                         self.NewBindCallback,
                                         bind=bind,
                                         dirty=dirty)

    def SetSelectMode(self, set=False):
        if (set != self.SelectMode):
            self.SelectMode = set
            self.view.SelectMode.set(set)
            if (self.view.Items != None):
                for item in [item.Item for item in self.view.Items]:
                    item.ShowEditButton(not set)
            if (set):
                self.NewBindButton.grid_forget()
                self.OkSelectButton.grid(row=0, column=1, sticky='nse')
                self.CancelSelectButton.grid(row=0, column=2, sticky='nse')
            else:
                self.NewBindButton.grid(row=0, column=3, sticky='nse')
                self.OkSelectButton.grid_forget()
                self.CancelSelectButton.grid_forget()

    def __init__(self,
                 parent,
                 bindFile: BindFile = None,
                 list=False,
                 showUploadBindButton=False,
                 onSaveCallback=None,
                 onSelectCallback=None):
        KeystoneEditFrame.__init__(self, parent)

        self.OnSetDirty.append(self.ShowSaveButtons)
        self.OnSetClean.append(self.HideSaveButtons)

        self.SaveButton = None

        self.CancelButton = None

        self.SelectMode = False
        self.OnSelectCallback = onSelectCallback

        self.columnconfigure(0, weight=1)
        self.columnconfigure(1, weight=0)
        self.columnconfigure(2, weight=0)
        self.columnconfigure(3, weight=0)
        self.columnconfigure(4, weight=0)
        self.columnconfigure(5, weight=0)
        self.rowconfigure(0, weight=0)
        self.rowconfigure(1, weight=1)

        self.PathLabel = KeystoneLabel(self)
        self.PathLabel.grid(row=0, column=0, sticky='nsew')

        self.SaveButton = KeystoneButton(self,
                                         text="Save",
                                         command=self.OnSave)
        self.SaveButton.Color("green", "black")

        self.CancelButton = KeystoneButton(self,
                                           text="Cancel",
                                           command=self.OnCancel)
        self.CancelButton.Color("red", "black")

        self.NewBindButton = KeystoneButton(self,
                                            text="New Bind",
                                            command=self.OnNewBind)
        self.NewBindButton.Color("yellow", "black")
        self.NewBindButton.grid(row=0, column=3, sticky='nse')

        self.OkSelectButton = KeystoneButton(self,
                                             text="Select",
                                             command=self.OnOkSelect)
        self.OkSelectButton.Color("green", "black")

        self.CancelSelectButton = KeystoneButton(self,
                                                 text="Cancel",
                                                 command=self.OnCancelSelect)
        self.CancelSelectButton.Color("red", "black")

        if (showUploadBindButton):
            self.UploadBindButton = KeystoneButton(self,
                                                   text="Add Upload Bind",
                                                   command=self.AddUploadBind)
            self.UploadBindButton.Color("orange", "black")
            self.UploadBindButton.grid(row=0, column=4, sticky='nse')

        scrollingFrame = ScrollingFrame(self)
        scrollingFrame.grid(row=1, column=0, columnspan=5, sticky='nsew')

        self.view = FrameListView(scrollingFrame.scrollwindow,
                                  showControlsOnFocus=(list))
        self.view.pack(fill=tk.BOTH, expand=1)
        self.view.OnSetDirty.append(self.SetDirty)

        self.List = tk.BooleanVar()
        self.List.set(list)

        self.Editor = None

        self.OnSaveCallback = onSaveCallback

        self.FilePath = None
        self.LoadedFile = None

        if (bindFile != None):
            self.Load(bindFile)
Beispiel #9
0
    def __init__(self,
                 parent,
                 resourceDir=None,
                 importCallback=None,
                 *args,
                 **kwargs):

        tk.Toplevel.__init__(self, parent, *args, **kwargs)
        self.maxsize(900, 700)
        self.attributes("-toolwindow", 1)
        self.attributes("-topmost", 1)

        icon = GetResourcePath('.\\Resources\\keystone.ico')
        if (icon != None):
            self.iconbitmap(icon)

        self.title("Some Key Binds...")

        #setup grid

        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)
        self.scroll = ScrollingFrame(self)
        self.scroll.grid(row=0, column=0, sticky='nsew')
        self.frame = KeystoneFrame(self.scroll.scrollwindow)
        self.frame.pack(fill=tk.BOTH, expand=1)
        self.frame.columnconfigure(0)
        self.frame.columnconfigure(1)
        self.frame.columnconfigure(2, weight=1)
        row = 0

        self.frame.grid(row=0, column=0, sticky='nsew')

        #get list of kst files from Resources
        if (resourceDir == None):
            self.ResourceDir = os.path.abspath(
                GetResourcePath('.\\Resources\\'))
        else:
            self.ResourceDir = resourceDir
        self.fileList = [
            f for f in os.listdir(self.ResourceDir) if f.endswith(".kst")
        ]
        self.buttons = []
        self.labels = []
        self.descriptions = []
        for filename in self.fileList:
            filePath = os.path.join(self.ResourceDir, filename)
            with open(filePath, "r") as json_file:
                data = json.load(json_file)
            self.buttons.append(
                KeystoneButton(self.frame,
                               text="Import",
                               command=lambda row=row: self.OnImportCallback(
                                   self.fileList[row])))
            self.buttons[-1].Color('yellow', 'black')
            self.buttons[-1].grid(row=row,
                                  column=0,
                                  sticky='nw',
                                  padx=3,
                                  pady=3)
            self.labels.append(KeystoneLabel(self.frame, text=filename))
            self.labels[-1].grid(row=row,
                                 column=1,
                                 sticky='new',
                                 padx=3,
                                 pady=3)
            self.descriptions.append(
                KeystoneMoreLabel(self.frame, text=data[DESCRIPTION]))
            self.descriptions[-1].grid(row=row, column=2, sticky='nsew')
            row = row + 1

        self.ImportCallback = importCallback
    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs)

        win = self
        win.title("Keystone")
        icon = GetResourcePath('.\\Resources\\keystone.ico')
        if (icon != None):
            win.iconbitmap(icon)

        speedBar = KeystoneFrame(win)
        speedBar.config(height=45)
        speedBar.pack(anchor='n', fill=tk.X, expand=False, side=tk.TOP)

        menu = tk.Menu(win)

        fileMenu = tk.Menu(menu, tearoff=0)
        self.AddCommand(menu=fileMenu,
                        frame=speedBar,
                        label="Open",
                        command=self.OnFileOpen)
        self.AddCommand(menu=fileMenu,
                        frame=speedBar,
                        label="New (Empty)",
                        command=self.OnFileNew)
        self.AddCommand(menu=fileMenu,
                        frame=speedBar,
                        label="New (Defaults)",
                        command=self.OnFileNewDefaults)
        self.AddCommand(menu=fileMenu,
                        frame=speedBar,
                        label="Save",
                        command=self.OnFileSave)
        self.AddCommand(menu=fileMenu,
                        frame=speedBar,
                        label="Save As...",
                        command=self.OnFileSaveAs)
        fileMenu.add_command(label="Save All", command=self.OnSaveAll)
        self.AddCommand(menu=fileMenu,
                        frame=speedBar,
                        label="Close",
                        command=self.OnFileClose)
        fileMenu.add_command(label="Close All", command=self.OnCloseAll)
        menu.add_cascade(label="File", menu=fileMenu)

        cohMenu = tk.Menu(menu, tearoff=0)
        cohMenu.add_command(label="Download File", command=self.OnDownloadFile)
        cohMenu.add_command(label="Upload File", command=self.OnUploadFile)
        cohMenu.add_command(label="Create Macro", command=self.OnCreateMacro)
        menu.add_cascade(label="Game Commands", menu=cohMenu)

        importExportMenu = tk.Menu(menu, tearoff=0)
        importExportMenu.add_command(label="Import Binds",
                                     command=self.OnImportBinds)
        importExportMenu.add_command(label="Export Binds",
                                     command=self.OnExportBinds)
        importExportMenu.add_command(label="Add Upload Bind",
                                     command=self.OnAddUploadBind)
        importExportMenu.add_command(
            label="Predefined Binds...",
            command=lambda parent=win, callback=self.OnPredefinedBindsCallback:
            ShowSelectKeybindImportWindow(parent, importCallback=callback))
        menu.add_cascade(label="Import\\Export", menu=importExportMenu)

        helpMenu = tk.Menu(menu, tearoff=0)
        helpMenu.add_command(
            label='Getting Started',
            command=lambda parent=win: ShowWalkthrough(parent))
        helpMenu.add_command(label='Import and Export',
                             command=lambda parent=win: ShowWalkthrough(
                                 parent,
                                 title="Import and Export Walkthrough",
                                 walkthrough=IMPORT_EXPORT_WALKTHROUGH))
        helpMenu.add_command(
            label='Collections and Loaded Files',
            command=lambda parent=win: ShowWalkthrough(
                parent,
                title="Collections and Loaded Files Walkthrough",
                walkthrough=COLLECTIONS_AND_KEYCHAINS_WALKTHROUGH,
                endPages=COLLECTIONS_AND_KEYCHAINS_WALKTHROUGH_END_PAGES))
        self.AddCommand(menu=helpMenu,
                        frame=speedBar,
                        label="About",
                        command=lambda parent=win: ShowHelpAbout(parent))
        menu.add_cascade(label='Help', menu=helpMenu)

        SetOpenLinkedFileCallback(self._openLinkedFileCallback)

        self.FirstFrame = KeystoneFrame(win)
        self.FirstFrame.columnconfigure(0, weight=1, minsize=800)
        self.FirstFrame.rowconfigure(0, weight=1, minsize=400)
        walkthroughButton = KeystoneButton(
            self.FirstFrame,
            text='Intro Walkthrough',
            command=lambda parent=win: ShowWalkthrough(parent))
        walkthroughButton.Color('lightskyblue', 'black')
        walkthroughButton.configure(relief=tk.RAISED)
        walkthroughButton.grid()
        self.FirstFrame.pack(fill=tk.BOTH, expand=True, side=tk.TOP)

        self.Notebook = FrameNotebook(win, EditBindFileCollection,
                                      [self.OnSaveCallback])
        self.ShowingNotebook = False
        self.SuppressCallback = False

        win.config(menu=menu, width=800, height=400)

        win.protocol("WM_DELETE_WINDOW", self.OnClosing)

        self.TabLock = threading.Lock()
 def AddCommand(self, menu: tk.Menu, frame, label, command):
     menu.add_command(label=label, command=command)
     KeystoneButton(frame, text=label, command=command).pack(anchor='nw',
                                                             side=tk.LEFT)
Beispiel #12
0
class FrameListView(KeystoneEditFrame):
    def __init__(self,
                 parent,
                 showControls=False,
                 showControlsOnFocus=True,
                 selectMode=False):
        KeystoneEditFrame.__init__(self, parent)

        self.MovingObject = None
        self.Items = None
        self.Constructor = None
        self.DefaultArgs = None

        self.columnconfigure(0, weight=0)
        self.columnconfigure(0, weight=0)
        self.columnconfigure(2, weight=1)
        self.rowconfigure(0, weight=1)

        #control were items are inserted
        self.RootItemRow = 1
        self.ItemColumn = 2

        #setup show controls vars
        self.ShowControls = tk.BooleanVar()
        self.ShowControls.set(showControls)
        self.ShowControls.trace("w", self.OnShowControls)

        self.ShowControlsOnFocus = tk.BooleanVar()
        self.ShowControlsOnFocus.set(showControlsOnFocus)

        self.SelectMode = tk.BooleanVar()
        self.SelectMode.set(selectMode)
        self.SelectMode.trace("w", self.OnSelectMode)

        self.SelectAll = KeystoneButton(self,
                                        text="Select All",
                                        command=self.OnSelectAll)
        self.DeselectAll = KeystoneButton(self,
                                          text="Deselect All",
                                          command=self.OnDeselectAll)

    def _gridItem(self, item, idx, gridForget=False):
        if (gridForget):
            item.grid_forget()
            self.rowconfigure(idx + self.RootItemRow, weight=0)
        else:
            item.grid(row=idx + self.RootItemRow,
                      column=0,
                      columnspan=self.ItemColumn + 1,
                      sticky='nsew')
            self.rowconfigure(idx + self.RootItemRow, weight=1)

    def Load(self, constructor, args, defaultArgs):
        if (self.Items != None):
            for item in self.Items:
                item.grid_forget()
        self.Constructor = constructor
        self.DefaultArgs = defaultArgs
        self.Items = [
            FrameListViewItem(self, constructor, item) for item in args
        ]
        self.OnShowControls()
        self.OnSelectMode()
        for idx, item in enumerate(self.Items):
            self._gridItem(item, idx)

        if (len(self.Items) > 0):
            self.Items[-1].SetIsLast(True)

        self.SetClean(self)

    def GetSelected(self):
        if (self.Items == None):
            return []
        return [p.Item for p in self.Items if p.Selected.get()]

    def OnShowControls(self, *args):
        if (self.Items == None):
            return
        show = self.ShowControls.get()
        for item in self.Items:
            item.ShowControls.set(show)

    def OnSelectMode(self, *args):
        if (self.Items == None):
            return
        show = self.SelectMode.get()
        for item in self.Items:
            item.SelectMode.set(show)
        if (show):
            self.SelectAll.grid(row=0, column=0, sticky='nw', padx=3, pady=3)
            self.DeselectAll.grid(row=0, column=1, sticky='nw', padx=3, pady=3)
        else:
            self.SelectAll.grid_forget()
            self.DeselectAll.grid_forget()

    def SelectOrDeselectAll(self, select=True):
        if (self.Items == None):
            return
        if (not self.SelectMode.get()):
            return
        for item in self.Items:
            item.Selected.set(select)

    def OnSelectAll(self, *args):
        self.SelectOrDeselectAll()

    def OnDeselectAll(self, *args):
        self.SelectOrDeselectAll(select=False)

    def EnterMoveMode(self, triggeringItem: FrameListViewItem):
        self.ShowControls.set(True)
        self.MovingObject = triggeringItem
        for item in self.Items:

            if (item != self.MovingObject):
                item.Move.configure(background='black')
                item.Move.configure(foreground='black')
                item.Move['state'] = tk.DISABLED
            else:
                item.Move.configure(background=FrameListViewItem.INSERT_COLOR)
                item.Move.configure(
                    foreground=FrameListViewItem.INSERT_TEXT_COLOR)

            item.TopInsert.configure(
                background=FrameListViewItem.INSERT_TEXT_COLOR)
            item.TopInsert.configure(foreground=FrameListViewItem.INSERT_COLOR)

            item.BottomInsert.configure(
                background=FrameListViewItem.INSERT_TEXT_COLOR)
            item.BottomInsert.configure(
                foreground=FrameListViewItem.INSERT_COLOR)

            item.Delete.configure(background='black')
            item.Delete.configure(foreground='black')
            item.Delete['state'] = tk.DISABLED

    def EnterDeleteMode(self):
        for item in self.Items:

            item.Move.configure(background='black')
            item.Move.configure(foreground='black')
            item.Move['state'] = tk.DISABLED

            item.TopInsert.configure(background='black')
            item.TopInsert.configure(foreground='black')
            item.TopInsert['state'] = tk.DISABLED

            item.BottomInsert.configure(background='black')
            item.BottomInsert.configure(foreground='black')
            item.BottomInsert['state'] = tk.DISABLED

    def ExitMoveMode(self):
        self.ShowControls.set(False)

        self.MovingObject = None

        for item in self.Items:
            item.Move.configure(background=FrameListViewItem.MOVE_COLOR)
            item.Move.configure(foreground=FrameListViewItem.MOVE_TEXT_COLOR)
            item.Move['state'] = tk.NORMAL

            item.Delete.configure(background=FrameListViewItem.DELETE_COLOR)
            item.Delete.configure(
                foreground=FrameListViewItem.DELETE_TEXT_COLOR)
            item.Delete['state'] = tk.NORMAL

            item.TopInsert.configure(background=FrameListViewItem.INSERT_COLOR)
            item.TopInsert.configure(
                foreground=FrameListViewItem.INSERT_TEXT_COLOR)

            item.BottomInsert.configure(
                background=FrameListViewItem.INSERT_COLOR)
            item.BottomInsert.configure(
                foreground=FrameListViewItem.INSERT_TEXT_COLOR)

            item.SetIsLast(False)

        self.Items[-1].SetIsLast(True)

    def ExitDeleteMode(self):

        for item in self.Items:

            item.Move.configure(background=FrameListViewItem.MOVE_COLOR)
            item.Move.configure(foreground=FrameListViewItem.MOVE_TEXT_COLOR)
            item.Move['state'] = tk.NORMAL

            item.TopInsert.configure(background=FrameListViewItem.INSERT_COLOR)
            item.TopInsert.configure(
                foreground=FrameListViewItem.INSERT_TEXT_COLOR)
            item.TopInsert['state'] = tk.NORMAL

            item.BottomInsert.configure(
                background=FrameListViewItem.INSERT_COLOR)
            item.BottomInsert.configure(
                foreground=FrameListViewItem.INSERT_TEXT_COLOR)
            item.BottomInsert['state'] = tk.NORMAL

            item.SetIsLast(False)

        if (len(self.Items) == 0):
            self.MoveOrCreate(-1)

        self.Items[-1].SetIsLast(True)

    def GetIndex(self, targetItem) -> int:
        #return index of item of -1 if not in Items
        index = -1
        for idx, item in enumerate(self.Items):
            if (item == targetItem):
                index = idx
                break
        return index

    def MoveOrCreate(self,
                     triggeringObject: FrameListViewItem,
                     below: bool = False):

        create = False
        if (self.MovingObject == None):
            self.MovingObject = FrameListViewItem(self, self.Constructor,
                                                  self.DefaultArgs)
            create = True

        #pass -1 to insert below last item
        if ((triggeringObject == -1)
                or (below and triggeringObject.IsLast.get())):
            triggeringIndex = -1
        else:
            for idx, item in enumerate(self.Items):
                if (item == triggeringObject):
                    triggeringIndex = idx
                    break

            if (below):
                triggeringIndex = triggeringIndex + 1

        if (not create):
            movingIndex = self.GetIndex(self.MovingObject)
            self.Remove(self.MovingObject)
            if (movingIndex < triggeringIndex):
                triggeringIndex = triggeringIndex - 1

        self.Insert(triggeringIndex, self.MovingObject)

        self.ExitMoveMode()

    def Remove(self, itemToRemove: FrameListViewItem):
        index = self.GetIndex(itemToRemove)
        if (index == -1):
            return
        for idx in range(index, len(self.Items)):
            self._gridItem(self.Items[idx], idx, gridForget=True)
        self.Items.remove(itemToRemove)
        for idx in range(index, len(self.Items)):
            self._gridItem(self.Items[idx], idx)

        self.SetDirty()

    def Insert(self, index: int, itemToInsert: FrameListViewItem):
        if ((index < 0) or (index >= len(self.Items))):
            self.Items.append(itemToInsert)
            idx = len(self.Items) - 1
            self._gridItem(self.Items[idx], idx)
        else:
            for idx in range(index, len(self.Items)):
                self._gridItem(self.Items[idx], idx, gridForget=True)
            self.Items.insert(index, itemToInsert)
            for idx in range(index, len(self.Items)):
                self._gridItem(self.Items[idx], idx)

        self.SetDirty()
Beispiel #13
0
    def __init__(self, parent, bind: Bind, lockKey=False, dirty=False):
        KeystoneEditFrame.__init__(self, parent)

        #StringVar for Key
        self.Key = None

        #StringVar for Chord
        self.Chord = None

        #StringVar for Key Description
        self.KeyDescription = None

        #StringVar for Chord Description
        self.ChordDescription = None

        #List of commands view frame
        self.Commands = None

        #Indicates keys cannot be edited
        self._lockKey = lockKey

        #layout grid
        self.columnconfigure(0, weight=1, minsize=200)
        self.columnconfigure(1, weight=0)
        self.columnconfigure(2, weight=7)
        self.rowconfigure(0, weight=1)

        #add controls

        self.KeyFrame = KeystoneFrame(self)
        self.KeyFrame.columnconfigure(1, weight=1)
        self.KeyFrame.columnconfigure(2, weight=0)
        self.KeyFrame.rowconfigure(4, weight=1)

        self.CommandsFrame = KeystoneFrame(self)
        self.CommandsFrame.columnconfigure(0, weight=1)

        self.Commands = FrameListView(self.CommandsFrame)
        self.Commands.OnSetDirty.append(self.SetDirty)
        self.Commands.grid(row=0, column=0, sticky='new')

        self.TextFrame = KeystoneFrame(self)
        self.TextFrame.rowconfigure(0, weight=1, minsize='55')
        self.TextFrame.columnconfigure(0, weight=1, minsize='405')

        self.Delete = tk.Button(self,
                                text=self.DELETE_TEXT,
                                background=self.DELETE_COLOR,
                                foreground=self.DELETE_TEXT_COLOR,
                                font=(TEXT_FONT, 7, "bold"),
                                relief=self.DELETE_STYLE,
                                width=1,
                                wraplength=1,
                                command=self.OnDelete)

        self.Assign = tk.Button(self,
                                text=self.ASSIGN_TEXT,
                                background=self.ASSIGN_COLOR,
                                foreground=self.ASSIGN_TEXT_COLOR,
                                font=(TEXT_FONT, 7, "bold"),
                                relief=self.DELETE_STYLE,
                                width=1,
                                wraplength=1,
                                command=self.AssignCommand)

        self.UIToTextButton = KeystoneButton(self,
                                             text="Edit As Text",
                                             command=self.SynchUIToText)

        keyLabel = KeystoneLabel(self.KeyFrame,
                                 anchor='nw',
                                 text="Key",
                                 width=5)
        keyLabel.grid(row=1, column=0, sticky="nw", padx="3", pady="3")
        self.Key = tk.StringVar()
        self.KeyValue = KeystoneLabel(self.KeyFrame,
                                      anchor='nw',
                                      textvariable=self.Key,
                                      width=5)
        self.KeyBox = KeystoneKeyCombo(self.KeyFrame,
                                       textvariable=self.Key,
                                       values=" ".join(
                                           [c[0] for c in KEY_NAMES]))
        self.Key.trace("w", self.SelectKey)

        self.KeyDescription = tk.StringVar()
        keyDescription = KeystoneLabel(self.KeyFrame,
                                       anchor="nw",
                                       textvariable=self.KeyDescription,
                                       wraplength=200)
        keyDescription.grid(row=2,
                            column=0,
                            columnspan=2,
                            sticky="nsew",
                            padx="3",
                            pady="3")

        self.Key.set(bind.Key)
        self.Key.trace("w", self.SetDirty)

        chordLabel = KeystoneLabel(self.KeyFrame,
                                   anchor='nw',
                                   text="Chord",
                                   width=5)
        chordLabel.grid(row=3, column=0, sticky="nw", padx="3", pady="3")
        self.Chord = tk.StringVar()
        self.ChordValue = KeystoneLabel(self.KeyFrame,
                                        anchor='nw',
                                        textvariable=self.Chord,
                                        width=5)
        self.ChordBox = KeystoneKeyCombo(self.KeyFrame,
                                         textvariable=self.Chord,
                                         values=" ".join(
                                             [c[0] for c in CHORD_KEYS]))
        self.Chord.trace("w", self.SelectChord)

        self.ChordDescription = tk.StringVar()
        chordDescription = KeystoneLabel(self.KeyFrame,
                                         anchor="nw",
                                         textvariable=self.ChordDescription,
                                         wraplength=200)
        chordDescription.grid(row=4,
                              column=0,
                              columnspan=2,
                              sticky="nsew",
                              padx="3",
                              pady="3")

        self.Chord.set(bind.Chord)
        self.Chord.trace("w", self.SetDirty)

        self.UnlockKeysButton = KeystoneButton(self,
                                               text="Change Assigned Key",
                                               command=self.UnlockKeys)
        self.UnlockKeysButton.Color(FOREGROUND, BACKGROUND)

        self.ShowCommands = tk.BooleanVar()
        self.ShowCommands.trace("w", self.OnShowCommands)

        self.TextEntry = KeystoneTextEntry(self.TextFrame, height=5)
        self.TextEntry.grid(row=0, column=0, sticky="nsew", padx="3", pady="3")
        self.TextEntry.bind("<Key>", self.SetDirty)

        self.ShowTextEditor = tk.BooleanVar()
        self.ShowTextEditor.set(False)
        self.ShowTextEditor.trace("w", self.OnShowTextEditor)

        self.TextToUIButton = KeystoneButton(self.TextFrame,
                                             text="Editor",
                                             command=self.SynchTextToUI)
        self.TextToUIButton.grid(row=1,
                                 column=0,
                                 sticky="nsew",
                                 padx="3",
                                 pady="3")

        self.OnShowTextEditor()
        self.UnlockKeys(not lockKey)

        self.Load(bind)
        self.Dirty.set(dirty)
    def __init__(self,
                 parent,
                 title=None,
                 icon=None,
                 onBack=None,
                 onNext=None,
                 onClose=None,
                 *args,
                 **kwargs):

        #initialize
        tk.Toplevel.__init__(self, parent, *args, **kwargs)

        if (title == None):
            title = type(parent).__name__ + " Wizard"
        self.title(title)

        if (icon == None):
            icon = GetResourcePath('.\\Resources\\keystone.ico')
        if (icon != None):
            self.iconbitmap(icon)

        self.Frame = KeystoneFrame(self)

        self.Pages = None
        self.CurrentPage = None

        self.PageIndex = tk.IntVar(value=0)
        self.PageIndex.trace("w", self.ShowPage)

        #callbacks
        self.OnBackCallback = onBack
        self.OnNexCallback = onNext
        self.OnCloseCallback = onClose

        #setup grid
        self.rowconfigure(0, weight=1, minsize=200)
        self.columnconfigure(0, weight=1, minsize=400)
        self.Frame.columnconfigure(0, weight=0, minsize=50)
        self.Frame.columnconfigure(1, weight=1)
        self.Frame.columnconfigure(2, weight=0, minsize=50)
        self.Frame.columnconfigure(3, weight=1)
        self.Frame.columnconfigure(4, weight=0, minsize=50)
        self.Frame.rowconfigure(0, weight=1)
        self.Frame.rowconfigure(1, weight=0)

        #setup controls
        self.Frame.grid(row=0, column=0, sticky='nsew')

        self.Back = KeystoneButton(self.Frame,
                                   text="Back",
                                   command=self.OnBack)
        self.Back.Color('green', 'black')
        self.ShowBack = tk.BooleanVar(value=False)
        self.ShowBack.trace("w", self.OnShowBack)

        self.Next = KeystoneButton(self.Frame,
                                   text="Next",
                                   command=self.OnNext)
        self.Next.Color('green', 'black')
        self.ShowNext = tk.BooleanVar(value=False)
        self.ShowNext.trace("w", self.OnShowNext)

        self.Close = KeystoneButton(self.Frame,
                                    text="Close",
                                    command=self.OnClose)
        self.Close.Color('red', 'black')
        self.ShowClose = tk.BooleanVar(value=False)
        self.ShowClose.trace("w", self.OnShowClose)
Beispiel #15
0
    def __init__(self,
                 parent,
                 bindFile: BindFile = None,
                 list=False,
                 showUploadBindButton=False,
                 onSaveCallback=None,
                 onSelectCallback=None):
        KeystoneEditFrame.__init__(self, parent)

        self.OnSetDirty.append(self.ShowSaveButtons)
        self.OnSetClean.append(self.HideSaveButtons)

        self.SaveButton = None

        self.CancelButton = None

        self.SelectMode = False
        self.OnSelectCallback = onSelectCallback

        self.columnconfigure(0, weight=1)
        self.columnconfigure(1, weight=0)
        self.columnconfigure(2, weight=0)
        self.columnconfigure(3, weight=0)
        self.columnconfigure(4, weight=0)
        self.columnconfigure(5, weight=0)
        self.rowconfigure(0, weight=0)
        self.rowconfigure(1, weight=1)

        self.PathLabel = KeystoneLabel(self)
        self.PathLabel.grid(row=0, column=0, sticky='nsew')

        self.SaveButton = KeystoneButton(self,
                                         text="Save",
                                         command=self.OnSave)
        self.SaveButton.Color("green", "black")

        self.CancelButton = KeystoneButton(self,
                                           text="Cancel",
                                           command=self.OnCancel)
        self.CancelButton.Color("red", "black")

        self.NewBindButton = KeystoneButton(self,
                                            text="New Bind",
                                            command=self.OnNewBind)
        self.NewBindButton.Color("yellow", "black")
        self.NewBindButton.grid(row=0, column=3, sticky='nse')

        self.OkSelectButton = KeystoneButton(self,
                                             text="Select",
                                             command=self.OnOkSelect)
        self.OkSelectButton.Color("green", "black")

        self.CancelSelectButton = KeystoneButton(self,
                                                 text="Cancel",
                                                 command=self.OnCancelSelect)
        self.CancelSelectButton.Color("red", "black")

        if (showUploadBindButton):
            self.UploadBindButton = KeystoneButton(self,
                                                   text="Add Upload Bind",
                                                   command=self.AddUploadBind)
            self.UploadBindButton.Color("orange", "black")
            self.UploadBindButton.grid(row=0, column=4, sticky='nse')

        scrollingFrame = ScrollingFrame(self)
        scrollingFrame.grid(row=1, column=0, columnspan=5, sticky='nsew')

        self.view = FrameListView(scrollingFrame.scrollwindow,
                                  showControlsOnFocus=(list))
        self.view.pack(fill=tk.BOTH, expand=1)
        self.view.OnSetDirty.append(self.SetDirty)

        self.List = tk.BooleanVar()
        self.List.set(list)

        self.Editor = None

        self.OnSaveCallback = onSaveCallback

        self.FilePath = None
        self.LoadedFile = None

        if (bindFile != None):
            self.Load(bindFile)
Beispiel #16
0
class BindListItem(KeystoneEditFrame):
    def EditorCallback(self, result, bind, *args):
        self.SetEdited()
        self.Editor = None
        if (result):
            if (bind.GetKeyWithChord(defaultNames=True) !=
                    self.Get().GetKeyWithChord(defaultNames=True)):
                self.BindFileEditor.NewBindCallback(True,
                                                    bind,
                                                    moving=self.master)
            else:
                self.Repr.set(bind.__repr__())
                if bind.IsLoadFileBind():
                    self.BindFileEditor.OnLinkedFilesFound(binds=[bind])
                self.SetDirty()

    def SetEdited(self, *args):
        dirty = self.Dirty.get()
        if dirty:
            self.Button.Color('yellow', BACKGROUND)
        else:
            self.Button.Color(BACKGROUND, FOREGROUND)

    def OnEdit(self, *args):
        if self.Editor == None:
            self.Button.Color(FOREGROUND, BACKGROUND)
            self.Editor = EditBindWindow(self,
                                         self.EditorCallback,
                                         self.Get(),
                                         lockKey=True)
        else:
            self.Editor.OnCancel()

    def ShowEditButton(self, show=False):
        if (show and (not self._showingEdit)):
            self.Button.grid(row=0, column=0, sticky="nsew")
            self._showingEdit = True
        elif ((not show) and self._showingEdit):
            self.Button.grid_forget()
            self._showingEdit = False

    def Get(self):
        return Bind(repr=self.Repr.get())

    def __init__(self, parent, bind: Bind, dirty=False):
        KeystoneEditFrame.__init__(self, parent)

        self.BindFileEditor = parent
        while (self.BindFileEditor.__class__.__name__ != "EditBindFile"):
            self.BindFileEditor = self.BindFileEditor.master
            if (self.BindFileEditor == None):
                break
        self.Editor = None

        self.columnconfigure(0, weight=0)
        self.columnconfigure(1, weight=1)
        self.rowconfigure(0, weight=0)
        self.rowconfigure(1, weight=0)
        self._showingEdit = True
        self.Button = KeystoneButton(self,
                                     text="...",
                                     width=6,
                                     command=self.OnEdit)
        self.Button.grid(row=0, column=0, sticky="nsew")
        self.Repr = tk.StringVar()
        self.Label = KeystoneLabel(self, textvariable=self.Repr)
        self.Repr.set(bind.__repr__())
        self.Label.grid(row=0, column=1, sticky="nsew")

        self.OnSetDirty.append(self.SetEdited)
        self.OnSetClean.append(self.SetEdited)
        self.BindFileEditor.OnSetClean.append(self.SetClean)
        if (dirty):
            self.SetDirty()
    def __init__(self, parent, command: SlashCommand):
        KeystoneEditFrame.__init__(self, parent)

        #Frame for formatting controls
        self.FormatFrame = None

        #Frame for decscription
        self.DescriptionFrame = None

        #StringVar for command name
        self.CommandName = None

        #text entry object
        self.TextEntry = None

        #color entry objects
        self.ColorEntry = None
        self.BackgroundEntry = None
        self.BorderEntry = None

        #StringVar for transparency
        self.TransparencyEntryText = None

        #StringVar for scale
        self.ScaleEntryText = None

        #StringVar for repeat selection
        self.RepeatText = None

        #StringVar for duration
        self.DurationText = None

        #StringVar for power description text
        self.DescriptionText = None

        #The text prompt for the last selected command, e.g. "power" for powexec_name
        self.TextPrompt = None

        #layout grid and frames
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=0)
        self.rowconfigure(1, weight=0)
        self.rowconfigure(2, weight=1)
        commandFrame = KeystoneFrame(self)
        commandFrame.grid(row=0, column=0, sticky='nsew')
        commandFrame.columnconfigure(0, weight=0)
        commandFrame.columnconfigure(1, weight=1)
        commandFrame.columnconfigure(2, weight=0)
        commandFrame.columnconfigure(3, weight=0)
        self.FormatFrame = formatFrame = KeystoneFrame(self)
        self.DescriptionFrame = descriptionFrame = KeystoneFrame(self)

        #add controls
        self.CommandName = tk.StringVar()
        commandBox = KeystoneCombo(commandFrame, textvariable=self.CommandName, values=" ".join([ c[0] for c in LIST_OF_SLASH_COMMANDS]), postcommand=self.LockShowFormat)
        commandBox.grid(row=0, column=0, sticky="w", padx="3", pady="3")
        self.CommandName.trace("w", self.SelectCommand)
        self.CommandName.trace("w", self.SetDirty)

        self.TextEntry = KeystoneTextEntry(commandFrame)
        self.TextEntry.grid(row=0, column=1, sticky="nsew", padx="3", pady="3")     
        self.TextEntry.bind("<Key>", self.SetDirty)

        self.BrowseButton = KeystoneButton(commandFrame, text=" ... ", command=self.OnBrowseButton)
        self.NewButton = KeystoneButton(commandFrame, text="New", command=self.OnNewButton)
        self.IsLoadFileCommand = tk.BooleanVar()
        self.IsLoadFileCommand.set(False)
        self.IsLoadFileCommand.trace("w", self.OnSetIsLoadFileCommand)

        label = KeystoneLabel(formatFrame, text="Repeat Mode", anchor='n')
        label.grid(row=0, column=0, pady="3")
        repeatModes = [("Once", ""), ("Repeat [%s]" % REPEAT_STR, REPEAT_STR), ("Toggle [%s]" %TOGGLE_STR , TOGGLE_STR)]
        self.RepeatText = tk.StringVar()
        for idx, (text, mode) in enumerate(repeatModes):
            b = KeystoneRadio(formatFrame, text=text, value=mode, variable=self.RepeatText)
            b.grid(row=1+idx, column=0, sticky='w')
        self.RepeatText.set("")
        self.RepeatText.trace("w", self.SetDirty)

        editLabels = ["Text Color", "Background Color", "Transparency", "Border Color", "Scale", "Duration"]
        for idx, text in enumerate(editLabels):
            label = KeystoneLabel(formatFrame, text=text, anchor='n', width=30)
            if (idx < 3):
                row = 1
            else:
                row = 3
            label.grid(row=row, column=1+(idx % 3))

        self.ColorEntry = ColorPicker(formatFrame)
        self.ColorEntry.Combo.configure(postcommand=self.LockShowFormat)
        self.ColorEntry.grid(row=0, column=1, padx="3", pady="3")
        self.ColorEntry.ColorEntryText.trace("w", self.FormatText)

        self.BackgroundEntry = ColorPicker(formatFrame)
        self.BackgroundEntry.Combo.configure(postcommand=self.LockShowFormat)
        self.BackgroundEntry.grid(row=0, column=2, padx="3", pady="3")
        self.BackgroundEntry.ColorEntryText.trace("w", self.FormatText)

        self.TransparencyEntryText = tk.StringVar()
        self.TransparencyEntry = KeystoneCombo(formatFrame, textvariable=self.TransparencyEntryText, values=" ".join([str(p) for p in range(0,101)]), width=3, postcommand=self.LockShowFormat)
        self.TransparencyEntry.grid(row=0, column=3)
        self.TransparencyEntryText.trace("w", self.FormatText)

        self.BorderEntry = ColorPicker(formatFrame)
        self.BorderEntry.Combo.configure(postcommand=self.LockShowFormat)
        self.BorderEntry.grid(row=2, column=1, padx="3", pady="3")
        self.BorderEntry.ColorEntryText.trace("w", self.FormatText)

        self.ScaleEntryText = tk.StringVar()
        scaleEntry = KeystoneEntry(formatFrame, textvariable=self.ScaleEntryText, width=5)
        scaleEntry.grid(row=2, column=2)
        self.ScaleEntryText.trace("w", self.FormatText)

        self.DurationText = tk.StringVar()
        durationEntry = KeystoneEntry(formatFrame, textvariable=self.DurationText, width=5)
        durationEntry.grid(row=2, column=3)
        self.DurationText.trace("w", self.FormatText)

        self.DescriptionText = tk.StringVar()
        description = KeystoneLabel(descriptionFrame, anchor="nw", textvariable=self.DescriptionText, wraplength=800)
        description.grid(sticky="nsew", padx="3", pady="3")

        #load model
        self.Load(command)

        #bind to hide format and desc
        self.BindWidgetToShowFormat(self)
class KeystoneWizard(tk.Toplevel):
    def __init__(self,
                 parent,
                 title=None,
                 icon=None,
                 onBack=None,
                 onNext=None,
                 onClose=None,
                 *args,
                 **kwargs):

        #initialize
        tk.Toplevel.__init__(self, parent, *args, **kwargs)

        if (title == None):
            title = type(parent).__name__ + " Wizard"
        self.title(title)

        if (icon == None):
            icon = GetResourcePath('.\\Resources\\keystone.ico')
        if (icon != None):
            self.iconbitmap(icon)

        self.Frame = KeystoneFrame(self)

        self.Pages = None
        self.CurrentPage = None

        self.PageIndex = tk.IntVar(value=0)
        self.PageIndex.trace("w", self.ShowPage)

        #callbacks
        self.OnBackCallback = onBack
        self.OnNexCallback = onNext
        self.OnCloseCallback = onClose

        #setup grid
        self.rowconfigure(0, weight=1, minsize=200)
        self.columnconfigure(0, weight=1, minsize=400)
        self.Frame.columnconfigure(0, weight=0, minsize=50)
        self.Frame.columnconfigure(1, weight=1)
        self.Frame.columnconfigure(2, weight=0, minsize=50)
        self.Frame.columnconfigure(3, weight=1)
        self.Frame.columnconfigure(4, weight=0, minsize=50)
        self.Frame.rowconfigure(0, weight=1)
        self.Frame.rowconfigure(1, weight=0)

        #setup controls
        self.Frame.grid(row=0, column=0, sticky='nsew')

        self.Back = KeystoneButton(self.Frame,
                                   text="Back",
                                   command=self.OnBack)
        self.Back.Color('green', 'black')
        self.ShowBack = tk.BooleanVar(value=False)
        self.ShowBack.trace("w", self.OnShowBack)

        self.Next = KeystoneButton(self.Frame,
                                   text="Next",
                                   command=self.OnNext)
        self.Next.Color('green', 'black')
        self.ShowNext = tk.BooleanVar(value=False)
        self.ShowNext.trace("w", self.OnShowNext)

        self.Close = KeystoneButton(self.Frame,
                                    text="Close",
                                    command=self.OnClose)
        self.Close.Color('red', 'black')
        self.ShowClose = tk.BooleanVar(value=False)
        self.ShowClose.trace("w", self.OnShowClose)

    def LoadPages(self, pages: [KeystoneWizardPage]):
        if (self.CurrentPage != None):
            self.CurrentPage.grid_forget()
            self.CurrentPage = None
        self.Pages = pages
        for eachPage in pages:
            eachPage.Wizard = self
        self.PageIndex.set(0)

    def PageCount(self) -> int:
        if (self.Pages == None):
            return 0
        return len(self.Pages)

    def OnShowBack(self, *args):
        if (self.PageIndex.get() == 0):
            show = False
        else:
            show = self.ShowBack.get()
        if (show):
            self.Back.grid(column=0, row=1, sticky='nsew')
        else:
            self.Back.grid_forget()

    def OnShowNext(self, *args):
        if (self.PageIndex.get() == (self.PageCount() - 1)):
            show = False
        else:
            show = self.ShowNext.get()
        if (show):
            self.Next.grid(column=4, row=1, sticky='nsew')
        else:
            self.Next.grid_forget()

    def OnShowClose(self, *args):
        show = self.ShowClose.get()
        if (show):
            self.Close.grid(column=2, row=1, sticky='nsew')
        else:
            self.Close.grid_forget()

    def ShowPage(self, *args):

        if (self.PageCount() == 0):
            return

        #get index
        index = self.PageIndex.get()
        if (index >= self.PageCount()):
            index = self.PageCount() - 1
            self.PageIndex.set(index)
            return  #as set will callback due to trace
        elif (index < 0):
            index = 0
            self.PageIndex.set(index)
            return  #as set will callback due to trace

        #drop current page
        if (self.CurrentPage != None):
            self.CurrentPage.grid_forget()

        #show page and buttons
        page = self.Pages[index]
        page.grid(row=0, column=0, columnspan=5, sticky='nsew')
        self.CurrentPage = page
        self.ShowBack.set(page.AllowBack.get())
        self.ShowNext.set(page.AllowNext.get())
        self.ShowClose.set(page.AllowClose.get())

    def _onButton(self, callback, pageCallback, allowVar, showVar,
                  indexChange):
        if (pageCallback != None):
            pageCallback(self, self.CurrentPage)
        allow = allowVar.get()
        showVar.set(allow)
        index = self.PageIndex.get() + indexChange
        if (index > self.PageCount()):
            index = self.PageCount() - 1
        elif (index < 0):
            index = 0
        if (index != self.PageIndex.get()):
            self.PageIndex.set(index)
            if (callback != None):
                callback(self)

    def OnBack(self, *args):
        page = self.CurrentPage
        self._onButton(self.OnBackCallback, page.OnBack, page.AllowBack,
                       self.ShowBack, -1)

    def OnNext(self, *args):
        page = self.CurrentPage
        self._onButton(self.OnNexCallback, page.OnNext, page.AllowClose,
                       self.ShowClose, 1)

    def OnClose(self, *args):
        page = self.CurrentPage
        if (page.OnClose != None):
            page.OnClose(self)
        if (page.AllowClose.get()):
            self.destroy()
        if (self.OnCloseCallback != None):
            self.OnCloseCallback(self)
Beispiel #19
0
class BindEditor(KeystoneEditFrame):

    DELETE_TEXT = 'UNBIND'
    DELETE_COLOR = 'black'
    DELETE_TEXT_COLOR = 'red'
    DELETE_STYLE = tk.FLAT

    ASSIGN_TEXT = 'BIND'
    UNASSIGN_TEXT = 'Unassign Bind'
    UNASSIGN_MESSAGE = 'Include no assignment?  Use "nop" to  assign a key to do nothing.  Use /unbind <key> to restore a default in the UI'
    DEFAULT_TEXT = 'Default Bind'
    DEFAULT_COLOR = 'yellow'
    DEFAULT_TEXT_COLOR = 'black'
    CANCEL_TEXT = 'Cancel'
    ASSIGN_COLOR = 'black'
    ASSIGN_TEXT_COLOR = 'green'

    def SetKeyDescription(self, keyVar: tk.StringVar, descVar: tk.StringVar,
                          list):
        keyName = keyVar.get()
        key = MatchKeyName(keyName, list)
        if (key != None):
            desc = key[2]
            altname = key[1]
            if ((desc == '') and (altname != '')):
                desc = altname
            descVar.set(desc)
        else:
            descVar.set('')

    def SelectKey(self, *args):
        self.SetKeyDescription(self.Key, self.KeyDescription, KEY_NAMES)

    def SelectChord(self, *args):
        self.SetKeyDescription(self.Chord, self.ChordDescription, CHORD_KEYS)

    def AssignCommand(self, *args):
        model = Bind(key=self.Key.get(),
                     chord=self.Chord.get(),
                     commands=[SlashCommand(repr=DEFAULT_COMMAND)])
        self.Load(model)
        self.SetDirty()

    def UnassignCommand(self, *args):
        text = args[0]
        if (text == self.UNASSIGN_TEXT):
            self.ShowCommands.set(False)
            self.SetDirty()
        elif (text == self.DEFAULT_TEXT):
            bind = GetDefaultBindForKey(self.Key.get(), self.Chord.get())
            self.Commands.Load(SlashCommandEditor, bind.Commands,
                               SlashCommand(repr=DEFAULT_COMMAND))
            self.ShowCommands.set(True)
            self.SetDirty()
        else:  #Cancel
            self.ShowCommands.set(True)

    def OnDelete(self, *args):
        self.CommandsFrame.grid_forget()
        self.Delete.grid_forget()
        buttons = [self.UNASSIGN_TEXT, self.DEFAULT_TEXT, self.CANCEL_TEXT]
        colors = [[self.DELETE_TEXT_COLOR, self.DELETE_COLOR],
                  [self.DEFAULT_COLOR, self.DEFAULT_TEXT_COLOR],
                  [self.ASSIGN_TEXT_COLOR, self.ASSIGN_COLOR]]
        results = [self.UNASSIGN_TEXT, self.DEFAULT_TEXT, self.CANCEL_TEXT]
        commands = [
            self.UnassignCommand, self.UnassignCommand, self.UnassignCommand
        ]
        unassignPrompt = KeystonePromptFrame(self,
                                             self.UNASSIGN_MESSAGE,
                                             buttons=buttons,
                                             colors=colors,
                                             results=results,
                                             commands=commands)
        unassignPrompt.grid(row=0, column=1, sticky='nsew')

    def OnShowCommands(self, *args):
        show = self.ShowCommands.get()
        if (show):
            self.Assign.grid_forget()
            self.Delete.grid(row=0, column=1, sticky='nsw')
            self.CommandsFrame.grid(row=0,
                                    column=2,
                                    sticky='nsew',
                                    padx="3",
                                    pady="3")
        else:
            self.Assign.grid(row=0, column=1, sticky='nsw')
            self.CommandsFrame.grid_forget()
            self.Delete.grid_forget()

    def OnShowTextEditor(self, *args):
        show = self.ShowTextEditor.get()
        if (show):
            self.Assign.grid_forget()
            self.Delete.grid_forget()
            self.KeyFrame.grid_forget()
            self.CommandsFrame.grid_forget()
            self.UIToTextButton.grid_forget()
            self.UnlockKeysButton.grid_forget()
            self.TextFrame.grid(row=0,
                                column=0,
                                rowspan="2",
                                columnspan="3",
                                sticky='nsew')
        else:
            self.TextFrame.grid_forget()
            self.KeyFrame.grid(row=0, column=0, sticky='nsew')
            if (self._lockKey):
                self.UIToTextButton.grid(row=1,
                                         column=1,
                                         columnspan="2",
                                         sticky="nsew",
                                         padx="3",
                                         pady="3")
                self.UnlockKeysButton.grid(row=1, column=0, sticky="sw")
            else:
                self.UIToTextButton.grid(row=1,
                                         column=0,
                                         columnspan="3",
                                         sticky="nsew",
                                         padx="3",
                                         pady="3")
            self.OnShowCommands()

    def UnlockKeys(self, unlock=True):
        if unlock:
            self._lockKey = False
            self.KeyBox.grid(row=1,
                             column=1,
                             sticky="nsew",
                             padx="3",
                             pady="3")
            self.ChordBox.grid(row=3,
                               column=1,
                               sticky="nsew",
                               padx="3",
                               pady="3")
            self.KeyValue.grid_forget()
            self.ChordValue.grid_forget()
            self.UnlockKeysButton.grid_forget()
        else:
            self._lockKey = True
            self.KeyBox.grid_forget()
            self.ChordBox.grid_forget()
            self.KeyValue.grid(row=1,
                               column=1,
                               sticky="nsew",
                               padx="3",
                               pady="3")
            self.ChordValue.grid(row=3,
                                 column=1,
                                 sticky="nsew",
                                 padx="3",
                                 pady="3")

    def Load(self, bind: Bind):
        self.Loading = True
        try:
            if (self._lockKey):
                self.TextEntry.SetText(bind.GetCommands())
            else:
                self.TextEntry.SetText(bind.__repr__())
            self.SynchTextToUI()
        finally:
            self.Loading = False
        self.SetClean(self)

    def SynchTextToUI(self):
        key = self.Key.get()
        chord = self.Chord.get()
        text = self.TextEntry.GetText()
        if (self._lockKey):
            text = "%s %s" % (FormatKeyWithChord(key, chord), text)
        bind = Bind(repr=text)
        if (key != bind.Key):
            self.Key.set(bind.Key)
        if (chord != bind.Chord):
            self.Chord.set(bind.Chord)
        if (bind.Commands != None):
            self.Commands.Load(SlashCommandEditor, bind.Commands,
                               SlashCommand(repr=DEFAULT_COMMAND))
            self.ShowCommands.set(True)
        else:
            self.ShowCommands.set(False)
        self.ShowTextEditor.set(False)

    def SynchUIToText(self):
        bind = self.GetBindFromUI()
        if (self._lockKey):
            self.TextEntry.SetText(bind.GetCommands())
        else:
            self.TextEntry.SetText(bind)
        self.ShowTextEditor.set(True)

    def GetBindFromUI(self) -> Bind:
        bind = Bind()
        if (self.ShowCommands.get()):
            bind.Commands = [item.Item.Get() for item in self.Commands.Items]
        else:
            bind.Commands = None
        bind.Key = self.Key.get()
        bind.Chord = self.Chord.get()
        return bind

    def Get(self) -> Bind:
        if (self.ShowTextEditor.get()):
            self.SynchTextToUI()
        model = self.GetBindFromUI()
        return model

    def __init__(self, parent, bind: Bind, lockKey=False, dirty=False):
        KeystoneEditFrame.__init__(self, parent)

        #StringVar for Key
        self.Key = None

        #StringVar for Chord
        self.Chord = None

        #StringVar for Key Description
        self.KeyDescription = None

        #StringVar for Chord Description
        self.ChordDescription = None

        #List of commands view frame
        self.Commands = None

        #Indicates keys cannot be edited
        self._lockKey = lockKey

        #layout grid
        self.columnconfigure(0, weight=1, minsize=200)
        self.columnconfigure(1, weight=0)
        self.columnconfigure(2, weight=7)
        self.rowconfigure(0, weight=1)

        #add controls

        self.KeyFrame = KeystoneFrame(self)
        self.KeyFrame.columnconfigure(1, weight=1)
        self.KeyFrame.columnconfigure(2, weight=0)
        self.KeyFrame.rowconfigure(4, weight=1)

        self.CommandsFrame = KeystoneFrame(self)
        self.CommandsFrame.columnconfigure(0, weight=1)

        self.Commands = FrameListView(self.CommandsFrame)
        self.Commands.OnSetDirty.append(self.SetDirty)
        self.Commands.grid(row=0, column=0, sticky='new')

        self.TextFrame = KeystoneFrame(self)
        self.TextFrame.rowconfigure(0, weight=1, minsize='55')
        self.TextFrame.columnconfigure(0, weight=1, minsize='405')

        self.Delete = tk.Button(self,
                                text=self.DELETE_TEXT,
                                background=self.DELETE_COLOR,
                                foreground=self.DELETE_TEXT_COLOR,
                                font=(TEXT_FONT, 7, "bold"),
                                relief=self.DELETE_STYLE,
                                width=1,
                                wraplength=1,
                                command=self.OnDelete)

        self.Assign = tk.Button(self,
                                text=self.ASSIGN_TEXT,
                                background=self.ASSIGN_COLOR,
                                foreground=self.ASSIGN_TEXT_COLOR,
                                font=(TEXT_FONT, 7, "bold"),
                                relief=self.DELETE_STYLE,
                                width=1,
                                wraplength=1,
                                command=self.AssignCommand)

        self.UIToTextButton = KeystoneButton(self,
                                             text="Edit As Text",
                                             command=self.SynchUIToText)

        keyLabel = KeystoneLabel(self.KeyFrame,
                                 anchor='nw',
                                 text="Key",
                                 width=5)
        keyLabel.grid(row=1, column=0, sticky="nw", padx="3", pady="3")
        self.Key = tk.StringVar()
        self.KeyValue = KeystoneLabel(self.KeyFrame,
                                      anchor='nw',
                                      textvariable=self.Key,
                                      width=5)
        self.KeyBox = KeystoneKeyCombo(self.KeyFrame,
                                       textvariable=self.Key,
                                       values=" ".join(
                                           [c[0] for c in KEY_NAMES]))
        self.Key.trace("w", self.SelectKey)

        self.KeyDescription = tk.StringVar()
        keyDescription = KeystoneLabel(self.KeyFrame,
                                       anchor="nw",
                                       textvariable=self.KeyDescription,
                                       wraplength=200)
        keyDescription.grid(row=2,
                            column=0,
                            columnspan=2,
                            sticky="nsew",
                            padx="3",
                            pady="3")

        self.Key.set(bind.Key)
        self.Key.trace("w", self.SetDirty)

        chordLabel = KeystoneLabel(self.KeyFrame,
                                   anchor='nw',
                                   text="Chord",
                                   width=5)
        chordLabel.grid(row=3, column=0, sticky="nw", padx="3", pady="3")
        self.Chord = tk.StringVar()
        self.ChordValue = KeystoneLabel(self.KeyFrame,
                                        anchor='nw',
                                        textvariable=self.Chord,
                                        width=5)
        self.ChordBox = KeystoneKeyCombo(self.KeyFrame,
                                         textvariable=self.Chord,
                                         values=" ".join(
                                             [c[0] for c in CHORD_KEYS]))
        self.Chord.trace("w", self.SelectChord)

        self.ChordDescription = tk.StringVar()
        chordDescription = KeystoneLabel(self.KeyFrame,
                                         anchor="nw",
                                         textvariable=self.ChordDescription,
                                         wraplength=200)
        chordDescription.grid(row=4,
                              column=0,
                              columnspan=2,
                              sticky="nsew",
                              padx="3",
                              pady="3")

        self.Chord.set(bind.Chord)
        self.Chord.trace("w", self.SetDirty)

        self.UnlockKeysButton = KeystoneButton(self,
                                               text="Change Assigned Key",
                                               command=self.UnlockKeys)
        self.UnlockKeysButton.Color(FOREGROUND, BACKGROUND)

        self.ShowCommands = tk.BooleanVar()
        self.ShowCommands.trace("w", self.OnShowCommands)

        self.TextEntry = KeystoneTextEntry(self.TextFrame, height=5)
        self.TextEntry.grid(row=0, column=0, sticky="nsew", padx="3", pady="3")
        self.TextEntry.bind("<Key>", self.SetDirty)

        self.ShowTextEditor = tk.BooleanVar()
        self.ShowTextEditor.set(False)
        self.ShowTextEditor.trace("w", self.OnShowTextEditor)

        self.TextToUIButton = KeystoneButton(self.TextFrame,
                                             text="Editor",
                                             command=self.SynchTextToUI)
        self.TextToUIButton.grid(row=1,
                                 column=0,
                                 sticky="nsew",
                                 padx="3",
                                 pady="3")

        self.OnShowTextEditor()
        self.UnlockKeys(not lockKey)

        self.Load(bind)
        self.Dirty.set(dirty)