Merged jpcgt/flatcam into master

This commit is contained in:
Kamil Sopko 2016-03-31 16:58:02 +02:00
commit e1e33e09e0
2 changed files with 50 additions and 43 deletions

View File

@ -476,7 +476,7 @@ class App(QtCore.QObject):
self.ui.menuviewdisableall.triggered.connect(self.disable_plots)
self.ui.menuviewdisableother.triggered.connect(lambda: self.disable_plots(except_current=True))
self.ui.menuviewenable.triggered.connect(self.enable_all_plots)
self.ui.menutoolshell.triggered.connect(lambda: self.shell.show())
self.ui.menutoolshell.triggered.connect(self.on_toggle_shell)
self.ui.menuhelp_about.triggered.connect(self.on_about)
self.ui.menuhelp_home.triggered.connect(lambda: webbrowser.open(self.app_url))
self.ui.menuhelp_manual.triggered.connect(lambda: webbrowser.open(self.manual_url))
@ -490,7 +490,7 @@ class App(QtCore.QObject):
self.ui.editgeo_btn.triggered.connect(self.edit_geometry)
self.ui.updategeo_btn.triggered.connect(self.editor2geometry)
self.ui.delete_btn.triggered.connect(self.on_delete)
self.ui.shell_btn.triggered.connect(lambda: self.shell.show())
self.ui.shell_btn.triggered.connect(self.on_toggle_shell)
# Object list
self.collection.view.activated.connect(self.on_row_activated)
# Options
@ -525,14 +525,24 @@ class App(QtCore.QObject):
self.shell = FCShell(self)
self.shell.setWindowIcon(self.ui.app_icon)
self.shell.setWindowTitle("FlatCAM Shell")
if self.defaults["shell_at_startup"]:
self.shell.show()
self.shell.resize(*self.defaults["shell_shape"])
self.shell.append_output("FlatCAM %s\n(c) 2014-2015 Juan Pablo Caram\n\n" % self.version)
self.shell.append_output("Type help to get started.\n\n")
self.tcl = Tkinter.Tcl()
self.setup_shell()
self.ui.shell_dock = QtGui.QDockWidget("FlatCAM TCL Shell")
self.ui.shell_dock.setWidget(self.shell)
self.ui.shell_dock.setAllowedAreas(QtCore.Qt.AllDockWidgetAreas)
self.ui.shell_dock.setFeatures(QtGui.QDockWidget.DockWidgetMovable |
QtGui.QDockWidget.DockWidgetFloatable | QtGui.QDockWidget.DockWidgetClosable)
self.ui.addDockWidget(QtCore.Qt.BottomDockWidgetArea, self.ui.shell_dock)
if self.defaults["shell_at_startup"]:
self.ui.shell_dock.show()
else:
self.ui.shell_dock.hide()
if self.cmd_line_shellfile:
try:
with open(self.cmd_line_shellfile, "r") as myfile:
@ -1009,6 +1019,16 @@ class App(QtCore.QObject):
if not silent:
self.inform.emit("Defaults saved.")
def on_toggle_shell(self):
"""
toggle shell if is visible close it if closed open it
:return:
"""
if self.ui.shell_dock.isVisible():
self.ui.shell_dock.hide()
else:
self.ui.shell_dock.show()
def on_edit_join(self):
"""
Callback for Edit->Join. Joins the selected geometry objects into

View File

@ -19,13 +19,13 @@ class _ExpandableTextEdit(QTextEdit):
historyNext = pyqtSignal()
historyPrev = pyqtSignal()
def __init__(self, termWidget, *args):
def __init__(self, termwidget, *args):
QTextEdit.__init__(self, *args)
self.setStyleSheet("font: 9pt \"Courier\";")
self._fittedHeight = 1
self.textChanged.connect(self._fit_to_document)
self._fit_to_document()
self._termWidget = termWidget
self._termWidget = termwidget
def sizeHint(self):
"""
@ -39,10 +39,10 @@ class _ExpandableTextEdit(QTextEdit):
"""
Update widget height to fit all text
"""
documentSize = self.document().size().toSize()
self._fittedHeight = documentSize.height() + (self.height() - self.viewport().height())
documentsize = self.document().size().toSize()
self._fittedHeight = documentsize.height() + (self.height() - self.viewport().height())
self.setMaximumHeight(self._fittedHeight)
self.updateGeometry();
self.updateGeometry()
def keyPressEvent(self, event):
"""
@ -55,30 +55,34 @@ class _ExpandableTextEdit(QTextEdit):
return
elif event.matches(QKeySequence.MoveToNextLine):
text = self.toPlainText()
cursorPos = self.textCursor().position()
textBeforeEnd = text[cursorPos:]
cursor_pos = self.textCursor().position()
textBeforeEnd = text[cursor_pos:]
# if len(textBeforeEnd.splitlines()) <= 1:
if len(textBeforeEnd.split('\n')) <= 1:
self.historyNext.emit()
return
elif event.matches(QKeySequence.MoveToPreviousLine):
text = self.toPlainText()
cursorPos = self.textCursor().position()
textBeforeStart = text[:cursorPos]
cursor_pos = self.textCursor().position()
text_before_start = text[:cursor_pos]
# lineCount = len(textBeforeStart.splitlines())
lineCount = len(textBeforeStart.split('\n'))
if len(textBeforeStart) > 0 and \
(textBeforeStart[-1] == '\n' or textBeforeStart[-1] == '\r'):
lineCount += 1
if lineCount <= 1:
line_count = len(text_before_start.split('\n'))
if len(text_before_start) > 0 and \
(text_before_start[-1] == '\n' or text_before_start[-1] == '\r'):
line_count += 1
if line_count <= 1:
self.historyPrev.emit()
return
elif event.matches(QKeySequence.MoveToNextPage) or \
event.matches(QKeySequence.MoveToPreviousPage):
event.matches(QKeySequence.MoveToPreviousPage):
return self._termWidget.browser().keyPressEvent(event)
QTextEdit.keyPressEvent(self, event)
def insertFromMimeData(self, mime_data):
# Paste only plain text.
self.insertPlainText(mime_data.text())
class TermWidget(QWidget):
"""
@ -94,8 +98,9 @@ class TermWidget(QWidget):
self._browser = QTextEdit(self)
self._browser.setStyleSheet("font: 9pt \"Courier\";")
self._browser.setReadOnly(True)
self._browser.document().setDefaultStyleSheet(self._browser.document().defaultStyleSheet() +
"span {white-space:pre;}")
self._browser.document().setDefaultStyleSheet(
self._browser.document().defaultStyleSheet() +
"span {white-space:pre;}")
self._edit = _ExpandableTextEdit(self, self)
self._edit.historyNext.connect(self._on_history_next)
@ -120,30 +125,12 @@ class TermWidget(QWidget):
assert style in ('in', 'out', 'err')
text = cgi.escape(text)
text = text.replace('\n', '<br/>')
if style != 'out':
def_bg = self._browser.palette().color(QPalette.Base)
h, s, v, a = def_bg.getHsvF()
if style == 'in':
if v > 0.5: # white background
v = v - (v / 8) # make darker
else:
v = v + ((1 - v) / 4) # make ligher
else: # err
if v < 0.5:
v = v + ((1 - v) / 4) # make ligher
if h == -1: # make red
h = 0
s = .4
else:
h = h + ((1 - h) * 0.5) # make more red
bg = QColor.fromHsvF(h, s, v).name()
text = '<span style="background-color: %s; font-weight: bold;">%s</span>' % (str(bg), text)
if style == 'in':
text = '<span style="font-weight: bold;">%s</span>' % text
elif style == 'err':
text = '<span style="font-weight: bold; color: red;">%s</span>' % text
else:
text = '<span>%s</span>' % text # without span <br/> is ignored!!!