|
9 | 9 | Refer to comments in EditorWindow autoindent code for details.
|
10 | 10 |
|
11 | 11 | """
|
| 12 | +import re |
| 13 | + |
12 | 14 | from tkinter import (Toplevel, Listbox, Text, Scale, Canvas,
|
13 | 15 | StringVar, BooleanVar, IntVar, TRUE, FALSE,
|
14 | 16 | TOP, BOTTOM, RIGHT, LEFT, SOLID, GROOVE,
|
@@ -1764,9 +1766,18 @@ class GenPage(Frame):
|
1764 | 1766 |
|
1765 | 1767 | def __init__(self, master):
|
1766 | 1768 | super().__init__(master)
|
| 1769 | + |
| 1770 | + self.init_validators() |
1767 | 1771 | self.create_page_general()
|
1768 | 1772 | self.load_general_cfg()
|
1769 | 1773 |
|
| 1774 | + def init_validators(self): |
| 1775 | + digits_or_empty_re = re.compile(r'[0-9]*') |
| 1776 | + def is_digits_or_empty(s): |
| 1777 | + "Return 's is blank or contains only digits'" |
| 1778 | + return digits_or_empty_re.fullmatch(s) is not None |
| 1779 | + self.digits_only = (self.register(is_digits_or_empty), '%P',) |
| 1780 | + |
1770 | 1781 | def create_page_general(self):
|
1771 | 1782 | """Return frame of widgets for General tab.
|
1772 | 1783 |
|
@@ -1883,16 +1894,23 @@ def create_page_general(self):
|
1883 | 1894 | frame_win_size, text='Initial Window Size (in characters)')
|
1884 | 1895 | win_width_title = Label(frame_win_size, text='Width')
|
1885 | 1896 | self.win_width_int = Entry(
|
1886 |
| - frame_win_size, textvariable=self.win_width, width=3) |
| 1897 | + frame_win_size, textvariable=self.win_width, width=3, |
| 1898 | + validatecommand=self.digits_only, validate='key', |
| 1899 | + ) |
1887 | 1900 | win_height_title = Label(frame_win_size, text='Height')
|
1888 | 1901 | self.win_height_int = Entry(
|
1889 |
| - frame_win_size, textvariable=self.win_height, width=3) |
| 1902 | + frame_win_size, textvariable=self.win_height, width=3, |
| 1903 | + validatecommand=self.digits_only, validate='key', |
| 1904 | + ) |
1890 | 1905 |
|
1891 | 1906 | frame_autocomplete = Frame(frame_window, borderwidth=0,)
|
1892 | 1907 | auto_wait_title = Label(frame_autocomplete,
|
1893 | 1908 | text='Completions Popup Wait (milliseconds)')
|
1894 | 1909 | self.auto_wait_int = Entry(frame_autocomplete, width=6,
|
1895 |
| - textvariable=self.autocomplete_wait) |
| 1910 | + textvariable=self.autocomplete_wait, |
| 1911 | + validatecommand=self.digits_only, |
| 1912 | + validate='key', |
| 1913 | + ) |
1896 | 1914 |
|
1897 | 1915 | frame_paren1 = Frame(frame_window, borderwidth=0)
|
1898 | 1916 | paren_style_title = Label(frame_paren1, text='Paren Match Style')
|
@@ -1922,20 +1940,26 @@ def create_page_general(self):
|
1922 | 1940 | format_width_title = Label(frame_format,
|
1923 | 1941 | text='Format Paragraph Max Width')
|
1924 | 1942 | self.format_width_int = Entry(
|
1925 |
| - frame_format, textvariable=self.format_width, width=4) |
| 1943 | + frame_format, textvariable=self.format_width, width=4, |
| 1944 | + validatecommand=self.digits_only, validate='key', |
| 1945 | + ) |
1926 | 1946 |
|
1927 | 1947 | frame_context = Frame(frame_editor, borderwidth=0)
|
1928 | 1948 | context_title = Label(frame_context, text='Max Context Lines :')
|
1929 | 1949 | self.context_int = Entry(
|
1930 |
| - frame_context, textvariable=self.context_lines, width=3) |
| 1950 | + frame_context, textvariable=self.context_lines, width=3, |
| 1951 | + validatecommand=self.digits_only, validate='key', |
| 1952 | + ) |
1931 | 1953 |
|
1932 | 1954 | # Frame_shell.
|
1933 | 1955 | frame_auto_squeeze_min_lines = Frame(frame_shell, borderwidth=0)
|
1934 | 1956 | auto_squeeze_min_lines_title = Label(frame_auto_squeeze_min_lines,
|
1935 | 1957 | text='Auto-Squeeze Min. Lines:')
|
1936 | 1958 | self.auto_squeeze_min_lines_int = Entry(
|
1937 |
| - frame_auto_squeeze_min_lines, width=4, |
1938 |
| - textvariable=self.auto_squeeze_min_lines) |
| 1959 | + frame_auto_squeeze_min_lines, width=4, |
| 1960 | + textvariable=self.auto_squeeze_min_lines, |
| 1961 | + validatecommand=self.digits_only, validate='key', |
| 1962 | + ) |
1939 | 1963 |
|
1940 | 1964 | # frame_help.
|
1941 | 1965 | frame_helplist = Frame(frame_help)
|
|
0 commit comments