Skip to content

Commit

Permalink
+ GUI
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Ponyatov <dponyatov@gmail.com>
  • Loading branch information
ponyatov committed Jun 12, 2019
1 parent 0cafa68 commit 1fc1d4b
Show file tree
Hide file tree
Showing 12 changed files with 641 additions and 331 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $(MODULE)_$(TODAY).pdf: book/$(MODULE).pdf
merge:
$(MAKE) pdf
git checkout master
git checkout ponyatov -- Makefile
git checkout ponyatov -- Makefile book/ metaL.py metaL.ml

release:
$(MAKE) pdf
Expand Down
4 changes: 4 additions & 0 deletions book/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ TEX += frames/active.tex
TEX += forth/forth.tex forth/dict.tex forth/ply.tex forth/repl.tex
TEX += forth/cmdline.tex

TEX += gui/gui.tex
LST += gui/gui00.py gui/gui01.py gui/gui02.py gui/gui03.py
LST += gui/gui05.py gui/gui04.py

TEX += web/web.tex
TEX += web/templ.tex
LST += web/templ.css web/templ.html web/templ.py
Expand Down
27 changes: 27 additions & 0 deletions book/gui/gui.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
\secrel{GUI /wxPython/}\label{wx}\secdown

\lst{gui/gui00.py}{language=Python}

\secrel{GUI фрейм}

\lst{gui/gui01.py}{language=Python}

\secrel{Editor: окно редактора}\secdown

\lst{gui/gui02.py}{language=Python}

\secrel{Меню}

\lst{gui/gui03.py}{language=Python}

\secrel{Область редактора}

\lst{gui/gui04.py}{language=Python}

\secup

\secrel{Запуск системы}

\lst{gui/gui05.py}{language=Python}

\secup
1 change: 1 addition & 0 deletions book/gui/gui00.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import wx,wx.stc
11 changes: 11 additions & 0 deletions book/gui/gui01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class GUI(Frame):
def __init__(self,V):
Frame.__init__(self, V)
self.app = wx.App()
self['main' ] = self.main = Editor(V)
self['stack'] = self.stack = Editor(V+'.stack')
self['words'] = self.words = Editor(V+'.words')
def start(self):
self.main.Show()
self.main.onUpdate(None)
self.app.MainLoop()
6 changes: 6 additions & 0 deletions book/gui/gui02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Editor(GUI,wx.Frame):
def __init__(self,V):
Frame.__init__(self, V)
wx.Frame.__init__(self,parent=None,title=V)
self.initMenu()
self.initEditor()
55 changes: 55 additions & 0 deletions book/gui/gui03.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
def initMenu(self):
self.menubar = wx.MenuBar()
self.SetMenuBar(self.menubar)
# file
self.file = wx.Menu()
self.menubar.Append(self.file,'&File')
# file/save
self.file.save = self.file.Append(\
wx.ID_SAVE,'&Save')
self.Bind(wx.EVT_MENU,self.onSave,self.file.save)
# file/quit
self.file.quit = self.file.Append(\
wx.ID_EXIT,'&Quit')
self.Bind(wx.EVT_MENU,self.onQuit,self.file.quit)
# debug
self.debug = wx.Menu()
self.menubar.Append(self.debug,'&Debug')
self.debug.update = self.debug.Append(\
wx.ID_REFRESH,'&Update\tF12')
self.Bind(wx.EVT_MENU,\
self.onUpdate,self.debug.update)
# debug/stack
self.debug.stack = self.debug.Append(\
wx.ID_ANY,'&Stack\tF9',kind=wx.ITEM_CHECK)
self.Bind(wx.EVT_MENU,\
self.onStack,self.debug.stack)
# debug/words
self.debug.words = self.debug.Append(\
wx.ID_ANY,'&Words\tF8',kind=wx.ITEM_CHECK)
self.Bind(wx.EVT_MENU,\
self.onWords,self.debug.words)
# help
self.help = wx.Menu()
self.menubar.Append(self.help,'&Help')
self.help.about = self.help.Append(\
wx.ID_ABOUT,'&About\tF1')
self.Bind(wx.EVT_MENU,\
self.onAbout,self.help.about)
def onSave(self,e):
with open(self.val,'w') as file:
file.write(self.editor.GetValue())
def onQuit(self,e):
vm['gui'].stack.Close()
vm['gui'].words.Close()
vm['gui'].main.Close()
def onUpdate(self,e):
vm['gui'].stack.editor.SetValue(\
vm.dump(voc=False))
vm['gui'].words.editor.SetValue(\
vm.dump(voc=True ))
def onAbout(self,e):
with open('README.md') as file:
info = file.read()
wx.MessageBox(info,'About',\
wx.OK|wx.ICON_INFORMATION)
21 changes: 21 additions & 0 deletions book/gui/gui04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Editor(GUI,wx.Frame):
def __init__(self,V):
...
self.initEditor()

def initEditor(self):
self.editor = wx.stc.StyledTextCtrl(self)
self.font = wx.Font(14,
wx.FONTFAMILY_MODERN,
wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_BOLD)
self.editor.StyleSetSpec(
wx.stc.STC_STYLE_DEFAULT,
"face:%s,size:%d" % (
self.font.GetFaceName(),
self.font.GetPointSize()
))
try:
with open(self.val,'r') as file:
self.editor.SetValue(file.read())
except IOError: pass
8 changes: 8 additions & 0 deletions book/gui/gui05.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if __name__ == '__main__':
infiles = sys.argv[1:] ; print infiles
for i in infiles:
vm // String(open(i).read()) ; INTERPRET()
# REPL(vm)
vm['gui'] = GUI(
re.sub(r'\.[a-z]+$',r'.ml',sys.argv[0]))
vm['gui'].start()
1 change: 1 addition & 0 deletions book/metaL.tex
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ \part{Реализация в деталях}\label{implement}\secdown
\input{frames/frames}
\input{forth/forth}
\input{meta/circ}
\input{gui/gui}
\input{web/web}
\input{prolog/prolog}
\input{dyna/dyna}
Expand Down
8 changes: 8 additions & 0 deletions metaL.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# metaL: homoiconic metaprogramming language /metacircular model/
\ (c) Dmitry Ponyatov <dponyatov@gmail.com> CC BY-NC-ND

\ FORTH line comments can be used

\ number literals test

-01 +02.30 -4e+5 0xDeadBeef 0b1101 ? . ?
Loading

0 comments on commit 1fc1d4b

Please sign in to comment.