gui.py 50 KB

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