Skip to content

Commit

Permalink
v5.5.0a2
Browse files Browse the repository at this point in the history
  • Loading branch information
Latte72R committed Feb 1, 2021
1 parent 5d335df commit 30f8f94
Showing 1 changed file with 39 additions and 20 deletions.
59 changes: 39 additions & 20 deletions easy_turtle.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
import urllib.request
import threading
import traceback
import subprocess

SIZE = 8
HEIGHT = 72
WIDTH = 520


def GET_CONFIG():
def UPDATE_CONFIG():
"""設定を取得"""
global CONFIG
if os.path.exists(CONFIG_FILE) is True:
with open(CONFIG_FILE, "r", encoding="UTF-8")as f:
data = json.load(f)
Expand All @@ -43,7 +45,7 @@ def GET_CONFIG():
config = DEFAULT_CONFIG
with open(CONFIG_FILE, "w", encoding="UTF-8")as f:
json.dump(config, f, indent=4)
return config
CONFIG = config


SYSTEM = platform.system()
Expand Down Expand Up @@ -81,7 +83,7 @@ def GET_CONFIG():
"user_document": True,
"auto_update": True}

CONFIG = GET_CONFIG()
UPDATE_CONFIG()

if CONFIG["user_document"] is True:
if os.path.exists(os.path.join("C:/Users", getpass.getuser(),
Expand Down Expand Up @@ -131,7 +133,7 @@ def GET_CONFIG():
"user_document": False,
"auto_update": True}

CONFIG = GET_CONFIG()
UPDATE_CONFIG()

if CONFIG["user_document"] is True:
if os.path.exists(os.path.join("/home/", getpass.getuser(),
Expand Down Expand Up @@ -169,7 +171,7 @@ def EXPAND(num): return int(round(num * WIN_MAG))

FONT = (FONT_TYPE1, EXPAND(12), "bold")

__version__ = (5, 5, "0a1")
__version__ = (5, 5, "0a2")


class EasyTurtle:
Expand Down Expand Up @@ -239,8 +241,7 @@ def version_info(self, event=None):

def edit_config(self, event=None):
"""設定を編集"""
global CONFIG
CONFIG = GET_CONFIG()
UPDATE_CONFIG()
self.win = tk.Toplevel(self.root)
self.win.tk.call('wm', 'iconphoto', self.win._w, self.icon)
self.win.title("設定 - EasyTurtle")
Expand Down Expand Up @@ -329,6 +330,7 @@ def close_window(self, event=None):

def all_redraw(self, change=True):
"""全部描き直し"""
UPDATE_CONFIG()
data = self.widgets

if (self.index < 0) or (len(data) < SIZE):
Expand Down Expand Up @@ -599,8 +601,8 @@ def run_program(self, event=None):
if widget.enabled is True:
widget.do(tur)
else:
return 1
except tk.TclError:
return 0
except Exception:
if self.killed_runner is True:
return 0
else:
Expand Down Expand Up @@ -723,7 +725,7 @@ def open_program(self, file=None):
# データが変更されていれば保存するか確認する
data = [d.get_data(more=False) for d in self.widgets]
if self.default_data != data:
res = messagebox.askyesno("確認", "保存しますか?")
res = messagebox.askyesnocancel("確認", "保存しますか?")
if res is None:
return
elif res is True:
Expand Down Expand Up @@ -815,7 +817,7 @@ def open_program(self, file=None):
# エラー表示
messagebox.showerror("エラー", "変換エラーが発生しました。")
traceback.print_exc()
return
return 1

def make_match_class(self, data, index=-1, version=tuple(__version__[:2])):
"""ウィジェットを作成"""
Expand Down Expand Up @@ -1126,6 +1128,14 @@ def new_program(self, event=None):
self.default_data = [d.get_data(more=False)
for d in self.widgets]

def new_window(self, event=None):
"""新規ウィンドウを起動"""
if sys.argv[0][-14:] == "EasyTurtle.exe":
command = [sys.argv[0]]
else:
command = [sys.executable, sys.argv[0]]
subprocess.Popen(command)

def setup(self):
"""セットアップ"""
# 基本ウィンドウを作成
Expand All @@ -1147,6 +1157,7 @@ def setup(self):
self.root.bind("<Control-Shift-Key-A>", self.select_all)
self.root.bind("<Control-Shift-Key-S>", self.save_program_as)
self.root.bind("<Control-Shift-Key-Z>", self.redo_change)
self.root.bind("<Control-Shift-Key-N>", self.new_window)
self.root.bind("<Control-Key-z>", self.undo_change)
self.root.bind("<Control-Key-l>", self.clear_selected)
self.root.bind("<Control-Key-n>", self.new_program)
Expand All @@ -1166,9 +1177,12 @@ def setup(self):

# FILEメニューの作成
filemenu = tk.Menu(self.menubar, tearoff=0, font=menu_font)
filemenu.add_command(label="新規", accelerator="Ctrl+N",
filemenu.add_command(label="新規ファイル", accelerator="Ctrl+N",
command=self.new_program)
filemenu.add_command(label="開く", accelerator="Ctrl+O",
filemenu.add_command(label="新しいウィンドウ", accelerator="Ctrl+Shift+N",
command=self.new_window)
filemenu.add_separator()
filemenu.add_command(label="ファイルを開く", accelerator="Ctrl+O",
command=self.open_program)
filemenu.add_command(label="上書き保存", accelerator="Ctrl+S",
command=self.save_program)
Expand Down Expand Up @@ -1634,7 +1648,7 @@ def stostr(self, string):
messagebox.showerror("エラー", f'\
line: {self.p.widgets.index(self)+1}, {self.__class__.__name__}\n\
変数"{name}"は定義されていません。')
return ""
self.p.kill_runner()
elif (self.p.variable_datas[name][1] == "S") or \
(CONFIG["show_warning"] is False):
string = string.replace(
Expand All @@ -1657,6 +1671,7 @@ def stobool(self, string):
messagebox.showerror("エラー", f'\
line: {self.p.widgets.index(self)+1}, {self.__class__.__name__}\n\
変数"{name}"は定義されていません。')
self.p.kill_runner()
elif (self.p.variable_datas[name][1] == "B") or \
(CONFIG["show_warning"] is False):
string = string.replace(
Expand All @@ -1675,6 +1690,7 @@ def stobool(self, string):
messagebox.showerror("エラー", f'\
line: {self.p.widgets.index(self)+1}, {self.__class__.__name__}\n\
{string}はBoolean型ではありません。')
self.p.kill_runner()
return boolean

def var_converter(self, string):
Expand All @@ -1685,7 +1701,7 @@ def var_converter(self, string):
messagebox.showerror("エラー", f'\
line: {self.p.widgets.index(self)+1}, {self.__class__.__name__}\n\
変数"{name}"は定義されていません。')
return 0
self.p.kill_runner()
elif (self.p.variable_datas[name][1] == "N") or \
(CONFIG["show_warning"] is False):
string = string.replace(
Expand All @@ -1705,7 +1721,7 @@ def calculator(self, string):
messagebox.showerror("エラー", f'\
line: {self.p.widgets.index(self)+1}, {self.__class__.__name__}\n\
値が入力されていません。')
return 0
self.p.kill_runner()
operators = ["**", "*", "//", "/", "%", "+", "-", "(", ")"]
formulas = [string]
for ope in operators:
Expand Down Expand Up @@ -1737,8 +1753,7 @@ def stofloat(self, string):
messagebox.showerror("エラー", f'\
line: {self.p.widgets.index(self)+1}, {self.__class__.__name__}\n\
"{string}"を数値に変換できませんでした。')
traceback.print_exc()
return 0
self.p.kill_runner()

def stoint(self, string):
"""文字列を整数に変換"""
Expand All @@ -1757,7 +1772,7 @@ def stouint(self, string):
messagebox.showerror("エラー", f'\
line: {self.p.widgets.index(self)+1}, {self.__class__.__name__}\n\
値は正の整数でなければなりません。')
return 0
self.p.kill_runner()
else:
return num

Expand All @@ -1768,7 +1783,7 @@ def stoufloat(self, string):
messagebox.showerror("エラー", f'\
line: {self.p.widgets.index(self)+1}, {self.__class__.__name__}\n\
値は正の小数でなければなりません。')
return 0
self.p.kill_runner()
else:
return num

Expand Down Expand Up @@ -3103,6 +3118,7 @@ def do(self, tur):
messagebox.showerror("エラー", f'\
line: {self.p.widgets.index(self)+1}, {self.__class__.__name__}\n\
"{self.color}"を色として認識できませんでした。', parent=self.p.root)
self.p.kill_runner()


class PenColor(Widget):
Expand Down Expand Up @@ -3185,6 +3201,7 @@ def do(self, tur):
messagebox.showerror("エラー", f'\
line: {self.p.widgets.index(self)+1}, {self.__class__.__name__}\n\
"{self.color}"を色として認識できませんでした。', parent=self.p.root)
self.p.kill_runner()


class FillColor(Widget):
Expand Down Expand Up @@ -3267,6 +3284,7 @@ def do(self, tur):
messagebox.showerror("エラー", f'\
line: {self.p.widgets.index(self)+1}, {self.__class__.__name__}\n\
"{self.color}"を色として認識できませんでした。', parent=self.p.root)
self.p.kill_runner()


class BGColor(Widget):
Expand Down Expand Up @@ -3349,6 +3367,7 @@ def do(self, tur):
messagebox.showerror("エラー", f'\
line: {self.p.widgets.index(self)+1}, {self.__class__.__name__}\n\
"{self.color}"を色として認識できませんでした。', parent=self.p.root)
self.p.kill_runner()


class GetPenColor(Widget):
Expand Down

0 comments on commit 30f8f94

Please sign in to comment.