factory.py 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725
  1. from __future__ import division # 让/恢复为除法
  2. import random
  3. import tkinter
  4. import tkinter.messagebox
  5. import os
  6. import logging
  7. import sympy
  8. from matplotlib import pyplot as plt
  9. from matplotlib import rcParams
  10. from matplotlib.animation import FuncAnimation
  11. from funcsystem.controller import ExpFunc as ExpFunc
  12. from newtkinter import asksaveasfilename
  13. from system import exception_catch, basicConfig, QueueController
  14. queue_controller = QueueController()
  15. logging.basicConfig(**basicConfig)
  16. func = None
  17. fig = None
  18. prompt_num = 0
  19. line_style = {
  20. "实线": "-",
  21. "短横线": "--",
  22. "点划线": "-,",
  23. "虚线": ":",
  24. "点标记": ".",
  25. "圆标记": "o",
  26. "倒三角": "v",
  27. "正三角": "^",
  28. "左三角": "&lt",
  29. "下箭头": "1",
  30. "上箭头": "2",
  31. "左箭头": "3",
  32. "右箭头": "4",
  33. "正方形": "s",
  34. "五边形": "p",
  35. "星形": "*",
  36. "六边形": "h",
  37. "六边形2": "H",
  38. "+号": "+",
  39. "X标记": "x",
  40. } # 函数样式翻译表
  41. point_style = ["g", "r", "c", "m", "y", "k"]
  42. SCREEN = tkinter.Tk()
  43. bg_color = "#FFFAFA" # 主颜色
  44. botton_color = "#FFFAFA" # 按钮颜色
  45. word_color = "#000000" # 文字颜色
  46. gui_width = 13 # 标准宽度
  47. gui_height = 2
  48. row = 0
  49. column = 1
  50. class UIAPI:
  51. @staticmethod
  52. @exception_catch()
  53. def dichotomy_gui():
  54. parameters = [100, 0.0001, 0.1, 0.5, False, True, 1000, 0.1, 0.1, False, None]
  55. for i in range(11):
  56. try:
  57. if i in (4, 5, 9):
  58. a = dicon_parameters[i].get()
  59. else:
  60. a = float(dicon_parameters[i].get())
  61. parameters[i] = a
  62. except BaseException as e:
  63. logging.warning(str(e))
  64. return parameters
  65. @staticmethod
  66. @exception_catch()
  67. def output_prompt_gui(news):
  68. global prompt_box, prompt_num, SCREEN
  69. prompt_num += 1
  70. news = str(news)
  71. prompt_box.insert(0, news + f"({prompt_num})")
  72. SCREEN.update()
  73. @staticmethod
  74. @exception_catch()
  75. def set_func_gui():
  76. new_func = func_exp.get().replace(" ", "")
  77. if new_func == "":
  78. API.output_prompt_gui("应用失败")
  79. raise Exception
  80. default_value = [-10, 10, 0.1, 2, 1, -10, 10, 1]
  81. get = [
  82. start_definition,
  83. end_definition,
  84. span_definition,
  85. accuracy,
  86. default_a,
  87. start_a,
  88. end_a,
  89. span_a,
  90. ]
  91. # 参数的处理
  92. span = None
  93. try:
  94. span_str = span_definition.get().replace(" ", "")
  95. if span_str[0] == "H":
  96. domain = {
  97. "Pi": sympy.pi,
  98. "e": sympy.E,
  99. "log": sympy.log,
  100. "sin": sympy.sin,
  101. "cos": sympy.cos,
  102. "tan": sympy.tan,
  103. "cot": lambda x: 1 / sympy.tan(x),
  104. "csc": lambda x: 1 / sympy.sin(x),
  105. "sec": lambda x: 1 / sympy.cos(x),
  106. "sinh": sympy.sinh,
  107. "cosh": sympy.cosh,
  108. "tanh": sympy.tanh,
  109. "asin": sympy.asin,
  110. "acos": sympy.acos,
  111. "atan": sympy.atan,
  112. }
  113. span = eval(span_str[1:], domain)
  114. except BaseException as e:
  115. logging.warning(str(e))
  116. for i in range(8):
  117. try:
  118. default_value[i] = float(get[i].get())
  119. except BaseException as e:
  120. logging.warning(str(e))
  121. if span is not None:
  122. default_value[2] = span
  123. # View的处理
  124. style_str = func_style.get().split("#")
  125. try:
  126. if style_str[0] not in point_style:
  127. style_str[0] = "b"
  128. line_style_str = line_style.get(style_str[1], "-")
  129. except IndexError:
  130. style_str = ["", ""]
  131. style_str[0] = random.choice(point_style)
  132. line_style_str = "-"
  133. style = style_str[0] + line_style_str
  134. # Name的处理
  135. name = func_name.get().replace(" ", "")
  136. if name == "":
  137. name = new_func
  138. return [new_func, name, style]+default_value
  139. @staticmethod
  140. @exception_catch()
  141. def get_y_value_gui():
  142. return y_value.get().split(",")
  143. @staticmethod
  144. @exception_catch()
  145. def update_prediction_box_gui(answer):
  146. prediction_box.delete(0, tkinter.END)
  147. prediction_box.insert(tkinter.END, *answer)
  148. @staticmethod
  149. @exception_catch()
  150. def get_projection_value_gui():
  151. return projection_value.get
  152. @staticmethod
  153. @exception_catch()
  154. def get_proximity_accuracy_gui():
  155. return proximity_accuracy.get()
  156. @staticmethod
  157. @exception_catch()
  158. def get_x_value_derivation_gui():
  159. return x_value_derivation.get().split(",")
  160. @staticmethod
  161. @exception_catch()
  162. def get_y_value_symbol_gui():
  163. return y_value_symbol.get().split(",")
  164. @staticmethod
  165. @exception_catch()
  166. def get_x_value_gui():
  167. return x_value.get().split(",")
  168. @staticmethod
  169. @exception_catch()
  170. def update_result_box_gui(answer):
  171. result_box.delete(0, tkinter.END) # 清空
  172. result_box.insert(tkinter.END, *answer)
  173. @staticmethod
  174. @exception_catch()
  175. def get_y_value_gradient_gui():
  176. return y_value_gradient.get()
  177. @staticmethod
  178. @exception_catch()
  179. def askokcancel_gui(message):
  180. return tkinter.messagebox.askokcancel("提示", message)
  181. @staticmethod
  182. @exception_catch()
  183. def add_projection_box_gui(result):
  184. projection_box.insert(tkinter.END, result)
  185. @staticmethod
  186. @exception_catch()
  187. def update_sheet_box_gui(sheet):
  188. sheet_box.delete(0, tkinter.END)
  189. sheet_box.insert(tkinter.END, *sheet)
  190. @staticmethod
  191. @exception_catch()
  192. def get_save_dir_gui():
  193. return asksaveasfilename(title="选择导出位置", filetypes=[("CSV", ".csv")])
  194. class API(UIAPI):
  195. @staticmethod
  196. @exception_catch()
  197. def type_selection(sequence, type_=float, convert=True): # Float筛选系统
  198. x = []
  199. for i in sequence:
  200. try:
  201. if type_(i) == type_(0) and convert:
  202. continue
  203. x.append(type_(i))
  204. except ValueError:
  205. pass
  206. return x
  207. @staticmethod
  208. @exception_catch()
  209. def save_to_csv(): # 导出CSV
  210. try:
  211. if not func.save_csv(API.get_save_dir_gui()):
  212. raise Exception
  213. API.output_prompt_gui("CSV导出成功")
  214. except BaseException:
  215. API.output_prompt_gui("CSV导出失败")
  216. raise
  217. @staticmethod
  218. @exception_catch()
  219. def save_to_sheet(): # 生成表格
  220. try:
  221. API.update_sheet_box_gui(func.return_list())
  222. API.output_prompt_gui("表格创建成功")
  223. except BaseException:
  224. API.output_prompt_gui("无法创建表格")
  225. raise
  226. @staticmethod
  227. @exception_catch()
  228. def sympy_computing(exp_str) -> tuple:
  229. try:
  230. named_domain = {
  231. "Pi": sympy.pi,
  232. "e": sympy.E,
  233. "log": sympy.log,
  234. "sin": sympy.sin,
  235. "cos": sympy.cos,
  236. "tan": sympy.tan,
  237. "cot": lambda x: 1 / sympy.tan(x),
  238. "csc": lambda x: 1 / sympy.sin(x),
  239. "sec": lambda x: 1 / sympy.cos(x),
  240. "sinh": sympy.sinh,
  241. "cosh": sympy.cosh,
  242. "tanh": sympy.tanh,
  243. "asin": sympy.asin,
  244. "acos": sympy.acos,
  245. "atan": sympy.atan,
  246. }
  247. answer = eval(exp_str, named_domain)
  248. return answer, True
  249. except (SyntaxError, ZeroDivisionError, NameError, TypeError, ValueError):
  250. return None, False
  251. @staticmethod
  252. @exception_catch()
  253. def computing_gui():
  254. accuracy_, must = API.sympy_computing(prediction_accuracy.get())
  255. return accuracy_
  256. @staticmethod
  257. @exception_catch()
  258. def confirmation_expression(c):
  259. get = API.sympy_computing(c)
  260. if not get[1]:
  261. return c
  262. return get[0]
  263. @staticmethod
  264. @exception_catch()
  265. def check_center_of_symmetry():
  266. accuracy_ = API.computing_gui()
  267. try:
  268. result = func.check_symmetry_center(
  269. API.confirmation_expression(API.get_projection_value_gui()), API.output_prompt_gui, accuracy_
  270. )
  271. if result[0]:
  272. API.add_projection_box_gui(result[1])
  273. API.output_prompt_gui("预测完成")
  274. else:
  275. raise Exception
  276. except BaseException:
  277. API.output_prompt_gui("预测失败")
  278. raise
  279. @staticmethod
  280. @exception_catch()
  281. def check_symmetry_axis():
  282. accuracy_ = API.computing_gui()
  283. try:
  284. result = func.check_symmetry_axis(
  285. API.confirmation_expression(API.get_projection_value_gui()), API.output_prompt_gui, accuracy_
  286. )
  287. if result[0]:
  288. API.add_projection_box_gui(result[1])
  289. API.output_prompt_gui("预测完成")
  290. else:
  291. raise Exception
  292. except BaseException:
  293. API.output_prompt_gui("预测失败")
  294. raise
  295. @staticmethod
  296. @exception_catch()
  297. def check_periodic():
  298. accuracy_ = API.computing_gui()
  299. try:
  300. result = func.check_periodic(
  301. API.confirmation_expression(API.get_projection_value_gui()), API.output_prompt_gui, accuracy_
  302. )
  303. if result[0]:
  304. API.add_projection_box_gui(result[1])
  305. API.output_prompt_gui("预测完成")
  306. else:
  307. raise Exception
  308. except BaseException:
  309. API.output_prompt_gui("预测失败")
  310. raise
  311. @staticmethod
  312. @exception_catch()
  313. def check_monotonic():
  314. accuracy_ = API.computing_gui()
  315. try:
  316. result = func.check_monotonic(
  317. API.get_projection_value_gui(), API.output_prompt_gui, accuracy_
  318. )
  319. if result[1]:
  320. API.add_projection_box_gui(result[1])
  321. API.output_prompt_gui("预测完成")
  322. else:
  323. raise Exception
  324. except BaseException:
  325. API.output_prompt_gui("预测失败")
  326. raise
  327. @staticmethod
  328. @exception_catch()
  329. def clear_memory():
  330. try:
  331. if API.askokcancel_gui(f"确定删除{func}的记忆吗?"):
  332. API.update_result_box_gui([])
  333. func.clean_memory()
  334. API.output_prompt_gui("删除完毕")
  335. else:
  336. API.output_prompt_gui("删除取消")
  337. except BaseException:
  338. API.output_prompt_gui("删除失败")
  339. raise
  340. @staticmethod
  341. @exception_catch()
  342. def show_hidden_memory(): # 显示xy
  343. try:
  344. API.update_result_box_gui([])
  345. func.hide_or_show()
  346. API.output_prompt_gui("已清空卡槽")
  347. except BaseException:
  348. API.output_prompt_gui("隐藏(显示)失败")
  349. raise
  350. @staticmethod
  351. @exception_catch()
  352. def gradient_method_calculation():
  353. try:
  354. API.output_prompt_gui("计算过程程序可能无响应")
  355. parameters = []
  356. for i in gradient_parameters:
  357. parameters.append(i.get())
  358. API.output_prompt_gui("系统运算中")
  359. answer = func.gradient_calculation(API.get_y_value_gradient_gui(), *parameters)
  360. if answer[1] is not None:
  361. API.update_result_box_gui(answer[0])
  362. API.output_prompt_gui("系统运算完成")
  363. else:
  364. API.output_prompt_gui("系统运算无结果")
  365. except BaseException:
  366. API.output_prompt_gui("系统运算失败,请注意参数设置")
  367. raise
  368. @staticmethod
  369. @exception_catch()
  370. def calculate():
  371. try:
  372. API.output_prompt_gui("计算过程程序可能无响应")
  373. answer = func.calculation(API.get_x_value_gui())
  374. if answer:
  375. API.output_prompt_gui("系统运算完毕")
  376. else:
  377. API.output_prompt_gui("系统运算无结果")
  378. API.update_result_box_gui(answer)
  379. except BaseException:
  380. API.output_prompt_gui("计算失败")
  381. raise
  382. # raise
  383. @staticmethod
  384. @exception_catch()
  385. def sympy_calculation_x():
  386. try:
  387. API.output_prompt_gui("计算过程程序可能无响应")
  388. answer = []
  389. for i in API.get_y_value_symbol_gui():
  390. answer += func.sympy_calculation(i)[0]
  391. if answer:
  392. API.output_prompt_gui("系统运算完毕")
  393. else:
  394. API.output_prompt_gui("系统运算无结果")
  395. API.update_result_box_gui(answer)
  396. except BaseException:
  397. API.output_prompt_gui("计算失败")
  398. raise
  399. @staticmethod
  400. @exception_catch()
  401. def function_differentiation():
  402. try:
  403. API.output_prompt_gui("计算过程程序可能无响应")
  404. accuracy_ = API.get_proximity_accuracy_gui()
  405. answer = []
  406. for i in API.get_x_value_derivation_gui():
  407. get = func.derivative(i, accuracy_)[0]
  408. if get is not None:
  409. answer.append(get)
  410. if answer:
  411. API.output_prompt_gui("系统运算完毕")
  412. else:
  413. API.output_prompt_gui("系统运算无结果")
  414. API.update_result_box_gui(answer)
  415. except IndexError:
  416. API.output_prompt_gui("计算失败")
  417. @staticmethod
  418. @exception_catch()
  419. def approximation(): # 逼近法
  420. try:
  421. API.output_prompt_gui("计算过程程序可能无响应")
  422. accuracy_ = API.get_proximity_accuracy_gui()
  423. answer = []
  424. for i in API.get_x_value_derivation_gui():
  425. get = func.derivative(i, accuracy_, True)[0]
  426. if get is not None:
  427. answer.append(get)
  428. if answer:
  429. API.output_prompt_gui("系统运算完毕")
  430. else:
  431. API.output_prompt_gui("系统运算无结果")
  432. API.update_result_box_gui(answer)
  433. except IndexError:
  434. API.output_prompt_gui("计算失败")
  435. @staticmethod
  436. @exception_catch()
  437. def dichotomy(): # 二分法
  438. global dicon_parameters, func, result_box
  439. try:
  440. API.output_prompt_gui("计算过程程序可能无响应")
  441. answer = []
  442. API.output_prompt_gui("系统运算中")
  443. for i in API.get_y_value_gui():
  444. try:
  445. answer += func.dichotomy(float(i), *API.dichotomy_gui())[0]
  446. except BaseException as e:
  447. logging.warning(str(e))
  448. if answer:
  449. API.output_prompt_gui("系统运算完成")
  450. else:
  451. API.output_prompt_gui("系统运算无结果")
  452. API.update_result_box_gui(answer)
  453. except BaseException:
  454. API.output_prompt_gui("系统运算失败")
  455. raise
  456. @staticmethod
  457. @exception_catch()
  458. def property_prediction():
  459. try:
  460. accuracy_ = API.computing_gui()
  461. API.output_prompt_gui("预测过程程序可能无响应")
  462. answer = func.property_prediction(API.output_prompt_gui, True, accuracy_)
  463. API.update_prediction_box_gui(*answer)
  464. API.output_prompt_gui("性质预测完成")
  465. except IndexError:
  466. API.output_prompt_gui("性质预测失败")
  467. @staticmethod
  468. @exception_catch()
  469. def function_drawing():
  470. global x_scale, start_x_plot, start_x_polt, span_x_plot, y_scale, start_y_plot, end_y_plot, span_y_plot
  471. global start_x_limit, end_x_limit, start_y_limit, end_y_limit
  472. global func, fig, show_point, show_best_value, show_text, plot_type, frame_rate
  473. try:
  474. draw_type = plot_type.curselection()[0]
  475. except IndexError:
  476. draw_type = 0
  477. # 画板创造
  478. API.output_prompt_gui("生成绘制取...")
  479. fig = plt.figure(num="CoTan函数") # 定义一个图像窗口
  480. if draw_type in (0, 1, 2, 3, 8, 9):
  481. plt.grid(True, ls="--") # 显示网格(不能放到后面,因为后面调整成为了笛卡尔坐标系)
  482. axis = plt.gca()
  483. text_y = ""
  484. text_x = ""
  485. def init():
  486. nonlocal text_x, text_y
  487. if draw_type in (0, 2, 4, 6, 8):
  488. axis.spines["right"].set_color("none")
  489. axis.spines["top"].set_color("none")
  490. axis.xaxis.set_ticks_position("bottom")
  491. axis.yaxis.set_ticks_position("left")
  492. axis.spines["bottom"].set_position(("data", 0)) # 设置x轴, y轴在(0, 0)的位置
  493. axis.spines["left"].set_position(("data", 0))
  494. # 检测x
  495. try:
  496. if x_scale.get()[0] == "c": # 如果输入函数cx#-10#10#1#1
  497. plot_parameter = [
  498. x_scale.get()[1:],
  499. start_x_plot.get(),
  500. start_x_polt.get(),
  501. span_x_plot.get(),
  502. 2,
  503. ] # 第一部分HS,第二部分S,第三部分E,第四部分KD,第五部分JD
  504. exp_parameter = ["x", -10, 10, 1, 2] # 保护系统
  505. try:
  506. exp_parameter[0] = plot_parameter[0]
  507. exp_parameter[1] = int(plot_parameter[1])
  508. exp_parameter[2] = int(plot_parameter[2])
  509. exp_parameter[3] = int(plot_parameter[3])
  510. exp_parameter[4] = int(plot_parameter[4])
  511. except BaseException as e:
  512. logging.warning(str(e))
  513. plot_parameter = exp_parameter
  514. x_exp_scale = API.type_selection(
  515. ExpFunc(
  516. plot_parameter[0],
  517. "x",
  518. "",
  519. plot_parameter[1],
  520. plot_parameter[2],
  521. plot_parameter[3],
  522. plot_parameter[4],
  523. ).data_packet()[1]
  524. ) # 取y
  525. axis.set_xticks(x_exp_scale) # 输入表达式计算刻度
  526. elif x_scale.get()[0] == "y": # 输入函数y
  527. # 不错要错误捕捉,外围有个大的捕捉
  528. x_exp_scale = abs(int(start_x_plot.get()))
  529. x_major_locator = plt.MultipleLocator(x_exp_scale)
  530. axis.xaxis.set_major_locator(x_major_locator)
  531. else: # 输入纯数字
  532. x_exp_scale = API.type_selection(x_scale.get().split(","))
  533. axis.set_xticks(x_exp_scale)
  534. except BaseException as e:
  535. logging.debug(str(e))
  536. x_major_locator = plt.MultipleLocator(2)
  537. axis.xaxis.set_major_locator(x_major_locator)
  538. # 检测y
  539. try: # 意外捕捉
  540. if y_scale.get()[0] == "c": # 如果输入函数cx#-10#10#1#1
  541. plot_parameter = [
  542. y_scale.get()[1:],
  543. start_y_plot.get(),
  544. end_y_plot.get(),
  545. span_y_plot.get(),
  546. 2,
  547. ] # 第一部分HS,第二部分S,第三部分E,第四部分KD,第五部分JD
  548. exp_parameter = ["x", -10, 10, 1, 2] # 保护系统
  549. try:
  550. exp_parameter[0] = plot_parameter[0]
  551. exp_parameter[1] = int(plot_parameter[1])
  552. exp_parameter[2] = int(plot_parameter[2])
  553. exp_parameter[3] = int(plot_parameter[3])
  554. exp_parameter[4] = int(plot_parameter[4])
  555. except BaseException as e:
  556. logging.warning(str(e))
  557. plot_parameter = exp_parameter
  558. y_exp_scale = API.type_selection(
  559. ExpFunc(
  560. plot_parameter[0],
  561. "y",
  562. "",
  563. plot_parameter[1],
  564. plot_parameter[2],
  565. plot_parameter[3],
  566. plot_parameter[4],
  567. ).data_packet()[1]
  568. ) # 取y
  569. axis.set_yticks(y_exp_scale)
  570. elif y_scale.get()[0] == "y": # 输入函数y
  571. y_exp_scale = abs(int(start_y_plot.get()))
  572. y_major_locator = plt.MultipleLocator(y_exp_scale)
  573. axis.yaxis.set_major_locator(y_major_locator)
  574. else:
  575. y_exp_scale = API.type_selection(y_scale.get().split(","))
  576. axis.set_yticks(y_exp_scale)
  577. except BaseException as e:
  578. logging.debug(str(e))
  579. y_major_locator = plt.MultipleLocator(2)
  580. axis.yaxis.set_major_locator(y_major_locator)
  581. # 极限
  582. _x_limit = [-10, 10]
  583. _y_limit = [-10, 10]
  584. try:
  585. x_limit = API.type_selection(
  586. [start_x_limit.get(), end_x_limit.get()], type_=int, convert=False
  587. )
  588. y_limit = API.type_selection(
  589. [start_y_limit.get(), end_y_limit.get()], type_=int, convert=False
  590. )
  591. try:
  592. _x_limit = [x_limit[0], x_limit[1]]
  593. except IndexError:
  594. _x_limit = [-10, 10]
  595. try:
  596. _y_limit = [y_limit[0], y_limit[1]]
  597. except IndexError:
  598. _y_limit = _x_limit
  599. except BaseException as e:
  600. logging.warning(str(e))
  601. _x_limit.sort()
  602. _y_limit.sort()
  603. axis.set_xlim(_x_limit)
  604. axis.set_ylim(_y_limit)
  605. text_x = _x_limit[0] + abs(_x_limit[0]) * 0.01
  606. text_y = _y_limit[1] - abs(_y_limit[1]) * 0.01
  607. init()
  608. # 函数绘图系统
  609. API.output_prompt_gui("图像绘制中...")
  610. if func is None:
  611. return False
  612. if draw_type in (0, 1, 4, 5):
  613. # 绘制曲线
  614. get = func.get_plot_data()
  615. plot_x = get[0]
  616. plot_y = get[1]
  617. func_label = get[2]
  618. exp_style = get[3]
  619. first = True
  620. for i in range(len(plot_x)):
  621. plot_x = plot_x[i]
  622. plot_y = plot_y[i]
  623. if first:
  624. plt.plot(plot_x, plot_y, exp_style, label=func_label) # plot()画出曲线
  625. first = False
  626. else:
  627. plt.plot(plot_x, plot_y, exp_style)
  628. # 绘制记忆点
  629. get = func.get_memory()
  630. plot_memory_x = get[0]
  631. plot_memory_y = get[1]
  632. max_x, max_y, min_x, min_y = func.best_value()
  633. if show_point.get():
  634. plt.plot(
  635. plot_memory_x,
  636. plot_memory_y,
  637. exp_style[0] + "o",
  638. label=f"Point of {func_label}",
  639. ) # 画出一些点
  640. memory_x = sorted(list(set(plot_memory_x))) # 去除list重复项目
  641. extreme_points = max_x + min_x
  642. if show_text.get():
  643. last_x = None
  644. for i in range(len(memory_x)):
  645. if i in extreme_points:
  646. continue # 去除极值点
  647. now_x = memory_x[i] # x
  648. if last_x is None or abs(now_x - last_x) >= 1: # 确保位置
  649. num = plot_memory_x.index(now_x) # y的座位
  650. now_y = plot_memory_y[num]
  651. plt.text(
  652. now_x,
  653. now_y,
  654. f"({now_x},{int(now_y)})",
  655. fontdict={"size": "10", "color": "b"},
  656. ) # 标出坐标
  657. last_x = now_x
  658. if show_best_value.get():
  659. last_x = None
  660. plot_max = []
  661. for i in range(len(max_x)): # 画出最大值
  662. now_x = max_x[i]
  663. if last_x is None or abs(now_x - last_x) >= 1: # 确保位置
  664. if show_text.get():
  665. plt.text(
  666. now_x - 1,
  667. max_y,
  668. f"max:({now_x},{int(max_y)})",
  669. fontdict={"size": "10", "color": "b"},
  670. ) # 标出坐标
  671. plot_max.append(now_x)
  672. last_x = now_x
  673. last_x = None
  674. plot_min = []
  675. for i in range(len(min_x)): # 画出最小值
  676. now_x = min_x[i]
  677. if last_x is None or abs(now_x - last_x) >= 1:
  678. plot_min.append(now_x)
  679. if show_text.get():
  680. plt.text(
  681. now_x - 1,
  682. min_y,
  683. f"min:({now_x},{int(min_y)})",
  684. fontdict={"size": "10", "color": "b"},
  685. ) # 标出坐标
  686. last_x = now_x
  687. plt.plot(plot_min, [min_y] * len(plot_min), exp_style[0] + "o") # 画出一些点
  688. plt.plot(plot_max, [max_y] * len(plot_max), exp_style[0] + "o") # 画出一些点
  689. plt.legend() # 显示图示
  690. elif draw_type in (8, 9):
  691. get = func.data_packet()
  692. plot_x = get[0]
  693. plot_y = get[1]
  694. plot_x_len = len(plot_x)
  695. x_data = []
  696. y_data = []
  697. func_label = get[2]
  698. exp_style = get[3]
  699. plot_ln = axis.plot([], [], exp_style, label=func_label, animated=False)[0]
  700. text = plt.text(text_x, text_y, "", fontdict={"size": "10", "color": "b"})
  701. def _init():
  702. init()
  703. return plot_ln, text
  704. def update(n):
  705. nonlocal x_data, y_data
  706. if n == 0:
  707. x_data = []
  708. y_data = []
  709. x_data.append(plot_x[n])
  710. y_data.append(plot_y[n])
  711. text.set_text(f"x={plot_x[n]},y={plot_y[n]}")
  712. plot_ln.set_data(x_data, y_data)
  713. return plot_ln, text
  714. try: # 自定义帧率
  715. frame = int(frame_rate.get())
  716. except ValueError:
  717. frame = 100
  718. FuncAnimation(
  719. fig,
  720. update,
  721. frames=plot_x_len,
  722. init_func=_init,
  723. interval=frame,
  724. blit=False,
  725. repeat_delay=3000,
  726. ) # 动态绘图
  727. elif draw_type in (2, 3, 6, 7):
  728. text = plt.text(text_x, text_y, "", fontdict={"size": "10", "color": "b"})
  729. all_func = func.return_son()
  730. func_cul_list = []
  731. plot_x_len = len(all_func)
  732. m = [] # 每个群组中fx分类的个数
  733. for i in all_func: # 预先生成函数
  734. API.output_prompt_gui(f"迭代计算中...(共{plot_x_len}次)")
  735. get = i.get_plot_data()
  736. m.append(len(get[0]))
  737. func_cul_list.append(get)
  738. func_cul_list += func_cul_list[::-1]
  739. ln_list = [text]
  740. for i in range(max(m)):
  741. ln_list.append(
  742. axis.plot([], [], func_cul_list[0][3], animated=False)[0]
  743. ) # 创建足够的i
  744. plot_x_len = len(func_cul_list)
  745. def _init():
  746. init()
  747. text.set_text("")
  748. return None
  749. def update(n):
  750. get_ = func_cul_list[n - 1]
  751. ln_list[0].set_text(get_[2])
  752. for i in range(max(m)):
  753. try:
  754. x = get_[0][i]
  755. y = get_[1][i]
  756. ln_list[i + 1].set_data(x, y)
  757. except IndexError:
  758. ln_list[i + 1].set_data([], [])
  759. return ln_list
  760. try: # 自定义帧率
  761. frame = int(frame_rate.get())
  762. except ValueError:
  763. frame = 100
  764. FuncAnimation(
  765. fig, update, frames=plot_x_len, init_func=_init, interval=frame, blit=False
  766. ) # 动态绘图
  767. API.output_prompt_gui("绘制完毕")
  768. plt.show() # 显示图像
  769. return True
  770. @staticmethod
  771. @exception_catch()
  772. def set_function():
  773. global func
  774. default_value = API.set_func_gui()
  775. try:
  776. func = ExpFunc(*default_value, have_son=True)
  777. API.output_prompt_gui("应用成功")
  778. SCREEN.title(f"CoTan函数工厂 {func}")
  779. except BaseException:
  780. API.output_prompt_gui("应用失败2")
  781. raise
  782. def function_factory_main(in_queue, out_queue): # H_S-默认函数GF-关闭时询问返回函数
  783. global SCREEN
  784. queue_controller.set_queue(in_queue, out_queue)
  785. queue_controller()
  786. SCREEN.mainloop()
  787. queue_controller.stop_process()
  788. SCREEN["bg"] = bg_color
  789. SCREEN.title("CoTan函数工厂")
  790. SCREEN.resizable(width=False, height=False)
  791. SCREEN.geometry("+10+10")
  792. SCREEN.iconbitmap(bitmap=f'Pic{os.sep}favicon.ico', default=f'Pic{os.sep}favicon.ico')
  793. FONT = (rf"Font{os.sep}ZKST.ttf", 11) # 设置字体
  794. rcParams["font.family"] = "simhei"
  795. rcParams["axes.unicode_minus"] = False
  796. tkinter.Label(
  797. SCREEN,
  798. text="输入解析式:",
  799. bg=bg_color,
  800. fg=word_color,
  801. font=FONT,
  802. width=gui_width,
  803. height=gui_height,
  804. ).grid(
  805. column=column, row=row
  806. ) # 设置说明
  807. func_exp = tkinter.Entry(SCREEN, width=gui_width * 2)
  808. func_exp.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  809. row += 1
  810. tkinter.Label(
  811. SCREEN,
  812. text="定义域前端点:",
  813. bg=bg_color,
  814. fg=word_color,
  815. font=FONT,
  816. width=gui_width,
  817. height=gui_height,
  818. ).grid(
  819. column=column, row=row
  820. ) # 设置说明
  821. start_definition = tkinter.Entry(SCREEN, width=gui_width * 2)
  822. start_definition.grid(
  823. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  824. )
  825. row += 1
  826. tkinter.Label(
  827. SCREEN,
  828. text="定义域后端点:",
  829. bg=bg_color,
  830. fg=word_color,
  831. font=FONT,
  832. width=gui_width,
  833. height=gui_height,
  834. ).grid(
  835. column=column, row=row
  836. ) # 设置说明
  837. end_definition = tkinter.Entry(SCREEN, width=gui_width * 2)
  838. end_definition.grid(
  839. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  840. )
  841. row += 1
  842. tkinter.Label(
  843. SCREEN,
  844. text="函数绘制跨度:",
  845. bg=bg_color,
  846. fg=word_color,
  847. font=FONT,
  848. width=gui_width,
  849. height=gui_height,
  850. ).grid(
  851. column=column, row=row
  852. ) # 设置说明
  853. span_definition = tkinter.Entry(SCREEN, width=gui_width * 2)
  854. span_definition.grid(
  855. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  856. )
  857. row += 1
  858. tkinter.Label(
  859. SCREEN,
  860. text="函数计算精度:",
  861. bg=bg_color,
  862. fg=word_color,
  863. font=FONT,
  864. width=gui_width,
  865. height=gui_height,
  866. ).grid(
  867. column=column, row=row
  868. ) # 设置说明
  869. accuracy = tkinter.Entry(SCREEN, width=gui_width * 2)
  870. accuracy.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  871. row += 1
  872. tkinter.Label(
  873. SCREEN,
  874. text="函数名字:",
  875. bg=bg_color,
  876. fg=word_color,
  877. font=FONT,
  878. width=gui_width,
  879. height=gui_height,
  880. ).grid(
  881. column=column, row=row
  882. ) # 设置说明
  883. func_name = tkinter.Entry(SCREEN, width=gui_width * 2)
  884. func_name.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  885. row += 1
  886. tkinter.Label(
  887. SCREEN,
  888. text="函数视图:",
  889. bg=bg_color,
  890. fg=word_color,
  891. font=FONT,
  892. width=gui_width,
  893. height=gui_height,
  894. ).grid(
  895. column=column, row=row
  896. ) # 设置说明
  897. func_style = tkinter.Entry(SCREEN, width=gui_width * 2)
  898. func_style.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  899. row += 1
  900. tkinter.Label(
  901. SCREEN,
  902. text="常量a默认值:",
  903. bg=bg_color,
  904. fg=word_color,
  905. font=FONT,
  906. width=gui_width,
  907. height=gui_height,
  908. ).grid(
  909. column=column, row=row
  910. ) # 设置说明
  911. default_a = tkinter.Entry(SCREEN, width=gui_width * 2)
  912. default_a.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  913. row += 1
  914. tkinter.Label(
  915. SCREEN,
  916. text="常量a起点:",
  917. bg=bg_color,
  918. fg=word_color,
  919. font=FONT,
  920. width=gui_width,
  921. height=gui_height,
  922. ).grid(
  923. column=column, row=row
  924. ) # 设置说明
  925. start_a = tkinter.Entry(SCREEN, width=gui_width * 2)
  926. start_a.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  927. row += 1
  928. tkinter.Label(
  929. SCREEN,
  930. text="常量a终点:",
  931. bg=bg_color,
  932. fg=word_color,
  933. font=FONT,
  934. width=gui_width,
  935. height=gui_height,
  936. ).grid(
  937. column=column, row=row
  938. ) # 设置说明
  939. end_a = tkinter.Entry(SCREEN, width=gui_width * 2)
  940. end_a.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  941. row += 1
  942. tkinter.Label(
  943. SCREEN,
  944. text="常量a跨度:",
  945. bg=bg_color,
  946. fg=word_color,
  947. font=FONT,
  948. width=gui_width,
  949. height=gui_height,
  950. ).grid(
  951. column=column, row=row
  952. ) # 设置说明
  953. span_a = tkinter.Entry(SCREEN, width=gui_width * 2)
  954. span_a.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  955. row += 1
  956. tkinter.Button(
  957. SCREEN,
  958. bg=botton_color,
  959. fg=word_color,
  960. text="应用函数",
  961. command=API.set_function,
  962. font=FONT,
  963. width=gui_width,
  964. height=gui_height,
  965. ).grid(
  966. column=column, row=row, sticky=tkinter.E + tkinter.W
  967. ) # 添加函数
  968. tkinter.Button(
  969. SCREEN,
  970. bg=botton_color,
  971. fg=word_color,
  972. text="绘制图像",
  973. command=API.function_drawing,
  974. font=FONT,
  975. width=gui_width,
  976. height=gui_height,
  977. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  978. tkinter.Button(
  979. SCREEN,
  980. bg=botton_color,
  981. fg=word_color,
  982. text="性质预测",
  983. command=API.property_prediction,
  984. font=FONT,
  985. width=gui_width,
  986. height=gui_height,
  987. ).grid(
  988. column=column + 2, row=row, sticky=tkinter.E + tkinter.W
  989. ) # 添加函数
  990. row += 1
  991. tkinter.Label(
  992. SCREEN,
  993. text="预测精度:",
  994. bg=bg_color,
  995. fg=word_color,
  996. font=FONT,
  997. width=gui_width,
  998. height=gui_height,
  999. ).grid(
  1000. column=column, row=row
  1001. ) # 设置说明
  1002. prediction_accuracy = tkinter.Entry(SCREEN, width=gui_width * 2)
  1003. prediction_accuracy.grid(
  1004. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1005. )
  1006. row += 1
  1007. # 显示函数的xy
  1008. prediction_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height*5) # 暂时不启用多选
  1009. prediction_box.grid(
  1010. column=column,
  1011. row=row,
  1012. columnspan=3,
  1013. rowspan=5,
  1014. sticky=tkinter.S + tkinter.N + tkinter.E + tkinter.W,
  1015. )
  1016. column += 3
  1017. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  1018. column=column, row=0
  1019. ) # 设置说明
  1020. # 第二排的开始
  1021. column += 1
  1022. row = 0
  1023. tkinter.Label(
  1024. SCREEN,
  1025. text="X轴刻度声明:",
  1026. bg=bg_color,
  1027. fg=word_color,
  1028. font=FONT,
  1029. width=gui_width,
  1030. height=gui_height,
  1031. ).grid(
  1032. column=column, row=row
  1033. ) # 设置说明
  1034. x_scale = tkinter.Entry(SCREEN, width=gui_width * 2)
  1035. x_scale.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1036. row += 1
  1037. tkinter.Label(
  1038. SCREEN,
  1039. text="X轴刻度起点:",
  1040. bg=bg_color,
  1041. fg=word_color,
  1042. font=FONT,
  1043. width=gui_width,
  1044. height=gui_height,
  1045. ).grid(
  1046. column=column, row=row
  1047. ) # 设置说明
  1048. start_x_plot = tkinter.Entry(SCREEN, width=gui_width * 2)
  1049. start_x_plot.grid(
  1050. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1051. )
  1052. row += 1
  1053. tkinter.Label(
  1054. SCREEN,
  1055. text="X轴刻度终点:",
  1056. bg=bg_color,
  1057. fg=word_color,
  1058. font=FONT,
  1059. width=gui_width,
  1060. height=gui_height,
  1061. ).grid(
  1062. column=column, row=row
  1063. ) # 设置说明
  1064. start_x_polt = tkinter.Entry(SCREEN, width=gui_width * 2)
  1065. start_x_polt.grid(
  1066. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1067. )
  1068. row += 1
  1069. tkinter.Label(
  1070. SCREEN,
  1071. text="X轴刻度间隔:",
  1072. bg=bg_color,
  1073. fg=word_color,
  1074. font=FONT,
  1075. width=gui_width,
  1076. height=gui_height,
  1077. ).grid(
  1078. column=column, row=row
  1079. ) # 设置说明
  1080. span_x_plot = tkinter.Entry(SCREEN, width=gui_width * 2)
  1081. span_x_plot.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1082. row += 1
  1083. tkinter.Label(
  1084. SCREEN,
  1085. text="Y轴刻度声明:",
  1086. bg=bg_color,
  1087. fg=word_color,
  1088. font=FONT,
  1089. width=gui_width,
  1090. height=gui_height,
  1091. ).grid(
  1092. column=column, row=row
  1093. ) # 设置说明
  1094. y_scale = tkinter.Entry(SCREEN, width=gui_width * 2)
  1095. y_scale.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1096. row += 1
  1097. tkinter.Label(
  1098. SCREEN,
  1099. text="Y轴刻度起点:",
  1100. bg=bg_color,
  1101. fg=word_color,
  1102. font=FONT,
  1103. width=gui_width,
  1104. height=gui_height,
  1105. ).grid(
  1106. column=column, row=row
  1107. ) # 设置说明
  1108. start_y_plot = tkinter.Entry(SCREEN, width=gui_width * 2)
  1109. start_y_plot.grid(
  1110. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1111. )
  1112. row += 1
  1113. tkinter.Label(
  1114. SCREEN,
  1115. text="Y轴刻度终点:",
  1116. bg=bg_color,
  1117. fg=word_color,
  1118. font=FONT,
  1119. width=gui_width,
  1120. height=gui_height,
  1121. ).grid(
  1122. column=column, row=row
  1123. ) # 设置说明
  1124. end_y_plot = tkinter.Entry(SCREEN, width=gui_width * 2)
  1125. end_y_plot.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1126. row += 1
  1127. tkinter.Label(
  1128. SCREEN,
  1129. text="Y轴刻度间隔:",
  1130. bg=bg_color,
  1131. fg=word_color,
  1132. font=FONT,
  1133. width=gui_width,
  1134. height=gui_height,
  1135. ).grid(
  1136. column=column, row=row
  1137. ) # 设置说明
  1138. span_y_plot = tkinter.Entry(SCREEN, width=gui_width * 2)
  1139. span_y_plot.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1140. row += 1
  1141. tkinter.Label(
  1142. SCREEN,
  1143. text="X轴显示起点:",
  1144. bg=bg_color,
  1145. fg=word_color,
  1146. font=FONT,
  1147. width=gui_width,
  1148. height=gui_height,
  1149. ).grid(
  1150. column=column, row=row
  1151. ) # 设置说明
  1152. start_x_limit = tkinter.Entry(SCREEN, width=gui_width * 2)
  1153. start_x_limit.grid(
  1154. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1155. )
  1156. row += 1
  1157. tkinter.Label(
  1158. SCREEN,
  1159. text="X轴显示终点:",
  1160. bg=bg_color,
  1161. fg=word_color,
  1162. font=FONT,
  1163. width=gui_width,
  1164. height=gui_height,
  1165. ).grid(
  1166. column=column, row=row
  1167. ) # 设置说明
  1168. end_x_limit = tkinter.Entry(SCREEN, width=gui_width * 2)
  1169. end_x_limit.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1170. row += 1
  1171. tkinter.Label(
  1172. SCREEN,
  1173. text="Y轴显示起点:",
  1174. bg=bg_color,
  1175. fg=word_color,
  1176. font=FONT,
  1177. width=gui_width,
  1178. height=gui_height,
  1179. ).grid(
  1180. column=column, row=row
  1181. ) # 设置说明
  1182. start_y_limit = tkinter.Entry(SCREEN, width=gui_width * 2)
  1183. start_y_limit.grid(
  1184. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1185. )
  1186. row += 1
  1187. tkinter.Label(
  1188. SCREEN,
  1189. text="Y轴显示终点:",
  1190. bg=bg_color,
  1191. fg=word_color,
  1192. font=FONT,
  1193. width=gui_width,
  1194. height=gui_height,
  1195. ).grid(
  1196. column=column, row=row
  1197. ) # 设置说明
  1198. end_y_limit = tkinter.Entry(SCREEN, width=gui_width * 2)
  1199. end_y_limit.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1200. row += 1
  1201. tkinter.Label(
  1202. SCREEN,
  1203. text="帧率(帧/ms):",
  1204. bg=bg_color,
  1205. fg=word_color,
  1206. font=FONT,
  1207. width=gui_width,
  1208. height=gui_height,
  1209. ).grid(
  1210. column=column, row=row
  1211. ) # 设置说明
  1212. frame_rate = tkinter.Entry(SCREEN, width=gui_width * 2)
  1213. frame_rate.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1214. row += 1
  1215. show_point = tkinter.IntVar()
  1216. show_best_value = tkinter.IntVar()
  1217. show_text = tkinter.IntVar()
  1218. tkinter.Checkbutton(
  1219. SCREEN,
  1220. bg=bg_color,
  1221. fg=word_color,
  1222. activebackground=bg_color,
  1223. activeforeground=word_color,
  1224. selectcolor=bg_color,
  1225. text="显示记忆点",
  1226. variable=show_point,
  1227. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1228. tkinter.Checkbutton(
  1229. SCREEN,
  1230. bg=bg_color,
  1231. fg=word_color,
  1232. activebackground=bg_color,
  1233. activeforeground=word_color,
  1234. selectcolor=bg_color,
  1235. text="显示最值",
  1236. variable=show_best_value,
  1237. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1238. tkinter.Checkbutton(
  1239. SCREEN,
  1240. bg=bg_color,
  1241. fg=word_color,
  1242. activebackground=bg_color,
  1243. activeforeground=word_color,
  1244. selectcolor=bg_color,
  1245. text="显示文字",
  1246. variable=show_text,
  1247. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1248. row += 1
  1249. # 显示函数的xy
  1250. plot_type = tkinter.Listbox(
  1251. SCREEN, width=gui_width * 3, height=gui_height * 4
  1252. ) # 暂时不启用多选
  1253. plot_type.grid(
  1254. column=column,
  1255. row=row,
  1256. columnspan=3,
  1257. rowspan=3,
  1258. sticky=tkinter.S + tkinter.N + tkinter.E + tkinter.W,
  1259. )
  1260. plot_type.insert(
  1261. tkinter.END,
  1262. *[
  1263. "笛卡尔坐标系静态图像(默认)",
  1264. "矩形坐标系静态图像",
  1265. "笛卡尔坐标系动态图像",
  1266. "矩形坐标系动态图像",
  1267. "笛卡尔坐标系静态图像(无线框)",
  1268. "矩形坐标系静态图像(无线框)",
  1269. "笛卡尔坐标系动态图像(无线框)",
  1270. "矩形坐标系动态图像(无线框)",
  1271. "笛卡尔坐标系动态画图",
  1272. "矩形坐标系动态画图",
  1273. ],
  1274. )
  1275. row += 3
  1276. # 显示函数的xy
  1277. prompt_box = tkinter.Listbox(
  1278. SCREEN, width=gui_width * 3, height=gui_height*1) # 暂时不启用多选
  1279. prompt_box.grid(
  1280. column=column,
  1281. row=row,
  1282. columnspan=3,
  1283. rowspan=1,
  1284. sticky=tkinter.S + tkinter.N + tkinter.E + tkinter.W,
  1285. )
  1286. column += 3
  1287. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  1288. column=column, row=0
  1289. ) # 设置说明
  1290. column += 1
  1291. row = 0
  1292. tkinter.Label(
  1293. SCREEN,
  1294. text="计算(y):",
  1295. bg=bg_color,
  1296. fg=word_color,
  1297. font=FONT,
  1298. width=gui_width,
  1299. height=gui_height,
  1300. ).grid(
  1301. column=column, row=row
  1302. ) # 设置说明
  1303. x_value = tkinter.Entry(SCREEN, width=gui_width * 2)
  1304. x_value.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1305. row += 1
  1306. tkinter.Label(
  1307. SCREEN,
  1308. text="二分法计算(x):",
  1309. bg=bg_color,
  1310. fg=word_color,
  1311. font=FONT,
  1312. width=gui_width,
  1313. height=gui_height,
  1314. ).grid(
  1315. column=column, row=row
  1316. ) # 设置说明
  1317. y_value = tkinter.Entry(SCREEN, width=gui_width * 2)
  1318. y_value.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1319. dicon_parameters = [] # 二分法参数输入
  1320. name_list = [
  1321. "最大迭代数",
  1322. "计算精度",
  1323. "最值允许偏移量",
  1324. "零点最小间隔",
  1325. "减少计算",
  1326. "允许梯度计算",
  1327. "最大扩张深度",
  1328. "扩张限制",
  1329. "扩张偏移量",
  1330. "开启二级验证",
  1331. "二级验证程度",
  1332. ]
  1333. for i in range(11):
  1334. row += 1
  1335. dicon_parameters.append(tkinter.StringVar())
  1336. tkinter.Label(
  1337. SCREEN,
  1338. bg=bg_color,
  1339. fg=word_color,
  1340. text=name_list[i] + ":",
  1341. font=FONT,
  1342. width=gui_width,
  1343. height=gui_height,
  1344. ).grid(
  1345. column=column, row=row
  1346. ) # 设置说明
  1347. tkinter.Entry(SCREEN, width=gui_width * 2, textvariable=dicon_parameters[-1]).grid(
  1348. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1349. )
  1350. row += 1
  1351. tkinter.Label(
  1352. SCREEN,
  1353. text="梯度法计算(x):",
  1354. bg=bg_color,
  1355. fg=word_color,
  1356. font=FONT,
  1357. width=gui_width,
  1358. height=gui_height,
  1359. ).grid(
  1360. column=column, row=row
  1361. ) # 设置说明
  1362. y_value_gradient = tkinter.Entry(SCREEN, width=gui_width * 2)
  1363. y_value_gradient.grid(
  1364. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1365. )
  1366. gradient_parameters = [] # 梯度法法参数输入
  1367. name_list = ["梯度起点", "梯度终点", "计算深度", "计算精度"]
  1368. for i in range(4):
  1369. row += 1
  1370. gradient_parameters.append(tkinter.StringVar())
  1371. tkinter.Label(
  1372. SCREEN,
  1373. bg=bg_color,
  1374. fg=word_color,
  1375. text=name_list[i] + ":",
  1376. font=FONT,
  1377. width=gui_width,
  1378. height=gui_height,
  1379. ).grid(
  1380. column=column, row=row
  1381. ) # 设置说明
  1382. tkinter.Entry(
  1383. SCREEN, width=gui_width * 2, textvariable=gradient_parameters[-1]
  1384. ).grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1385. column += 3
  1386. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  1387. column=column, row=0
  1388. ) # 设置说明
  1389. column += 1
  1390. row = 0
  1391. tkinter.Label(
  1392. SCREEN,
  1393. text="代数法计算(x):",
  1394. bg=bg_color,
  1395. fg=word_color,
  1396. font=FONT,
  1397. width=gui_width,
  1398. height=gui_height,
  1399. ).grid(
  1400. column=column, row=row
  1401. ) # 设置说明
  1402. y_value_symbol = tkinter.Entry(SCREEN, width=gui_width * 2)
  1403. y_value_symbol.grid(
  1404. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1405. )
  1406. row += 1
  1407. tkinter.Label(
  1408. SCREEN,
  1409. text="求(x)导数:",
  1410. bg=bg_color,
  1411. fg=word_color,
  1412. font=FONT,
  1413. width=gui_width,
  1414. height=gui_height,
  1415. ).grid(
  1416. column=column, row=row
  1417. ) # 设置说明
  1418. x_value_derivation = tkinter.Entry(SCREEN, width=gui_width * 2)
  1419. x_value_derivation.grid(
  1420. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1421. )
  1422. row += 1
  1423. tkinter.Label(
  1424. SCREEN,
  1425. text="逼近求导精度:",
  1426. bg=bg_color,
  1427. fg=word_color,
  1428. font=FONT,
  1429. width=gui_width,
  1430. height=gui_height,
  1431. ).grid(
  1432. column=column, row=row
  1433. ) # 设置说明
  1434. proximity_accuracy = tkinter.Entry(SCREEN, width=gui_width * 2)
  1435. proximity_accuracy.grid(
  1436. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1437. )
  1438. row += 1
  1439. tkinter.Button(
  1440. SCREEN,
  1441. bg=botton_color,
  1442. fg=word_color,
  1443. text="计算(y)",
  1444. command=API.calculate,
  1445. font=FONT,
  1446. width=gui_width,
  1447. height=gui_height,
  1448. ).grid(
  1449. column=column, row=row
  1450. ) # 设置说明
  1451. tkinter.Button(
  1452. SCREEN,
  1453. bg=botton_color,
  1454. fg=word_color,
  1455. text="二分法计算(x)",
  1456. command=API.dichotomy,
  1457. font=FONT,
  1458. width=gui_width,
  1459. height=gui_height,
  1460. ).grid(column=column + 1, row=row)
  1461. tkinter.Button(
  1462. SCREEN,
  1463. bg=botton_color,
  1464. fg=word_color,
  1465. text="梯度法计算(x)",
  1466. command=API.gradient_method_calculation,
  1467. font=FONT,
  1468. width=gui_width,
  1469. height=gui_height,
  1470. ).grid(column=column + 2, row=row)
  1471. row += 1
  1472. tkinter.Button(
  1473. SCREEN,
  1474. bg=botton_color,
  1475. fg=word_color,
  1476. text="代数法计算",
  1477. command=API.sympy_calculation_x,
  1478. font=FONT,
  1479. width=gui_width,
  1480. height=gui_height,
  1481. ).grid(column=column, row=row, sticky=tkinter.N + tkinter.E + tkinter.W)
  1482. tkinter.Button(
  1483. SCREEN,
  1484. bg=botton_color,
  1485. fg=word_color,
  1486. text="逼近法导数计算",
  1487. command=API.approximation,
  1488. font=FONT,
  1489. width=gui_width,
  1490. height=gui_height,
  1491. ).grid(column=column + 1, row=row, sticky=tkinter.N + tkinter.E + tkinter.W)
  1492. tkinter.Button(
  1493. SCREEN,
  1494. bg=botton_color,
  1495. fg=word_color,
  1496. text="导数计算",
  1497. command=API.function_differentiation,
  1498. font=FONT,
  1499. width=gui_width,
  1500. height=gui_height,
  1501. ).grid(column=column + 2, row=row, sticky=tkinter.N + tkinter.E + tkinter.W)
  1502. row += 1
  1503. k = 5
  1504. result_box = tkinter.Listbox(SCREEN, height=gui_height * (k - 1)) # 暂时不启用多选
  1505. result_box.grid(
  1506. column=column,
  1507. row=row,
  1508. columnspan=3,
  1509. rowspan=k,
  1510. sticky=tkinter.N + tkinter.E + tkinter.W,
  1511. )
  1512. row += k - 1
  1513. tkinter.Label(
  1514. SCREEN,
  1515. text="性质预测值:",
  1516. bg=bg_color,
  1517. fg=word_color,
  1518. font=FONT,
  1519. width=gui_width,
  1520. height=gui_height,
  1521. ).grid(
  1522. column=column, row=row, sticky=tkinter.N + tkinter.S
  1523. ) # 设置说明
  1524. projection_value = tkinter.Entry(SCREEN, width=gui_width * 2)
  1525. projection_value.grid(
  1526. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1527. )
  1528. row += 1
  1529. tkinter.Button(
  1530. SCREEN,
  1531. bg=botton_color,
  1532. fg=word_color,
  1533. text="周期性",
  1534. command=API.check_periodic,
  1535. font=FONT,
  1536. width=gui_width,
  1537. height=gui_height,
  1538. ).grid(column=column, row=row, sticky=tkinter.N + tkinter.E + tkinter.W)
  1539. tkinter.Button(
  1540. SCREEN,
  1541. bg=botton_color,
  1542. fg=word_color,
  1543. text="对称轴",
  1544. command=API.check_symmetry_axis,
  1545. font=FONT,
  1546. width=gui_width,
  1547. height=gui_height,
  1548. ).grid(column=column + 1, row=row, sticky=tkinter.N + tkinter.E + tkinter.W)
  1549. tkinter.Button(
  1550. SCREEN,
  1551. bg=botton_color,
  1552. fg=word_color,
  1553. text="对称中心",
  1554. command=API.check_center_of_symmetry,
  1555. font=FONT,
  1556. width=gui_width,
  1557. height=gui_height,
  1558. ).grid(column=column + 2, row=row, sticky=tkinter.N + tkinter.E + tkinter.W)
  1559. row += 1
  1560. tkinter.Button(
  1561. SCREEN,
  1562. bg=botton_color,
  1563. fg=word_color,
  1564. text="单调性",
  1565. command=API.check_monotonic,
  1566. font=FONT,
  1567. width=gui_width,
  1568. height=gui_height,
  1569. ).grid(column=column, row=row, columnspan=3, sticky=tkinter.N + tkinter.E + tkinter.W)
  1570. row += 1
  1571. # 显示函数的xy
  1572. projection_box = tkinter.Listbox(
  1573. SCREEN, width=gui_width * 3, height=gui_height*6
  1574. ) # 暂时不启用多选
  1575. projection_box.grid(
  1576. column=column,
  1577. row=row,
  1578. columnspan=3,
  1579. rowspan=6,
  1580. sticky=tkinter.S + tkinter.N + tkinter.E + tkinter.W,
  1581. )
  1582. column += 3
  1583. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  1584. column=column, row=0
  1585. ) # 设置说明
  1586. column += 1
  1587. row = 0
  1588. tkinter.Button(
  1589. SCREEN,
  1590. bg=botton_color,
  1591. fg=word_color,
  1592. text="生成表格",
  1593. command=API.save_to_sheet,
  1594. font=FONT,
  1595. width=gui_width * 2,
  1596. height=gui_height,
  1597. ).grid(column=column, row=row, columnspan=2)
  1598. tkinter.Button(
  1599. SCREEN,
  1600. bg=botton_color,
  1601. fg=word_color,
  1602. text="导出表格",
  1603. command=API.save_to_csv,
  1604. font=FONT,
  1605. width=gui_width,
  1606. height=gui_height,
  1607. ).grid(column=column + 2, row=row)
  1608. row += 1
  1609. # 显示函数的xy
  1610. sheet_box = tkinter.Listbox(SCREEN, width=gui_width * 3) # 暂时不启用多选
  1611. sheet_box.grid(
  1612. column=column,
  1613. row=row,
  1614. columnspan=3,
  1615. rowspan=17,
  1616. sticky=tkinter.S + tkinter.N + tkinter.E + tkinter.W,
  1617. )
  1618. API.output_prompt_gui("加载完毕")