Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 0 additions & 102 deletions BinEditor.py

This file was deleted.

6 changes: 6 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- Integrate TextDraw.py and the buffer provided into kernel.py
Specifications:
- Should contain a variable that controls the availability of the buffer
- Because of this, apps will trigger the buffer by setting the value of that variable
- Should have a button to go back (to the desktop), which means integrating a button too
- Preferably make this into a class and make the buffer sizeable
61 changes: 48 additions & 13 deletions TextDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,44 @@

import pygame, sys

def wrap(txtBuffer):
lines = []
temp = ""
for c in txtBuffer:
if c == '\n':
lines.append(temp)
temp = ""
else:
temp += c
lines.append(temp)
return lines

def drawTxt(screen, lines, y = 0):
for line in lines:
img = raster.render(line, True, (255, 255, 255))
screen.blit(img, (0, y))
y += 16


width, height = 800, 600

txtBuffer = []
# ↓ Magic! ↓
caps = { '`': '~', '1': '!', '2': '@', '3': '#', '4': '$', '5': '%', '6': '^', '7': '&', '8': '*', '9': '(', '0': ')', '-': '_', '=': '+', '[': '{', ']': '}', '\\': '|', ';': ':', '\'': '"', ',': '<', '.': '>', '/': '?', 'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D', 'e': 'E', 'f': 'F', 'g': 'G', 'h': 'H', 'i': 'I', 'j': 'J', 'k': 'K', 'l': 'L', 'm': 'M', 'n': 'N', 'o': 'O', 'p': 'P', 'q': 'Q', 'r': 'R', 's': 'S', 't': 'T', 'u': 'U', 'v': 'V', 'w': 'W', 'x': 'X', 'y': 'Y', 'z': 'Z' }

pygame.init()
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("TextDraw")
clock = pygame.time.Clock()

raster = pygame.font.Font("res/vga936.fon", 32)

shift = False
capsLock = False

