Esempio n. 1
0
    def DeleteZoom(self):
        '''Delete the amount of zoomed from the json file'''

        font_details = Include.get_font_details()

        if 'Zoomed' in font_details:
            font_details.pop('Zoomed')

        Include.save_font_details(font_details)
Esempio n. 2
0
    def ApplyAndSaveDetails(self, event=None):
        '''Set font_family, font_size and font_style to the text-widget and save
           them to the file so that same font details are used when the program
           runs next time.'''

        font_family = self.FontFamiliesFrame.EntryVar.get().strip()
        font_style = self.FontStyleFrame.EntryVar.get().strip().lower()
        font_size = self.FontSizeFrame.EntryVar.get().strip()

        if font_family.lower() not in self.LowerFontName:
            messagebox.showinfo(
                'Font',
                'There is no font with that name.\nChoose a font from the list of fonts.',
                parent=self.FontWindow)
            return

        elif font_style not in self.LowerFontStyles:
            messagebox.showinfo(
                'Font',
                'This font is not available in that style.\nChoose a style from the list of styles.',
                parent=self.FontWindow)
            return

        try:
            font_size = int(font_size)

        except ValueError:
            font_size = 9

        if font_style == 'regular':
            font_style = 'normal'

        Include.ConfigFontStyle(font_style, self.font)
        font_details = Include.GetFontDetails()

        if 'Zoomed' in font_details:
            self.font.configure(family=font_family,
                                size=font_size + font_details['Zoomed'])

        else:
            self.font.configure(family=font_family, size=font_size)

        font_index = self.LowerFontName.index(font_family.lower(
        ))  # Getting index of the font_family in entry_widget

        font_details['Font Family'] = self.FontFamilies[font_index]
        font_details['Font Size'] = font_size
        font_details['Font Style'] = font_style

        Include.SaveFontDetails(font_details)  # Saving font_details in file
        self.FontWindow.destroy()
Esempio n. 3
0
    def exit(self, event=None):
        '''When user wants to exit the program'''

        if self.fmc.IsFileChanged():
            choice = messagebox.askyesnocancel(
                'GPAD', 'Do you really want to quit without saving?')

            if choice is False:
                self.fmc.Save()

        else:
            choice = True

        if choice:
            exit = True
            MasterDestroy = False
            content = Include.GetFontDetails()

            if 'Zoomed' in content:
                content.pop('Zoomed')

            NumberOfWindows = content[
                'Number of Windows']  # Getting number of Toplevel windows

            if self.master.winfo_class(
            ) == 'Tk':  # When user wants to close the root window
                if NumberOfWindows > 0:  # When some Toplevel windows is opened
                    exit = False
                    self.master.withdraw(
                    )  # Withdrawing Tk window from the window

            elif self.master.winfo_class(
            ) == 'Toplevel':  # When user wants to close the Toplevel window
                NumberOfWindows -= 1
                content['Number of Windows'] = NumberOfWindows

                if NumberOfWindows == 0:  # If the window is the last Toplevel window
                    MasterDestroy = True

            content.update({'window_dimension': self.master.geometry()})
            Include.SaveFontDetails(content)

            if MasterDestroy:  # Ending the mainloop of Tk window if there is no any Toplevel window
                self.master.master.destroy()

            else:  # When user wants to close the Toplevel window opening another Toplevel window
                if exit:
                    self.master.destroy()
Esempio n. 4
0
    def SaveZoom(self, zoomed=None):
        '''Save the amount of zoom in and zoom out to the json file'''

        font_details = Include.GetFontDetails()

        if zoomed is None:  # This means remove zoomed amount
            self.Zoomed = 0

            if 'Zoomed' in font_details:
                font_details.pop('Zoomed')

            self.font.configure(family=font_details['Font Family'],
                                size=font_details['Font Size'])

        else:
            font_details['Zoomed'] = self.Zoomed

        Include.SaveFontDetails(font_details)
