Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
7b9cb79f
Commit
7b9cb79f
authored
Jul 15, 2011
by
Keegi
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote branch 'k-eex/master' (macro editor)
parents
655ab135
1d5ce77a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
7 deletions
+89
-7
pronsole.py
pronsole.py
+13
-7
pronterface.py
pronterface.py
+76
-0
No files found.
pronsole.py
View file @
7b9cb79f
...
@@ -182,6 +182,15 @@ class pronsole(cmd.Cmd):
...
@@ -182,6 +182,15 @@ class pronsole(cmd.Cmd):
print
"Empty macro - cancelled"
print
"Empty macro - cancelled"
del
self
.
cur_macro
,
self
.
cur_macro_name
,
self
.
cur_macro_def
del
self
.
cur_macro
,
self
.
cur_macro_name
,
self
.
cur_macro_def
def
start_macro
(
self
,
macro_name
,
prev_definition
=
""
,
suppress_instructions
=
False
):
if
not
self
.
processing_rc
and
not
suppress_instructions
:
print
"Enter macro using indented lines, end with empty line"
self
.
cur_macro_name
=
macro_name
self
.
cur_macro_def
=
""
self
.
cur_macro
=
"def macro(self,*arg):
\n
"
self
.
onecmd
=
self
.
hook_macro
# override onecmd temporarily
self
.
prompt
=
"..>"
def
do_macro
(
self
,
args
):
def
do_macro
(
self
,
args
):
if
args
.
strip
()
==
""
:
if
args
.
strip
()
==
""
:
self
.
print_topics
(
"User-defined macros"
,
self
.
macros
.
keys
(),
15
,
80
)
self
.
print_topics
(
"User-defined macros"
,
self
.
macros
.
keys
(),
15
,
80
)
...
@@ -214,13 +223,10 @@ class pronsole(cmd.Cmd):
...
@@ -214,13 +223,10 @@ class pronsole(cmd.Cmd):
self
.
cur_macro
=
"def macro(self,*arg):
\n
self.onecmd('"
+
macro_def
+
"'.format(*arg))
\n
"
self
.
cur_macro
=
"def macro(self,*arg):
\n
self.onecmd('"
+
macro_def
+
"'.format(*arg))
\n
"
self
.
end_macro
()
self
.
end_macro
()
return
return
if
not
self
.
processing_rc
:
if
self
.
macros
.
has_key
(
macro_name
):
print
"Enter macro using indented lines, end with empty line"
self
.
start_macro
(
macro_name
,
self
.
macros
[
macro_name
])
self
.
cur_macro_name
=
macro_name
else
:
self
.
cur_macro_def
=
""
self
.
start_macro
(
macro_name
)
self
.
cur_macro
=
"def macro(self,*arg):
\n
"
self
.
onecmd
=
self
.
hook_macro
# override onecmd temporarily
self
.
prompt
=
"..>"
def
help_macro
(
self
):
def
help_macro
(
self
):
print
"Define single-line macro: macro <name> <definition>"
print
"Define single-line macro: macro <name> <definition>"
...
...
pronterface.py
View file @
7b9cb79f
...
@@ -178,6 +178,28 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
...
@@ -178,6 +178,28 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
except
:
except
:
print
"You must enter a temperature."
print
"You must enter a temperature."
def
start_macro
(
self
,
macro_name
,
old_macro_definition
=
""
):
if
not
self
.
processing_rc
:
def
cb
(
definition
):
if
"
\n
"
not
in
definition
and
len
(
definition
.
strip
())
>
0
:
macro_def
=
definition
.
strip
()
self
.
cur_macro_def
=
macro_def
self
.
cur_macro_name
=
macro_name
if
macro_def
.
startswith
(
"!"
):
self
.
cur_macro
=
"def macro(self,*arg):
\n
"
+
macro_def
[
1
:]
+
"
\n
"
else
:
self
.
cur_macro
=
"def macro(self,*arg):
\n
self.onecmd('"
+
macro_def
+
"'.format(*arg))
\n
"
self
.
end_macro
()
return
pronsole
.
pronsole
.
start_macro
(
self
,
macro_name
,
True
)
for
line
in
definition
.
split
(
"
\n
"
):
if
hasattr
(
self
,
"cur_macro_def"
):
self
.
hook_macro
(
line
)
if
hasattr
(
self
,
"cur_macro_def"
):
self
.
end_macro
()
macroed
(
macro_name
,
old_macro_definition
,
cb
)
else
:
pronsole
.
pronsole
.
start_macro
(
self
,
macro_name
,
old_macro_definition
)
def
catchprint
(
self
,
l
):
def
catchprint
(
self
,
l
):
wx
.
CallAfter
(
self
.
logbox
.
AppendText
,
l
)
wx
.
CallAfter
(
self
.
logbox
.
AppendText
,
l
)
...
@@ -827,6 +849,60 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
...
@@ -827,6 +849,60 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self
.
printbtn
.
SetLabel
(
"Print"
)
self
.
printbtn
.
SetLabel
(
"Print"
)
self
.
paused
=
0
self
.
paused
=
0
class
macroed
(
wx
.
Frame
):
"""Really simple editor to edit macro definitions"""
def
__init__
(
self
,
macro_name
,
definition
,
callback
):
self
.
indent_chars
=
" "
wx
.
Frame
.
__init__
(
self
,
None
,
title
=
"macro
%
s"
%
macro_name
)
self
.
callback
=
callback
self
.
panel
=
wx
.
Panel
(
self
,
-
1
)
titlesizer
=
wx
.
BoxSizer
(
wx
.
HORIZONTAL
)
title
=
wx
.
StaticText
(
self
.
panel
,
-
1
,
" macro
%
s: "
%
macro_name
)
title
.
SetFont
(
wx
.
Font
(
11
,
wx
.
NORMAL
,
wx
.
NORMAL
,
wx
.
BOLD
))
titlesizer
.
Add
(
title
,
1
)
self
.
okb
=
wx
.
Button
(
self
.
panel
,
-
1
,
"Save"
)
self
.
okb
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
save
)
titlesizer
.
Add
(
self
.
okb
)
self
.
cancelb
=
wx
.
Button
(
self
.
panel
,
-
1
,
"Cancel"
)
self
.
cancelb
.
Bind
(
wx
.
EVT_BUTTON
,
self
.
close
)
titlesizer
.
Add
(
self
.
cancelb
)
topsizer
=
wx
.
BoxSizer
(
wx
.
VERTICAL
)
topsizer
.
Add
(
titlesizer
,
0
,
wx
.
EXPAND
)
self
.
e
=
wx
.
TextCtrl
(
self
.
panel
,
style
=
wx
.
TE_MULTILINE
+
wx
.
HSCROLL
,
size
=
(
200
,
200
))
self
.
e
.
SetValue
(
self
.
unindent
(
definition
))
topsizer
.
Add
(
self
.
e
,
1
,
wx
.
ALL
+
wx
.
EXPAND
)
self
.
panel
.
SetSizer
(
topsizer
)
topsizer
.
Layout
()
topsizer
.
Fit
(
self
)
self
.
Show
()
def
save
(
self
,
ev
):
self
.
Close
()
self
.
callback
(
self
.
reindent
(
self
.
e
.
GetValue
()))
def
close
(
self
,
ev
):
self
.
Close
()
def
unindent
(
self
,
text
):
import
re
self
.
indent_chars
=
text
[:
len
(
text
)
-
len
(
text
.
lstrip
())]
unindented
=
""
lines
=
re
.
split
(
r"(?:\r\n?|\n)"
,
text
)
#print lines
if
len
(
lines
)
<=
1
:
return
text
for
line
in
lines
:
if
line
.
startswith
(
self
.
indent_chars
):
unindented
+=
line
[
len
(
self
.
indent_chars
):]
+
"
\n
"
else
:
unindented
+=
line
+
"
\n
"
return
unindented
def
reindent
(
self
,
text
):
import
re
lines
=
re
.
split
(
r"(?:\r\n?|\n)"
,
text
)
if
len
(
lines
)
<=
1
:
return
text
reindented
=
""
for
line
in
lines
:
reindented
+=
self
.
indent_chars
+
line
+
"
\n
"
return
reindented
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment