Home | Reviews | GUIpedia | Forum | Fun500
pharoah | PQML Progress ThreadRight now I'm writing a simple QML reader in Python, so that mac users like Brandon can view Quickspace. Unfortunately I'm going to have to stick to some restrictions to make it cross platform that mean using only standard I/O, so no colors, no nice scrolling, etc... for the first version anyway. The program is fairly modular, there's a module that returns a bunch of lists (a list of 80 col rendered lines, a list of link number URLs, a list of form data). Then there will be other modules for the interface. That way, if people want to add things they c an change one or both of the modules.
Python is a pretty good choice for this because it's fairly cross-platform and has great string parsing capabilities. Unfortunately it doesn't have great built-in console I/O (you can't even request kepresses one at a time without a library). | 2009-03-11 | 4:24 PM |
Brandon | Re:PQML Progress ThreadDoes it compile? Will I need dependencies? | 2009-03-11 | 5:08 PM |
pharoah | Re:PQML Progress ThreadPython comes with OS X, but it's a strictly interpreted language (though it gets compiled to bytecode at runtime). I am going to only use the standard libraries, so it should be fine.
In case you're curious about how Python code looks, here's my current simple render function:
[code]
def tab_strip(string):
if string[0] == chr(9):
return tab_strip(string[1:])
else:
return string
def render(page):
disp = [""]
links = []
for line in page.split("n"):
line = tab_strip(line)
if line != "":
tag = line[0]
if tag == "$":
disp[len(disp)-1] = disp[len(disp)-1] + line[1:]
elif tag == "|":
for i in range(0, len(line.strip())):
disp.append("")
elif tag == "-":
disp.append(line[1:].center(80))
disp.append("")
elif tag == "=":
disp.append("="*80)
disp.append("")
elif tag == "_":
(title, url) = line[1:].split(">")
links.append(url)
disp[len(disp)-1] = disp[len(disp)-1] + title +"("+str(len(links))+")"
return (disp,links)
[/code]
Whitespace is important in python, the tabs delimit blocks | 2009-03-11 | 5:16 PM |
ksr | Re:PQML Progress ThreadCool. split looks like a very useful function. | 2009-03-11 | 5:32 PM |
pharoah | Re:PQML Progress ThreadYeah split is nice to have. I actually wrote a Qbasic (not FB ) version of split a while ago. I sent it to Brandon as part of the ill-fated QML Newsletter which doesn't seem to be online anymore, and I can't find the original.
EDIT:
I was wrong, here it is. It's called explode because that was what PHP called it.
[code]
'$DYNAMIC
DECLARE SUB explode (source$, delimiter$, destination$())
CLS
DIM destiny$(1)
parseme$ = "One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten"
with$ = ", "
explode parseme$, with$, destiny$()
PRINT (UBOUND(destiny$) + 1); "substrings found:"
FOR i = 0 TO UBOUND(destiny$)
PRINT i; "==> "; destiny$(i)
NEXT
REM $STATIC
SUB explode (source$, delimiter$, destination$())
'$DYNAMIC
work$ = source$
delimiter.length% = LEN(delimiter$)
DO
IF LEFT$(work$, delimiter.length%) = delimiter$ THEN
next.element$ = ""
next.part = delimiter.length% + 1
IF next.part > LEN(work$) THEN
work$ = ""
ELSE
work$ = MID$(work$, next.part)
END IF
ELSE
loc.instr% = INSTR(work$, delimiter$)
IF loc.instr% = 0 THEN
next.element$ = work$
work$ = ""
ELSE
next.element$ = LEFT$(work$, loc.instr% - 1)
next.part = loc.instr% + delimiter.length%
IF next.part > LEN(work$) THEN
work$ = ""
ELSE
work$ = MID$(work$, next.part)
END IF
END IF
END IF
old.ubound% = UBOUND(destination$)
DIM dummy.array$(old.ubound% + 1)
FOR x% = 0 TO old.ubound%
dummy.array$(x%) = destination$(x%)
NEXT
IF substrings.found% > 0 THEN
REDIM destination$(substrings.found%)
END IF
FOR x% = 0 TO old.ubound%
destination$(x%) = dummy.array$(x%)
NEXT
ERASE dummy.array$
destination$(substrings.found%) = next.element$
substrings.found% = substrings.found% + 1
LOOP UNTIL work$ = ""
END SUB
[/code] | 2009-03-11 | 5:37 PM |
Todd | Re:PQML Progress ThreadMy Mom had to learn how to program in Python. Python can be tricky when using object-oriented aspects. I remember one class wasn't loading and the constructor wasn't even being called.
Pharoah it seems like you're a jack of all languages when it comes to programming. I have an idea to make a universal-like programming language that can translate into several different programming languages. | 2009-03-11 | 5:49 PM |
SonicBrit | Re:PQML Progress ThreadPharoah you could maybe use ANSI colouring?
tlsuess woah like a root language of programming languages, should call it latin :P | 2009-03-11 | 6:38 PM |
pharoah | Re:PQML Progress ThreadYeah I thought about that, but then it wouldn't work in windows without ANSI.sys, and IDK how it would in mac. Maybe I'll add it later on. There's still the issue that python doesn't let you input just one character in a cross-platform way.
Later versions might use ncurses for all this, but this first simple version will be classic black and white. I'm hoping I can get one of my electronic typewriters working as a teletype and then use it with pyqml and bash.
http://www.instructables.com/answers/Does_anyone_know_anything_about_this_typewriter_in/ | 2009-03-11 | 6:47 PM |
Other
2021 Brandon Cornell