Esempio n. 5
0
    def __init__(self, master, text_widget):
        self.TextWidget = text_widget

        self.GoToWindow = Toplevel(master)
        self.GoToWindow.transient(master)
        self.GoToWindow.grab_set()

        self.GoToWindow.withdraw()
        self.GoToWindow.after(0, self.GoToWindow.deiconify)
        self.GoToWindow.title('Go To Line')
        self.GoToWindow.iconbitmap(Include.resource_path('transparent.ico'))
        pos_x, pos_y = master.winfo_x() + 55, master.winfo_y() + 170
        self.GoToWindow.geometry('{}x{}+{}+{}'.format(250, 100, pos_x, pos_y))
        self.GoToWindow.focus_set()

        self.GoToLabelEntryFrame = Frame(self.GoToWindow)
        self.GoToLabel = ttk.Label(self.GoToLabelEntryFrame,
                                   text='Line Number:')
        self.GoToEntry = ttk.Entry(self.GoToLabelEntryFrame, width=37)
        self.GoToLabel.grid(row=0, column=0, sticky='w')
        self.GoToEntry.grid(row=1, column=0)
        self.GoToEntry.focus_set()
        self.GoToLabelEntryFrame.place(x=10, y=7)

        self.ButtonsFrame = Frame(self.GoToWindow)
        self.GoToButton = ttk.Button(self.ButtonsFrame,
                                     text='Go To',
                                     width=10,
                                     command=self.GoTo)
        self.CancelButton = ttk.Button(self.ButtonsFrame,
                                       text='Cancel',
                                       width=10,
                                       command=self.GoToWindow.destroy)
        self.GoToButton.grid(row=0, column=0, padx=8)
        self.CancelButton.grid(row=0, column=1)
        self.ButtonsFrame.place(x=80, y=65)

        self.shortcut = ShortCut.ShortCut(self.GoToWindow)
        self.GoToEntry.bind('<Control-h>', self.entry_bind)
        self.GoToButton.bind(
            '<Enter>', lambda e: self.shortcut.ShowShortCut(
                self.GoToButton, 'Enter', True))
        self.GoToButton.bind('<Leave>', lambda e: self.shortcut.destroy())
        self.CancelButton.bind(
            '<Enter>', lambda e: self.shortcut.ShowShortCut(
                self.CancelButton, 'Esc', True))
        self.CancelButton.bind('<Leave>', lambda e: self.shortcut.destroy())

        self.GoToWindow.bind('<Return>', self.GoTo)
        self.GoToWindow.bind('<Escape>', lambda e: self.GoToWindow.destroy())
        self.GoToWindow.mainloop()
Esempio n. 6
0
    def SetToDefault(self):
        '''Get font_family, font_size and font_styles from the file and set
           details to the text-widget when the program opens for the first
           time'''

        self.FontFamiliesFrame.EntryVar.set('')
        self.FontStyleFrame.EntryVar.set('')
        self.FontSizeFrame.EntryVar.set('')

        curr_font = Include.GetFontDetails()  # Getting font details
        font_family, font_size, font_style = curr_font[
            'Font Family'], curr_font['Font Size'], curr_font['Font Style']

        if font_style == 'normal':
            font_style = 'Regular'

        self.FontFamiliesFrame.EntryVar.set(font_family)
        self.FontSizeFrame.EntryVar.set(font_size)
        self.FontStyleFrame.EntryVar.set(font_style.title())

        # List boxes
        font_family_listbox = self.FontFamiliesFrame.ListBox
        font_size_listbox = self.FontSizeFrame.ListBox
        font_style_listbox = self.FontStyleFrame.ListBox

        # Getting index of the font_family, font_size and font_style from the json file
        font_family_index = self.FontFamilies.index(font_family)
        font_family_listbox.yview(font_family_index)
        font_family_listbox.selection_set(font_family_index)

        if str(font_size) in self.FontSizes:
            font_size_index = self.FontSizes.index(str(font_size))
            font_size_listbox.yview(font_size_index)
            font_size_listbox.selection_set(font_size_index)

        font_style_index = self.FontStyles.index(font_style.title())
        font_style_listbox.selection_set(font_style_index)
Esempio n. 7
0
    def SetVar(self, text, time=4000):
        '''Config text to the status_label'''

        Include.set_var(self.master, self.var, text, time)
