Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
pyMKcam
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
pyMKcam
Commits
7c3658bb
Commit
7c3658bb
authored
Jan 24, 2012
by
Lars Kruse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed stdin/stdout handling of Console plugin
parent
bafdbdd3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
21 deletions
+28
-21
GtkConsole.py
pycam/Plugins/GtkConsole.py
+27
-21
Log.py
pycam/Plugins/Log.py
+1
-0
No files found.
pycam/Plugins/GtkConsole.py
View file @
7c3658bb
...
...
@@ -51,17 +51,28 @@ class GtkConsole(pycam.Plugins.PluginBase):
self
.
_gtk
=
gtk
self
.
_console
=
code
.
InteractiveConsole
(
locals
=
self
.
core
.
get_namespace
(),
filename
=
"PyCAM"
)
self
.
_console_output
=
StringIO
.
StringIO
()
# TODO: clean up this stdin/stdout mess (maybe subclass "sys"?)
code
.
sys
.
stdout
=
self
.
_console_output
code
.
sys
.
stdin
=
StringIO
.
StringIO
()
# redirect sys.stdin/stdout - "exec" always writes there
self
.
_original_stdout
=
sys
.
stdout
self
.
_original_stdin
=
sys
.
stdin
self
.
_console_buffer
=
self
.
gui
.
get_object
(
"ConsoleViewBuffer"
)
def
console_write
(
data
):
self
.
_console_buffer
.
insert
(
self
.
_console_buffer
.
get_end_iter
(),
data
)
self
.
_console_buffer
.
place_cursor
(
self
.
_console_buffer
.
get_end_iter
())
self
.
_console
.
write
=
console_write
class
ConsoleReplacement
(
object
):
def
__init__
(
self
):
# clone sys.stdout
for
item
in
dir
(
sys
.
stdout
):
if
item
.
startswith
(
"_"
)
or
(
item
==
"write"
):
continue
child
=
getattr
(
sys
.
stdout
,
item
)
setattr
(
self
,
item
,
child
)
def
write
(
self_obj
,
data
):
self
.
_console_buffer
.
insert
(
self
.
_console_buffer
.
get_end_iter
(),
data
)
self
.
_console_buffer
.
place_cursor
(
self
.
_console_buffer
.
get_end_iter
())
self
.
_original_stdout
.
write
(
data
)
sys
.
stdout
=
ConsoleReplacement
()
# make sure that we are never waiting for input (e.g. "help()")
sys
.
stdin
=
StringIO
.
StringIO
()
self
.
_console
.
write
=
sys
.
stdout
.
write
self
.
_clear_console
()
console_action
=
self
.
gui
.
get_object
(
"ToggleConsoleWindow"
)
self
.
register_gtk_accelerator
(
"console"
,
console_action
,
None
,
...
...
@@ -89,13 +100,14 @@ class GtkConsole(pycam.Plugins.PluginBase):
def
teardown
(
self
):
if
self
.
gui
:
self
.
_toggle_window
(
value
=
False
)
sys
.
stdout
=
self
.
_original_stdout
sys
.
stdin
=
self
.
_original_stdin
console_action
=
self
.
gui
.
get_object
(
"ToggleConsoleWindow"
)
self
.
unregister_gtk_accelerator
(
"console"
,
console_action
)
self
.
core
.
unregister_ui
(
"view_menu"
,
console_action
)
self
.
unregister_gtk_handlers
(
self
.
_gtk_handlers
)
def
_hide_window
(
self
,
widget
=
None
,
event
=
None
):
self
.
gui
.
get_object
(
"ConsoleDialog"
)
.
hide
()
# don't close window (for "destroy" event)
return
True
def
_clear_console
(
self
,
widget
=
None
):
start
,
end
=
self
.
_console_buffer
.
get_bounds
()
self
.
_console_buffer
.
delete
(
start
,
end
)
...
...
@@ -111,15 +123,9 @@ class GtkConsole(pycam.Plugins.PluginBase):
self
.
_console
.
write
(
text
+
os
.
linesep
)
# execute command - check if it needs more input
if
not
self
.
_console
.
push
(
text
):
# append result to console view
self
.
_console_output
.
seek
(
0
)
for
line
in
self
.
_console_output
.
readlines
():
self
.
_console
.
write
(
line
)
# scroll down console view to the end of the buffer
view
=
self
.
gui
.
get_object
(
"ConsoleView"
)
view
.
scroll_mark_onscreen
(
self
.
_console_buffer
.
get_insert
())
# clear the buffer
self
.
_console_output
.
truncate
(
0
)
# show the prompt again
self
.
_console
.
write
(
self
.
PROMPT_PS1
)
else
:
...
...
pycam/Plugins/Log.py
View file @
7c3658bb
...
...
@@ -25,6 +25,7 @@ import os
import
datetime
import
pycam.Plugins
import
pycam.Utils
class
Log
(
pycam
.
Plugins
.
PluginBase
):
...
...
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