1

そこの!テキストエディタを作ろうとしています。テキストの選択に困っています。新しい行に遷移するまで、選択機能は正常に機能します。これは私がやろうとしたことです:

import curses
import string
from dlist_mod import DoubleList


stdscr=curses.initscr()
curses.start_color()
stdscr.keypad(1)
curses.noecho()
curses.cbreak()
class Editor:
"""klasa Editor"""

    def __init__(self, stdscr):        
    """"inicijalizacija"""

        self.stdscr = stdscr
        self.maxy, self.maxx = self.stdscr.getmaxyx()
        curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_WHITE)
        self.lines = DoubleList()
        self.lines.append("6)Like s str other dynamic languages, Python is often used as a                  scripting language, but is also used in a wide range of non-scripting contexts.")
        self.lines.append("7)Using third-party tools, Python code can be packaged into standalone executable programs.")    
        self.lines.append("3)The language provides constructs intended to enable clear programs on both a small and large scale.")
        self.lines.append("4)Python supports multiple programming paradigms, including object-oriented, imperative and functional programming styles.")
        self.lines.append("5)It features a dynamic type system and automatic memory management and has a large and comprehensive standard library.")
        self.lines.append("8)Python interpreters are available for many operating systems. ")
        self.lines.append("9)CPython, the reference implementation of Python, is free and          open source software and has a community-based development model.")       
        self.lines.append("1)Python is a popular general-purpose, high-level programming language whose design philosophy emphasizes code readability.")
        self.lines.append("2)Python's syntax allows programmers to express concepts in         fewer lines of code than would be possible in languages such as C.")
        self.cursorY = 0
        self.cursorX = 0

        self.offsetY = 0
        self.offsetX = 0

        self.selectX = 0
        self.selectY = 0

        self.isSelecting = False
  def draw(self):
    """Ova funkcija sluzi za iscrtavanje prozora"""
    # iscrtavanje
    self.maxy, self.maxx = self.stdscr.getmaxyx()

    self.stdscr.clear()

    for i, line in enumerate(self.lines.values()):
        # ograniciti prostor ispisa
        dy = i - self.offsetY+1
        visibleLine = line[self.offsetX:self.maxx + self.offsetX - 1]
        self.stdscr.addstr(dy, 0, visibleLine)
        if dy >= 0 and dy < self.maxy:

            for l in line:
                if self.isSelecting and self.selectY==i:

                    x1 = min(self.selectX, self.cursorX) 
                    x2 = max(self.selectX,self.cursorX)

                    SelectedLine = line [x1:x2] 
                    self.stdscr.chgat(dy, x1,len(SelectedLine), curses.color_pair(1))
    def right(self):
    """ Funkcija za pomeranje kursora desno."""
        self.maxy, self.maxx = self.stdscr.getmaxyx()
        line = self.lines.index(self.cursorY)
        if self.cursorX < len(line):
            if self.cursorX - self.offsetX == self.maxx - 1:
                self.offsetX += 1
            self.cursorX += 1
        elif self.cursorY != self.lines.size() - 1:
            self.home()
            self.down()

    def down(self):
    """Funkcija za pomeranje kursora dole."""
    if self.cursorY < self.lines.size() - 1:
        if self.cursorY - self.offsetY == self.maxy - 1:
            self.offsetY += 1
        self.cursorY += 1

        line = self.lines.index(self.cursorY)
        while self.cursorX > len(line):
            self.left()


def up(self):
    """Funkcija za pomeranje kursora gore."""
    if self.cursorY > 0:
        if self.offsetY == self.cursorY:
            self.offsetY -= 1
        self.cursorY -= 1

        line = self.lines.index(self.cursorY)
        while self.cursorX > len(line):
            self.left()


     def handleInput(self):

        ch = self.stdscr.getch()
        logging.error(ch)


        if ch == curses.KEY_LEFT:
            if self.isSelecting:
                self.isSelecting = False
            self.left()

        elif ch == curses.KEY_RIGHT:
            if self.isSelecting:
                self.isSelecting = False
            self.right()

テキストを選択するにはどうすればよいですか?

4

1 に答える 1

1

マウスが有効になっているためだと思います。

選択中にホールドShiftすると、選択は通常どおり機能します。

于 2014-09-13T05:53:50.487 に答える