Esempio n. 8
0
    def __init__(self, master, text_widget):
        self.FindIndex = None
        self.WordIndexes = []
        self.TransparentICO = Include.resource_path('transparent.ico')

        self.master = master
        self.TextWidget = text_widget
        self.DummyTextWidget = Text(master)

        self.MatchVar, self.WrapVar = IntVar(), IntVar()
        self.WrapVar.set(1)

        self.ReplaceWindow = Toplevel()
        self.ReplaceWindow.transient(self.master)
        self.ReplaceWindow.grab_set()

        self.ReplaceWindow.withdraw()
        self.ReplaceWindow.after(0, self.ReplaceWindow.deiconify)
        self.ReplaceWindow.title('Replace')
        self.ReplaceWindow.iconbitmap(self.TransparentICO)
        self.pos_x, self.pos_y = self.master.winfo_x() + 55, self.master.winfo_y() + 170
        self.ReplaceWindow.geometry('{}x{}+{}+{}'.format(350, 155, self.pos_x, self.pos_y))
        self.ReplaceWindow.resizable(0, 0)

        self.FindWhatFrame = Frame(self.ReplaceWindow)

        self.FindWhatLabel = ttk.Label(self.FindWhatFrame, text='Find what:')
        self.ReplaceFindWhatEntry = ttk.Entry(self.FindWhatFrame, width=31)
        self.FindWhatLabel.grid(row=0, column=0)
        self.ReplaceFindWhatEntry.focus_set()
        self.ReplaceFindWhatEntry.grid(row=0, column=1, padx=18)
        self.FindWhatFrame.place(x=0, y=5)

        self.ReplaceWithFrame = Frame(self.ReplaceWindow)
        self.ReplaceWithLabel = ttk.Label(self.ReplaceWithFrame, text='Replace what:')
        self.ReplaceWithEntry = ttk.Entry(self.ReplaceWithFrame, width=31)
        self.ReplaceWithLabel.grid(row=0, column=0)
        self.ReplaceWithEntry.grid(row=0, column=1, pady=5)
        self.ReplaceWithFrame.place(x=0, y=30)

        self.ButtonsFrame = Frame(self.ReplaceWindow)
        self.style = ttk.Style()
        self.style.configure('my.TButton', font=('Helvetica', 8))
        self.FindNextButton = ttk.Button(self.ButtonsFrame, text='Find Next', width=9, style='my.TButton', command=self.FindNext)
        self.ReplaceButton = ttk.Button(self.ButtonsFrame, text='Replace', width=9, style='my.TButton', command=self.Replace)
        self.ReplaceAllButton = ttk.Button(self.ButtonsFrame, text='Replace All', width=9, style='my.TButton', command=self.ReplaceAll)
        self.CancelButton = ttk.Button(self.ButtonsFrame, text='Cancel', width=9, style='my.TButton', command=self.exit)
        self.FindNextButton.grid(row=0, column=0, ipadx=3)
        self.ReplaceButton.grid(row=1, column=0, ipadx=3, pady=5)
        self.ReplaceAllButton.grid(row=2, column=0, ipadx=3)
        self.CancelButton.grid(row=3, column=0, ipadx=3, pady=5)
        self.ButtonsFrame.place(x=275, y=5)

        self.CheckButtonFrame = Frame(self.ReplaceWindow)
        self.MatchCaseCheckButton = ttk.Checkbutton(self.CheckButtonFrame, text='Match case', variable=self.MatchVar, takefocus=False)
        self.WrapAroundCaseCheckButton = ttk.Checkbutton(self.CheckButtonFrame, text='Wrap around', variable=self.WrapVar, takefocus=False)
        self.MatchCaseCheckButton.pack(anchor='w')
        self.WrapAroundCaseCheckButton.pack(anchor='w', pady=5)
        self.CheckButtonFrame.place(x=5, y=100)

        self.shortcut = ShortCut.ShortCut(self.ReplaceWindow)
        self.FindNextButton.bind('<Enter>', lambda e: self.shortcut.ShowShortCut(self.FindNextButton, 'F3'))
        self.FindNextButton.bind('<Leave>', lambda e: self.shortcut.destroy())
        self.ReplaceButton.bind('<Enter>', lambda e: self.shortcut.ShowShortCut(self.ReplaceButton, 'Ctrl+Shift+H'))
        self.ReplaceButton.bind('<Leave>', lambda e: self.shortcut.destroy())
        self.ReplaceAllButton.bind('<Enter>', lambda e: self.shortcut.ShowShortCut(self.ReplaceAllButton, 'Ctrl+Alt+Enter'))
        self.ReplaceAllButton.bind('<Leave>', lambda e: self.shortcut.destroy())
        self.CancelButton.bind('<Enter>', lambda e: self.shortcut.ShowShortCut(self.CancelButton, 'Esc'))
        self.CancelButton.bind('<Leave>', lambda e: self.shortcut.destroy())

        self.InsertSelectedText()
        self.ReplaceWindow.bind('<Control-Alt-Return>', self.ReplaceAll)
        self.ReplaceWindow.bind('<Control-H>', self.Replace)
        self.ReplaceWindow.bind('<Escape>', self.exit)
        self.ReplaceWithEntry.bind('<Control-h>', self.entry_bind)
        self.ReplaceFindWhatEntry.bind('<Control-h>', self.entry_bind)
        self.FindNextButton.bind('<Return>', self.FindNext)
        self.ReplaceButton.bind('<Return>', self.Replace)
        self.ReplaceAllButton.bind('<Return>', self.ReplaceAll)
        self.CancelButton.bind('<Return>', self.exit)
        self.ReplaceWindow.protocol('WM_DELETE_WINDOW', self.exit)
        self.ReplaceWindow.mainloop()
