コード例 #1
0
    def __init__(self, master, **kw):
        kw.setdefault("background", "white")
        self._xscrollcommand = kw.pop("xscrollcommand", None)
        self._yscrollcommand = kw.pop("yscrollcommand", None)
        self._encoding = kw.pop("encoding", "utf-8")
        self._encoding_errors = kw.pop("encoding_errors", "replace")
        stream = kw.pop("stream", None)

        Canvas.__init__(self, master, **kw)

        self.bind("<Configure>", self._on_configure, "+")
        bind_mouse_wheel(self, self._on_mouse_wheel)

        self.bind("<Enter>", self._on_enter, "+")

        self.bind("<Prior>", self._on_prior, "+") # Page Up
        self.bind("<Next>", self._on_next, "+") # Page Down

        self._var_total_lines = total_var = IntVar(self)
        total_var.set(0)
        # Contains showed line number. It's one greater than internally used
        # index of line.
        self._var_lineno = lineno_var = IntVar(self)
        lineno_var.set(1)

        # TODO: make it configurable
        fonts = [
            Font(font = ("Courier", 10, NORMAL)),
            Font(font = ("Courier", 10, BOLD)),
        ]
        self._main_font, self._lineno_font = fonts
        self._linespace = max(f.metrics("linespace") for f in fonts)
        # Note, padding space is used for selected lines highlighting.
        self._ylinepadding = 1
        self._lineno_padding = 10
        self._page_size = 100 # in lines
        self._page_width = 0 # in Canvas units
        self._x_offset = 0
        self._index = None # index of lines offsets

        self._stream = None
        # trigger the property
        self.stream = stream

        self._state = None

        # Selection is defined by two tuples: (lineidx, charidx)
        self._sel_start = None # first selected char
        self._sel_limit = None # a char immediately after last selected one
        self.selection_threshold = 10

        self.bind("<ButtonPress-1>", self._on_bt1_press, "+")
        self.bind("<ButtonRelease-1>", self._on_bt1_release, "+")
        self.bind("<Motion>", self._on_motion, "+")

        self.bind("<Control-Key>", self._on_ctrl_key, "+")
コード例 #2
0
    def _init_fonts(self, root):
        # See: <http://www.astro.washington.edu/owen/ROTKFolklore.html>
        self._sysfont = Font(font=Button()["font"])
        root.option_add("*Font", self._sysfont)

        # TWhat's our font size (default=same as sysfont)
        self._size = IntVar(root)
        self._size.set(self._sysfont.cget('size'))

        self._boldfont = Font(family='helvetica', weight='bold', size=self._size.get())
        self._font = Font(family='helvetica', size=self._size.get())
コード例 #3
0
ファイル: concordance_app.py プロジェクト: wurentidai/nltk
 def _init_results_box(self, parent):
     innerframe = Frame(parent)
     i1 = Frame(innerframe)
     i2 = Frame(innerframe)
     vscrollbar = Scrollbar(i1, borderwidth=1)
     hscrollbar = Scrollbar(i2, borderwidth=1, orient='horiz')
     self.results_box = Text(i1,
                             font=Font(family='courier', size='16'),
                             state='disabled',
                             borderwidth=1,
                             yscrollcommand=vscrollbar.set,
                             xscrollcommand=hscrollbar.set,
                             wrap='none',
                             width='40',
                             height='20',
                             exportselection=1)
     self.results_box.pack(side='left', fill='both', expand=True)
     self.results_box.tag_config(self._HIGHLIGHT_WORD_TAG,
                                 foreground=self._HIGHLIGHT_WORD_COLOUR)
     self.results_box.tag_config(self._HIGHLIGHT_LABEL_TAG,
                                 foreground=self._HIGHLIGHT_LABEL_COLOUR)
     vscrollbar.pack(side='left', fill='y', anchor='e')
     vscrollbar.config(command=self.results_box.yview)
     hscrollbar.pack(side='left', fill='x', expand=True, anchor='w')
     hscrollbar.config(command=self.results_box.xview)
     #there is no other way of avoiding the overlap of scrollbars while using pack layout manager!!!
     Label(i2, text='   ',
           background=self._BACKGROUND_COLOUR).pack(side='left', anchor='e')
     i1.pack(side='top', fill='both', expand=True, anchor='n')
     i2.pack(side='bottom', fill='x', anchor='s')
     innerframe.pack(side='top', fill='both', expand=True)
