factory.py 49 KB

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