Esempio n. 9
0
    def __init__(self, master, _font):
        self.font = _font

        self.master = master
        self.transparent_ico = Include.resource_path('transparent.ico')

        self.FontWindow = Toplevel(self.master)
        self.FontWindow.transient(self.master)
        self.FontWindow.withdraw()
        self.FontWindow.title('Font')
        self.FontWindow.grab_set()
        self.FontWindow.iconbitmap(self.transparent_ico)
        self.FontWindow.resizable(0, 0)

        self.pos_x, self.pos_y = self.master.winfo_x(
        ) + 30, self.master.winfo_y() + 60
        self.FontWindow.geometry(f'415x245+{self.pos_x}+{self.pos_y}')

        self.FontFamilies = list(font.families(self.FontWindow))
        self.FontFamilies.sort()
        self.FontFamilies = self.FontFamilies[26:]
        self.NonDuplicatesFonts()
        self.LowerFontName = [f.lower() for f in self.FontFamilies]

        self.FontStyles = [
            'Regular', 'Italic', 'Bold', 'Bold Italic', 'Underline',
            'Overstrike'
        ]
        self.LowerFontStyles = [s.lower() for s in self.FontStyles]
        self.FontSizes = [str(i) for i in range(9, 73)]

        self.ContainerFrame = Frame(self.FontWindow)
        self.ContainerFrame.pack(padx=5)

        self.FontFamiliesFrame = Widgets(self.FontWindow, self.ContainerFrame,
                                         'Font:', self.FontFamilies, 29, 27)
        self.FontStyleFrame = Widgets(self.FontWindow, self.ContainerFrame,
                                      'Font Style:', self.FontStyles, 21, 19)
        self.FontSizeFrame = Widgets(self.FontWindow, self.ContainerFrame,
                                     'Size:', self.FontSizes, 9, 7)

        for frame in [
                self.FontFamiliesFrame, self.FontStyleFrame, self.FontSizeFrame
        ]:
            frame.Entry.bind('<Up>', frame.UpDirection)
            frame.Entry.bind('<Tab>', frame.TabCompletion)
            frame.Entry.bind('<BackSpace>', frame.BackSpace)
            frame.Entry.bind('<Down>', frame.DownDirection)
            frame.Entry.bind('<KeyPress>', frame.KeyPressed)
            frame.Entry.bind('<KeyRelease>', frame.KeyReleased)
            frame.Entry.bind('<Escape>', lambda e: self.FontWindow.destroy())

        self.SampleLabelFrame = LabelFrame(self.FontWindow, text='Sample')
        self.pixel = PhotoImage(width=1, height=1)
        self.SampleLabel = Label(self.SampleLabelFrame,
                                 text='AaBbYyZz',
                                 compound='center',
                                 image=self.pixel,
                                 width=200,
                                 height=40,
                                 takefocus=False)
        self.SampleLabel.grid(row=0, column=0)
        self.SampleLabelFrame.pack()

        self.BottomFrame = Frame(self.FontWindow)
        self.OkButton = ttk.Button(self.BottomFrame,
                                   text='OK',
                                   command=self.ApplyAndSaveDetails)
        self.CancelButton = ttk.Button(self.BottomFrame,
                                       text='Cancel',
                                       command=self.FontWindow.destroy)
        self.OkButton.pack(side=LEFT)
        self.CancelButton.pack(side=LEFT, padx=5)
        self.BottomFrame.pack(side=RIGHT, pady=5)

        self.SetToDefault()

        self.FontFamiliesFrame.Entry.bind('<Return>', self.ApplyAndSaveDetails)
        self.FontStyleFrame.Entry.bind('<Return>', self.ApplyAndSaveDetails)
        self.FontStyleFrame.Entry.bind('<Return>', self.ApplyAndSaveDetails)

        self.entry_listbox = {
            self.FontFamiliesFrame.Entry: self.FontFamiliesFrame.ListBox,
            self.FontStyleFrame.Entry: self.FontStyleFrame.ListBox,
            self.FontSizeFrame.Entry: self.FontSizeFrame.ListBox
        }

        self.NonDuplicatesFonts()
        self.master.after(0, self.FontWindow.deiconify)

        self.FontWindow.bind('<Key>', self.UpDown)
        self.FontWindow.after(
            250, lambda: SetSelection(self.FontFamiliesFrame.Entry, self.
                                      FontFamiliesFrame.EntryVar))
        self.FontWindow.after(100, self.ConfigSampleLabel)
        self.FontWindow.mainloop()