while True:
screen.fill((0, 0, 0))
drawTxt(screen, wrap(txtBuffer))
pygame.display.update()
clock.tick(50)
for event in pygame.event.get():
Expand All @@ -23,21 +51,28 @@
if event.key == pygame.K_BACKSPACE:
try:
txtBuffer.pop()
for c in txtBuffer:
print(txtBuffer)
except:
print(txtBuffer)
pass
elif event.key == pygame.K_RETURN:
txtBuffer.append('\n')
print(txtBuffer)
elif event.key == pygame.K_LSHIFT or event == pygame.K_RSHIFT:
# TODO: do shift
pass
elif event.key == pygame.K_TAB:
for i in range(4):
txtBuffer.append(' ')
elif event.key == pygame.K_LSHIFT or event.key == pygame.K_RSHIFT:
shift = True
elif event.key == pygame.K_CAPSLOCK:
# TODO: always do shift
pass
capsLock = 1 - capsLock
else:
if 32 <= event.key <= 126 or event.key == pygame.K_TAB:
txtBuffer.append(chr(event.key))
for c in txtBuffer:
print(txtBuffer)
if 32 <= event.key <= 126:
# ↓ Also magic! ↓
if (44 <= event.key <= 57 or event.key == 59 or event.key == 61 or event.key == 96 or 91 <= event.key <= 93 or event.key == 39) and shift:
txtBuffer.append(caps[chr(event.key)])
elif 97 <= event.key <= 122 and (shift or capsLock):
txtBuffer.append(caps[chr(event.key)])
else:
txtBuffer.append(chr(event.key))
elif event.type == pygame.KEYUP:
if event.key == pygame.K_LSHIFT or event.key == pygame.K_RSHIFT:
shift = False
elif event.key == pygame.K_CAPSLOCK:
capsLock = 1 - capsLock
Binary file modified backup/files.img
Binary file not shown.
8 changes: 3 additions & 5 deletions files.img
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ class DlgStatus(Enum):
class Dialog:
def __init__(self, title, content, status = DlgStatus.INFO):
self.img = pygame.image.load("res/dialog/dialog.png")
self.icon = pygame.image.load("res/dialog/" + str(status) + ".bmp")
self.icon.set_colorkey((255, 255, 255))
self.icon = pygame.transform.scale(pygame.image.load("res/dialog/" + str(status) + ".bmp"), (32, 32))
self.icon.set_colorkey((255, 0, 255))
self.title = framework.raster.render(title, True, (255, 255, 255))
self.content = lineWrap(content, 35)
self.dialogID = 0
Expand All @@ -212,8 +212,7 @@ term = App("res/term.jpg")
framework.appID = bg.appID
framework.addApp(bg)
framework.addApp(term)
framework.addDialog(Dialog("Hey there!", "Welcome to our OS emulator! As you can see, line wrap is working perfectly here. Now we just need some art for the icons."))
framework.addDialog(Dialog("Hi!", "Another one"))
framework.addDialog(Dialog("Hey there!", "Welcome to our OS emulator!"))
bg.addButton(Button('U', "res/button/txt_btn.bmp", width // 2 - 35, 20, term.appID, font=framework.raster, content="TERMINAL"))
term.addButton(Button('D', "res/button/txt_btn.bmp", width // 2 - 35, 20, bg.appID, font=framework.raster, content="CLOSE"))

Expand All @@ -238,7 +237,6 @@ while True:

!LOC=/bin/
!FNAME=vis.py

# vis.py
# Basic CLI text editor

Expand Down
20 changes: 10 additions & 10 deletions kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,20 @@ def __init__(self, picName):
self.pic = Pic(picName)
self.appID = 0
self.btnList = []
self.txtList = []
self.tooltipList = []
self.txtFieldList = []
self.secretList = []
def draw(self, screen):
if framework.appID != self.appID:
return
screen.blit(self.pic.img, (0, 0))
for button in self.btnList:
button.draw(screen)
for txt in self.txtList:
txt.draw(screen)
for tooltip in self.tooltipList:
tooltip.draw(screen)
def addButton(self, b):
self.btnList.append(b)
def addTxt(self, txt, font, x, y, c, rect):
def addTooltip(self, txt, font, x, y, c, rect):
t = Txt(txt, font, x, y, c, rect)
self.txtList.append(t)
def mouseDown(self, pos, button):
Expand Down Expand Up @@ -157,7 +158,7 @@ def mouseMove(self, pos):
else:
self.status = 0

class Txt:
class Tooltip:
def __init__(self, txt, font, x, y, c, rect):
self.txt = txt
self.img = font.render(txt, True, c)
Expand All @@ -174,7 +175,7 @@ def __init__(self, rect, dialogID):
self.dialogID = dialogID
def mouseDown(self, pos, button):
if self.rect.collidepoint(pos):
framework.dialogs.pop(len(framework.dialogs) - 1)
framework.dialogs.pop()
print(len(framework.dialogs) - 1)

class DlgStatus(Enum):
Expand All @@ -185,8 +186,8 @@ class DlgStatus(Enum):
class Dialog:
def __init__(self, title, content, status = DlgStatus.INFO):
self.img = pygame.image.load("res/dialog/dialog.png")
self.icon = pygame.image.load("res/dialog/" + str(status) + ".bmp")
self.icon.set_colorkey((255, 255, 255))
self.icon = pygame.transform.scale(pygame.image.load("res/dialog/" + str(status) + ".bmp"), (32, 32))
self.icon.set_colorkey((255, 0, 255))
self.title = framework.raster.render(title, True, (255, 255, 255))
self.content = lineWrap(content, 35)
self.dialogID = 0
Expand All @@ -208,8 +209,7 @@ def mouseDown(self, pos, button):
framework.appID = bg.appID
framework.addApp(bg)
framework.addApp(term)
framework.addDialog(Dialog("Hey there!", "Welcome to our OS emulator! As you can see, line wrap is working perfectly here. Now we just need some art for the icons."))
framework.addDialog(Dialog("Hi!", "Another one"))
framework.addDialog(Dialog("Hey there!", "Welcome to our OS emulator!"))
bg.addButton(Button('U', "res/button/txt_btn.bmp", width // 2 - 35, 20, term.appID, font=framework.raster, content="TERMINAL"))
term.addButton(Button('D', "res/button/txt_btn.bmp", width // 2 - 35, 20, bg.appID, font=framework.raster, content="CLOSE"))

Expand Down
Binary file modified res/dialog/DlgStatus.ERROR.bmp
Binary file not shown.
Binary file modified res/dialog/DlgStatus.INFO.bmp
Binary file not shown.
Binary file modified res/dialog/DlgStatus.WARNING.bmp
Binary file not shown.
6 changes: 3 additions & 3 deletions stub.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#
# OS emulator using pygame.
# Copyright (C) 2020 The-UltimateGamer & pythonleo
#
Expand Down Expand Up @@ -37,9 +36,10 @@
dsk_spl = img.read().split('\n')
kernel = []
for i, line in enumerate(dsk_spl):
if line == '!LOC=/sys/' and dsk_spl[i+1] == '!FNAME=kernel.py':
if line == '!LOC=/sys/' and dsk_spl[i + 1] == '!FNAME=kernel.py':
for j in range(i+2, len(dsk_spl)):
if len(dsk_spl[j]) > 0 and dsk_spl[j][0] == '!': break
if len(dsk_spl[j]) > 0 and dsk_spl[j][0] == '!':
break
kernel.append(dsk_spl[j])
break

Expand Down