Skip to content

Commit

Permalink
cursor index Label to status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
etern committed Jun 7, 2020
1 parent 3b71cf2 commit eccd34d
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions YEDDA.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@


class Editor(ScrolledText):
def __init__(self, parent, **kwargs):
super().__init__(parent, **kwargs)
def __init__(self, parent):
super().__init__(parent, selectbackground='light salmon')
self.entity_pattern = r'\[\@.*?\#.*?\*\](?!\#)' # TODO dup
self.recommend_pattern = r'\[\$.*?\#.*?\*\](?!\#)' # TODO dup
fnt = font.Font(family='Times', size=20, weight="bold", underline=0)
Expand Down Expand Up @@ -177,9 +177,9 @@ def __init__(self, parent):
self.Version = "YEDDA-V1.0 Annotator"
self.OS = platform.system().lower()
self.fileName = ""
self.file_encoding = 'utf-8'
self.debug = False
self.history = deque(maxlen=20)
self.currentContent = deque(maxlen=1)
self.pressCommand = [KeyDef('a', "Artifical"),
KeyDef('b', "Event"),
KeyDef('c', "Fin-Concept"),
Expand All @@ -188,8 +188,6 @@ def __init__(self, parent):
KeyDef('f', "Person"),
KeyDef('g', "Sector"),
KeyDef('h', "Other")]
self.configListBox = None
self.file_encoding = 'utf-8'

# default GUI display parameter
self.textRow = max(len(self.pressCommand), 20)
Expand All @@ -199,8 +197,6 @@ def __init__(self, parent):
self.entity_regex = r'\[\@.*?\#.*?\*\](?!\#)'
self.recommendRe = r'\[\$.*?\#.*?\*\](?!\#)'
self.goldAndrecomRe = r'\[[\@\$)].*?\#.*?\*\](?!\#)'
## configure color
self.selectColor = 'light salmon'
self.textFontStyle = "Times"
self.initUI()

Expand All @@ -218,8 +214,8 @@ def initUI(self):

self.filename_lbl = Label(self, text="File: no file is opened")
self.filename_lbl.grid(sticky=W, pady=4, padx=5)
self.text = Editor(self, selectbackground=self.selectColor)
self.text.grid(row=1, column=0, columnspan=self.textColumn, rowspan=self.textRow, padx=12, sticky=E + W + S + N)
self.text = Editor(self)
self.text.grid(row=1, column=0, columnspan=self.textColumn, rowspan=self.textRow, padx=12, sticky=NSEW)

abtn = Button(self, text="Open", command=self.onOpen)
abtn.grid(row=1, column=self.textColumn + 1)
Expand All @@ -246,18 +242,15 @@ def initUI(self):
command=lambda: self.text.show_annotation_tag(show_tags_var.get()))
show_tags_check.grid(row=7, column=self.textColumn + 1, sticky=W)

self.cursor_index_label = Label(self, text="1:0", foreground="red", font=(self.textFontStyle, 14, "bold"))
self.cursor_index_label.grid(row=10, column=self.textColumn + 1, pady=4)

lbl_entry = Label(self, text="Command:")
lbl_entry.grid(row=self.textRow + 1, sticky=E + W + S + N, pady=4, padx=4)
self.cursor_index_label = Label(self, text="Ln 1, Col 0")
self.cursor_index_label.grid(row=self.textRow + 1, sticky=NSEW, pady=4, padx=4)
self.entry = Entry(self)
self.entry.grid(row=self.textRow + 1, columnspan=self.textColumn + 1, rowspan=1, sticky=E + W + S + N, pady=4,
padx=80)
self.entry.grid(row=self.textRow + 1, column=1, columnspan=self.textColumn - 2, sticky=NSEW, pady=4,
padx=8)
self.entry.bind('<Return>', self.returnEnter)

self.enter = Button(self, text="Enter", command=self.returnButton)
self.enter.grid(row=self.textRow + 1, column=self.textColumn + 1)
self.enter.grid(row=self.textRow + 1, column=self.textColumn - 1)

all_keys = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
for press_key in all_keys:
Expand Down Expand Up @@ -288,7 +281,7 @@ def initUI(self):
def show_cursor_pos(self, event):
cursor_index = self.text.index(INSERT)
row, col = cursor_index.split('.')
self.cursor_index_label.config(text=f"{row}:{col}")
self.cursor_index_label.config(text=f"Ln {row}, Col {col}")

## TODO: select entity by double left click
def doubleLeftClick(self, event):
Expand Down Expand Up @@ -316,7 +309,7 @@ def onOpen(self):
self.filename_lbl.config(text="File: " + filename)
self.autoLoadNewFile(self.fileName, "1.0")
self.text.mark_set(INSERT, "1.0")
self.setCursorLabel(self.text.index(INSERT))
self.show_cursor_pos(None)

def readFile(self, filename):
f = open(filename)
Expand All @@ -339,7 +332,7 @@ def setFont(self, value):

def setCursorLabel(self, cursor_index):
row, col = cursor_index.split('.')
self.cursor_index_label.config(text=f"{row}:{col}")
self.cursor_index_label.config(text=f"Ln {row}, Col {col}")

def returnButton(self):
if self.debug:
Expand Down Expand Up @@ -490,7 +483,7 @@ def executeEntryCommand(self, command):
currentCursor = self.text.index(INSERT)
newCurrentCursor = str(int(currentCursor.split('.')[0]) + 1) + ".0"
self.text.mark_set(INSERT, newCurrentCursor)
self.setCursorLabel(newCurrentCursor)
self.show_cursor_pos(None)
else:
command_list = decompositCommand(command)
for idx in range(0, len(command_list)):
Expand Down Expand Up @@ -569,7 +562,7 @@ def autoLoadNewFile(self, fileName, newcursor_index):
self.filename_lbl.config(text="File: " + fileName)
self.text.mark_set(INSERT, newcursor_index)
self.text.see(newcursor_index)
self.setCursorLabel(newcursor_index)
self.show_cursor_pos(None)
self.text.update_view()

def pushToHistory(self):
Expand Down

0 comments on commit eccd34d

Please sign in to comment.