Esempio n. 10
0
    def __init__(self, NewWindow=False):
        self.get_font = Include.GetFontDetails()

        if NewWindow:  # When user wants to make a new window
            self.master = Toplevel()

            if 'Number of Windows' not in self.get_font:  # Tracking the number of Toplevel Windows
                self.get_font['Number of Windows'] = 1

            else:
                self.get_font['Number of Windows'] += 1

            Include.SaveFontDetails(self.get_font)

        else:  # When programs starts for the first time
            self.master = Tk()

        self.font = Font(family=self.get_font['Font Family'],
                         size=self.get_font['Font Size'])
        Include.ConfigFontStyle(self.get_font['Font Style'], self.font)

        self.menu = Menu(self.master)
        self.file_menu = Menu(self.menu, tearoff=0)
        self.edit_menu = Menu(self.menu, tearoff=0)
        self.format_menu = Menu(self.menu, tearoff=0)
        self.view_menu = Menu(self.menu, tearoff=0)
        self.help_menu = Menu(self.menu, tearoff=0)

        for label, menu in {
                'File': self.file_menu,
                'Edit': self.edit_menu,
                'Format': self.format_menu,
                'View': self.view_menu,
                'Help': self.help_menu
        }.items():
            self.menu.add_cascade(label=label, menu=menu)

        self.master.config(menu=self.menu)

        self.CanvasFrame = Frame(self.master)
        self.LineCanvas = Canvas(self.CanvasFrame, width=50)
        self.CanvasHSB = Scrollbar(self.CanvasFrame,
                                   orient='horizontal',
                                   command=self.LineCanvas.xview)
        self.LineCanvas.configure(xscrollcommand=self.CanvasHSB.set)
        self.CanvasHSB.pack(side='bottom', fill='x')
        self.LineCanvas.pack(side='left', fill='y')

        self.TextWidgetFrame = Frame(self.master, width=659, height=424)
        self.TextWidgetFrame.grid_propagate(False)
        self.TextWidget = Text(master=self.TextWidgetFrame,
                               bd=0,
                               undo=True,
                               font=self.font,
                               maxundo=-1,
                               autoseparators=True)
        self.VSB = Scrollbar(self.TextWidgetFrame,
                             orient='vertical',
                             command=self.TextWidget.yview)
        self.HSB = Scrollbar(self.TextWidgetFrame,
                             orient='horizontal',
                             command=self.TextWidget.xview)
        self.TextWidget.configure(yscrollcommand=self.VSB.set,
                                  xscrollcommand=self.HSB.set)

        self.TextWidget.grid(row=0, column=0, sticky='nsew')
        self.VSB.grid(row=0, column=1, sticky='ns')
        self.HSB.grid(row=1, column=0, sticky='ew')

        self.TextWidgetFrame.grid_rowconfigure(0, weight=1)
        self.TextWidgetFrame.grid_columnconfigure(0, weight=1)
        self.TextWidget.focus_set()
        self.TextWidgetFrame.pack(side='top', fill='both', expand=True)

        self.LineColumnVar = StringVar()
        self.status_label_var = StringVar()
        self.LineColumnVar.set('Ln 1, Col 1')

        self.StatusBarFrame = Frame(self.TextWidgetFrame)
        self.StatusBarFrame.grid(row=2, column=0, sticky='e')

        self.StatusLabel = Label(self.StatusBarFrame,
                                 textvariable=self.status_label_var)
        self.StatusLabel.grid(row=0, column=0, sticky='w')
        self.LineColumn = Label(self.StatusBarFrame,
                                textvariable=self.LineColumnVar)
        self.LineColumn.grid(row=0, column=1, ipadx=20)
        self.ZoomLabel = Label(self.StatusBarFrame, text='100%')
        self.ZoomLabel.grid(row=0, column=2, ipadx=10)
        self.TextFormatter = Label(self.StatusBarFrame, text='Windows (CRLF)')
        self.TextFormatter.grid(row=0, column=3, ipadx=14)
        self.encoding = Label(self.StatusBarFrame, text='UTF-8')
        self.encoding.grid(row=0, column=4, ipadx=10)

        self.fmc = FileMenu.File_Menu(self.master, self.TextWidget,
                                      self.status_label_var)
        self.FileMenuOptions = [
            'New', 'New Window ', 'Open... ', 'Save', 'SaveAs...', 'Exit'
        ]
        self.FileMenuCommands = [
            self.fmc.New, self.fmc.NewWindow, self.fmc.Open, self.fmc.Save,
            self.fmc.SaveAs, self.exit
        ]
        self.FileMenuAccelerator = [
            'Ctrl+N', 'Ctrl+Shift+N', 'Ctrl+O', 'Ctrl+S', 'Ctrl+Shift+S',
            'Ctrl+Q'
        ]

        self.emc = EditMenu.Edit_Menu(self.master, self.TextWidget,
                                      self.status_label_var)
        self.EditMenuOptions = [
            'Undo', 'Cut', 'Copy', 'Paste', 'Delete', 'Search with Google',
            'Find...', 'Replace...', 'Go To...', 'Select All', 'Time / Date',
            'Strip Trailing Whitespace'
        ]
        self.EditMenuCommands = [
            self.emc.undo, self.emc.cut, self.emc.copy, self.emc.paste,
            self.emc.delete, self.emc.SearchWithGoogle, self.emc.FindWidget,
            self.emc.ReplaceWidget, self.emc.GoToWidget, self.emc.SelectAll,
            self.emc.GetDateTime, self.emc.StripWhitespaces
        ]
        self.EditMenuAccelerator = [
            'Ctrl+Z', 'Ctrl+X', 'Ctrl+C', 'Ctrl+V', 'DEL', 'Ctrl+E', 'Ctrl+F',
            'Ctrl+H', 'Ctr+G', 'Ctrl+A', 'F5', 'Alt+Enter'
        ]

        self.Fmc = FormatMenu.Format(self.master, self.TextWidget, self.font)
        self.FormatMenuOptions = ['Word Wrap', 'Font...']
        self.FormatMenuAccelerator = ['Ctrl+W', 'Ctrl+Shift+F']

        self.vmc = ViewMenu.View(self.master, self.TextWidget,
                                 self.TextWidgetFrame, self.CanvasFrame,
                                 self.LineCanvas, self.StatusBarFrame,
                                 self.ZoomLabel, self.font)
        self.ViewMenuOptions = [
            'Zoom', 'Status Bar', 'FullScreen', 'Show Line Numbers'
        ]
        self.ZoomCommands = [
            self.vmc.ZoomIn, self.vmc.ZoomOut, self.vmc.DefaultZoom
        ]
        self.ViewMenuZoomAccelerator = {
            'Zoom In': '            Ctrl+Plus',
            'Zoom Out': '        Ctrl+Minus',
            'Restore Default Zoom': '                 Ctrl+0'
        }

        self.HelpMenuOptions = ['About']
        self.HelpMenuAccelerator = ['F12']
        self.HelpMenuCommands = [self.about]

        for index, value in enumerate(self.FileMenuOptions):
            if index in [5, 7]:
                self.file_menu.add_separator()

            self.file_menu.add_command(
                label=value.ljust(23),
                accelerator=self.FileMenuAccelerator[index],
                command=self.FileMenuCommands[index])

        for index, value in enumerate(self.EditMenuOptions):
            if index in [1, 5, 11]:
                self.edit_menu.add_separator()

            self.edit_menu.add_command(
                label=value.ljust(40),
                accelerator=self.EditMenuAccelerator[index],
                command=self.EditMenuCommands[index])

        for index, value in enumerate(self.FormatMenuOptions):
            if index == 1:
                self.format_menu.add_command(
                    label=value.ljust(30),
                    accelerator=self.FormatMenuAccelerator[index],
                    command=self.Fmc.FontSelection)

            else:
                self.format_menu.add_checkbutton(
                    label=value,
                    onvalue=True,
                    offvalue=False,
                    variable=self.Fmc.WrapAroundVar,
                    accelerator=self.FormatMenuAccelerator[index],
                    command=self.Fmc.WrapAround)

        for index, value in enumerate(self.ViewMenuOptions):
            if index == 0:
                self.sub_view_menu = Menu(self.view_menu, tearoff=0)
                self.view_menu.add_cascade(label=value,
                                           menu=self.sub_view_menu)

                for index, values in enumerate(
                        self.ViewMenuZoomAccelerator.items()):
                    self.sub_view_menu.add_command(
                        label=values[0],
                        accelerator=values[1],
                        command=self.ZoomCommands[index])

            elif index == 1:
                self.view_menu.add_checkbutton(
                    label=value,
                    onvalue=1,
                    offvalue=False,
                    variable=self.vmc.ShowStatusBar,
                    accelerator='Alt+S'.rjust(30),
                    command=self.vmc.toggle_statusbar)

            elif index == 2:
                self.view_menu.add_checkbutton(
                    label=value,
                    onvalue=1,
                    offvalue=False,
                    variable=self.vmc.FullScreenVar,
                    accelerator='F11'.rjust(28),
                    command=self.vmc.set_full_screen)

            elif index == 3:
                self.view_menu.add_checkbutton(
                    label=value,
                    onvalue=1,
                    offvalue=False,
                    variable=self.vmc.LineNumberVar,
                    accelerator='Alt+L'.rjust(30),
                    command=self.vmc.ToggleLineNumber)

        for index, value in enumerate(self.HelpMenuOptions):
            self.help_menu.add_command(
                label=value.ljust(20),
                accelerator=self.HelpMenuAccelerator[index],
                command=self.HelpMenuCommands[index])

        self.Fmc.WrapAround()
        self.vmc.ToggleLineNumber()
        self.UpdateLineColumn()
        self.EnableDisableMenu()
        self.UpdateLabelText()

        self.TextWidget.bind('<Control-q>', self.exit)
        self.TextWidget.bind('<Button-3>', self.button_3)
        self.TextWidget.bind('<Delete>', self.emc.delete)
        self.TextWidget.bind('<Control-n>', self.fmc.New)
        self.TextWidget.bind('<Control-x>', self.emc.cut)
        self.TextWidget.bind('<Control-o>', self.fmc.Open)
        self.TextWidget.bind('<Control-s>', self.fmc.Save)
        self.TextWidget.bind('<Control-z>', self.emc.undo)
        self.TextWidget.bind('<Control-c>', self.emc.copy)
        self.TextWidget.bind('<BackSpace>', self.backspace)
        self.TextWidget.bind('<Control-v>', self.emc.paste)
        self.TextWidget.bind('<Key>', self.RemoveSelection)
        self.TextWidget.bind('<F5>', self.emc.GetDateTime)
        self.master.bind('<F12>', self.HelpMenuCommands[0])
        self.master.protocol('WM_DELETE_WINDOW', self.exit)
        self.TextWidget.bind('<Control-S>', self.fmc.SaveAs)
        self.TextWidget.bind('<Control-N>', self.fmc.NewWindow)
        self.TextWidget.bind('<Control-a>', self.emc.SelectAll)
        self.TextWidget.bind('<Control-N>', self.fmc.NewWindow)
        self.TextWidget.bind('<Control-plus>', self.vmc.ZoomIn)
        self.TextWidget.bind('<Control-g>', self.emc.GoToWidget)
        self.TextWidget.bind('<MouseWheel>', self.vmc.WheelZoom)
        self.TextWidget.bind('<Button-1>', self.SingleLeftClick)
        self.TextWidget.bind('<Control-f>', self.ShowFindWidget)
        self.TextWidget.bind('<Control-minus>', self.vmc.ZoomOut)
        self.TextWidget.bind('<Control-0>', self.vmc.DefaultZoom)
        self.TextWidget.bind('<Triple-Button-1>', self.TripleClick)
        self.TextWidget.bind('<Control-h>', self.ShowReplaceWidget)
        self.master.bind('<F11>', lambda e: self.view_menu.invoke(2))
        self.master.bind('<Alt-s>', lambda e: self.view_menu.invoke(1))
        self.TextWidget.bind('<Control-e>', self.emc.SearchWithGoogle)
        self.TextWidget.bind('<Double-Button-1>', self.DoubleLeftClick)
        self.TextWidget.bind('<Alt-Return>', self.ActivateStripWhiteSpace)
        self.master.after(0, lambda: Include.initial_position(self.master))
        self.TextWidget.bind('<Alt-l>', lambda e: self.view_menu.invoke(3))
        self.TextWidget.bind('<Control-F>', lambda e: self.Fmc.FontSelection())
        self.TextWidget.bind('<Control-w>',
                             lambda e: self.format_menu.invoke(0))
        self.TextWidget.bind(
            '<Configure>', lambda e: self.TextWidget.configure(
                scrollregion=self.TextWidget.bbox('end')))
        self.master.mainloop()
