예제 #1
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')
예제 #2
0
    def __init__(self, parent, *args, **kwargs):

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

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

        self.title("About")

        frame = KeystoneFrame(self)

        #setup grid
        self.columnconfigure(0, weight=1, minsize=324)
        self.rowconfigure(0, weight=1, minsize=180)
        frame.columnconfigure(0, minsize=108)
        frame.columnconfigure(1, minsize=216)
        frame.rowconfigure(0, minsize=60)
        frame.rowconfigure(1, minsize=120)

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

        #logo
        imgPath = GetResourcePath('.\\Resources\\Keystone.png')
        if (imgPath != None):
            img = Image.open(imgPath)
            img = img.resize((54, 54))
            self.Logo = ImageTk.PhotoImage(img)
            logoLabel = KeystoneLabel(frame, image=self.Logo)
            logoLabel.grid(row=0, column=0, padx=3, pady=3)

        #name
        nameLabel = KeystoneLabel(frame,
                                  text='Keystone',
                                  font=(TEXT_FONT, LARGE_FONT_SIZE))
        nameLabel.grid(row=0, column=1, sticky='nw')
        subtextLabel = KeystoneLabel(frame,
                                     text='City of Heroes Keybind Editor')
        subtextLabel.grid(row=0, column=1, sticky='sw')

        #version
        versionPath = GetResourcePath('VERSION.txt')
        if (versionPath != None):
            file = open(versionPath, "r")
            try:
                version = file.read()
            finally:
                file.close()
            version = version.split("\n")
            versionLabel = KeystoneLabel(frame,
                                         text=version[0],
                                         font=(TEXT_FONT, LARGE_FONT_SIZE))
            versionLabel.grid(row=1, column=0, columnspan=2)
            dateLabel = KeystoneLabel(frame, text=version[1])
            dateLabel.grid(row=1, column=0, columnspan=2, sticky='s', pady=3)
예제 #3
0
class EditMacro(KeystoneFrame):

    def Load(self, macro: Macro):
        self.Name.set(macro.Name)
        self.Commands.Load(SlashCommandEditor, macro.Commands, SlashCommand(repr=DEFAULT_COMMAND))

    def Get(self) -> Macro:
        commands = [item.Item.Get() for item in self.Commands.Items]
        if (self.CommandOnly.get()):
            name = None
        else:
            name = self.Name.get()
        return Macro(name, commands)
    
    def __init__(self, parent, macro: Macro):
        KeystoneFrame.__init__(self, parent)

        #StringVar for Name
        self.Name = ""

        #List of commands view frame
        self.Commands = None

        #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.NameFrame = KeystoneFrame(self)
        self.NameFrame.columnconfigure(1, weight=1)
        self.NameFrame.columnconfigure(2, weight=0)
        self.NameFrame.rowconfigure(4, weight=1)
        self.NameFrame.grid(row=0, column=0, sticky='nsew') 

        self.CommandsFrame=KeystoneFrame(self)
        self.CommandsFrame.columnconfigure(0, weight=1)
        self.CommandsFrame.grid(row=0, column=2, sticky='nsew', padx="3", pady="3")
        
        self.Commands = FrameListView(self.CommandsFrame)
        self.Commands.grid(row=0, column=0, sticky='new')

        nameLabel = KeystoneLabel(self.NameFrame, anchor='nw', text="Name", width=5)
        nameLabel.grid(row=1, column=0, sticky="nw", padx="3", pady="3")
        self.Name = tk.StringVar()
        self.NameBox = KeystoneEntry(self.NameFrame, textvariable=self.Name)
        self.NameBox.grid(row=1, column=1, sticky="nsew", padx="3", pady="3")

        self.CommandOnly = tk.BooleanVar(value=False)
        self.CommandOnlyCheck = KeystoneCheckbutton(self.NameFrame, variable=self.CommandOnly)
        self.CommandOnlyCheck.grid(row=2, column=0, sticky="ne", padx="3", pady="3")
        commandOnlyLabel = KeystoneLabel(self.NameFrame, anchor='nw', text='Copy command only')
        commandOnlyLabel.grid(row=2, column=1, sticky="nw", padx="3", pady="3")
        
        self.Load(macro)
    def __init__(self,
                 wizard: KeystoneWizard,
                 text: str,
                 urls=None,
                 *args,
                 **kwargs):

        KeystoneWizardPage.__init__(self,
                                    wizard,
                                    allowBack=True,
                                    allowClose=True,
                                    allowNext=True,
                                    *args,
                                    **kwargs)

        self.columnconfigure(0, weight=0)
        self.columnconfigure(1, weight=1, minsize=510)
        self.rowconfigure(0, weight=1)

        label = KeystoneLabel(self, text=text, wraplength=500, justify=tk.LEFT)
        label.grid(row=0, column=1, sticky='n', padx=5, pady=5)
        global LeadBrickImage
        if (LeadBrickImage == None):
            imgPath = GetResourcePath('.\\Resources\\LeadBrick1.jpg')
            if (imgPath != None):
                LeadBrickImage = ImageTk.PhotoImage(Image.open(imgPath))
            else:
                LeadBrickImage = 0
        if (LeadBrickImage != 0):
            self.Image = LeadBrickImage
            self.ImagePanel = tk.Label(self, image=self.Image)
            self.ImagePanel.grid(row=0, column=0, sticky='nsew')

        if (urls != None):
            urlFrame = KeystoneFrame(self)
            for idx, eachURL in enumerate(urls):
                link = KeystoneLabel(urlFrame, text=eachURL)
                link.bind("<Button-1>",
                          lambda e, url=eachURL: self.callback(url))
                link.grid(row=idx, column=0, sticky='nsew')
            urlFrame.grid(row=0, column=1)
    def __init__(self, parent, showScroll=False):

        KeystoneFrame.__init__(self, parent)
        self.columnconfigure(0, weight=1)
        self.columnconfigure(1, weight=0)
        self.rowconfigure(0, weight=0)
        self.rowconfigure(1, weight=1)

        # creating a scrollbars
        self.yscrlbr = ttk.Scrollbar(self)
        if showScroll:
            self.yscrlbr.grid(column=1, row=1, sticky='ns')

        #create tree
        self.Tree = KeystoneTree(self,
                                 selectmode=tk.BROWSE,
                                 yscrollcommand=self.yscrlbr.set)
        self.Tree.grid(row=1, column=0, sticky='nsew')

        self.Tree['columns'] = ('bound_files')
        self.Tree.heading("#0", text="Keybind Collection", anchor='w')
        self.Tree.column("#0", stretch=True, width=300)
        self.Tree.column("#1", stretch=False, width=0)

        # accociating scrollbar comands to tree scroling
        self.yscrlbr.config(command=self.Tree.yview)

        self.yscrlbr.lift(self.Tree)

        #create file browse frame
        browseFrame = KeystoneFrame(self)
        browseFrame.grid(row=0, column=0, columnspan=2, sticky='nsew')
        browseFrame.columnconfigure(0, weight=1)
        browseFrame.columnconfigure(1, weight=0)
        self.Directory = ""

        self.Tree.OnSelect.append(self.OnSelectItem)
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)
예제 #7
0
class SelectKeybindImportWindow(tk.Toplevel):
    def OnImportCallback(self, fileName, *args):
        if (self.ImportCallback != None):
            filePath = os.path.join(self.ResourceDir, fileName)
            SetTopmost(self, 0)
            try:
                self.ImportCallback(self, filePath)
            finally:
                SetTopmost(self, 1)

    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, 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)