用户:小苏打_查看:0 回复:0 评论:0 创建时间:2021-04-15T22:25:42
2020.11 PASTeditor v0.1 出现:使用Pygame,界面极其简陋,bug多
2020.12 PASTeditor v0.2 修好一个bug,冒出10个bug
2021.4.10 PASTeditor v2.0(未完成) 重拾PASTeditor,开始从零重新开发v2.0
2021.4.15 PASTeditor v2.0(未完成) 基本的输入功能已经可以实现,但无法保存到电脑
v2.0(未完成)源码如下:希望这能对你用Pygame开发文书编辑程序(editor)能有所帮助。
import pygame as pg
pastwords = { #字母表
0:"Φ",
1:"?",
2:"O",
3:">",
4:"F",
5:"–",
6:"ν",
7:"x",
8:"e"
}
texts = [[['']]] # [all[everypage[everyline]]] 保存文字
gb_page = 0 #游标
gb_line = 0 #游标
gb_char = 0 #游标
#functions#
def drawFrame(): #绘制框架
pg.draw.rect(window,BLUE,[0,0,windowlength,60])
pg.draw.rect(window,WHITE,[15,15,70,30])
fonts = pg.font.Font(None,30)
text_save = fonts.render("save",True,(0,0,0))
window.blit(text_save,(25,20))
def drawTexts(): #绘制文字
gb_page = 0
gb_line = 0
gb_char = 0
textx = ""
for i in range(len(texts[gb_page])):
for j in range(len(texts[gb_page][i])):
textx = textx + texts[gb_page][i][j]
gb_char = gb_char+1
t = fonts.render(textx,True,(0,0,0))
window.blit(t,(5,gb_line*20+70))
gb_char = 0
gb_line += 1
textx = ""
pg.init() #main
#colors#
WHITE = (255,255,255)
YELLOW = (255,255,0)
BLUE = (0, 229, 238)
#windowSurface setting#
window = pg.display.set_mode([800,600])
window.fill(WHITE)
pg.display.set_caption('PAST editor v2.0')
oclock = pg.time.Clock()
fonts = pg.font.Font(None,30)
windowlength = 800
windowwidth = 600
running = True
while running:
for event in pg.event.get():
if event.type is pg.QUIT:
running = False
if event.type == pg.KEYDOWN:
if event.key is pg.K_a:
texts[gb_page][gb_line].append(pastwords[0])
gb_char += 1
if gb_char >= 50:
gb_char = 0
gb_line +=1
if gb_line+1 > len(texts[gb_page]):
texts[gb_page].append([""])
if event.key is pg.K_s:
texts[gb_page][gb_line].append(pastwords[1])
gb_char += 1
if gb_char >= 50:
gb_char = 0
gb_line +=1
if gb_line+1 > len(texts[gb_page]):
texts[gb_page].append([""])
if event.key is pg.K_d:
texts[gb_page][gb_line].append(pastwords[2])
gb_char += 1
if gb_char >= 50:
gb_char = 0
gb_line +=1
if gb_line+1 > len(texts[gb_page]):
texts[gb_page].append([""])
if event.key is pg.K_f:
texts[gb_page][gb_line].append(pastwords[3])
gb_char += 1
if gb_char >= 50:
gb_char = 0
gb_line +=1
if gb_line+1 > len(texts[gb_page]):
texts[gb_page].append([""])
if event.key is pg.K_g:
texts[gb_page][gb_line].append(pastwords[4])
gb_char += 1
if gb_char >= 50:
gb_char = 0
gb_line +=1
if gb_line+1 > len(texts[gb_page]):
texts[gb_page].append([""])
if event.key is pg.K_h:
texts[gb_page][gb_line].append(pastwords[5])
gb_char += 1
if gb_char >= 50:
gb_char = 0
gb_line +=1
if gb_line+1 > len(texts[gb_page]):
texts[gb_page].append([""])
if event.key is pg.K_j:
texts[gb_page][gb_line].append(pastwords[6])
gb_char += 1
if gb_char >= 50:
gb_char = 0
gb_line +=1
if gb_line+1 > len(texts[gb_page]):
texts[gb_page].append([""])
if event.key is pg.K_k:
texts[gb_page][gb_line].append(pastwords[7])
gb_char += 1
if gb_char >= 50:
gb_char = 0
gb_line +=1
if gb_line+1 > len(texts[gb_page]):
texts[gb_page].append([""])
if event.key is pg.K_l:
texts[gb_page][gb_line].append(pastwords[8])
gb_char += 1
if gb_char >= 50:
gb_char = 0
gb_line +=1
if gb_line+1 > len(texts[gb_page]):
texts[gb_page].append([""])
if event.key is pg.K_SPACE:
texts[gb_page][gb_line].append(" ")
gb_char += 1
if gb_char >= 50:
gb_char = 0
gb_line +=1
if gb_line+1 > len(texts[gb_page]):
texts[gb_page].append([""])
if event.key is pg.K_RETURN:
texts[gb_page].append([""])
gb_line+=1
gb_char = 0
if event.key is pg.K_BACKSPACE:
if len(texts[gb_page][0]) <= 1:
if len(texts[gb_page][0]) is 0:
texts[gb_page][0].append("")
else:
if gb_char is 0:
if gb_line is 0:
if gb_page is not -1:
del texts[gb_page-1][gb_line][gb_char]
gb_page -= 1
else:
del texts[gb_page][gb_line]
gb_line -= 1
gb_char = len(texts[gb_page][gb_line])-1
else:
del texts[gb_page][gb_line][gb_char]
gb_char -= 1
window.fill(WHITE)
drawFrame()
drawTexts()
pg.display.update()
oclock.tick(60)
pg.quit()