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
049400b6
Commit
049400b6
authored
Jul 15, 2011
by
Keegi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
indent/unindent multiline macros automatically for macro editor
parent
b9ccd433
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
4 deletions
+24
-4
pronterface.py
pronterface.py
+24
-4
No files found.
pronterface.py
View file @
049400b6
...
...
@@ -843,7 +843,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
class
macroed
(
wx
.
Frame
):
"""Really simple editor to edit macro definitions"""
def
__init__
(
self
,
macro_name
,
definition
,
callback
):
# TBD: remove top-level indent from the definition (if any)
self
.
indent_chars
=
" "
wx
.
Frame
.
__init__
(
self
,
None
,
title
=
"macro
%
s"
%
macro_name
)
self
.
callback
=
callback
self
.
panel
=
wx
.
Panel
(
self
,
-
1
)
...
...
@@ -860,7 +860,7 @@ class macroed(wx.Frame):
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
(
definition
)
self
.
e
.
SetValue
(
self
.
unindent
(
definition
)
)
topsizer
.
Add
(
self
.
e
,
1
,
wx
.
ALL
+
wx
.
EXPAND
)
self
.
panel
.
SetSizer
(
topsizer
)
topsizer
.
Layout
()
...
...
@@ -868,10 +868,30 @@ class macroed(wx.Frame):
self
.
Show
()
def
save
(
self
,
ev
):
self
.
Close
()
# TBD: add back top-level indent unless single line.
self
.
callback
(
self
.
e
.
GetValue
())
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
)
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
):
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__'
:
...
...
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