Esempio n. 11
0
    def __init__(self, master):
        self.BuildNumber = '2.4.0'

        self.master = master
        self.AuthorAddress = 'http://github.com/ghanteyyy'
        self.SourceCodeAddress = 'https://github.com/ghanteyyy/nppy/tree/master/PROJECT GUIs/GPAD'

        self.AboutWindow = Toplevel(self.master)
        self.AboutWindow.transient(self.master)
        self.AboutWindow.grab_set()
        self.AboutWindow.withdraw()
        self.WindowInitialPosition()
        self.AboutWindow.after(0, self.AboutWindow.deiconify)
        self.AboutWindow.title('About')
        self.AboutWindow.iconbitmap(Include.resource_path('transparent.ico'))

        self.search = Search.Search(self.AboutWindow)
        self.DescriptionFrame = Frame(self.AboutWindow, bg='white')
        self.BuildLabel = Label(self.DescriptionFrame,
                                text='Build:',
                                bg='white')
        self.BuildNumberLabel = Label(self.DescriptionFrame,
                                      text=self.BuildNumber,
                                      bg='white')

        self.AuthorLabel = Label(self.DescriptionFrame,
                                 text='Author:',
                                 bg='white')
        self.AuthorNameButton = Button(self.DescriptionFrame,
                                       text='\t\tghanteyyy',
                                       bg='white',
                                       activebackground='white',
                                       activeforeground='black',
                                       fg='black',
                                       bd=0,
                                       command=self.GoToAuthorAddress)

        self.SourceCodeLabel = Label(self.DescriptionFrame,
                                     text='Source Code:',
                                     bg='white')
        self.SourceCodeButton = Button(self.DescriptionFrame,
                                       text='\t\tGPAD',
                                       bg='white',
                                       activebackground='white',
                                       activeforeground='black',
                                       fg='black',
                                       bd=0,
                                       command=self.GoToSourceCodeAddress)

        self.BuildLabel.grid(row=0, column=0, sticky='w')
        self.BuildNumberLabel.grid(row=0, column=1, sticky='e')
        self.AuthorLabel.grid(row=1, column=0, sticky='w')
        self.AuthorNameButton.grid(row=1, column=1, sticky='e')
        self.SourceCodeLabel.grid(row=2, column=0, sticky='w')
        self.SourceCodeButton.grid(row=2, column=1, sticky='e')
        self.DescriptionFrame.pack(pady=20)

        self.ShowLinkFrame = Frame(self.AboutWindow)
        self.LinkLabel = Label(self.ShowLinkFrame, bg='white')
        self.LinkLabel.grid(row=0, column=1)
        self.ShowLinkFrame.pack(side=LEFT)

        self.OkFrame = Frame(self.AboutWindow)
        self.OkButton = ttk.Button(self.OkFrame,
                                   text='Ok',
                                   command=self.AboutWindow.destroy)
        self.OkButton.grid(row=0, column=0)
        self.OkFrame.pack(side=RIGHT)

        self.AuthorNameButton.bind(
            '<Enter>',
            lambda e: self.Enter(self.AuthorNameButton, self.AuthorAddress))
        self.AuthorNameButton.bind('<Leave>',
                                   lambda e: self.Leave(self.AuthorNameButton))
        self.SourceCodeButton.bind(
            '<Enter>', lambda e: self.Enter(self.SourceCodeButton, self.
                                            SourceCodeAddress))
        self.SourceCodeButton.bind('<Leave>',
                                   lambda e: self.Leave(self.SourceCodeButton))
        self.AuthorLabel.bind(
            '<Enter>',
            lambda e: self.Enter(self.AuthorLabel, self.AuthorAddress))
        self.AuthorLabel.bind('<Leave>',
                              lambda e: self.Leave(self.AuthorLabel))
        self.SourceCodeLabel.bind(
            '<Enter>',
            lambda e: self.Enter(self.SourceCodeLabel, self.SourceCodeAddress))
        self.SourceCodeLabel.bind('<Leave>',
                                  lambda e: self.Leave(self.SourceCodeLabel))

        self.AuthorLabel.bind('<Button-1>', self.GoToAuthorAddress)
        self.SourceCodeLabel.bind('<Button-1>', self.GoToSourceCodeAddress)
        self.AboutWindow.bind('<Return>', lambda e: self.AboutWindow.destroy())
        self.AboutWindow.bind('<Escape>', lambda e: self.AboutWindow.destroy())
        self.AboutWindow.config(bg='white')
        self.AboutWindow.mainloop()
