gui.py 51 KB

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