1
0

gui.py 52 KB

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