Exemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        """The main class for bringing the whole shebang together"""
        tk.Frame.__init__(self, *args, **kwargs)
        master.title('untitled - Quiet Text')
        # defined size of the editer window
        master.geometry('700x785')
        self.configure(bg='black')
        self.loader = QuietLoaders()
        self.operating_system = system()
        self.quiet_icon_path = self.loader.resource_path(os.path.join('data', 'q.png'))
        self.icon = tk.PhotoImage(file = self.quiet_icon_path)
        master.iconphoto(False, self.icon)

        # start editor according to defined settings in settings.yaml

        self.settings = self.loader.load_settings_data()

        self.browser = self.settings['web_browser']
        self.font_family = self.settings['font_family']
        self.bg_color = self.settings['textarea_background_color']
        self.font_color = self.settings['font_color']
        self.tab_size = self.settings['tab_size']
        self.font_size = int(self.settings['font_size'])
        self.top_spacing = self.settings['text_top_lineheight']
        self.bottom_spacing = self.settings['text_bottom_lineheight']
        self.padding_x = self.settings['textarea_padding_x']
        self.padding_y = self.settings['textarea_padding_y']
        self.insertion_blink = 300 if self.settings['insertion_blink'] else 0
        self.insertion_color = self.settings['insertion_color']
        self.tab_size_spaces = self.settings['tab_size']
        self.text_wrap = self.settings['text_wrap']
        self.autoclose_parentheses = self.settings['autoclose_parentheses']
        self.autoclose_curlybraces = self.settings['autoclose_curlybraces']
        self.autoclose_squarebrackets = self.settings['autoclose_squarebrackets']
        self.autoclose_singlequotes = self.settings['autoclose_singlequotes']
        self.autoclose_doublequotes = self.settings['autoclose_doublequotes']
        self.border = self.settings['textarea_border']
        self.text_selection_bg = self.settings['text_selection_bg']
        self.scrollx_clr = self.settings['horizontal_scrollbar_color']
        self.troughx_clr = self.settings['horizontal_scrollbar_trough_color']
        self.scrollx_width = self.settings['horizontal_scrollbar_width']
        self.scrollx_active_bg = self.settings['horizontal_scrollbar_active_bg']
        self.scrolly_clr = self.settings['vertical_scrollbar_color']
        self.troughy_clr = self.settings['vertical_scrollbar_trough_color']
        self.scrolly_width = self.settings['vertical_scrollbar_width']
        self.scrolly_active_bg = self.settings['vertical_scrollbar_active_bg']
        self.menubar_active_fg = self.settings['menubar_active_fg']
        self.menubar_active_bg = self.settings['menubar_active_bg']
        self.menu_fg = self.settings['menu_fg']
        self.menu_bg = self.settings['menu_bg']
        self.current_line_symbol = self.settings['current_line_indicator_symbol']
        self.current_line_indicator = self.settings['current_line_indicator']

        #configuration of the file dialog text colors.
        self.font_style = tk_font.Font(family=self.font_family,
                                       size=self.font_size)

        self.italics = tk_font.Font(family=self.font_family, slant='italic', size=self.font_size)
        self.bold = tk_font.Font(family=self.font_family, weight='bold', size=self.font_size)
        self.header1 = tk_font.Font(family=self.font_family, weight='bold', size=self.font_size + 15)
        self.header2 = tk_font.Font(family=self.font_family, weight='bold', size=self.font_size + 7)

        self.master = master
        self.filename = os.getcwd()
        self.dirname = os.getcwd()

        self.previous_file = None
        self.textarea = CustomText(self)

        self.scrolly = tk.Scrollbar(
            master,
            command=self.textarea.yview,
            bg=self.scrolly_clr,
            troughcolor=self.troughy_clr,
            bd=0,
            width=self.scrolly_width,
            highlightthickness=0,
            activebackground=self.scrolly_active_bg,
            orient='vertical')

        self.scrollx = tk.Scrollbar(
            master,
            command=self.textarea.xview,
            bg=self.scrollx_clr,
            troughcolor=self.troughx_clr,
            bd=0,
            width=self.scrollx_width,
            highlightthickness=0,
            activebackground=self.scrollx_active_bg,
            orient='horizontal')

        self.textarea.configure(
            yscrollcommand=self.scrolly.set,
            xscrollcommand=self.scrollx.set,
            bg=self.bg_color,
            fg=self.font_color,
            wrap= self.text_wrap,
            spacing1=self.top_spacing, 
            spacing3=self.bottom_spacing,
            selectbackground= self.text_selection_bg,
            insertbackground=self.insertion_color,
            insertofftime=self.insertion_blink,
            bd=self.border,
            highlightthickness=self.border,
            highlightbackground='black',
            font=self.font_style,
            undo=True,
            autoseparators=True,
            maxundo=-1,
            padx=self.padding_x,
            pady=self.padding_y)

        self.initial_content = self.textarea.get("1.0", tk.END)

        #retrieving the font from the text area and setting a tab width
        self._font = tk_font.Font(font=self.textarea['font'])
        self._tab_width = self._font.measure(' ' * self.tab_size_spaces)
        self.textarea.config(tabs=(self._tab_width,))

        self.context_menu = ContextMenu(self)
        self.linenumbers = TextLineNumbers(self)
        self.syntax_highlighter = SyntaxHighlighting(self, self.textarea, self.initial_content)
        self.menubar = Menubar(self)
        self.statusbar = Statusbar(self)
        self.syntax_highlighter.syntax_and_themes.load_default()

        self.linenumbers.attach(self.textarea)
        self.scrolly.pack(side=tk.RIGHT, fill=tk.Y)
        self.scrollx.pack(side=tk.BOTTOM, fill=tk.X)
        self.linenumbers.pack(side=tk.LEFT, fill=tk.Y)
        self.textarea.pack(side=tk.RIGHT, fill='both', expand=True)
        
        self.textarea.find_match_index = None
        self.textarea.find_search_starting_index = 1.0

        #calling function to bind hotkeys.
        self.bind_shortcuts()
        self.control_key = False
        self.menu_hidden = False
        self.first_word = True
Exemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        tk.Frame.__init__(self, *args, **kwargs)
        master.title('untitled - Quiet Text')
        # defined size of the editer window
        master.geometry('1920x1080')
        self.loader = QuietLoaders()
        user_operating_system = system()

        # start editor according to defined settings in settings.yaml
        self.settings = self.loader.load_settings_data()
        self.default_theme = self.loader.load_default_theme()

        self.settings['font_color'] = self.default_theme['font_color']
        self.settings['textarea_background_color'] = self.default_theme['bg_color']
        self.settings['menubar_active_bg'] = self.default_theme['menu_bg_active']
        self.settings['menubar_active_fg'] = self.default_theme['menu_fg_active']  
        self.settings['menu_active_bg'] = self.default_theme['menu_bg_active']
        self.settings['menu_active_fg'] = self.default_theme['menu_fg_active']
        self.settings['menu_bg'] = self.default_theme['bg_color']
        self.settings['font_color'] = self.default_theme['font_color']

        self.font_family = self.settings['font_family']
        self.bg_color = self.settings['textarea_background_color']
        self.font_color = self.settings['font_color']
        self.tab_size = self.settings['tab_size']
        self.font_size = int(self.settings['font_size'])
        self.top_spacing = self.settings['text_top_lineheight']
        self.bottom_spacing = self.settings['text_bottom_lineheight']
        self.padding_x = self.settings['textarea_padding_x']
        self.padding_y = self.settings['textarea_padding_y']
        self.insertion_blink = 300 if self.settings['insertion_blink'] else 0
        self.insertion_color = self.settings['insertion_color']
        self.tab_size_spaces = self.settings['tab_size']
        self.text_wrap = self.settings['text_wrap']
        self.autoclose_parens = self.settings['autoclose_parentheses']
        self.autoclose_curlybraces = self.settings['autoclose_curlybraces']
        self.autoclose_squarebrackets = self.settings['autoclose_squarebrackets']
        self.autoclose_singlequotes = self.settings['autoclose_singlequotes']
        self.autoclose_doublequotes = self.settings['autoclose_doublequotes']
        self.border = self.settings['textarea_border']
        self.text_selection_bg = self.settings['text_selection_bg']
        self.scrollx_clr = self.settings['horizontal_scrollbar_color']
        self.troughx_clr = self.settings['horizontal_scrollbar_trough_color']
        self.scrollx_width = self.settings['horizontal_scrollbar_width']
        self.scrollx_active_bg = self.settings['horizontal_scrollbar_active_bg']
        self.scrolly_clr = self.settings['vertical_scrollbar_color']
        self.troughy_clr = self.settings['vertical_scrollbar_trough_color']
        self.scrolly_width = self.settings['vertical_scrollbar_width']
        self.scrolly_active_bg = self.settings['vertical_scrollbar_active_bg']
        self.menu_fg = self.settings['menu_fg']
        self.menu_bg = self.settings['menu_bg']



        master.tk_setPalette(background=self.bg_color, foreground='black')
        self.font_style = tk_font.Font(family=self.font_family,
                                       size=self.settings['font_size'])

        #configuration of the file dialog text colors.

        self.italics = tk_font.Font(family=self.font_family, slant='italic')
        self.master = master
        self.filename = None
                                
        self.textarea = CustomText(self)

        self.scrolly = tk.Scrollbar(master,
                                    command=self.textarea.yview,
                                    bg=self.scrolly_clr,
                                    troughcolor=self.troughy_clr,
                                    bd=0,
                                    width=self.scrolly_width,
                                    highlightthickness=0,
                                    activebackground=self.scrolly_active_bg,
                                    orient='vertical')

        self.scrollx = tk.Scrollbar(master,
                                    command=self.textarea.xview,
                                    bg=self.scrollx_clr,
                                    troughcolor=self.troughx_clr,
                                    bd=0,
                                    width=self.scrollx_width,
                                    highlightthickness=0,
                                    activebackground=self.scrollx_active_bg,
                                    orient='horizontal')

        self.textarea.configure(yscrollcommand=self.scrolly.set,
                                xscrollcommand=self.scrollx.set,
                                bg=self.bg_color,
                                fg=self.font_color,
                                wrap= self.text_wrap,
                                spacing1=self.top_spacing, 
                                spacing3=self.bottom_spacing,
                                selectbackground= self.text_selection_bg,
                                insertbackground=self.insertion_color,
                                insertofftime=self.insertion_blink,
                                bd=self.border,
                                highlightthickness=self.border,
                                highlightbackground='black',
                                font=self.font_family,
                                undo=True,
                                autoseparators=True,
                                maxundo=-1,
                                padx=self.padding_x,
                                pady=self.padding_y)

        self.initial_content = self.textarea.get("1.0", tk.END)

        #retrieving the font from the text area and setting a tab width
        self._font = tk_font.Font(font=self.textarea['font'])
        self._tab_width = self._font.measure(' ' * self.tab_size_spaces)
        self.textarea.config(tabs=(self._tab_width,))

        self.menu_hidden = False
        self.context_menu = ContextMenu(self)
        self.statusbar = Statusbar(self)
        self.linenumbers = TextLineNumbers(self)
        self.syntax_highlighter = SyntaxHighlighting(self, self.textarea, self.initial_content)
        self.menubar = Menubar(self)

        self.linenumbers.attach(self.textarea)
        self.scrolly.pack(side=tk.RIGHT, fill=tk.Y)
        self.scrollx.pack(side=tk.BOTTOM, fill='both')
        self.linenumbers.pack(side=tk.LEFT, fill=tk.Y)
        self.textarea.pack(side=tk.RIGHT, fill='both', expand=True)
        
        self.textarea.tag_configure('find_match', background='#75715e')
        self.textarea.find_match_index = None
        self.textarea.find_search_starting_index = 1.0

        self.tags_configured = False
        #calling function to bind hotkeys.
        self.bind_shortcuts()
        self.control_key = False