Skip to content
Permalink
Browse files

[GRASS] addapted to the new qtermwidget

  • Loading branch information
blazek committed Aug 26, 2015
1 parent 61a1121 commit 40828e843d984a88ea4798cbff06df3ed9ab07fc
@@ -2,7 +2,9 @@ ADD_SUBDIRECTORY(modules)
ADD_SUBDIRECTORY(scripts)

#ADD_DEFINITIONS(-DGRASS_BASE=\\\"${GRASS_PREFIX}\\\")
ADD_DEFINITIONS(-DHAVE_OPENPTY=${HAVE_OPENPTY})
if (HAVE_OPENPTY)
ADD_DEFINITIONS(-DHAVE_OPENPTY)
ENDIF (HAVE_OPENPTY)
ADD_DEFINITIONS("-DGRASS_EXPORT=${DLLIMPORT} -DGRASS_LIB_EXPORT=${DLLIMPORT}")

IF (WIN32)
@@ -66,36 +68,50 @@ IF(NOT WIN32)
SET (GRASS_PLUGIN_SRCS ${GRASS_PLUGIN_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassshell.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/BlockArray.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/ColorScheme.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/Emulation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/Filter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/History.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/HistorySearch.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/KeyboardTranslator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/Pty.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/SearchBar.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/Screen.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/ScreenWindow.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/Session.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/ShellCommand.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/TerminalCharacterDecoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/TerminalDisplay.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/Vt102Emulation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/k3process.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/k3processcontroller.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/kprocess.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/k3processcontroller.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/konsole_wcwidth.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/kpty.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/kptydevice.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/kptyprocess.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/qtermwidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/tools.cpp
)

SET (GRASS_PLUGIN_UIS ${GRASS_PLUGIN_UIS}
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/SearchBar.ui
)

SET (GRASS_PLUGIN_MOC_HDRS ${GRASS_PLUGIN_MOC_HDRS}
${CMAKE_CURRENT_SOURCE_DIR}/qgsgrassshell.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/Emulation.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/Filter.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/HistorySearch.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/Pty.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/ScreenWindow.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/SearchBar.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/Session.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/TerminalDisplay.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/Vt102Emulation.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/k3process.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/k3processcontroller.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/kprocess.h
# ${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/k3processcontroller.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/kptydevice.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/kptyprocess.h
${CMAKE_CURRENT_SOURCE_DIR}/qtermwidget/qtermwidget.h
)

@@ -109,6 +125,13 @@ IF(NOT WIN32)
PROPERTIES COMPILE_FLAGS "-Wno-overloaded-virtual -Wno-mismatched-tags"
)
ENDIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")

