gui.py 51 KB

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