1
0

GIT.py 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. import tkinter
  2. import tkinter.messagebox
  3. from tkinter import ttk
  4. from tkinter.filedialog import asksaveasfilename,askdirectory,askopenfilenames
  5. import os
  6. from Git_controller import Git_Ctrl
  7. from tkinter.scrolledtext import ScrolledText
  8. import time
  9. import threading
  10. def Main():
  11. global top,Git,PATH,bg,bbg,fg,Git_List,Last_Name,FileList
  12. FileList = []
  13. PATH = os.getcwd()
  14. Git = Git_Ctrl.git_Ctrol()
  15. Git_List = []
  16. top = tkinter.Tk()
  17. Last_Name = None
  18. bg = '#FFFAFA' # 主颜色
  19. bbg = '#FFFAFA' # 按钮颜色
  20. fg = '#000000' # 文字颜色
  21. top["bg"] = bg
  22. FONT = ('黑体', 11) # 设置字体
  23. top.title('CoTan仓库管理器')
  24. top.resizable(width=False, height=False)
  25. top.geometry('+10+10') # 设置所在位置
  26. width_B = 13 # 标准宽度
  27. height_B = 2
  28. a_y = 0
  29. a_x = 0
  30. global clone_url,Git_Box,Git_Dir
  31. global commit_m,head,master,no_ff
  32. global TagName,TagMessage,TagCommit,Show_Key
  33. global RemoteSSH,RemoteName,RemoteBranch,LocalBranch,push_bind,allow_history
  34. global BranchName, StashName, CommitName, BranchNOrigin
  35. tkinter.Button(top, bg=bbg, fg=fg, text='克隆仓库', command=clone_git, font=FONT, width=width_B,
  36. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  37. tkinter.Button(top, bg=bbg, fg=fg, text='打开仓库', command=init_git, font=FONT, width=width_B,
  38. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  39. tkinter.Button(top, bg=bbg, fg=fg, text='查看文件', command=get_Git_Dir, font=FONT, width=width_B,
  40. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  41. a_y += 1
  42. tkinter.Label(top, text='克隆URL:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  43. Dic_Var = tkinter.StringVar()#当前的Dic
  44. clone_url = tkinter.Entry(top, width=width_B * 2, textvariable=Dic_Var)
  45. clone_url.grid(column=a_x+1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  46. a_y += 1
  47. Git_Box = tkinter.Listbox(top, width=width_B * 3, height=height_B * 4)
  48. Git_Box.grid(column=a_x, row=a_y, columnspan=3, rowspan=4, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  49. a_y += 4
  50. tkinter.Label(top, text='【仓库文件列表】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(
  51. column=a_x,columnspan=3,row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  52. a_y += 1
  53. Git_Dir = tkinter.Listbox(top, width=width_B * 3, height=height_B * 4)
  54. Git_Dir.grid(column=a_x, row=a_y, columnspan=3, rowspan=4, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  55. a_y += 4
  56. tkinter.Label(top, text='【添加文件列表】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(
  57. column=a_x,columnspan=3,row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  58. global File_Input,File_BOX
  59. a_y += 1
  60. File_Input = tkinter.Entry(top, width=width_B * 2)
  61. File_Input.grid(column=a_x, row=a_y, columnspan=3, sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S)
  62. a_y += 1
  63. tkinter.Button(top, bg=bbg, fg=fg, text='填充路径并添加', command=Add_FileByGit, font=FONT, width=width_B,
  64. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  65. tkinter.Button(top, bg=bbg, fg=fg, text='直接添加', command=Add_FileInput, font=FONT, width=width_B,
  66. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  67. tkinter.Button(top, bg=bbg, fg=fg, text='选择文件', command=Add_FileList, font=FONT, width=width_B,
  68. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  69. a_y += 1
  70. tkinter.Button(top, bg=bbg, fg=fg, text='把文件移除出列表', command=Del_FileBox, font=FONT, width=width_B,
  71. height=height_B).grid(column=a_x, row=a_y,columnspan=2, sticky=tkinter.E + tkinter.W)
  72. tkinter.Button(top, bg=bbg, fg=fg, text='清空列表', command=Tra_FileBox, font=FONT, width=width_B,
  73. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  74. a_y += 1
  75. File_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 4)
  76. File_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=4, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  77. a_y += 4
  78. tkinter.Button(top, bg=bbg, fg=fg, text='添加暂存区文件', command=Add_File, font=FONT, width=width_B,
  79. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  80. tkinter.Button(top, bg=bbg, fg=fg, text='移除暂存区文件', command=Reset_File, font=FONT, width=width_B,
  81. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  82. tkinter.Button(top, bg=bbg, fg=fg, text='提交到git', command=Commit_File, font=FONT, width=width_B,
  83. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  84. a_y += 1
  85. tkinter.Button(top, bg=bbg, fg=fg, text='查看执行日志', command=lambda :not_Args(Git.reflog), font=FONT, width=width_B,
  86. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  87. tkinter.Button(top, bg=bbg, fg=fg, text='查看文件日志', command=log, font=FONT, width=width_B,
  88. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  89. tkinter.Button(top, bg=bbg, fg=fg, text='查看状态', command=lambda :not_Args(Git.status), font=FONT, width=width_B,
  90. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  91. global log_Type,reset_Type
  92. a_y += 1
  93. log_Type = []
  94. lable = ['显示轴','commit完全显示','简化显示']#复选框
  95. for i in range(3):
  96. log_Type.append(tkinter.IntVar())
  97. tkinter.Checkbutton(top,bg = bg,fg = fg,activebackground=bg,activeforeground=fg,selectcolor=bg, text=lable[i],
  98. variable=log_Type[-1]).grid(column=a_x+i, row=a_y, sticky=tkinter.W)
  99. log_Type[-1].set(1)
  100. a_y += 1
  101. tkinter.Button(top, bg=bbg, fg=fg, text='版本回退', command=Back_version, font=FONT, width=width_B,
  102. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  103. tkinter.Button(top, bg=bbg, fg=fg, text='放弃修改', command=Back_File, font=FONT, width=width_B,
  104. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  105. tkinter.Button(top, bg=bbg, fg=fg, text='删除文件', command=rm_file, font=FONT, width=width_B,
  106. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  107. a_y += 1
  108. reset_Type = tkinter.IntVar()#正,负,0
  109. lable = ['回退到工作区','回退到暂存区','无痕回退']#复选框
  110. for i in range(3):
  111. tkinter.Radiobutton(top,bg = bg,fg = fg,activebackground=bg,activeforeground=fg,selectcolor=bg,text=lable[i],
  112. variable=reset_Type, value=i).grid(column=a_x+i, row=a_y, sticky=tkinter.W)
  113. a_x += 3
  114. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  115. a_x += 1
  116. a_y = 0
  117. tkinter.Label(top, text='【参数操作】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(
  118. column=a_x,columnspan=3,row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  119. a_y += 1
  120. tkinter.Label(top, text='提交描述:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  121. commit_m = tkinter.Entry(top, width=width_B * 2)
  122. commit_m.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  123. a_y += 1
  124. tkinter.Label(top, text='diff分支:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  125. master = tkinter.Entry(top, width=width_B * 2)
  126. master.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  127. a_y += 1
  128. tkinter.Label(top, text='回退版本号:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  129. head = tkinter.Entry(top, width=width_B * 2)
  130. head.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  131. a_y += 1
  132. tkinter.Label(top, text='本地分支:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  133. BranchName = tkinter.Entry(top, width=width_B * 2)
  134. BranchName.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  135. a_y += 1
  136. tkinter.Label(top, text='远程分支:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  137. BranchNOrigin = tkinter.Entry(top, width=width_B * 2)
  138. BranchNOrigin.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  139. a_y += 1
  140. tkinter.Label(top, text='远程仓库链接:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  141. RemoteSSH = tkinter.Entry(top, width=width_B)
  142. RemoteSSH.grid(column=a_x + 1,columnspan=2, row=a_y, sticky=tkinter.E + tkinter.W)
  143. a_y += 1
  144. tkinter.Label(top, text='远程仓库名:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  145. RemoteName = tkinter.Entry(top, width=width_B)
  146. RemoteName.grid(column=a_x + 1, row=a_y, columnspan=2,sticky=tkinter.E + tkinter.W)
  147. a_y += 1
  148. tkinter.Label(top, text='commit:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  149. CommitName = tkinter.Entry(top, width=width_B)
  150. CommitName.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  151. a_y += 1
  152. tkinter.Label(top, text='标签名字:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  153. TagName = tkinter.Entry(top, width=width_B)
  154. TagName.grid(column=a_x + 1,columnspan=2, row=a_y, sticky=tkinter.E + tkinter.W)
  155. a_y += 1
  156. tkinter.Label(top, text='查询关键字:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  157. Show_Key = tkinter.Entry(top, width=width_B)
  158. Show_Key.grid(column=a_x + 1,columnspan=2, row=a_y, sticky=tkinter.E + tkinter.W)
  159. a_y += 1
  160. tkinter.Label(top, text='工作区序号:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  161. StashName = tkinter.Entry(top, width=width_B)
  162. StashName.grid(column=a_x + 1, row=a_y,columnspan=2, sticky=tkinter.E + tkinter.W)
  163. a_y += 1
  164. tkinter.Label(top, text='【高级操作】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(
  165. column=a_x,columnspan=3,row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  166. a_y += 1
  167. tkinter.Button(top, bg=bbg, fg=fg, text='查看分支', command=lambda :not_Args(Git.check_Branch), font=FONT, width=width_B,
  168. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  169. tkinter.Button(top, bg=bbg, fg=fg, text='新建分支', command=make_Branch, font=FONT, width=width_B,
  170. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  171. tkinter.Button(top, bg=bbg, fg=fg, text='切换分支', command=switch_Branch, font=FONT, width=width_B,
  172. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  173. a_y += 1
  174. tkinter.Button(top, bg=bbg, fg=fg, text='删除分支', command=lambda :Delete_Branch(1), font=FONT, width=width_B,
  175. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  176. tkinter.Button(top, bg=bbg, fg=fg, text='丢弃分支', command=lambda :Delete_Branch(0), font=FONT, width=width_B,
  177. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  178. tkinter.Button(top, bg=bbg, fg=fg, text='合并分支', command=switch_Branch, font=FONT, width=width_B,
  179. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  180. no_ff = tkinter.IntVar()
  181. a_y += 1
  182. tkinter.Button(top, bg=bbg, fg=fg, text='合并分支', command=merge_Branch, font=FONT, width=width_B,
  183. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  184. tkinter.Button(top, bg=bbg, fg=fg, text='退出冲突处理', command=lambda :not_Args(Git.merge_abort), font=FONT, width=width_B,
  185. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  186. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='使用快速合并',
  187. variable=no_ff).grid(column=a_x + 1, row=a_y, sticky=tkinter.W)
  188. no_ff.set(0)
  189. a_y += 1
  190. tkinter.Button(top, bg=bbg, fg=fg, text='连接远程仓库', command=Add_remote, font=FONT, width=width_B,
  191. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  192. tkinter.Button(top, bg=bbg, fg=fg, text='推送到远程仓库', command=lambda :Pull_Push_remote(1), font=FONT, width=width_B,
  193. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  194. tkinter.Button(top, bg=bbg, fg=fg, text='从远程仓库抓取', command=lambda :Pull_Push_remote(0), font=FONT, width=width_B,
  195. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  196. push_bind = tkinter.IntVar()
  197. allow_history = tkinter.IntVar()
  198. a_y += 1
  199. tkinter.Button(top, bg=bbg, fg=fg, text='分支绑定', command=Bind_remote, font=FONT, width=width_B,
  200. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  201. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='无视历史记录',
  202. variable=allow_history).grid(column=a_x + 1, row=a_y, sticky=tkinter.W)
  203. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='推送时绑定',
  204. variable=push_bind).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  205. allow_history.set(0)
  206. push_bind.set(0)
  207. a_y += 1
  208. tkinter.Button(top, bg=bbg, fg=fg, text='应用标签', command=add_tag, font=FONT, width=width_B,
  209. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  210. tkinter.Button(top, bg=bbg, fg=fg, text='查看已有标签', command=lambda :show_tag(1), font=FONT, width=width_B,
  211. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  212. tkinter.Button(top, bg=bbg, fg=fg, text='查询commit记录',command=lambda :show_tag(0), font=FONT, width=width_B,
  213. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  214. a_y += 1
  215. tkinter.Button(top, bg=bbg, fg=fg, text='推送标签', command=push_tag, font=FONT, width=width_B,
  216. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  217. tkinter.Button(top, bg=bbg, fg=fg, text='推送所有标签', command=push_alltag, font=FONT, width=width_B,
  218. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  219. tkinter.Button(top, bg=bbg, fg=fg, text='删除本地标签',command=del_Tag, font=FONT, width=width_B,
  220. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  221. a_y += 1
  222. tkinter.Button(top, bg=bbg, fg=fg, text='删除远程标签', command=del_Tag_remote, font=FONT, width=width_B,
  223. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  224. tkinter.Button(top, bg=bbg, fg=fg, text='删除远程分支', command=del_Branch_remote, font=FONT, width=width_B,
  225. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  226. tkinter.Button(top, bg=bbg, fg=fg, text='刷新远程分支', command=Fetch_remote, font=FONT, width=width_B,
  227. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  228. a_y += 1
  229. tkinter.Button(top, bg=bbg, fg=fg, text='commit补丁', command=cherry_pick, font=FONT, width=width_B,
  230. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  231. tkinter.Button(top, bg=bbg, fg=fg, text='删除远程仓库', command=Del_remote, font=FONT, width=width_B,
  232. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  233. tkinter.Button(top, bg=bbg, fg=fg, text='工作区列表', command=lambda :not_Args(Git.Stash_List), font=FONT, width=width_B,
  234. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  235. global newName_Input
  236. a_y += 1
  237. tkinter.Button(top, bg=bbg, fg=fg, text='文件回退', command=Back_version_File, font=FONT, width=width_B,
  238. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  239. tkinter.Button(top, bg=bbg, fg=fg, text='分支重命名', command=Branch_new, font=FONT, width=width_B,
  240. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  241. newName_Input = tkinter.Entry(top, width=width_B)
  242. newName_Input.grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  243. a_y += 1
  244. tkinter.Button(top, bg=bbg, fg=fg, text='保存工作区', command=lambda :not_Args(Git.Save_stash), font=FONT, width=width_B,
  245. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  246. tkinter.Button(top, bg=bbg, fg=fg, text='恢复工作区', command=lambda :Open_Stash(1), font=FONT, width=width_B,
  247. height=height_B).grid(column=a_x+1, row=a_y, sticky=tkinter.E + tkinter.W)
  248. tkinter.Button(top, bg=bbg, fg=fg, text='删除工作区', command=lambda :Open_Stash(0), font=FONT, width=width_B,
  249. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  250. global Customize_Input, th_do, wait_do
  251. a_y += 1
  252. th_do = tkinter.IntVar()
  253. wait_do = tkinter.IntVar()
  254. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='多进程刷新',
  255. variable=th_do).grid(column=0, row=a_y, sticky=tkinter.W)
  256. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='异步显示',
  257. variable=wait_do).grid(column=1, row=a_y, sticky=tkinter.W)
  258. Customize_Input = tkinter.Entry(top, width=width_B * 3)
  259. Customize_Input.grid(column=2, row=a_y, columnspan=4, sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S)
  260. tkinter.Button(top, bg=bbg, fg=fg, text='执行操作', command=Customize, font=FONT, width=width_B,
  261. height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  262. th_do.set(0)
  263. wait_do.set(1)
  264. TagMessage = commit_m
  265. TagCommit = CommitName
  266. RemoteBranch = BranchNOrigin
  267. LocalBranch = BranchName
  268. top.mainloop()
  269. def Branch_new():#克隆仓库
  270. global BranchName, newName_Input
  271. new_name = newName_Input.get()
  272. old_name = BranchName.get()
  273. do_Sys(Git.Branch_new, (get_Name(), old_name, new_name),show=False)
  274. Updata_GitBox()
  275. def clone_git():#克隆仓库
  276. global clone_url
  277. new_Dic = askdirectory(title = '选择仓库地址')
  278. if new_Dic == '':return False
  279. name = Git.Clone_init(new_Dic)
  280. Clone(name, clone_url.get())
  281. Updata_GitBox()
  282. def Clone(name,url):
  283. do_Sys(Git.Clone, (name, url),
  284. break_time=0,text_n=f'{url}:正在执行克隆操作',th=True,wait=True)
  285. Git.After_Clone(name)
  286. update_Git_Dir()
  287. def Customize():
  288. global Git, Customize_Input, th_do, wait_do
  289. command = Customize_Input.get()
  290. do_Sys(Git.Customize, (get_Name(), command),
  291. break_time=0,text_n=f'{command}:操作进行中',th=bool(th_do.get()),wait=bool(wait_do.get()))
  292. update_Git_Dir()
  293. def Fetch_remote():
  294. global RemoteBranch, LocalBranch, Git, RemoteName
  295. Branch = RemoteBranch.get()
  296. Remote = RemoteName.get()
  297. Local = LocalBranch.get()
  298. do_Sys(Git.Fetch, (get_Name(), Local, Remote, Branch),
  299. break_time=0,text_n=f'此操作需要连接远程仓库,请稍等...',th=True,wait=True)
  300. update_Git_Dir()
  301. def del_Tag():
  302. global Git, RemoteName, TagName
  303. Tag = TagName.get()
  304. do_Sys(Git.del_tag, (get_Name(),Tag))
  305. update_Git_Dir()
  306. def del_Branch_remote():
  307. global Git, RemoteName, TagName
  308. Remoto = RemoteName.get()
  309. Remoto_Branch = RemoteBranch.get()
  310. do_Sys(Git.del_Branch_remote, (get_Name(),Remoto,Remoto_Branch),break_time=0,text_n=f'此操作需要连接远程仓库,请稍等...',
  311. th=True,wait=True)
  312. update_Git_Dir()
  313. def del_Tag_remote():
  314. global Git, RemoteName, TagName
  315. Remoto = RemoteName.get()
  316. Tag = TagName.get()
  317. do_Sys(Git.del_Tag_remote, (get_Name(),Remoto,Tag),break_time=0,text_n=f'此操作需要连接远程仓库,请稍等...',
  318. th=True,wait=True)
  319. update_Git_Dir()
  320. def push_alltag():
  321. global Git, RemoteName
  322. Remoto = RemoteName.get()
  323. do_Sys(Git.push_allTag, (get_Name(),Remoto),break_time=0,text_n=f'此操作需要连接远程仓库,请稍等...',
  324. th=True,wait=True)
  325. update_Git_Dir()
  326. def push_tag():
  327. global TagName, Git, RemoteName
  328. tag_name = TagName.get()
  329. Remoto = RemoteName.get()
  330. do_Sys(Git.push_Tag, (get_Name(), tag_name,Remoto),break_time=0,text_n=f'此操作需要连接远程仓库,请稍等...',
  331. th=True,wait=True)
  332. update_Git_Dir()
  333. def add_tag():
  334. global TagName, Git, commit, tag_message
  335. tag_name = TagName.get()
  336. commit = TagCommit.get()
  337. tag_message = TagMessage.get()
  338. do_Sys(Git.Add_Tag, (get_Name(), tag_name,commit,tag_message),show=False)
  339. update_Git_Dir()
  340. def show_tag(type_):
  341. global Show_Key, Git
  342. key = Show_Key.get()
  343. do_Sys({1:Git.Tag,0:Git.show_new}.get(type_,Git.show_new), (get_Name(), key))
  344. update_Git_Dir()
  345. def Pull_Push_remote(type_):
  346. global RemoteBranch, LocalBranch, Git, allow_history, RemoteName
  347. Branch = RemoteBranch.get()
  348. Remote = RemoteName.get()
  349. Local = LocalBranch.get()
  350. allow = bool(allow_history.get())
  351. u = bool(push_bind.get())
  352. f = tkinter.messagebox.askokcancel('提示', f'是否需要强制推送?(强制推送不被建议)')
  353. do_Sys({0:Git.Pull_remote,1:Git.Push_remote}.get(type_,Git.Pull_remote), (get_Name(), Local, Remote, Branch, allow, u, f),
  354. break_time=0,text_n=f'此操作需要连接远程仓库,请稍等...',th=True,wait=True)
  355. update_Git_Dir()
  356. def Bind_remote():
  357. global RemoteBranch, LocalBranch, Git
  358. Remote = RemoteBranch.get()
  359. Local = LocalBranch.get()
  360. do_Sys(Git.Bind_remote, (get_Name(), Local, Remote))
  361. update_Git_Dir()
  362. def Del_remote():
  363. global RemoteSSH, RemoteName, Git
  364. name = RemoteName.get()
  365. do_Sys(Git.Del_remote, (get_Name(), name))
  366. update_Git_Dir()
  367. def Add_remote():
  368. global RemoteSSH, RemoteName, Git
  369. SSH = RemoteSSH.get()
  370. name = RemoteName.get()
  371. do_Sys(Git.Add_remote, (get_Name(), SSH, name))
  372. update_Git_Dir()
  373. def cherry_pick():
  374. global CommitName, Git
  375. commit = CommitName.get()
  376. do_Sys(Git.cherry_pick, (get_Name(), commit))
  377. update_Git_Dir()
  378. def Open_Stash(type_):
  379. global StashName, Git
  380. stash_num = StashName.get()
  381. if stash_num == '':stash_num = '0'
  382. do_Sys([Git.Drop_stash,Git.Apply_stash][type_], (get_Name(), stash_num))
  383. update_Git_Dir()
  384. def merge_Branch():
  385. global BranchName, Git, no_ff,commit_m
  386. m = commit_m.get()
  387. no = not bool(no_ff.get()) # 对于no_ff来说,True - 使用快速合并,所以要翻转
  388. if m.replace(' ','') == '' and no:
  389. tkinter.messagebox.showinfo('警告!', '非常遗憾,我不同意你commit而不添加任何描述!\n描述是很重要的!'
  390. '(如果你不想添加描述,请使用快速合并,但我并不建议!)')
  391. return False
  392. name = BranchName.get()
  393. do_Sys(Git.merge_Branch, (get_Name(), name, no, m))
  394. update_Git_Dir()
  395. def Delete_Branch(type_):
  396. global BranchName, Git
  397. name = BranchName.get()
  398. do_Sys(Git.Del_Branch, (get_Name(), name, type_))
  399. update_Git_Dir()
  400. def switch_Branch():
  401. global BranchName,Git
  402. name = BranchName.get()
  403. do_Sys(Git.switch_Branch, (get_Name(), name),break_time=1,show=False)
  404. update_Git_Dir()
  405. def make_Branch():
  406. global BranchName,Git,BranchNOrigin
  407. name = BranchName.get()
  408. origin = BranchNOrigin.get()
  409. do_Sys(Git.new_Branch, (get_Name(), name, origin),break_time=1,show=False)
  410. update_Git_Dir()
  411. def rm_file():
  412. global Git,head
  413. dic = FileList
  414. if dic == []: return False
  415. do_Sys(Git.rm,(get_Name(),dic))
  416. update_Git_Dir()
  417. def Back_File():#从暂存区、仓库返回文件
  418. global Git,head
  419. dic = FileList
  420. if dic == []: return False
  421. do_Sys(Git.checkout_version,(get_Name(),dic))
  422. update_Git_Dir()
  423. def Back_version_File():#使用reset回退文件
  424. global Git,head,reset_Type
  425. HEAD = head.get()
  426. if HEAD == '': HEAD = 'HEAD~1'
  427. File = FileList
  428. do_Sys(Git.back_version_file,(get_Name(),HEAD,File))
  429. update_Git_Dir()
  430. def Back_version():
  431. global Git,head,reset_Type
  432. HEAD = head.get()
  433. if HEAD == '': HEAD = 'HEAD~1'
  434. Type = reset_Type.get()
  435. do_Sys(Git.back_version,(get_Name(),HEAD,Type))
  436. update_Git_Dir()
  437. def do_Sys(func,args,name='CoTan Git',break_time=0,show=True,text_n='',th=False,wait=False,stop=True):
  438. p = func(*args)
  439. flat = True
  440. stopKey = Git_Ctrl.stopKey
  441. def Out_Txt():
  442. nonlocal data
  443. dic = asksaveasfilename(title='选择文件保存位置',filetypes=[("TXT", ".txt")])
  444. try:
  445. if dic == '':return False
  446. if dic[-4] == '.txt':pass
  447. else:raise Exception
  448. except:
  449. dic += '.txt'
  450. with open(dic,'w',encoding='utf-8') as f:
  451. f.write(data)
  452. kb = True
  453. sb = True
  454. def update_b():
  455. if not kb:
  456. b_list[1].config(state=tkinter.DISABLED)
  457. if not sb:
  458. b_list[0].config(state=tkinter.DISABLED)
  459. def Stop():
  460. nonlocal start,kb,sb
  461. start = 0
  462. sb = False
  463. kb = False
  464. update_b()
  465. def keep():
  466. nonlocal start,kb
  467. start = float('inf')
  468. kb = False
  469. update_b()
  470. def pipe():pass
  471. def not_out():
  472. nonlocal text,out_data,data,flat
  473. text.clear()
  474. if flat:
  475. text.insert(tkinter.END,data)
  476. else:
  477. text.insert(tkinter.END, out_data)
  478. flat = not flat
  479. start = time.time()
  480. data = ''
  481. out_data = ''#包含out的data
  482. if show:
  483. text, new_top, b_list = show_Now(Out_Txt,Stop,keep,not_out,pipe,name=name)#[close,keep]
  484. update_b()
  485. if text_n != '':
  486. text.insert('0.0',f'载入前提示>>> {text_n}\n')
  487. out_data += f'载入前提示>>> {text_n}\n'
  488. data += f'{text_n}\n'
  489. new_top.update()
  490. else:
  491. u = threading.Thread(target=up)
  492. u.start()
  493. top.update()
  494. def Update():
  495. nonlocal start
  496. while True:
  497. try:
  498. top.update()
  499. if show:
  500. try:
  501. new_top.update()
  502. except:pass
  503. if time.time() - start >= break_time and break_time != 0:
  504. raise Exception
  505. elif break_time == 0 and start == 0:
  506. raise Exception
  507. except:
  508. start = 0
  509. break
  510. if th or not wait:
  511. j = threading.Thread(target=Update)#如果没有启动到多进程的效果,请检查Update是不是加了(),这里需要回调
  512. j.start()
  513. if wait:#等待后显示
  514. if break_time == 0:break_ti = None# 此处break_ti是为了别面覆盖break_time,因为Update进程需要用
  515. else:break_ti = break_time
  516. def wait_p():
  517. nonlocal start
  518. p.wait(break_ti)
  519. start = 0
  520. j = threading.Thread(target=wait_p) # 这么做不是多此一举,如果没有wait,进程并不会退出
  521. j.start()
  522. Update()#遇到sleep等主线程阻塞,top.update等会阻塞子线程,因此,必须保证主线程不会被wait所阻塞
  523. out = p.stdout.read().split('\n')
  524. for i in out:
  525. if show:
  526. try: # 如果界面被关掉了,会报错
  527. new_top.title(f'{name} : 运行中')
  528. except:
  529. text, new_top, b_list = show_Now(Out_Txt, Stop, keep, not_out, pipe,
  530. name=f'{name} : 运行中')
  531. update_b()
  532. text.insert(tkinter.END, out_data)
  533. if stop and i.replace(' ', '').replace('\n', '') != stopKey:
  534. text.insert(tkinter.END, f'[out]> {i}\n')
  535. data += i + '\n'
  536. out_data += f'[out]> {i}\n'
  537. if show:
  538. text.insert(tkinter.END, '[END]')
  539. out_data += f'[END]'
  540. data += f'[END]'
  541. start = 0
  542. else:#即时显示
  543. while True:
  544. #界面设置
  545. try:#如果界面被关掉了,会报错
  546. if show: new_top.title(f'{name} : 运行中')
  547. except:
  548. text, new_top, b_list = show_Now(Out_Txt, Stop, keep, not_out, pipe,
  549. name=f'{name} : 运行中')
  550. update_b()
  551. text.insert(tkinter.END,out_data)
  552. #界面刷新
  553. try:
  554. if not th:
  555. top.update()
  556. if show: new_top.update()
  557. except:
  558. break
  559. #输出字符
  560. try:
  561. i = p.stdout.readline()#.decode(str_code)#不需要decode,因为Popen已经设置了universal_newlines=True
  562. bool_text = i.replace(' ','').replace('\n','')
  563. if bool_text != '':
  564. if stop and bool_text == stopKey:
  565. start = 0
  566. else:
  567. if show: text.insert(tkinter.END, f'[out]> {i}')
  568. data += i
  569. out_data += f'[out]> {i}'
  570. if p.returncode == 0 or (time.time() - start >= break_time and break_time != 0) or (break_time == 0 and start == 0):
  571. if show:
  572. text.insert(tkinter.END,'[END]')
  573. out_data += f'[END]'
  574. data += f'[END]'
  575. break
  576. elif p.returncode != None:
  577. raise Exception
  578. except:
  579. try:
  580. if show:
  581. text.insert(tkinter.END, '[ERROR]')
  582. out_data += f'[ERROR]'
  583. data += f'[ERROR]'
  584. raise Exception
  585. except:break
  586. try: # 如果界面被关掉了,会报错
  587. if show: new_top.title(f'{name} : 运行完毕')
  588. except:pass
  589. p.kill()
  590. try:
  591. if show:
  592. b_list[0].config(state=tkinter.DISABLED)
  593. b_list[1].config(state=tkinter.DISABLED)
  594. except:pass
  595. return data
  596. def log():
  597. global Git,log_Type
  598. name = get_Name()
  599. graph = bool(log_Type[0].get())
  600. abbrev = bool(log_Type[1].get())
  601. pretty = bool(log_Type[2].get())
  602. do_Sys(Git.log,(name,graph,pretty,abbrev))
  603. update_Git_Dir()
  604. def not_Args(func):
  605. global Git
  606. name = get_Name()
  607. do_Sys(func,(name,))
  608. update_Git_Dir()
  609. def Commit_File():
  610. global Git,commit_m
  611. m = commit_m.get()
  612. if m.replace(' ','') == '':
  613. tkinter.messagebox.showinfo('警告!', '非常遗憾,我不同意你commit而不添加任何描述!\n描述是很重要的!')
  614. return False
  615. name = get_Name()
  616. do_Sys(Git.commit_File,(name,m))
  617. update_Git_Dir()
  618. def Diff_File():
  619. global Git,master
  620. MASTER = master.get()
  621. if MASTER == '':MASTER = 'HEAD'
  622. do_Sys(Git.diff_File,(get_Name(),MASTER))
  623. update_Git_Dir()
  624. def Reset_File():
  625. global Git,Last_Name,FileList
  626. dic = FileList
  627. if dic == []:dic = '.'
  628. do_Sys(Git.reset_File,(get_Name(),dic))
  629. update_Git_Dir()
  630. def Add_File():
  631. global Git,Last_Name,FileList
  632. dic = FileList
  633. if dic == []:dic = '.'#查一下取消的dic
  634. do_Sys(Git.add_File,(get_Name(),dic))
  635. update_Git_Dir()
  636. def Add_FileList():
  637. global FileList, File_BOX
  638. a = set(askopenfilenames(title=f'选择要add的文件(取消为全选)'))
  639. b = set(FileList)
  640. dic = list(a - (a & b))#筛选出重复
  641. FileList += dic
  642. Update_FileBox()
  643. def Add_FileInput():
  644. global File_Input
  645. dic = File_Input.get()
  646. if dic.replace(' ','') != '' and dic not in FileList:
  647. FileList.append(dic)
  648. Update_FileBox()
  649. def Add_FileByGit():
  650. global File_Input
  651. dic = File_Input.get()
  652. if dic.replace(' ', '') != '':
  653. name = get_Name()
  654. new_dir = Git.make_Dir(name,dic)
  655. if new_dir not in FileList:
  656. FileList.append(new_dir)
  657. Update_FileBox()
  658. def Del_FileBox():
  659. global FileList, File_BOX
  660. try:
  661. del FileList[File_BOX.curselection()]
  662. Update_FileBox()
  663. except:pass
  664. def Tra_FileBox():
  665. global FileList
  666. FileList = []
  667. Update_FileBox()
  668. def Update_FileBox():
  669. global FileList, File_BOX
  670. File_BOX.delete(0, tkinter.END)
  671. File_BOX.insert(tkinter.END, *FileList)
  672. def update_Git_Dir():
  673. global Last_Name
  674. if Last_Name == None:return False
  675. Git_dir(Last_Name)
  676. def get_Git_Dir():
  677. name = get_Name()
  678. Git_dir(name)
  679. def Git_dir(name):
  680. global Git, Git_Dir,Last_Name
  681. dir_list = Git.get_Dir(name)
  682. try:#窗口可能已经关闭
  683. Git_Dir.delete(0,tkinter.END)
  684. Git_Dir.insert(tkinter.END,*dir_list)
  685. except:
  686. pass
  687. Last_Name = name
  688. def init_git():#创建仓库
  689. global Git
  690. new_Dic = askdirectory(title = '选择仓库地址')
  691. if new_Dic == '':return False
  692. Git.Add_init(new_Dic,)
  693. Updata_GitBox()
  694. def get_Name(): # 获得名字统一接口
  695. global Git,Git_List,Git_Box
  696. try:
  697. return Git_List[Git_Box.curselection()[0]]
  698. except:
  699. try:
  700. return Git_List[0]
  701. except:
  702. return None
  703. def Updata_GitBox():
  704. global Git,Git_List,Git_Box
  705. Git_List = list(Git.get_git_Dic().keys())
  706. Git_Box.delete(0,tkinter.END)
  707. Git_Box.insert(tkinter.END,*Git_List)
  708. def show_Now(out_func,close_func,keepFunc,not_out,pipeFunc,name='CoTan_Git >>> 命令行'):
  709. global bg
  710. new_top = tkinter.Toplevel(bg=bg)
  711. new_top.title(name)
  712. new_top.geometry('+10+10') # 设置所在位置
  713. new_top.resizable(width=False, height=False)
  714. class ScrolledText_new(ScrolledText):
  715. def __init__(self,*args,**kwargs):
  716. super(ScrolledText_new, self).__init__(*args,**kwargs)
  717. def insert(self, index, chars, *args):
  718. text.config(state=tkinter.NORMAL)
  719. super(ScrolledText_new, self).insert(index, chars, *args)
  720. text.config(state=tkinter.DISABLED)
  721. def clear(self):
  722. text.config(state=tkinter.NORMAL)
  723. self.delete('0.0',tkinter.END)
  724. text.config(state=tkinter.DISABLED)
  725. text = ScrolledText_new(new_top, font=('黑体', 11), height=30,width=100)
  726. text.grid(column=0, row=0,columnspan=5, sticky=tkinter.E + tkinter.W)
  727. text.config(state=tkinter.DISABLED)
  728. tkinter.Button(new_top, bg=bg, fg=fg, text='输出文档', font=('黑体', 11),width=20, height=2, command=out_func).grid(
  729. column=4, row=1, sticky=tkinter.E + tkinter.W)
  730. close = tkinter.Button(new_top, bg=bg, fg=fg, text='关闭子线程连接', font=('黑体', 11),width=20, height=2, command=close_func)
  731. close.grid(column=0, row=1, sticky=tkinter.E + tkinter.W)
  732. keep = tkinter.Button(new_top, bg=bg, fg=fg, text='保持线程连接', font=('黑体', 11),width=20, height=2, command=keepFunc)
  733. keep.grid(column=1, row=1, sticky=tkinter.E + tkinter.W)
  734. tkinter.Button(new_top, bg=bg, fg=fg, text='格式化输出', font=('黑体', 11),width=20, height=2, command=not_out).grid(
  735. column=2, row=1, sticky=tkinter.E + tkinter.W)
  736. tkinter.Button(new_top, bg=bg, fg=fg, text='启动CoTan命令行', font=('黑体', 11),width=20, height=2,
  737. command=pipeFunc,state=tkinter.DISABLED).grid(column=3, row=1, sticky=tkinter.E + tkinter.W)
  738. new_top.update()
  739. return text,new_top,[close,keep]
  740. def up(*args,name='CoTan_Git >>> 运行中...',**kwargs):
  741. new_top = tkinter.Toplevel(bg=bg)
  742. new_top.title(name)
  743. new_top.geometry('+10+10') # 设置所在位置
  744. mpb = ttk.Progressbar(new_top, orient="horizontal", length=300, mode="determinate")
  745. mpb.pack()
  746. new_top.resizable(width=False, height=False)
  747. mpb["maximum"] = 50
  748. mpb["value"] = 0
  749. for i in range(50):
  750. mpb["value"] = i + 1
  751. new_top.update()
  752. top.update()
  753. time.sleep(0.001)
  754. new_top.destroy()