SET(KB_LAYOUT_DIR "${QGIS_DATA_DIR}/grass/qtermwidget/kb-layouts")
ADD_DEFINITIONS(-DKB_LAYOUT_DIR=\\\"${CMAKE_INSTALL_PREFIX}/${KB_LAYOUT_DIR}\\\")

SET(COLORSCHEMES_DIR "${QGIS_DATA_DIR}/grass/qtermwidget/color-schemes")
ADD_DEFINITIONS(-DCOLORSCHEMES_DIR=\\\"${CMAKE_INSTALL_PREFIX}/${COLORSCHEMES_DIR}\\\")

ENDIF(NOT WIN32)

SET (GRASS_PLUGIN_RCCS ${CMAKE_CURRENT_SOURCE_DIR}/qgsgrass_plugin.qrc)
@@ -200,6 +223,13 @@ INSTALL (FILES ${GMLS}
INSTALL (FILES themes/default/grass_arrow.svg themes/default/grass_plus.svg themes/default/grass_arrow.png themes/default/grass_plus.png
DESTINATION ${QGIS_DATA_DIR}/grass/modules)

IF(NOT WIN32)
INSTALL(DIRECTORY qtermwidget/kb-layouts/ DESTINATION "${KB_LAYOUT_DIR}" FILES_MATCHING PATTERN "*.keytab" )
INSTALL(DIRECTORY qtermwidget/kb-layouts/ DESTINATION "${KB_LAYOUT_DIR}" )
message(STATUS "Keyboard layouts will be installed in: ${KB_LAYOUT_DIR}")
INSTALL(DIRECTORY qtermwidget/color-schemes/ DESTINATION "${COLORSCHEMES_DIR}" FILES_MATCHING PATTERN "*.*schem*")
ENDIF(NOT WIN32)

FOREACH(GRASS_BUILD_VERSION 6 7) # GRASS 6 and GRASS 7
IF(GRASS_FOUND${GRASS_BUILD_VERSION})
ADD_SUBDIRECTORY(${GRASS_BUILD_VERSION})
@@ -157,6 +157,7 @@ QProcessEnvironment QgsGrassModule::processEnvironment( bool direct )
QStringList paths = QgsGrass::grassModulesPaths();
paths += environment.value( "PATH" ).split( QgsGrass::pathSeparator() );
environment.insert( "PATH", paths.join( QgsGrass::pathSeparator() ) );
environment.insert( "PYTHONPATH", QgsGrass::getPythonPath() );

if ( direct )
{
@@ -1005,9 +1005,10 @@ QDomDocument QgsGrassModuleStandardOptions::readInterfaceDescription( const QStr
QString pathVariable = QgsGrassModule::libraryPathVariable();
QgsDebugMsg( "process.exitCode() = " + QString::number( process.exitCode() ) );
QString msg = tr( "Cannot start module %1" ).arg( mXName )
+ "<br>" + pathVariable + "=" + environment.value( pathVariable )
+ "<br>PATH=" + getenv( "PATH" )
+ "<br>" + tr( "command" ) + QString( ": %1 %2<br>%3<br>%4" )
+ "<br><br>" + pathVariable + "=" + environment.value( pathVariable )
+ "<br><br>PATH=" + environment.value( "PATH" )
+ "<br><br>PYTHONPATH=" + environment.value( "PYTHONPATH" )
+ "<br><br>" + tr( "command" ) + QString( ": %1 %2<br>%3<br>%4" )
.arg( cmd ).arg( arguments.join( " " ) )
.arg( process.readAllStandardOutput().constData() )
.arg( process.readAllStandardError().constData() );
@@ -39,7 +39,7 @@ QgsGrassShell::QgsGrassShell( QgsGrassTools *tools, QTabWidget *parent, const ch
{
Q_UNUSED( name );
QVBoxLayout *mainLayout = new QVBoxLayout( this );
QTermWidget *mTerminal = new QTermWidget( 0, this );
mTerminal = new QTermWidget( 0, this );
initTerminal( mTerminal );
QShortcut *pasteShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Shift+V" ) ), mTerminal );
QShortcut *copyShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Shift+C" ) ), mTerminal );
@@ -63,13 +63,20 @@ QgsGrassShell::QgsGrassShell( QgsGrassTools *tools, QTabWidget *parent, const ch
#endif

mTerminal->setSize( 80, 25 );
mTerminal->setColorScheme( COLOR_SCHEME_BLACK_ON_WHITE );
//mTerminal->setColorScheme( COLOR_SCHEME_BLACK_ON_WHITE );
mTerminal->setColorScheme( QgsApplication::pkgDataPath() + "/grass/qtermwidget/color-schemes/BlackOnWhite.schema" );
mTerminal->startShellProgram();
mTerminal->setFocus( Qt::MouseFocusReason );

// QTermWidget does set default font family Monospace, size 10 via QWidget::setFont()
// but QWidget::setFont() does not guarantee to really change the font (see doc)
// setStyleSheet() works (it is applied to QTermWidget children TerminalDisplay)
mTerminal->setStyleSheet( "font-family: Monospace; font-size: 10pt;" );
}

QgsGrassShell::~QgsGrassShell()
{
QgsDebugMsg( "entered" );
}

void QgsGrassShell::closeShell()
@@ -98,6 +105,13 @@ void QgsGrassShell::initTerminal( QTermWidget *terminal )
//QString shellProgram = QString( "%1/etc/Init.sh" ).arg( ::getenv( "GISBASE" ) );

//terminal->setShellProgram( shellProgram );

QString path = getenv( "PATH" );
path += QgsGrass::pathSeparator() + QgsGrass::grassModulesPaths().join( QgsGrass::pathSeparator() );
QgsDebugMsg( "path = " + path );

env << "PATH=" + path;
env << "PYTHONPATH=" + QgsGrass::getPythonPath();
env << "TERM=vt100";
env << "GISRC_MODE_MEMORY";
// TODO: we should check if these environment variable were set by user before QGIS was started
@@ -258,7 +258,7 @@ void QgsGrassTools::runModule( QString name, bool direct )
return; // Section
}

#if defined(HAVE_OPENPTY) && !defined(Q_OS_WIN)
#ifdef HAVE_POSIX_OPENPT
QgsGrassShell* sh = 0;
#endif

@@ -274,14 +274,14 @@ void QgsGrassTools::runModule( QString name, bool direct )
return;
#else

#ifdef HAVE_OPENPTY
#ifdef HAVE_POSIX_OPENPT
sh = new QgsGrassShell( this, mTabWidget );
m = qobject_cast<QWidget *>( sh );
#else
QMessageBox::warning( 0, tr( "Warning" ), tr( "GRASS Shell is not compiled." ) );
#endif // HAVE_OPENPTY
#endif

#endif // ! Q_OS_WIN
#endif // Q_OS_WIN
}
else
{
@@ -319,9 +319,11 @@ void QgsGrassTools::runModule( QString name, bool direct )
/* TODO: Implement something that resizes the terminal without
* crashes.
*/
#ifdef HAVE_OPENPTY
#ifdef HAVE_POSIX_OPENPT
if ( sh )
{
sh->resizeTerminal();
}
#endif
#endif
}
@@ -450,14 +450,7 @@ void QgsGrass::init( void )
QgsDebugMsg( "mGrassModulesPaths = " + mGrassModulesPaths.join( "," ) );
//putEnv( "PATH", path );

// TODO: move setting of PYTHONPATH to QProcess where necessary
// Set PYTHONPATH
QString pythonpath = gisbase() + "/etc/python";
QString pp = getenv( "PYTHONPATH" );
pythonpath.append( pathSeparator() + pp );
QgsDebugMsg( QString( "set PYTHONPATH: %1" ).arg( pythonpath ) );
putEnv( "PYTHONPATH", pythonpath );

// TODO: move where it is required for QProcess
// Set GRASS_PAGER if not set, it is necessary for some
// modules printing to terminal, e.g. g.list
// We use 'cat' because 'more' is not present in MSYS (Win)
@@ -2355,6 +2348,15 @@ void QgsGrass::putEnv( QString name, QString value )
putenv( envChar );
}

QString QgsGrass::getPythonPath()
{
QString pythonpath = getenv( "PYTHONPATH" );
pythonpath += pathSeparator() + gisbase() + "/etc/python";
pythonpath += pathSeparator() + gisbase() + "/gui/wxpython";
QgsDebugMsg( "pythonpath = " + pythonpath );
return pythonpath;
}

QString QgsGrass::modulesConfigDefaultDirPath()
{
if ( QgsApplication::isRunningFromBuildDir() )
@@ -474,6 +474,9 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
return QgsApplication::libexecPath() + "grass/modules";
}

// Get PYTHONPATH with paths to GRASS Python modules
static QString getPythonPath();

// path to default modules interface config dir
static QString modulesConfigDefaultDirPath();

1 comment on commit 40828e8

@jctull

This comment has been minimized.

Copy link

@jctull jctull commented on 40828e8 Aug 27, 2015

Please sign in to comment.
You can’t perform that action at this time.