Esempio n. 12
0
    def __init__(self, master, text_widget):
        self.changed = False
        self.FindIndex = None
        self.WordIndexes = []
        self.DirectionVar, self.MatchCaseVar, self.WrapAroundVar = IntVar(
        ), IntVar(), IntVar()

        self.master = master
        self.TextWidget = text_widget
        self.TransparentICO = Include.resource_path('transparent.ico')

        self.FindWindow = Toplevel()
        self.FindWindow.transient(self.master)
        self.FindWindow.grab_set()
        self.DummyTextWidget = Text(self.FindWindow)

        self.FindWindow.withdraw()
        self.FindWindow.after(0, self.FindWindow.deiconify)
        self.FindWindow.title('Find')
        self.FindWindow.iconbitmap(self.TransparentICO)
        self.pos_x, self.pos_y = self.master.winfo_x(
        ) + 55, self.master.winfo_y() + 170
        self.FindWindow.geometry('{}x{}+{}+{}'.format(355, 123, self.pos_x,
                                                      self.pos_y))
        self.FindWindow.resizable(0, 0)

        self.LabelEntryFrame = Frame(self.FindWindow)
        self.ButtonsFrame = Frame(self.FindWindow)

        self.FindWhatLabel = ttk.Label(self.LabelEntryFrame, text='Find what:')
        self.FindWhatEntry = ttk.Entry(self.LabelEntryFrame, width=34)
        self.FindWhatLabel.grid(row=0, column=0)
        self.FindWhatEntry.grid(row=0, column=1, padx=5)
        self.LabelEntryFrame.place(x=0, y=5)
        self.FindWhatEntry.focus_set()

        self.style = ttk.Style()
        self.style.configure('my.TButton', font=('Helvetica', 8))
        self.FindNextButton = ttk.Button(self.ButtonsFrame,
                                         text='Find Next',
                                         width=9,
                                         style='my.TButton',
                                         command=self.Find)
        self.CancelButton = ttk.Button(self.ButtonsFrame,
                                       text='Cancel',
                                       width=9,
                                       style='my.TButton',
                                       command=self.exit)
        self.FindNextButton.grid(row=0, column=0, ipadx=3)
        self.CancelButton.grid(row=1, column=0, pady=5, ipadx=3)
        self.ButtonsFrame.place(x=280, y=5)

        self.DirectionVar.set(2)
        self.ttkLabelFrame = LabelFrame(self.FindWindow,
                                        text="Direction",
                                        padx=5,
                                        pady=5)
        self.UpRadioButton = ttk.Radiobutton(self.ttkLabelFrame,
                                             text='Up',
                                             takefocus=False,
                                             value=1,
                                             variable=self.DirectionVar)
        self.DownRadioButton = ttk.Radiobutton(self.ttkLabelFrame,
                                               text='Down',
                                               takefocus=False,
                                               value=2,
                                               variable=self.DirectionVar)
        self.UpRadioButton.pack(side=LEFT)
        self.DownRadioButton.pack(side=LEFT)
        self.ttkLabelFrame.place(x=165, y=30)

        self.CheckButtonFrame = Frame(self.FindWindow)
        self.MatchCaseCheckButton = ttk.Checkbutton(self.CheckButtonFrame,
                                                    text='Match case',
                                                    variable=self.MatchCaseVar,
                                                    takefocus=False)
        self.WrapAroundCaseCheckButton = ttk.Checkbutton(
            self.CheckButtonFrame,
            text='Wrap around',
            variable=self.WrapAroundVar,
            takefocus=False)
        self.MatchCaseCheckButton.pack(anchor='w')
        self.WrapAroundCaseCheckButton.pack(anchor='w', pady=5)
        self.CheckButtonFrame.place(x=5, y=70)

        self.InsertSelectedText()
        self.shortcut = ShortCut.ShortCut(self.FindWindow)

        self.FindNextButton.bind(
            '<Enter>',
            lambda e: self.shortcut.ShowShortCut(self.FindNextButton, 'F3'))
        self.FindNextButton.bind('<Leave>', lambda e: self.shortcut.destroy())
        self.CancelButton.bind(
            '<Enter>',
            lambda e: self.shortcut.ShowShortCut(self.CancelButton, 'ESC'))
        self.CancelButton.bind('<Leave>', lambda e: self.shortcut.destroy())

        self.FindWindow.bind('<F3>', self.Find)
        self.CancelButton.bind('<Return>', self.exit)
        self.FindNextButton.bind('<Return>', self.Find)
        self.FindWindow.protocol('WM_DELETE_WINDOW', self.exit)
        self.FindWindow.bind('<Escape>', self.exit)
        self.FindWhatEntry.bind('<Control-h>', self.entry_bind)
        self.FindWindow.mainloop()