Skip to content

Commit

Permalink
Merge pull request #50 from PALIN2018/master
Browse files Browse the repository at this point in the history
fix bugs of loading configs
  • Loading branch information
jiesutd authored Apr 21, 2022
2 parents 3f70a6d + 0817908 commit 11d703a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
45 changes: 29 additions & 16 deletions YEDDA.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from tkinter.scrolledtext import ScrolledText
from dataclasses import dataclass
from typing import List, Optional, Tuple
import json

from utils.recommend import *

Expand Down Expand Up @@ -242,33 +243,43 @@ class Application(Frame):
def __init__(self, parent):
super().__init__(parent)
self.Version = "YEDDA-V1.0 Annotator"
self.configFile = "configs/default.config"
self.OS = platform.system().lower()
self.fileName = ""
self.file_encoding = 'utf-8'
self.debug = False
self.history = deque(maxlen=20)
self.pressCommand = [KeyDef('a', "Artificial"),
KeyDef('b', "Event"),
KeyDef('c', "Fin-Concept"),
KeyDef('d', "Location"),
KeyDef('e', "Organization"),
KeyDef('f', "Person"),
KeyDef('g', "Sector"),
KeyDef('h', "Other")]
for key, color in zip(self.pressCommand, all_colors()):
key.color = color

# default GUI display parameter
self.textRow = max(len(self.pressCommand), 20)
self.readConfig()
self.textColumn = 5

self.configFile = "configs/default.config"

self.entity_regex = r'\[\@.*?\#.*?\*\](?!\#)'
self.recommendRe = r'\[\$.*?\#.*?\*\](?!\#)'
self.goldAndrecomRe = r'\[[\@\$)].*?\#.*?\*\](?!\#)'
self.textFontStyle = "Times"
self.initUI()

def KeyDef2Dic(self):
config_dic = {}
for item in self.pressCommand:
config_dic[item.key] = item.name
return config_dic

def readConfig(self):
self.pressCommand = []
with open(self.configFile, 'r') as fp:
config_dict = json.load(fp)
for index,entity in config_dict.items():
self.pressCommand.append(KeyDef(index,entity))
for key, color in zip(self.pressCommand, all_colors()):
key.color = color

# default GUI display parameter
self.textRow = max(len(self.pressCommand), 20)


def initUI(self):
self.master.title(self.Version)
self.pack(fill=BOTH, expand=True)
Expand Down Expand Up @@ -617,8 +628,8 @@ def renewPressCommand(self):
if self.debug:
print("Action Track: renewPressCommand")
self.pressCommand = self.keymap_frame.read_keymap()
with open(self.configFile, 'w') as fp:
fp.write(str(self.pressCommand))
with open(self.configFile, 'wb') as fp:
json.dump(self.KeyDef2Dic(self.pressCommand), fp)
self.keymap_frame.update_keymap(self.pressCommand)
messagebox.showinfo("Remap Notification",
"Shortcut map has been updated!\n\n" +
Expand All @@ -639,8 +650,8 @@ def savenewPressCommand(self):
# make sure ending with ".config"
if not self.configFile.endswith(".config"):
self.configFile += ".config"
with open(self.configFile, 'w') as fp:
fp.write(str(self.pressCommand))
with open(self.configFile, 'wb') as fp:
json.dump(self.KeyDef2Dic(self.pressCommand), fp)
self.keymap_frame.update_keymap(self.pressCommand)
messagebox.showinfo("Save New Map Notification",
"Shortcut map has been saved and updated!\n\n"
Expand All @@ -650,6 +661,8 @@ def on_select_configfile(self, event=None):
if event and self.debug:
print("Change shortcut map to: ", event.widget.get())
self.configFile = os.path.join("configs", event.widget.get())
self.configListBox.set(self.configFile.split(os.sep)[-1])
self.readConfig()
self.keymap_frame.update_keymap(self.pressCommand)


Expand Down
2 changes: 1 addition & 1 deletion configs/default.config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{'a': 'Person', 'b': 'Organization', 'c': 'Location', 'd': 'Title', 'e': 'Sector', 'h': 'Other'}
{"a": "Artifical", "c": "Fin-Concept", "b": "Event", "e": "Organization", "d": "Location", "g": "Sector", "f": "Person", "h": "Other"}

0 comments on commit 11d703a

Please sign in to comment.