コード例 #4
0
ファイル: drt_glue_demo.py プロジェクト: EricChh20/EZ-Mail
 def __init__(self, canvas, drs, **attribs):
     self._drs = drs
     self._canvas = canvas
     canvas.font = Font(
         font=canvas.itemcget(canvas.create_text(0, 0, text=''), 'font'))
     canvas._BUFFER = 3
     self.bbox = (0, 0, 0, 0)
コード例 #5
0
 def _init_results_box(self, parent):
     innerframe = Frame(parent)
     i1 = Frame(innerframe)
     i2 = Frame(innerframe)
     vscrollbar = Scrollbar(i1, borderwidth=1)
     hscrollbar = Scrollbar(i2, borderwidth=1, orient="horiz")
     self.results_box = Text(
         i1,
         font=Font(family="courier", size="16"),
         state="disabled",
         borderwidth=1,
         yscrollcommand=vscrollbar.set,
         xscrollcommand=hscrollbar.set,
         wrap="none",
         width="40",
         height="20",
         exportselection=1,
     )
     self.results_box.pack(side="left", fill="both", expand=True)
     vscrollbar.pack(side="left", fill="y", anchor="e")
     vscrollbar.config(command=self.results_box.yview)
     hscrollbar.pack(side="left", fill="x", expand=True, anchor="w")
     hscrollbar.config(command=self.results_box.xview)
     # there is no other way of avoiding the overlap of scrollbars while using pack layout manager!!!
     Label(i2, text="   ",
           background=self._BACKGROUND_COLOUR).pack(side="left", anchor="e")
     i1.pack(side="top", fill="both", expand=True, anchor="n")
     i2.pack(side="bottom", fill="x", anchor="s")
     innerframe.pack(side="top", fill="both", expand=True)
コード例 #6
0
ファイル: drt_glue_demo.py プロジェクト: zlpmichelle/nltk
    def _init_fonts(self, root):
        # See: <http://www.astro.washington.edu/owen/ROTKFolklore.html>
        self._sysfont = Font(font=Button()["font"])
        root.option_add("*Font", self._sysfont)

        # TWhat's our font size (default=same as sysfont)
        self._size = IntVar(root)
        self._size.set(self._sysfont.cget("size"))

        self._boldfont = Font(family="helvetica",
                              weight="bold",
                              size=self._size.get())
        self._font = Font(family="helvetica", size=self._size.get())
        if self._size.get() < 0:
            big = self._size.get() - 2
        else:
            big = self._size.get() + 2
        self._bigfont = Font(family="helvetica", weight="bold", size=big)
コード例 #7
0
def get_font_name(font):
    # create font name
    # i.e. "helvetica 12" -> ("helvetica", 12, "roman", "normal")
    from six.moves.tkinter_font import Font
    font_name = None
    try:
        f = Font(font=font)
    except:
        print_err(_('invalid font name: ') + font)
        if DEBUG:
            traceback.print_exc()
    else:
        fa = f.actual()
        font_name = (fa['family'], fa['size'], fa['slant'], fa['weight'])
    return font_name
コード例 #8
0
ファイル: project_widget.py プロジェクト: laerreal/qdt
    def adjust_widths(self):
        f = Font()

        max_name_len = f.measure(self.heading("#0")["text"])
        max_dir_len = f.measure(self.heading("directory")["text"])

        for d in self.descs:
            l = f.measure(d.name)
            if l > max_name_len:
                max_name_len = l

            l = f.measure(d.directory)
            if l > max_dir_len:
                max_dir_len = l

            self.column("#0", width=max_name_len)
            self.column("directory", width=max_dir_len)
コード例 #9
0
    def adjust_widths(self, hidden=False):
        f = Font()

        for col_idx, col in enumerate(("#0", ) + self.cget("columns")):
            if not col in self.auto_columns:
                continue

            col_max_len = f.measure(self.heading(col)["text"])

            max_cell_width = self.get_max_width("", col_idx, f, hidden)

            if col == "#0":
                max_cell_width += self.zero_column_extra_width

            cur_width = self.column(col, "width")
            max_width = max(col_max_len, max_cell_width)

            if cur_width < max_width or not self.column(col, "stretch"):
                self.column(col, width=max_width)