Exemplo n.º 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, "+")
Exemplo n.º 2
0
 def __init__(self, master, home=False):
     '''Create a new grid. home determines if this is your grid or the opponent's.'''
 
     Canvas.__init__(self, master)
     
     self.size = self.GRID_SIZE * self.RECT_SIZE + 2 * max(self.GRID_X_OFFSET, self.GRID_Y_OFFSET)
     self.config(height=self.size, width=self.size)
     
     self._home = home
     self._model = GridModel()
     
     self._make_grid()
     self.reset()
Exemplo n.º 3
0
    def __init__(self, master, home=False):
        '''Create a new grid. home determines if this is your grid or the opponent's.'''

        Canvas.__init__(self, master)

        self.size = self.GRID_SIZE * self.RECT_SIZE + 2 * max(
            self.GRID_X_OFFSET, self.GRID_Y_OFFSET)
        self.config(height=self.size, width=self.size)

        self._home = home
        self._model = GridModel()

        self._make_grid()
        self.reset()
Exemplo n.º 4
0
 def __init__(self,
              master=None,
              min_val=0,
              max_val=100,
              converter=None,
              **kw):
     self.log = logging.getLogger(__name__)
     self.min_val = min_val
     self.max_val = max_val
     self.converter = converter
     kw['width'] = kw.get('width', 100)
     kw['height'] = kw.get('height', 10)
     kw['background'] = kw.get('background', "black")
     self.rect = None
     Canvas.__init__(*(self, master), **kw)
Exemplo n.º 5
0
    def __init__(self,
                 master,
                 id_priority_sort_function=lambda ids: ids,
                 mesh_step=20,
                 **kw):
        # override some defaults
        for arg, val in [("width", 100), ("height", 100), ("relief", RIDGE),
                         ("background", "white"), ("borderwidth", 1)]:
            kw.setdefault(arg, val)

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

        self.align = False
        self.mesh_step = IntVar(value=mesh_step)
        self._state = None
        self.off = None
        self.bind("<ButtonPress-1>", self.down, "+")
        self.bind("<ButtonRelease-1>", self.up, "+")
        self.bind("<ButtonPress-3>", self.b3down, "+")
        self.bind("<ButtonRelease-3>", self.b3up, "+")
        self.bind("<Motion>", self.motion, "+")

        self.id_priority_sort_function = id_priority_sort_function