GIT.py 43 KB

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