Skip to content

Commit

Permalink
コピー候補をconfigファイルにて定義できるように変更 #2
Browse files Browse the repository at this point in the history
  • Loading branch information
TakamiChie committed Jun 28, 2021
1 parent 91dc455 commit 24f9357
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
13 changes: 13 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
copytext:
-
style: Plain
text: "{TEXT} {URL}"
-
style: Markdown
text: "[{TEXT}]({URL})"
-
style: URL Only
text: "{URL}"
-
style: Plain+
text: "{TEXT} [{URL}]({URL})"
datalist:
-
title: SBCast.
Expand Down
21 changes: 10 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ def getbuttonbar(self, owner: tkinter.Frame) -> tkinter.Frame:
ボタンバー
"""
frame = tkinter.Frame(owner)
candidates = []
for c in self.config["copytext"]:
candidates.append(c["style"])
openbtn = tkinter.Button(frame, text="OPEN", command=self.on_openbtn_click)
openbtn.pack(fill=tkinter.X, side=tkinter.LEFT, expand=True, padx=4, pady=4)
copyvalues = tkinter.StringVar(frame)
copyvalues.set("COPY")
copybtn = tkinter.OptionMenu(frame, copyvalues,
"Plain", "Markdown", "URL Only", "Plain+", command=self.on_copybtn_click)
copybtn = tkinter.OptionMenu(frame, copyvalues, *candidates, command=self.on_copybtn_click)
copybtn.pack(fill=tkinter.X, side=tkinter.LEFT, expand=True, padx=4, pady=4)
return frame

Expand All @@ -137,18 +139,15 @@ def on_copybtn_click(self, selection: str) -> None:
item = self.getcurrentitem()
if item is not None:
text = ""
if selection == "Plain":
text = f"{item['title']} {item['link']}"
elif selection == "Markdown":
text = f"[{item['title']}]({item['link']})"
elif selection == "URL Only":
text = f"{item['link']}"
elif selection == "Plain+":
text = f"{item['title']} [{item['link']}]({item['link']})"
for c in self.config["copytext"]:
if selection == c["style"]:
text = c["text"].replace("{URL}", item["link"]) \
.replace("{TEXT}", item["title"]) \
.replace("{DESC}", item["description"])
break
if text != "":
pyperclip.copy(text)


def getcurrentitem(self) -> Optional[dict[str, str]]:
"""
現在の選択中タブのリストで選択中の項目を示す値を取得する
Expand Down

0 comments on commit 24f9357

Please sign in to comment.