gui.py 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  1. import time
  2. import threading
  3. import tkinter
  4. import os
  5. import tkinter.messagebox
  6. from tkinter import ttk
  7. from newtkinter import asksaveasfilename, askdirectory, askopenfilenames
  8. from tkinter.scrolledtext import ScrolledText
  9. import gitrepo.template
  10. from gitrepo import controller
  11. class UIAPI:
  12. @staticmethod
  13. def cli_gui(
  14. func,
  15. args,
  16. name="CoTan Git",
  17. break_time=0,
  18. show_screen=True,
  19. tip_text="",
  20. is_threaded_refresh=False,
  21. is_asynchronous_display=False,
  22. ):
  23. command_thread = func(*args)
  24. format_flat = True
  25. stop_key = gitrepo.template.stop_key
  26. def save_to_txt():
  27. nonlocal data
  28. dic = asksaveasfilename(title="选择文件保存位置", filetypes=[("TXT", ".txt")])
  29. try:
  30. if dic == "":
  31. return False
  32. if dic[-4] == ".txt":
  33. pass
  34. else:
  35. raise Exception
  36. except BaseException:
  37. dic += ".txt"
  38. with open(dic, "w", encoding="utf-8") as f:
  39. f.write(data)
  40. keep_button = True
  41. stop_button = True
  42. def update_button():
  43. if not keep_button:
  44. button_list[1].config(state=tkinter.DISABLED)
  45. if not stop_button:
  46. button_list[0].config(state=tkinter.DISABLED)
  47. def stop():
  48. nonlocal start, keep_button, stop_button
  49. start = 0
  50. stop_button = False
  51. keep_button = False
  52. update_button()
  53. def keep():
  54. nonlocal start, keep_button
  55. start = float("inf")
  56. keep_button = False
  57. update_button()
  58. def pipe():
  59. pass
  60. def format():
  61. nonlocal text, out_data, data, format_flat
  62. text.clear()
  63. if format_flat:
  64. text.insert(tkinter.END, data)
  65. else:
  66. text.insert(tkinter.END, out_data)
  67. format_flat = not format_flat
  68. start = time.time()
  69. data = ""
  70. out_data = "" # 包含out的data
  71. if show_screen:
  72. text, cli_screen, button_list = API.show_cli_gui(
  73. save_to_txt, stop, keep, format, pipe, name=name
  74. ) # [close,keep]
  75. update_button()
  76. if tip_text != "":
  77. text.insert("0.0", f"载入前提示>>> {tip_text}\n")
  78. out_data += f"载入前提示>>> {tip_text}\n"
  79. data += f"{tip_text}\n"
  80. cli_screen.update()
  81. else:
  82. class TkNone:
  83. def title(self, *args, **kwargs):
  84. return
  85. def insert(self, *args, **kwargs):
  86. return
  87. def update(self, *args, **kwargs):
  88. return
  89. def config(self, *args, **kwargs):
  90. return
  91. text = TkNone()
  92. cli_screen = TkNone()
  93. button_list = [TkNone(), TkNone()]
  94. u = threading.Thread(target=API.progress_bar_gui)
  95. u.start()
  96. SCREEN.update()
  97. def update_screen():
  98. nonlocal start
  99. while True:
  100. try:
  101. SCREEN.update()
  102. if show_screen:
  103. try:
  104. cli_screen.update()
  105. except BaseException:
  106. pass
  107. if time.time() - start >= break_time != 0:
  108. raise Exception
  109. elif break_time == 0 and start == 0:
  110. raise Exception
  111. except BaseException:
  112. start = 0
  113. break
  114. if is_threaded_refresh or not is_asynchronous_display:
  115. # 如果没有启动到多进程的效果,请检查Update是不是加了(),这里需要回调
  116. threaded_update = threading.Thread(target=update_screen)
  117. threaded_update.start()
  118. if is_asynchronous_display: # 等待后显示
  119. if break_time == 0:
  120. break_ti = None # 此处break_ti是为了别面覆盖break_time,因为Update进程需要用
  121. else:
  122. break_ti = break_time
  123. def wait_command_thread():
  124. nonlocal start
  125. command_thread.wait(break_ti)
  126. start = 0
  127. threaded_update = threading.Thread(
  128. target=wait_command_thread
  129. ) # 这么做不是多此一举,如果没有wait,进程并不会退出
  130. threaded_update.start()
  131. update_screen() # 遇到sleep等主线程阻塞,top.update等会阻塞子线程,因此,必须保证主线程不会被wait所阻塞
  132. out = command_thread.stdout.read().split("\n")
  133. for i in out:
  134. if not show_screen:
  135. break
  136. try: # 如果界面被关掉了,会报错
  137. cli_screen.title(f"{name} : 运行中")
  138. except BaseException:
  139. text, cli_screen, button_list = API.show_cli_gui(
  140. save_to_txt, stop, keep, format, pipe, name=f"{name} : 运行中"
  141. )
  142. update_button()
  143. text.insert(tkinter.END, out_data)
  144. if stop and i.replace(" ", "").replace("\n", "") != stop_key:
  145. text.insert(tkinter.END, f"[out]> {i}\n")
  146. data += i + "\n"
  147. out_data += f"[out]> {i}\n"
  148. else:
  149. text.insert(tkinter.END, "[END]")
  150. out_data += f"[END]"
  151. data += f"[END]"
  152. start = 0
  153. else: # 即时显示
  154. while True:
  155. # 界面设置
  156. try: # 如果界面被关掉了,会报错
  157. cli_screen.title(f"{name} : 运行中")
  158. except BaseException:
  159. text, cli_screen, button_list = API.show_cli_gui(
  160. save_to_txt, stop, keep, format, pipe, name=f"{name} : 运行中"
  161. )
  162. update_button()
  163. text.insert(tkinter.END, out_data)
  164. # 界面刷新
  165. try:
  166. if not is_threaded_refresh:
  167. SCREEN.update()
  168. cli_screen.update()
  169. except BaseException:
  170. break
  171. # 输出字符
  172. try:
  173. # .decode(str_code)#不需要decode,因为Popen已经设置了universal_newlines=True
  174. i = command_thread.stdout.readline()
  175. bool_text = i.replace(" ", "").replace("\n", "")
  176. if bool_text != "":
  177. if stop and bool_text == stop_key:
  178. start = 0
  179. else:
  180. text.insert(tkinter.END, f"[out]> {i}")
  181. data += i
  182. out_data += f"[out]> {i}"
  183. if (
  184. command_thread.returncode == 0
  185. or (time.time() - start >= break_time != 0)
  186. or (break_time == 0 and start == 0)
  187. ):
  188. text.insert(tkinter.END, "[END]")
  189. out_data += f"[END]"
  190. data += f"[END]"
  191. break
  192. elif command_thread.returncode is not None:
  193. raise Exception
  194. except BaseException:
  195. try:
  196. if show_screen:
  197. text.insert(tkinter.END, "[ERROR]")
  198. out_data += f"[ERROR]"
  199. data += f"[ERROR]"
  200. raise Exception
  201. except BaseException:
  202. break
  203. try: # 如果界面被关掉了,会报错
  204. if show_screen:
  205. cli_screen.title(f"{name} : 运行完毕")
  206. except BaseException:
  207. pass
  208. command_thread.kill()
  209. try:
  210. button_list[0].config(state=tkinter.DISABLED)
  211. button_list[1].config(state=tkinter.DISABLED)
  212. except BaseException:
  213. pass
  214. return data
  215. @staticmethod
  216. def progress_bar_gui(*args, name="CoTan_Git >>> 运行中...", **kwargs):
  217. progress_screen = tkinter.Toplevel(bg=bg_color)
  218. progress_screen.title(name)
  219. progress_screen.geometry("+10+10") # 设置所在位置
  220. mpb = ttk.Progressbar(
  221. progress_screen, orient="horizontal", length=300, mode="determinate"
  222. )
  223. mpb.pack()
  224. progress_screen.resizable(width=False, height=False)
  225. mpb["maximum"] = 50
  226. mpb["value"] = 0
  227. for i in range(50):
  228. mpb["value"] = i + 1
  229. progress_screen.update()
  230. SCREEN.update()
  231. time.sleep(0.001)
  232. progress_screen.destroy()
  233. @staticmethod
  234. def get_commit_id_gui():
  235. global commit
  236. the_commit = commit.get()
  237. return the_commit
  238. @staticmethod
  239. def show_cli_gui(
  240. out_func, close_func, keep_func, not_out, pipe_func, name="CoTan_Git >>> 命令行"
  241. ):
  242. global bg_color
  243. cli_screen = tkinter.Toplevel(bg=bg_color)
  244. cli_screen.title(name)
  245. cli_screen.geometry("+10+10") # 设置所在位置
  246. cli_screen.resizable(width=False, height=False)
  247. class ScrolledCli(ScrolledText):
  248. def __init__(self, *args, **kwargs):
  249. super(ScrolledCli, self).__init__(*args, **kwargs)
  250. def insert(self, index, chars, *args):
  251. text.config(state=tkinter.NORMAL)
  252. super(ScrolledCli, self).insert(index, chars, *args)
  253. text.config(state=tkinter.DISABLED)
  254. def clear(self):
  255. text.config(state=tkinter.NORMAL)
  256. self.delete("0.0", tkinter.END)
  257. text.config(state=tkinter.DISABLED)
  258. text = ScrolledCli(cli_screen, font=("黑体", 11), height=30, width=100)
  259. text.grid(column=0, row=0, columnspan=5, sticky=tkinter.E + tkinter.W)
  260. text.config(state=tkinter.DISABLED)
  261. tkinter.Button(
  262. cli_screen,
  263. bg=bg_color,
  264. fg=word_color,
  265. text="输出文档",
  266. font=("黑体", 11),
  267. width=20,
  268. height=2,
  269. command=out_func,
  270. ).grid(column=4, row=1, sticky=tkinter.E + tkinter.W)
  271. close = tkinter.Button(
  272. cli_screen,
  273. bg=bg_color,
  274. fg=word_color,
  275. text="关闭子线程连接",
  276. font=("黑体", 11),
  277. width=20,
  278. height=2,
  279. command=close_func,
  280. )
  281. close.grid(column=0, row=1, sticky=tkinter.E + tkinter.W)
  282. keep = tkinter.Button(
  283. cli_screen,
  284. bg=bg_color,
  285. fg=word_color,
  286. text="保持线程连接",
  287. font=("黑体", 11),
  288. width=20,
  289. height=2,
  290. command=keep_func,
  291. )
  292. keep.grid(column=1, row=1, sticky=tkinter.E + tkinter.W)
  293. tkinter.Button(
  294. cli_screen,
  295. bg=bg_color,
  296. fg=word_color,
  297. text="格式化输出",
  298. font=("黑体", 11),
  299. width=20,
  300. height=2,
  301. command=not_out,
  302. ).grid(column=2, row=1, sticky=tkinter.E + tkinter.W)
  303. tkinter.Button(
  304. cli_screen,
  305. bg=bg_color,
  306. fg=word_color,
  307. text="启动CoTan命令行",
  308. font=("黑体", 11),
  309. width=20,
  310. height=2,
  311. command=pipe_func,
  312. state=tkinter.DISABLED,
  313. ).grid(column=3, row=1, sticky=tkinter.E + tkinter.W)
  314. cli_screen.update()
  315. return text, cli_screen, [close, keep]
  316. @staticmethod
  317. def repo_init_gui():
  318. new_dir = askdirectory(title="选择仓库地址")
  319. if new_dir == "":
  320. raise Exception
  321. return new_dir
  322. @staticmethod
  323. def get_repo_name_gui(): # 获得名字统一接口
  324. global git, repo_list, repo_box
  325. try:
  326. return repo_list[repo_box.curselection()[0]]
  327. except BaseException:
  328. try:
  329. return repo_list[0]
  330. except BaseException:
  331. return None
  332. @staticmethod
  333. def update_repo_box_gui():
  334. global git, repo_list, repo_box
  335. repo_list = list(git.get_git_dict().keys())
  336. repo_box.delete(0, tkinter.END)
  337. repo_box.insert(tkinter.END, *repo_list)
  338. @staticmethod
  339. def update_file_box_gui():
  340. global file_list, file_box
  341. file_box.delete(0, tkinter.END)
  342. file_box.insert(tkinter.END, *file_list)
  343. @staticmethod
  344. def update_git_file_last_gui():
  345. global last_name
  346. if last_name is None:
  347. return False
  348. API.update_git_file_gui(last_name)
  349. @staticmethod
  350. def update_git_file_select_gui():
  351. name = API.get_repo_name_gui()
  352. API.update_git_file_gui(name)
  353. @staticmethod
  354. def update_git_file_gui(name):
  355. global git, repo_dir, last_name
  356. dir_list = git.get_dir(name)
  357. try: # 窗口可能已经关闭
  358. repo_dir.delete(0, tkinter.END)
  359. repo_dir.insert(tkinter.END, *dir_list)
  360. except BaseException:
  361. pass
  362. last_name = name
  363. @staticmethod
  364. def add_file_list_gui():
  365. global file_list, file_box
  366. new_file = set(askopenfilenames(title=f"选择文件"))
  367. have_file = set(file_list)
  368. file_list += list(new_file - (new_file & have_file)) # 筛选出重复
  369. API.update_file_box_gui()
  370. @staticmethod
  371. def add_file_input_dir_gui():
  372. global file_dir
  373. new_dir = file_dir.get()
  374. if new_dir.replace(" ", "") != "" and new_dir not in file_list:
  375. file_list.append(new_dir)
  376. API.update_file_box_gui()
  377. @staticmethod
  378. def add_file_by_git_gui():
  379. global file_dir
  380. new_dir = file_dir.get()
  381. if new_dir.replace(" ", "") != "":
  382. name = API.get_repo_name_gui()
  383. new_dir = git.make_dir(name, new_dir)
  384. if new_dir not in file_list:
  385. file_list.append(new_dir)
  386. API.update_file_box_gui()
  387. @staticmethod
  388. def diff_gui():
  389. branch = master.get()
  390. if branch == "":
  391. branch = "HEAD"
  392. return branch
  393. @staticmethod
  394. def commit_file_gui():
  395. m = commit_message.get()
  396. if m.replace(" ", "") == "":
  397. tkinter.messagebox.showinfo("警告!", "非常遗憾,我不同意你commit而不添加任何描述!\n描述是很重要的!")
  398. raise Exception
  399. return m
  400. @staticmethod
  401. def log_gui(log_type):
  402. graph = bool(log_type[0].get())
  403. abbrev = bool(log_type[1].get())
  404. pretty = bool(log_type[2].get())
  405. return abbrev, graph, pretty
  406. @staticmethod
  407. def reset_head_gui():
  408. repo_head = head.get()
  409. if repo_head == "":
  410. repo_head = "HEAD~1"
  411. the_reset_type = reset_type.get()
  412. return repo_head, the_reset_type
  413. @staticmethod
  414. def reset_file_gui():
  415. repo_head = head.get()
  416. if repo_head == "":
  417. repo_head = "HEAD~1"
  418. return repo_head
  419. @staticmethod
  420. def add_new_branch_gui():
  421. name = API.get_branch_name_gui()
  422. origin = origin_branch.get()
  423. return name, origin
  424. @staticmethod
  425. def branch_merge_gui():
  426. message = commit_message.get()
  427. parameters_no_ff = not bool(no_fast_forward.get()) # 对于no_ff来说,True - 使用快速合并,所以要翻转
  428. if message.replace(" ", "") == "" and parameters_no_ff:
  429. tkinter.messagebox.showinfo(
  430. "警告!", "非常遗憾,我不同意你commit而不添加任何描述!\n描述是很重要的!" "(如果你不想添加描述,请使用快速合并,但我并不建议!)"
  431. )
  432. raise Exception
  433. name = API.get_branch_name_gui()
  434. return message, name, parameters_no_ff
  435. @staticmethod
  436. def get_branch_name_gui():
  437. return branch_name.get()
  438. @staticmethod
  439. def get_stash_gui():
  440. stash_num = stash_name.get()
  441. return stash_num
  442. @staticmethod
  443. def add_remote_gui():
  444. ssh = remote_ssh.get()
  445. name = remote_name.get()
  446. return name, ssh
  447. @staticmethod
  448. def del_remote_gui():
  449. name = remote_name.get()
  450. return name
  451. @staticmethod
  452. def bind_remote_branch_gui():
  453. remote = remote_branch.get()
  454. local = local_branch.get()
  455. return local, remote
  456. @staticmethod
  457. def pull_push_gui():
  458. branch = remote_branch.get()
  459. remote = remote_name.get()
  460. local = local_branch.get()
  461. allow = bool(allow_history.get())
  462. parameters_u = bool(push_bind.get())
  463. parameters_f = tkinter.messagebox.askokcancel("提示", f"是否需要强制推送?(强制推送不被建议)")
  464. return allow, branch, local, parameters_f, parameters_u, remote
  465. @staticmethod
  466. def get_search_key_gui():
  467. return show_search_key.get()
  468. @staticmethod
  469. def add_tag_gui():
  470. global tag_name, commit, tag_message
  471. the_tag_name = tag_name.get()
  472. the_commit = tag_commit.get()
  473. the_tag_message = tag_message.get()
  474. return the_tag_name, the_commit, the_tag_message
  475. @staticmethod
  476. def push_tag_gui():
  477. global tag_name
  478. the_tag_name = tag_name.get()
  479. remoto = remote_name.get()
  480. return remoto, the_tag_name
  481. @staticmethod
  482. def get_remote_name_gui():
  483. remoto = remote_name.get()
  484. return remoto
  485. @staticmethod
  486. def del_remote_tag_gui():
  487. remoto = remote_name.get()
  488. tag = tag_name.get()
  489. return remoto, tag
  490. @staticmethod
  491. def del_remote_branch_gui():
  492. remote = remote_name.get()
  493. branch = remote_branch.get()
  494. return branch, remote
  495. @staticmethod
  496. def del_tag_gui():
  497. tag = tag_name.get()
  498. return tag
  499. @staticmethod
  500. def featch_remote_gui():
  501. branch = remote_branch.get()
  502. remote = remote_name.get()
  503. local = local_branch.get()
  504. return branch, local, remote
  505. @staticmethod
  506. def get_customize_gui():
  507. command = customize_input.get()
  508. is_threaded_refresh = bool(threaded_refresh.get())
  509. is_asynchronous_display = bool(asynchronous_display.get())
  510. return command, is_asynchronous_display, is_threaded_refresh
  511. @staticmethod
  512. def clone_git_gui():
  513. new_dir = askdirectory(title="选择仓库地址")
  514. name = git.clone_repo(new_dir)
  515. return name
  516. @staticmethod
  517. def branch_new_gui():
  518. new_name = branch_new_name.get()
  519. old_name = API.get_branch_name_gui()
  520. return new_name, old_name
  521. class API(UIAPI):
  522. @staticmethod
  523. def branch_new(): # 克隆仓库
  524. new_name, old_name = API.branch_new_gui()
  525. API.cli_gui(git.rename_branch, (API.get_repo_name_gui(), old_name, new_name), show_screen=False)
  526. API.update_repo_box_gui()
  527. @staticmethod
  528. def clone_git(): # 克隆仓库
  529. name = API.clone_git_gui()
  530. API.clone_core(name, clone_repo.get())
  531. API.update_repo_box_gui()
  532. @staticmethod
  533. def clone_core(name, url):
  534. API.cli_gui(
  535. git.clone,
  536. (name, url),
  537. break_time=0,
  538. tip_text=f"{url}:正在执行克隆操作",
  539. is_threaded_refresh=True,
  540. is_asynchronous_display=True,
  541. )
  542. git.after_clone(name)
  543. API.update_git_file_last_gui()
  544. @staticmethod
  545. def customize():
  546. command, is_asynchronous_display, is_threaded_refresh = API.get_customize_gui()
  547. API.cli_gui(
  548. git.customize_command,
  549. (API.get_repo_name_gui(), command),
  550. break_time=0,
  551. tip_text=f"{command}:操作进行中",
  552. is_threaded_refresh=is_threaded_refresh,
  553. is_asynchronous_display=is_asynchronous_display,
  554. )
  555. API.update_git_file_last_gui()
  556. @staticmethod
  557. def fetch_remote():
  558. branch, local, remote = API.featch_remote_gui()
  559. API.cli_gui(
  560. git.fetch,
  561. (API.get_repo_name_gui(), local, remote, branch),
  562. break_time=0,
  563. tip_text=f"此操作需要连接远程仓库,请稍等...",
  564. is_threaded_refresh=True,
  565. is_asynchronous_display=True,
  566. )
  567. API.update_git_file_last_gui()
  568. @staticmethod
  569. def del_tag():
  570. tag = API.del_tag_gui()
  571. API.cli_gui(git.del_tag, (API.get_repo_name_gui(), tag))
  572. API.update_git_file_last_gui()
  573. @staticmethod
  574. def del_remote_branch():
  575. branch, remote = API.del_remote_branch_gui()
  576. API.cli_gui(
  577. git.del_branch_remote,
  578. (API.get_repo_name_gui(), remote, branch),
  579. break_time=0,
  580. tip_text=f"此操作需要连接远程仓库,请稍等...",
  581. is_threaded_refresh=True,
  582. is_asynchronous_display=True,
  583. )
  584. API.update_git_file_last_gui()
  585. @staticmethod
  586. def del_remote_tag():
  587. remoto, tag = API.del_remote_tag_gui()
  588. API.cli_gui(
  589. git.del_tag_remote,
  590. (API.get_repo_name_gui(), remoto, tag),
  591. break_time=0,
  592. tip_text=f"此操作需要连接远程仓库,请稍等...",
  593. is_threaded_refresh=True,
  594. is_asynchronous_display=True,
  595. )
  596. API.update_git_file_last_gui()
  597. @staticmethod
  598. def push_all_tag():
  599. remoto = API.get_remote_name_gui()
  600. API.cli_gui(
  601. git.push_all_tag,
  602. (API.get_repo_name_gui(), remoto),
  603. break_time=0,
  604. tip_text=f"此操作需要连接远程仓库,请稍等...",
  605. is_threaded_refresh=True,
  606. is_asynchronous_display=True,
  607. )
  608. API.update_git_file_last_gui()
  609. @staticmethod
  610. def push_tag():
  611. remoto, the_tag_name = API.push_tag_gui()
  612. API.cli_gui(
  613. git.push_tag,
  614. (API.get_repo_name_gui(), the_tag_name, remoto),
  615. break_time=0,
  616. tip_text=f"此操作需要连接远程仓库,请稍等...",
  617. is_threaded_refresh=True,
  618. is_asynchronous_display=True,
  619. )
  620. API.update_git_file_last_gui()
  621. @staticmethod
  622. def add_tag():
  623. the_tag_name, the_commit, the_tag_message = API.add_tag_gui()
  624. API.cli_gui(
  625. git.add_tag, (API.get_repo_name_gui(), the_tag_name, the_commit, the_tag_message), show_screen=False
  626. )
  627. API.update_git_file_last_gui()
  628. @staticmethod
  629. def show_tag(type_):
  630. global git
  631. key = API.get_search_key_gui()
  632. API.cli_gui(
  633. {1: git.get_tag_list, 0: git.search_commit}.get(type_, git.search_commit),
  634. (API.get_repo_name_gui(), key),
  635. )
  636. API.update_git_file_last_gui()
  637. @staticmethod
  638. def pull_push_remote(type_):
  639. allow, branch, local, parameters_f, parameters_u, remote = API.pull_push_gui()
  640. API.cli_gui(
  641. {0: git.pull_from_remote, 1: git.push_to_remote}.get(
  642. type_, git.pull_from_remote
  643. ),
  644. (API.get_repo_name_gui(), local, remote, branch, allow, parameters_u, parameters_f),
  645. break_time=0,
  646. tip_text=f"此操作需要连接远程仓库,请稍等...",
  647. is_threaded_refresh=True,
  648. is_asynchronous_display=True,
  649. )
  650. API.update_git_file_last_gui()
  651. @staticmethod
  652. def bind_remote_branch():
  653. local, remote = API.bind_remote_branch_gui()
  654. API.cli_gui(git.bind_branch, (API.get_repo_name_gui(), local, remote))
  655. API.update_git_file_last_gui()
  656. @staticmethod
  657. def del_remote():
  658. name = API.del_remote_gui()
  659. API.cli_gui(git.del_remote, (API.get_repo_name_gui(), name))
  660. API.update_git_file_last_gui()
  661. @staticmethod
  662. def add_remote():
  663. name, ssh = API.add_remote_gui()
  664. API.cli_gui(git.remote_add, (API.get_repo_name_gui(), ssh, name))
  665. API.update_git_file_last_gui()
  666. @staticmethod
  667. def cherry_pick():
  668. the_commit = API.get_commit_id_gui()
  669. API.cli_gui(git.cherry_pick, (API.get_repo_name_gui(), the_commit))
  670. API.update_git_file_last_gui()
  671. @staticmethod
  672. def open_stash(type_):
  673. stash_num = API.get_stash_gui()
  674. if stash_num == "":
  675. stash_num = "0"
  676. API.cli_gui([git.drop_stash, git.apply_stash][type_], (API.get_repo_name_gui(), stash_num))
  677. API.update_git_file_last_gui()
  678. @staticmethod
  679. def branch_merge():
  680. message, name, parameters_no_ff = API.branch_merge_gui()
  681. API.cli_gui(git.merge_branch, (API.get_repo_name_gui(), name, parameters_no_ff, message))
  682. API.update_git_file_last_gui()
  683. @staticmethod
  684. def del_branch(type_):
  685. name = API.get_branch_name_gui()
  686. API.cli_gui(git.del_branch, (API.get_repo_name_gui(), name, type_))
  687. API.update_git_file_last_gui()
  688. @staticmethod
  689. def switch_branch():
  690. name = API.get_branch_name_gui()
  691. API.cli_gui(git.switch_branch, (API.get_repo_name_gui(), name), break_time=1, show_screen=False)
  692. API.update_git_file_last_gui()
  693. @staticmethod
  694. def add_new_branch():
  695. name, origin = API.add_new_branch_gui()
  696. API.cli_gui(
  697. git.new_branch, (API.get_repo_name_gui(), name, origin), break_time=1, show_screen=False
  698. )
  699. API.update_git_file_last_gui()
  700. @staticmethod
  701. def remove_file():
  702. if not file_list:
  703. return False
  704. API.cli_gui(git.rm, (API.get_repo_name_gui(), file_list))
  705. API.update_git_file_last_gui()
  706. @staticmethod
  707. def checkout_file(): # 从暂存区、仓库返回文件
  708. if not file_list:
  709. return False
  710. API.cli_gui(git.checkout_version, (API.get_repo_name_gui(), file_list))
  711. API.update_git_file_last_gui()
  712. @staticmethod
  713. def reset_file(): # 使用reset回退文件
  714. repo_head = API.reset_file_gui()
  715. API.cli_gui(git.back_version_file, (API.get_repo_name_gui(), repo_head, file_list))
  716. API.update_git_file_last_gui()
  717. @staticmethod
  718. def reset_head():
  719. repo_head, the_reset_type = API.reset_head_gui()
  720. API.cli_gui(git.back_version, (API.get_repo_name_gui(), repo_head, the_reset_type))
  721. API.update_git_file_last_gui()
  722. @staticmethod
  723. def log():
  724. global git, log_type
  725. name = API.get_repo_name_gui()
  726. abbrev, graph, pretty = API.log_gui(log_type)
  727. API.cli_gui(git.log, (name, graph, pretty, abbrev))
  728. API.update_git_file_last_gui()
  729. @staticmethod
  730. def not_parameters_call(func):
  731. global git
  732. name = API.get_repo_name_gui()
  733. API.cli_gui(func, (name,))
  734. API.update_git_file_last_gui()
  735. @staticmethod
  736. def commit_file():
  737. name = API.get_repo_name_gui()
  738. API.cli_gui(git.commit_file, (name, API.commit_file_gui()))
  739. API.update_git_file_last_gui()
  740. @staticmethod
  741. def diff():
  742. branch = API.diff_gui()
  743. API.cli_gui(git.diff_file, (API.get_repo_name_gui(), branch))
  744. API.update_git_file_last_gui()
  745. @staticmethod
  746. def remove_the_staging():
  747. global git
  748. dic = file_list
  749. if not dic:
  750. dic = "."
  751. API.cli_gui(git.reset_file, (API.get_repo_name_gui(), dic))
  752. API.update_git_file_last_gui()
  753. @staticmethod
  754. def add():
  755. dic = file_list
  756. if not dic:
  757. dic = "." # 查一下取消的dic
  758. API.cli_gui(git.add_file, (API.get_repo_name_gui(), dic))
  759. API.update_git_file_last_gui()
  760. @staticmethod
  761. def get_file_box_index():
  762. return file_box.curselection()
  763. @staticmethod
  764. def del_file():
  765. try:
  766. del file_list[API.get_file_box_index()]
  767. API.update_file_box_gui()
  768. except BaseException:
  769. pass
  770. @staticmethod
  771. def clean_file():
  772. global file_list
  773. file_list = []
  774. API.update_file_box_gui()
  775. @staticmethod
  776. def repo_init(): # 创建仓库
  777. global git
  778. new_dir = API.repo_init_gui()
  779. git.open_repo(new_dir)
  780. API.update_repo_box_gui()
  781. def git_main():
  782. global SCREEN, git, PATH, bg_color, buttom_color, word_color, repo_list, last_name, file_list, FONT
  783. SCREEN.mainloop()
  784. file_list = []
  785. PATH = os.getcwd()
  786. git = controller.GitCtrol()
  787. repo_list = []
  788. SCREEN = tkinter.Tk()
  789. last_name = None
  790. bg_color = "#FFFAFA" # 主颜色
  791. buttom_color = "#FFFAFA" # 按钮颜色
  792. word_color = "#000000" # 文字颜色
  793. SCREEN["bg"] = bg_color
  794. FONT = ("黑体", 11) # 设置字体
  795. SCREEN.title("CoTan仓库管理器")
  796. SCREEN.resizable(width=False, height=False)
  797. SCREEN.geometry("+10+10") # 设置所在位置
  798. gui_width = 13 # 标准宽度
  799. gui_height = 2
  800. row = 0
  801. column = 0
  802. tkinter.Button(
  803. SCREEN,
  804. bg=buttom_color,
  805. fg=word_color,
  806. text="克隆仓库",
  807. command=API.clone_git,
  808. font=FONT,
  809. width=gui_width,
  810. height=gui_height,
  811. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  812. tkinter.Button(
  813. SCREEN,
  814. bg=buttom_color,
  815. fg=word_color,
  816. text="打开仓库",
  817. command=API.repo_init,
  818. font=FONT,
  819. width=gui_width,
  820. height=gui_height,
  821. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  822. tkinter.Button(
  823. SCREEN,
  824. bg=buttom_color,
  825. fg=word_color,
  826. text="查看文件",
  827. command=API.update_git_file_select_gui,
  828. font=FONT,
  829. width=gui_width,
  830. height=gui_height,
  831. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  832. row += 1
  833. tkinter.Label(
  834. SCREEN,
  835. text="克隆URL:",
  836. bg=bg_color,
  837. fg=word_color,
  838. font=FONT,
  839. width=gui_width,
  840. height=gui_height,
  841. ).grid(column=column, row=row)
  842. clone_repo = tkinter.Entry(SCREEN, width=gui_width * 2)
  843. clone_repo.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  844. row += 1
  845. repo_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 4)
  846. repo_box.grid(
  847. column=column,
  848. row=row,
  849. columnspan=3,
  850. rowspan=4,
  851. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  852. )
  853. row += 4
  854. tkinter.Label(
  855. SCREEN,
  856. text="【仓库文件列表】",
  857. bg=bg_color,
  858. fg=word_color,
  859. font=FONT,
  860. width=gui_width * 3,
  861. height=gui_height,
  862. ).grid(
  863. column=column,
  864. columnspan=3,
  865. row=row,
  866. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  867. ) # 设置说明
  868. row += 1
  869. repo_dir = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 4)
  870. repo_dir.grid(
  871. column=column,
  872. row=row,
  873. columnspan=3,
  874. rowspan=4,
  875. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  876. )
  877. row += 4
  878. tkinter.Label(
  879. SCREEN,
  880. text="【添加文件列表】",
  881. bg=bg_color,
  882. fg=word_color,
  883. font=FONT,
  884. width=gui_width * 3,
  885. height=gui_height,
  886. ).grid(
  887. column=column,
  888. columnspan=3,
  889. row=row,
  890. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  891. ) # 设置说明
  892. row += 1
  893. file_dir = tkinter.Entry(SCREEN, width=gui_width * 2)
  894. file_dir.grid(
  895. column=column,
  896. row=row,
  897. columnspan=3,
  898. sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S,
  899. )
  900. row += 1
  901. tkinter.Button(
  902. SCREEN,
  903. bg=buttom_color,
  904. fg=word_color,
  905. text="填充路径并添加",
  906. command=API.add_file_by_git_gui,
  907. font=FONT,
  908. width=gui_width,
  909. height=gui_height,
  910. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  911. tkinter.Button(
  912. SCREEN,
  913. bg=buttom_color,
  914. fg=word_color,
  915. text="直接添加",
  916. command=API.add_file_input_dir_gui,
  917. font=FONT,
  918. width=gui_width,
  919. height=gui_height,
  920. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  921. tkinter.Button(
  922. SCREEN,
  923. bg=buttom_color,
  924. fg=word_color,
  925. text="选择文件",
  926. command=API.add_file_list_gui,
  927. font=FONT,
  928. width=gui_width,
  929. height=gui_height,
  930. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  931. row += 1
  932. tkinter.Button(
  933. SCREEN,
  934. bg=buttom_color,
  935. fg=word_color,
  936. text="把文件移除出列表",
  937. command=API.del_file,
  938. font=FONT,
  939. width=gui_width,
  940. height=gui_height,
  941. ).grid(column=column, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  942. tkinter.Button(
  943. SCREEN,
  944. bg=buttom_color,
  945. fg=word_color,
  946. text="清空列表",
  947. command=API.clean_file,
  948. font=FONT,
  949. width=gui_width,
  950. height=gui_height,
  951. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  952. row += 1
  953. file_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 4)
  954. file_box.grid(
  955. column=column,
  956. row=row,
  957. columnspan=3,
  958. rowspan=4,
  959. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  960. )
  961. row += 4
  962. tkinter.Button(
  963. SCREEN,
  964. bg=buttom_color,
  965. fg=word_color,
  966. text="添加暂存区文件",
  967. command=API.add,
  968. font=FONT,
  969. width=gui_width,
  970. height=gui_height,
  971. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  972. tkinter.Button(
  973. SCREEN,
  974. bg=buttom_color,
  975. fg=word_color,
  976. text="移除暂存区文件",
  977. command=API.remove_the_staging,
  978. font=FONT,
  979. width=gui_width,
  980. height=gui_height,
  981. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  982. tkinter.Button(
  983. SCREEN,
  984. bg=buttom_color,
  985. fg=word_color,
  986. text="提交到git",
  987. command=API.commit_file,
  988. font=FONT,
  989. width=gui_width,
  990. height=gui_height,
  991. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  992. row += 1
  993. tkinter.Button(
  994. SCREEN,
  995. bg=buttom_color,
  996. fg=word_color,
  997. text="查看执行日志",
  998. command=lambda: API.not_parameters_call(git.do_log),
  999. font=FONT,
  1000. width=gui_width,
  1001. height=gui_height,
  1002. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1003. tkinter.Button(
  1004. SCREEN,
  1005. bg=buttom_color,
  1006. fg=word_color,
  1007. text="查看文件日志",
  1008. command=API.log,
  1009. font=FONT,
  1010. width=gui_width,
  1011. height=gui_height,
  1012. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1013. tkinter.Button(
  1014. SCREEN,
  1015. bg=buttom_color,
  1016. fg=word_color,
  1017. text="查看状态",
  1018. command=lambda: API.not_parameters_call(git.status),
  1019. font=FONT,
  1020. width=gui_width,
  1021. height=gui_height,
  1022. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1023. row += 1
  1024. log_type = []
  1025. lable = ["显示轴", "commit完全显示", "简化显示"] # 复选框
  1026. for i in range(3):
  1027. log_type.append(tkinter.IntVar())
  1028. tkinter.Checkbutton(
  1029. SCREEN,
  1030. bg=bg_color,
  1031. fg=word_color,
  1032. activebackground=bg_color,
  1033. activeforeground=word_color,
  1034. selectcolor=bg_color,
  1035. text=lable[i],
  1036. variable=log_type[-1],
  1037. ).grid(column=column + i, row=row, sticky=tkinter.W)
  1038. log_type[-1].set(1)
  1039. row += 1
  1040. tkinter.Button(
  1041. SCREEN,
  1042. bg=buttom_color,
  1043. fg=word_color,
  1044. text="版本回退",
  1045. command=API.reset_head,
  1046. font=FONT,
  1047. width=gui_width,
  1048. height=gui_height,
  1049. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1050. tkinter.Button(
  1051. SCREEN,
  1052. bg=buttom_color,
  1053. fg=word_color,
  1054. text="放弃修改",
  1055. command=API.checkout_file,
  1056. font=FONT,
  1057. width=gui_width,
  1058. height=gui_height,
  1059. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1060. tkinter.Button(
  1061. SCREEN,
  1062. bg=buttom_color,
  1063. fg=word_color,
  1064. text="删除文件",
  1065. command=API.remove_file,
  1066. font=FONT,
  1067. width=gui_width,
  1068. height=gui_height,
  1069. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1070. row += 1
  1071. reset_type = tkinter.IntVar() # 正,负,0
  1072. lable = ["回退到工作区", "回退到暂存区", "无痕回退"] # 复选框
  1073. for i in range(3):
  1074. tkinter.Radiobutton(
  1075. SCREEN,
  1076. bg=bg_color,
  1077. fg=word_color,
  1078. activebackground=bg_color,
  1079. activeforeground=word_color,
  1080. selectcolor=bg_color,
  1081. text=lable[i],
  1082. variable=reset_type,
  1083. value=i,
  1084. ).grid(column=column + i, row=row, sticky=tkinter.W)
  1085. column += 3
  1086. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  1087. column=column, row=row
  1088. ) # 设置说明
  1089. column += 1
  1090. row = 0
  1091. tkinter.Label(
  1092. SCREEN,
  1093. text="【参数操作】",
  1094. bg=bg_color,
  1095. fg=word_color,
  1096. font=FONT,
  1097. width=gui_width * 3,
  1098. height=gui_height,
  1099. ).grid(
  1100. column=column,
  1101. columnspan=3,
  1102. row=row,
  1103. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1104. ) # 设置说明
  1105. row += 1
  1106. tkinter.Label(
  1107. SCREEN,
  1108. text="提交描述:",
  1109. bg=bg_color,
  1110. fg=word_color,
  1111. font=FONT,
  1112. width=gui_width,
  1113. height=gui_height,
  1114. ).grid(column=column, row=row)
  1115. commit_message = tkinter.Entry(SCREEN, width=gui_width * 2)
  1116. commit_message.grid(
  1117. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1118. )
  1119. row += 1
  1120. tkinter.Label(
  1121. SCREEN,
  1122. text="diff分支:",
  1123. bg=bg_color,
  1124. fg=word_color,
  1125. font=FONT,
  1126. width=gui_width,
  1127. height=gui_height,
  1128. ).grid(column=column, row=row)
  1129. master = tkinter.Entry(SCREEN, width=gui_width * 2)
  1130. master.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1131. row += 1
  1132. tkinter.Label(
  1133. SCREEN,
  1134. text="回退版本号:",
  1135. bg=bg_color,
  1136. fg=word_color,
  1137. font=FONT,
  1138. width=gui_width,
  1139. height=gui_height,
  1140. ).grid(column=column, row=row)
  1141. head = tkinter.Entry(SCREEN, width=gui_width * 2)
  1142. head.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1143. row += 1
  1144. tkinter.Label(
  1145. SCREEN,
  1146. text="本地分支:",
  1147. bg=bg_color,
  1148. fg=word_color,
  1149. font=FONT,
  1150. width=gui_width,
  1151. height=gui_height,
  1152. ).grid(column=column, row=row)
  1153. branch_name = tkinter.Entry(SCREEN, width=gui_width * 2)
  1154. branch_name.grid(
  1155. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1156. )
  1157. row += 1
  1158. tkinter.Label(
  1159. SCREEN,
  1160. text="远程分支:",
  1161. bg=bg_color,
  1162. fg=word_color,
  1163. font=FONT,
  1164. width=gui_width,
  1165. height=gui_height,
  1166. ).grid(column=column, row=row)
  1167. origin_branch = tkinter.Entry(SCREEN, width=gui_width * 2)
  1168. origin_branch.grid(
  1169. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1170. )
  1171. row += 1
  1172. tkinter.Label(
  1173. SCREEN,
  1174. text="远程仓库链接:",
  1175. bg=bg_color,
  1176. fg=word_color,
  1177. font=FONT,
  1178. width=gui_width,
  1179. height=gui_height,
  1180. ).grid(column=column, row=row)
  1181. remote_ssh = tkinter.Entry(SCREEN, width=gui_width)
  1182. remote_ssh.grid(column=column + 1, columnspan=2, row=row, sticky=tkinter.E + tkinter.W)
  1183. row += 1
  1184. tkinter.Label(
  1185. SCREEN,
  1186. text="远程仓库名:",
  1187. bg=bg_color,
  1188. fg=word_color,
  1189. font=FONT,
  1190. width=gui_width,
  1191. height=gui_height,
  1192. ).grid(column=column, row=row)
  1193. remote_name = tkinter.Entry(SCREEN, width=gui_width)
  1194. remote_name.grid(
  1195. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  1196. )
  1197. row += 1
  1198. tkinter.Label(
  1199. SCREEN,
  1200. text="commit:",
  1201. bg=bg_color,
  1202. fg=word_color,
  1203. font=FONT,
  1204. width=gui_width,
  1205. height=gui_height,
  1206. ).grid(column=column, row=row)
  1207. commit = tkinter.Entry(SCREEN, width=gui_width)
  1208. commit.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1209. row += 1
  1210. tkinter.Label(
  1211. SCREEN,
  1212. text="标签名字:",
  1213. bg=bg_color,
  1214. fg=word_color,
  1215. font=FONT,
  1216. width=gui_width,
  1217. height=gui_height,
  1218. ).grid(column=column, row=row)
  1219. tag_name = tkinter.Entry(SCREEN, width=gui_width)
  1220. tag_name.grid(column=column + 1, columnspan=2, row=row, sticky=tkinter.E + tkinter.W)
  1221. row += 1
  1222. tkinter.Label(
  1223. SCREEN,
  1224. text="查询关键字:",
  1225. bg=bg_color,
  1226. fg=word_color,
  1227. font=FONT,
  1228. width=gui_width,
  1229. height=gui_height,
  1230. ).grid(column=column, row=row)
  1231. show_search_key = tkinter.Entry(SCREEN, width=gui_width)
  1232. show_search_key.grid(
  1233. column=column + 1, columnspan=2, row=row, sticky=tkinter.E + tkinter.W
  1234. )
  1235. row += 1
  1236. tkinter.Label(
  1237. SCREEN,
  1238. text="工作区序号:",
  1239. bg=bg_color,
  1240. fg=word_color,
  1241. font=FONT,
  1242. width=gui_width,
  1243. height=gui_height,
  1244. ).grid(column=column, row=row)
  1245. stash_name = tkinter.Entry(SCREEN, width=gui_width)
  1246. stash_name.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1247. row += 1
  1248. tkinter.Label(
  1249. SCREEN,
  1250. text="【高级操作】",
  1251. bg=bg_color,
  1252. fg=word_color,
  1253. font=FONT,
  1254. width=gui_width * 3,
  1255. height=gui_height,
  1256. ).grid(
  1257. column=column,
  1258. columnspan=3,
  1259. row=row,
  1260. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1261. ) # 设置说明
  1262. row += 1
  1263. tkinter.Button(
  1264. SCREEN,
  1265. bg=buttom_color,
  1266. fg=word_color,
  1267. text="查看分支",
  1268. command=lambda: API.not_parameters_call(git.branch_view),
  1269. font=FONT,
  1270. width=gui_width,
  1271. height=gui_height,
  1272. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1273. tkinter.Button(
  1274. SCREEN,
  1275. bg=buttom_color,
  1276. fg=word_color,
  1277. text="新建分支",
  1278. command=API.add_new_branch,
  1279. font=FONT,
  1280. width=gui_width,
  1281. height=gui_height,
  1282. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1283. tkinter.Button(
  1284. SCREEN,
  1285. bg=buttom_color,
  1286. fg=word_color,
  1287. text="切换分支",
  1288. command=API.switch_branch,
  1289. font=FONT,
  1290. width=gui_width,
  1291. height=gui_height,
  1292. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1293. row += 1
  1294. tkinter.Button(
  1295. SCREEN,
  1296. bg=buttom_color,
  1297. fg=word_color,
  1298. text="删除分支",
  1299. command=lambda: API.del_branch(1),
  1300. font=FONT,
  1301. width=gui_width,
  1302. height=gui_height,
  1303. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1304. tkinter.Button(
  1305. SCREEN,
  1306. bg=buttom_color,
  1307. fg=word_color,
  1308. text="丢弃分支",
  1309. command=lambda: API.del_branch(0),
  1310. font=FONT,
  1311. width=gui_width,
  1312. height=gui_height,
  1313. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1314. tkinter.Button(
  1315. SCREEN,
  1316. bg=buttom_color,
  1317. fg=word_color,
  1318. text="合并分支",
  1319. command=API.switch_branch,
  1320. font=FONT,
  1321. width=gui_width,
  1322. height=gui_height,
  1323. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1324. no_fast_forward = tkinter.IntVar()
  1325. row += 1
  1326. tkinter.Button(
  1327. SCREEN,
  1328. bg=buttom_color,
  1329. fg=word_color,
  1330. text="合并分支",
  1331. command=API.branch_merge,
  1332. font=FONT,
  1333. width=gui_width,
  1334. height=gui_height,
  1335. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1336. tkinter.Button(
  1337. SCREEN,
  1338. bg=buttom_color,
  1339. fg=word_color,
  1340. text="退出冲突处理",
  1341. command=lambda: API.not_parameters_call(git.merge_abort),
  1342. font=FONT,
  1343. width=gui_width,
  1344. height=gui_height,
  1345. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1346. tkinter.Checkbutton(
  1347. SCREEN,
  1348. bg=bg_color,
  1349. fg=word_color,
  1350. activebackground=bg_color,
  1351. activeforeground=word_color,
  1352. selectcolor=bg_color,
  1353. text="使用快速合并",
  1354. variable=no_fast_forward,
  1355. ).grid(column=column + 1, row=row, sticky=tkinter.W)
  1356. no_fast_forward.set(0)
  1357. row += 1
  1358. tkinter.Button(
  1359. SCREEN,
  1360. bg=buttom_color,
  1361. fg=word_color,
  1362. text="连接远程仓库",
  1363. command=API.add_remote,
  1364. font=FONT,
  1365. width=gui_width,
  1366. height=gui_height,
  1367. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1368. tkinter.Button(
  1369. SCREEN,
  1370. bg=buttom_color,
  1371. fg=word_color,
  1372. text="推送到远程仓库",
  1373. command=lambda: API.pull_push_remote(1),
  1374. font=FONT,
  1375. width=gui_width,
  1376. height=gui_height,
  1377. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1378. tkinter.Button(
  1379. SCREEN,
  1380. bg=buttom_color,
  1381. fg=word_color,
  1382. text="从远程仓库抓取",
  1383. command=lambda: API.pull_push_remote(0),
  1384. font=FONT,
  1385. width=gui_width,
  1386. height=gui_height,
  1387. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1388. push_bind = tkinter.IntVar()
  1389. allow_history = tkinter.IntVar()
  1390. row += 1
  1391. tkinter.Button(
  1392. SCREEN,
  1393. bg=buttom_color,
  1394. fg=word_color,
  1395. text="分支绑定",
  1396. command=API.bind_remote_branch,
  1397. font=FONT,
  1398. width=gui_width,
  1399. height=gui_height,
  1400. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1401. tkinter.Checkbutton(
  1402. SCREEN,
  1403. bg=bg_color,
  1404. fg=word_color,
  1405. activebackground=bg_color,
  1406. activeforeground=word_color,
  1407. selectcolor=bg_color,
  1408. text="无视历史记录",
  1409. variable=allow_history,
  1410. ).grid(column=column + 1, row=row, sticky=tkinter.W)
  1411. tkinter.Checkbutton(
  1412. SCREEN,
  1413. bg=bg_color,
  1414. fg=word_color,
  1415. activebackground=bg_color,
  1416. activeforeground=word_color,
  1417. selectcolor=bg_color,
  1418. text="推送时绑定",
  1419. variable=push_bind,
  1420. ).grid(column=column + 2, row=row, sticky=tkinter.W)
  1421. allow_history.set(0)
  1422. push_bind.set(0)
  1423. row += 1
  1424. tkinter.Button(
  1425. SCREEN,
  1426. bg=buttom_color,
  1427. fg=word_color,
  1428. text="应用标签",
  1429. command=API.add_tag,
  1430. font=FONT,
  1431. width=gui_width,
  1432. height=gui_height,
  1433. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1434. tkinter.Button(
  1435. SCREEN,
  1436. bg=buttom_color,
  1437. fg=word_color,
  1438. text="查看已有标签",
  1439. command=lambda: API.show_tag(1),
  1440. font=FONT,
  1441. width=gui_width,
  1442. height=gui_height,
  1443. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1444. tkinter.Button(
  1445. SCREEN,
  1446. bg=buttom_color,
  1447. fg=word_color,
  1448. text="查询commit记录",
  1449. command=lambda: API.show_tag(0),
  1450. font=FONT,
  1451. width=gui_width,
  1452. height=gui_height,
  1453. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1454. row += 1
  1455. tkinter.Button(
  1456. SCREEN,
  1457. bg=buttom_color,
  1458. fg=word_color,
  1459. text="推送标签",
  1460. command=API.push_tag,
  1461. font=FONT,
  1462. width=gui_width,
  1463. height=gui_height,
  1464. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1465. tkinter.Button(
  1466. SCREEN,
  1467. bg=buttom_color,
  1468. fg=word_color,
  1469. text="推送所有标签",
  1470. command=API.push_all_tag,
  1471. font=FONT,
  1472. width=gui_width,
  1473. height=gui_height,
  1474. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1475. tkinter.Button(
  1476. SCREEN,
  1477. bg=buttom_color,
  1478. fg=word_color,
  1479. text="删除本地标签",
  1480. command=API.del_tag,
  1481. font=FONT,
  1482. width=gui_width,
  1483. height=gui_height,
  1484. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1485. row += 1
  1486. tkinter.Button(
  1487. SCREEN,
  1488. bg=buttom_color,
  1489. fg=word_color,
  1490. text="删除远程标签",
  1491. command=API.del_remote_tag,
  1492. font=FONT,
  1493. width=gui_width,
  1494. height=gui_height,
  1495. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1496. tkinter.Button(
  1497. SCREEN,
  1498. bg=buttom_color,
  1499. fg=word_color,
  1500. text="删除远程分支",
  1501. command=API.del_remote_branch,
  1502. font=FONT,
  1503. width=gui_width,
  1504. height=gui_height,
  1505. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1506. tkinter.Button(
  1507. SCREEN,
  1508. bg=buttom_color,
  1509. fg=word_color,
  1510. text="刷新远程分支",
  1511. command=API.fetch_remote,
  1512. font=FONT,
  1513. width=gui_width,
  1514. height=gui_height,
  1515. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1516. row += 1
  1517. tkinter.Button(
  1518. SCREEN,
  1519. bg=buttom_color,
  1520. fg=word_color,
  1521. text="commit补丁",
  1522. command=API.cherry_pick,
  1523. font=FONT,
  1524. width=gui_width,
  1525. height=gui_height,
  1526. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1527. tkinter.Button(
  1528. SCREEN,
  1529. bg=buttom_color,
  1530. fg=word_color,
  1531. text="删除远程仓库",
  1532. command=API.del_remote,
  1533. font=FONT,
  1534. width=gui_width,
  1535. height=gui_height,
  1536. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1537. tkinter.Button(
  1538. SCREEN,
  1539. bg=buttom_color,
  1540. fg=word_color,
  1541. text="工作区列表",
  1542. command=lambda: API.not_parameters_call(git.stash_list),
  1543. font=FONT,
  1544. width=gui_width,
  1545. height=gui_height,
  1546. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1547. row += 1
  1548. tkinter.Button(
  1549. SCREEN,
  1550. bg=buttom_color,
  1551. fg=word_color,
  1552. text="文件回退",
  1553. command=API.reset_file,
  1554. font=FONT,
  1555. width=gui_width,
  1556. height=gui_height,
  1557. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1558. tkinter.Button(
  1559. SCREEN,
  1560. bg=buttom_color,
  1561. fg=word_color,
  1562. text="分支重命名",
  1563. command=API.branch_new,
  1564. font=FONT,
  1565. width=gui_width,
  1566. height=gui_height,
  1567. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1568. branch_new_name = tkinter.Entry(SCREEN, width=gui_width)
  1569. branch_new_name.grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1570. row += 1
  1571. tkinter.Button(
  1572. SCREEN,
  1573. bg=buttom_color,
  1574. fg=word_color,
  1575. text="保存工作区",
  1576. command=lambda: API.not_parameters_call(git.save_stash),
  1577. font=FONT,
  1578. width=gui_width,
  1579. height=gui_height,
  1580. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  1581. tkinter.Button(
  1582. SCREEN,
  1583. bg=buttom_color,
  1584. fg=word_color,
  1585. text="恢复工作区",
  1586. command=lambda: API.open_stash(1),
  1587. font=FONT,
  1588. width=gui_width,
  1589. height=gui_height,
  1590. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1591. tkinter.Button(
  1592. SCREEN,
  1593. bg=buttom_color,
  1594. fg=word_color,
  1595. text="删除工作区",
  1596. command=lambda: API.open_stash(0),
  1597. font=FONT,
  1598. width=gui_width,
  1599. height=gui_height,
  1600. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1601. row += 1
  1602. threaded_refresh = tkinter.IntVar()
  1603. asynchronous_display = tkinter.IntVar()
  1604. tkinter.Checkbutton(
  1605. SCREEN,
  1606. bg=bg_color,
  1607. fg=word_color,
  1608. activebackground=bg_color,
  1609. activeforeground=word_color,
  1610. selectcolor=bg_color,
  1611. text="多进程刷新",
  1612. variable=threaded_refresh,
  1613. ).grid(column=0, row=row, sticky=tkinter.W)
  1614. tkinter.Checkbutton(
  1615. SCREEN,
  1616. bg=bg_color,
  1617. fg=word_color,
  1618. activebackground=bg_color,
  1619. activeforeground=word_color,
  1620. selectcolor=bg_color,
  1621. text="异步显示",
  1622. variable=asynchronous_display,
  1623. ).grid(column=1, row=row, sticky=tkinter.W)
  1624. customize_input = tkinter.Entry(SCREEN, width=gui_width * 3)
  1625. customize_input.grid(
  1626. column=2,
  1627. row=row,
  1628. columnspan=4,
  1629. sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S,
  1630. )
  1631. tkinter.Button(
  1632. SCREEN,
  1633. bg=buttom_color,
  1634. fg=word_color,
  1635. text="执行操作",
  1636. command=API.customize,
  1637. font=FONT,
  1638. width=gui_width,
  1639. height=gui_height,
  1640. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  1641. threaded_refresh.set(0)
  1642. asynchronous_display.set(1)
  1643. tag_message = commit_message
  1644. tag_commit = commit
  1645. remote_branch = origin_branch
  1646. local_branch = branch_name