From 697be73cb19b395786e76773a7e4e304c8cfa476 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 28 Jul 2016 16:45:47 +0300 Subject: [PATCH] PyEditor refactoring * Remove dependency on Qtx in PyEditor package * Redesign editor class; * Change the way preferences are managed; * Add main window class for PyEditor; * Add pyeditor standalone executable; * Redesign build procedure for PyEditor; * Move PyEditor to standalone project in tools directory; * Add Python wrappings (via sip) for PyEditor widget. --- src/CMakeLists.txt | 1 - src/LightApp/LightApp_Application.cxx | 39 +- src/PyEditor/PyEditor_Settings.cxx | 169 ----- src/PyEditor/PyEditor_Settings.h | 83 --- src/PyEditor/PyEditor_SettingsDlg.cxx | 228 ------- .../resources/translations/PyEditor_msg_en.ts | 71 -- .../resources/translations/PyEditor_msg_fr.ts | 71 -- .../resources/translations/PyEditor_msg_ja.ts | 71 -- src/PyViewer/CMakeLists.txt | 48 +- src/PyViewer/PyViewer.cxx | 59 -- src/PyViewer/PyViewer_Settings.cxx | 68 ++ src/PyViewer/PyViewer_Settings.h | 45 ++ src/PyViewer/PyViewer_ViewModel.cxx | 21 +- src/PyViewer/PyViewer_ViewModel.h | 3 - src/PyViewer/PyViewer_ViewWindow.cxx | 604 ++++++++---------- src/PyViewer/PyViewer_ViewWindow.h | 26 +- src/PyViewer/resources/PyViewer_images.ts | 59 ++ src/PyViewer/resources/PyViewer_msg_en.ts | 206 ++++++ src/PyViewer/resources/PyViewer_msg_fr.ts | 206 ++++++ .../{translations => }/PyViewer_msg_ja.ts | 144 +++-- .../resources/translations/PyViewer_msg_en.ts | 170 ----- .../resources/translations/PyViewer_msg_fr.ts | 170 ----- tools/CMakeLists.txt | 14 +- tools/PyEditor/CMakeLists.txt | 104 +++ .../PyEditor/src}/CMakeLists.txt | 46 +- tools/PyEditor/src/PyEditor.cxx | 109 ++++ .../PyEditor/src}/PyEditor.h | 0 .../PyEditor/src}/PyEditor_Editor.cxx | 362 ++++++----- .../PyEditor/src}/PyEditor_Editor.h | 33 +- .../PyEditor/src}/PyEditor_LineNumberArea.cxx | 6 +- .../PyEditor/src}/PyEditor_LineNumberArea.h | 2 +- .../PyEditor/src}/PyEditor_PyHighlighter.cxx | 14 +- .../PyEditor/src}/PyEditor_PyHighlighter.h | 2 +- tools/PyEditor/src/PyEditor_Settings.cxx | 283 ++++++++ tools/PyEditor/src/PyEditor_Settings.h | 106 +++ tools/PyEditor/src/PyEditor_SettingsDlg.cxx | 326 ++++++++++ .../PyEditor/src}/PyEditor_SettingsDlg.h | 46 +- tools/PyEditor/src/PyEditor_StdSettings.cxx | 92 +++ tools/PyEditor/src/PyEditor_StdSettings.h | 50 ++ tools/PyEditor/src/PyEditor_Window.cxx | 467 ++++++++++++++ tools/PyEditor/src/PyEditor_Window.h | 71 ++ tools/PyEditor/src/python/CMakeLists.txt | 62 ++ tools/PyEditor/src/python/PyEditorPy.sip | 98 +++ .../PyEditor/src}/resources/PyEditor.qrc | 6 +- tools/PyEditor/src/resources/about.txt | 36 ++ .../src}/resources/images/py_copy.png | Bin .../PyEditor/src}/resources/images/py_cut.png | Bin .../src}/resources/images/py_delete.png | Bin .../src/resources/images/py_editor.png | Bin 0 -> 4164 bytes .../PyEditor/src/resources/images/py_exit.png | Bin .../PyEditor/src/resources/images/py_help.png | Bin .../PyEditor/src}/resources/images/py_new.png | Bin .../src}/resources/images/py_open.png | Bin .../src}/resources/images/py_paste.png | Bin .../src}/resources/images/py_preferences.png | Bin .../src}/resources/images/py_redo.png | Bin .../src}/resources/images/py_save.png | Bin .../src}/resources/images/py_save_as.png | Bin .../src}/resources/images/py_select_all.png | Bin .../src}/resources/images/py_undo.png | Bin .../resources/translations/PyEditor_msg_en.ts | 310 +++++++++ .../resources/translations/PyEditor_msg_fr.ts | 310 +++++++++ .../resources/translations/PyEditor_msg_ja.ts | 310 +++++++++ 63 files changed, 4008 insertions(+), 1819 deletions(-) delete mode 100644 src/PyEditor/PyEditor_Settings.cxx delete mode 100644 src/PyEditor/PyEditor_Settings.h delete mode 100644 src/PyEditor/PyEditor_SettingsDlg.cxx delete mode 100644 src/PyEditor/resources/translations/PyEditor_msg_en.ts delete mode 100644 src/PyEditor/resources/translations/PyEditor_msg_fr.ts delete mode 100644 src/PyEditor/resources/translations/PyEditor_msg_ja.ts delete mode 100644 src/PyViewer/PyViewer.cxx create mode 100644 src/PyViewer/PyViewer_Settings.cxx create mode 100644 src/PyViewer/PyViewer_Settings.h create mode 100644 src/PyViewer/resources/PyViewer_images.ts create mode 100644 src/PyViewer/resources/PyViewer_msg_en.ts create mode 100644 src/PyViewer/resources/PyViewer_msg_fr.ts rename src/PyViewer/resources/{translations => }/PyViewer_msg_ja.ts (57%) delete mode 100644 src/PyViewer/resources/translations/PyViewer_msg_en.ts delete mode 100644 src/PyViewer/resources/translations/PyViewer_msg_fr.ts create mode 100644 tools/PyEditor/CMakeLists.txt rename {src/PyEditor => tools/PyEditor/src}/CMakeLists.txt (60%) create mode 100644 tools/PyEditor/src/PyEditor.cxx rename {src/PyEditor => tools/PyEditor/src}/PyEditor.h (100%) rename {src/PyEditor => tools/PyEditor/src}/PyEditor_Editor.cxx (69%) rename {src/PyEditor => tools/PyEditor/src}/PyEditor_Editor.h (83%) rename {src/PyEditor => tools/PyEditor/src}/PyEditor_LineNumberArea.cxx (90%) rename {src/PyEditor => tools/PyEditor/src}/PyEditor_LineNumberArea.h (97%) rename {src/PyEditor => tools/PyEditor/src}/PyEditor_PyHighlighter.cxx (97%) rename {src/PyEditor => tools/PyEditor/src}/PyEditor_PyHighlighter.h (98%) create mode 100644 tools/PyEditor/src/PyEditor_Settings.cxx create mode 100644 tools/PyEditor/src/PyEditor_Settings.h create mode 100644 tools/PyEditor/src/PyEditor_SettingsDlg.cxx rename {src/PyEditor => tools/PyEditor/src}/PyEditor_SettingsDlg.h (65%) create mode 100644 tools/PyEditor/src/PyEditor_StdSettings.cxx create mode 100644 tools/PyEditor/src/PyEditor_StdSettings.h create mode 100644 tools/PyEditor/src/PyEditor_Window.cxx create mode 100644 tools/PyEditor/src/PyEditor_Window.h create mode 100644 tools/PyEditor/src/python/CMakeLists.txt create mode 100644 tools/PyEditor/src/python/PyEditorPy.sip rename {src/PyViewer => tools/PyEditor/src}/resources/PyEditor.qrc (79%) create mode 100644 tools/PyEditor/src/resources/about.txt rename {src/PyViewer => tools/PyEditor/src}/resources/images/py_copy.png (100%) rename {src/PyViewer => tools/PyEditor/src}/resources/images/py_cut.png (100%) rename {src/PyViewer => tools/PyEditor/src}/resources/images/py_delete.png (100%) create mode 100644 tools/PyEditor/src/resources/images/py_editor.png rename src/PyViewer/resources/images/py_close.png => tools/PyEditor/src/resources/images/py_exit.png (100%) rename src/PyViewer/resources/images/py_browser.png => tools/PyEditor/src/resources/images/py_help.png (100%) rename {src/PyViewer => tools/PyEditor/src}/resources/images/py_new.png (100%) rename {src/PyViewer => tools/PyEditor/src}/resources/images/py_open.png (100%) rename {src/PyViewer => tools/PyEditor/src}/resources/images/py_paste.png (100%) rename {src/PyViewer => tools/PyEditor/src}/resources/images/py_preferences.png (100%) rename {src/PyViewer => tools/PyEditor/src}/resources/images/py_redo.png (100%) rename {src/PyViewer => tools/PyEditor/src}/resources/images/py_save.png (100%) rename {src/PyViewer => tools/PyEditor/src}/resources/images/py_save_as.png (100%) rename {src/PyViewer => tools/PyEditor/src}/resources/images/py_select_all.png (100%) rename {src/PyViewer => tools/PyEditor/src}/resources/images/py_undo.png (100%) create mode 100644 tools/PyEditor/src/resources/translations/PyEditor_msg_en.ts create mode 100644 tools/PyEditor/src/resources/translations/PyEditor_msg_fr.ts create mode 100644 tools/PyEditor/src/resources/translations/PyEditor_msg_ja.ts diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f7161a9cc..f4b1b7fed 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -119,7 +119,6 @@ ENDIF() # Python Viewer ## IF(SALOME_USE_PYVIEWER) - ADD_SUBDIRECTORY(PyEditor) ADD_SUBDIRECTORY(PyViewer) ENDIF(SALOME_USE_PYVIEWER) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 70ddd87e9..9702d04f2 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -85,6 +85,7 @@ #include #include +#include #include #include #include @@ -2898,8 +2899,9 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) int pyeditTab = pref->addPreference( tr( "PREF_TAB_PYEDITOR" ), salomeCat ); // ... "Font settings" group <> int pyFontGroup = pref->addPreference( tr( "PREF_GROUP_PY_FONT" ), pyeditTab ); - pref->addPreference( tr( "PREF_PY_FONT" ), pyFontGroup, - LightApp_Preferences::Font, "PyEditor", "Font" ); + int pyFont = pref->addPreference( tr( "PREF_PY_FONT" ), pyFontGroup, + LightApp_Preferences::Font, "PyEditor", "Font" ); + pref->setItemProperty( "features", QtxFontEdit::Family | QtxFontEdit::Size | QtxFontEdit::UserSize, pyFont ); // ... "Font settings" group <> // ... "Display settings" group <> int pyDispGroup = pref->addPreference( tr( "PREF_GROUP_PY_DISPLAY" ), pyeditTab ); @@ -3686,39 +3688,6 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString } } #endif - -#ifndef DISABLE_PYVIEWER - if ( sec == QString( "PyViewer" ) && ( param == QString( "HighlightCurrentLine" ) || - param == QString( "LineNumberArea" ) || - param == QString( "TextWrapping" ) || - param == QString( "CenterCursorOnScroll" ) || - param == QString( "TabSpaceVisible" ) || - param == QString( "TabSize" ) || - param == QString( "VerticalEdge" ) || - param == QString( "NumberColumns" ) || - param == QString( "Font" ) ) ) - { - QList lst; - viewManagers( PyViewer_Viewer::Type(), lst ); - QListIterator itPy( lst ); - while ( itPy.hasNext() ) - { - SUIT_ViewManager* viewMgr = itPy.next(); - SUIT_ViewModel* vm = viewMgr->getViewModel(); - if ( !vm || !vm->inherits( "PyViewer_Viewer" ) ) - continue; - - PyViewer_Viewer* pyEditVM = dynamic_cast( vm ); - - viewMgr->setViewModel( vm ); - PyViewer_ViewWindow* pyView = dynamic_cast( viewMgr->getActiveView() ); - if( pyView ) - { - pyView->setPreferences(); - } - } - } -#endif } /*! diff --git a/src/PyEditor/PyEditor_Settings.cxx b/src/PyEditor/PyEditor_Settings.cxx deleted file mode 100644 index 69309d13f..000000000 --- a/src/PyEditor/PyEditor_Settings.cxx +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (C) 2015-2016 OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// File : PyEditor_Settings.cxx -// Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com) -// - -#include "PyEditor_Settings.h" - -#include - -#include -#include -#include - -/*! - \class PyEditor_Settings - \brief Manager of setting values. -*/ - -/*! - \brief Constructor. - \param isSingle flag determined single application or reccesed. -*/ -PyEditor_Settings::PyEditor_Settings( QtxResourceMgr* theMgr, bool isSingle ) - : p_HighlightCurrentLine( true ), - p_LineNumberArea( true ), - p_TextWrapping( false ), - p_CenterCursorOnScroll( true ), - p_TabSpaceVisible( true ), - p_TabSize( 4 ), - p_VerticalEdge( true ), - p_NumberColumns( 80 ), - p_Font( "Courier", 10 ), - m_ResourceMgr(theMgr), - m_Single(isSingle) - -{ - if ( m_Single ) - { - m_Settings = new QSettings( "config.ini", QSettings::IniFormat ); - if ( !QFile::exists( m_Settings->fileName() ) ) - toSettings( PY_EDITOR ); - } - - readSettings(); -} - -/*! - \brief Reads the setting values. - */ -void PyEditor_Settings::readSettings() -{ - if ( isSingle() ) - fromSettings( PY_EDITOR ); - else - readPreferences(); -} - -/*! - \brief Writes the setting values. - */ -void PyEditor_Settings::writeSettings() -{ - if ( isSingle() ) - toSettings( PY_EDITOR ); - else - writePreferences(); -} - -/*! - \return \c true if the application is single - */ -bool PyEditor_Settings::isSingle() -{ - return m_Single; -} - -/*! - \brief Loads the setting values from file settings. - */ -void PyEditor_Settings::fromSettings( const QString &theCategory ) -{ - QString aGroup = theCategory; - aGroup += "/"; - - p_HighlightCurrentLine = m_Settings->value(aGroup + QLatin1String( HIGHLIGHT_CURRLINE ), p_HighlightCurrentLine).toBool(); - p_LineNumberArea = m_Settings->value(aGroup + QLatin1String( LINE_NUMBER_AREA ), p_LineNumberArea).toBool(); - p_TextWrapping = m_Settings->value(aGroup + QLatin1String( TEXT_WRAP ), p_TextWrapping).toBool(); - p_CenterCursorOnScroll = m_Settings->value(aGroup + QLatin1String( CURSOR_SCROLL ), p_CenterCursorOnScroll).toBool(); - p_TabSpaceVisible = m_Settings->value(aGroup + QLatin1String( TAB_WHITESPACES ), p_TabSpaceVisible).toBool(); - p_TabSize = m_Settings->value(aGroup + QLatin1String( TAB_SIZE ), p_TabSize).toInt(); - p_VerticalEdge = m_Settings->value(aGroup + QLatin1String( VERTICAL_EDGE ), p_VerticalEdge).toBool(); - p_NumberColumns = m_Settings->value(aGroup + QLatin1String( NUM_COLUMNS ), p_NumberColumns).toInt(); - p_Font = QFont( m_Settings->value(aGroup + QLatin1String( FONT_FAMILY ), p_Font.family()).toString(), - m_Settings->value(aGroup + QLatin1String( FONT_SIZE ), p_Font.pointSize()).toInt() ); -} - -/*! - \brief Saves the setting values into file settings. - */ -void PyEditor_Settings::toSettings( const QString &theCategory ) const -{ - m_Settings->beginGroup( theCategory ); - m_Settings->setValue( QLatin1String( HIGHLIGHT_CURRLINE ), p_HighlightCurrentLine ); - m_Settings->setValue( QLatin1String( LINE_NUMBER_AREA ), p_LineNumberArea ); - m_Settings->setValue( QLatin1String( TEXT_WRAP ), p_TextWrapping ); - m_Settings->setValue( QLatin1String( CURSOR_SCROLL ), p_CenterCursorOnScroll ); - m_Settings->setValue( QLatin1String( TAB_WHITESPACES ), p_TabSpaceVisible ); - m_Settings->setValue( QLatin1String( TAB_SIZE ), p_TabSize ); - m_Settings->setValue( QLatin1String( VERTICAL_EDGE ), p_VerticalEdge ); - m_Settings->setValue( QLatin1String( NUM_COLUMNS ), p_NumberColumns ); - m_Settings->setValue( QLatin1String( FONT_FAMILY ), p_Font.family() ); - m_Settings->setValue( QLatin1String( FONT_SIZE ), p_Font.pointSize() ); - m_Settings->endGroup(); -} - -/*! - \brief Loads the setting values from setting resources. - */ -void PyEditor_Settings::readPreferences() -{ - if(m_ResourceMgr) - { - p_HighlightCurrentLine = m_ResourceMgr->booleanValue( "PyEditor", "HighlightCurrentLine", p_HighlightCurrentLine ); - p_LineNumberArea = m_ResourceMgr->booleanValue( "PyEditor", "LineNumberArea", p_LineNumberArea ); - p_TextWrapping = m_ResourceMgr->booleanValue( "PyEditor", "TextWrapping", p_TextWrapping ); - p_CenterCursorOnScroll = m_ResourceMgr->booleanValue( "PyEditor", "CenterCursorOnScroll", p_CenterCursorOnScroll ); - p_TabSpaceVisible = m_ResourceMgr->booleanValue( "PyEditor", "TabSpaceVisible", p_TabSpaceVisible ); - p_TabSize = m_ResourceMgr->integerValue( "PyEditor", "TabSize", p_TabSize ); - p_VerticalEdge = m_ResourceMgr->booleanValue( "PyEditor", "VerticalEdge", p_VerticalEdge ); - p_NumberColumns = m_ResourceMgr->integerValue( "PyEditor", "NumberColumns", p_NumberColumns ); - p_Font = m_ResourceMgr->fontValue( "PyEditor", "Font", p_Font ); - } -} - -/*! - \brief Saves the setting values into setting resources. - */ -void PyEditor_Settings::writePreferences() -{ - if(m_ResourceMgr) - { - m_ResourceMgr->setValue( "PyEditor", "HighlightCurrentLine", p_HighlightCurrentLine ); - m_ResourceMgr->setValue( "PyEditor", "LineNumberArea", p_LineNumberArea ); - m_ResourceMgr->setValue( "PyEditor", "TextWrapping", p_TextWrapping ); - m_ResourceMgr->setValue( "PyEditor", "CenterCursorOnScroll", p_CenterCursorOnScroll ); - m_ResourceMgr->setValue( "PyEditor", "TabSpaceVisible", p_TabSpaceVisible ); - m_ResourceMgr->setValue( "PyEditor", "TabSize", p_TabSize ); - m_ResourceMgr->setValue( "PyEditor", "VerticalEdge", p_VerticalEdge ); - m_ResourceMgr->setValue( "PyEditor", "NumberColumns", p_NumberColumns ); - m_ResourceMgr->setValue( "PyEditor", "Font", p_Font ); - } -} diff --git a/src/PyEditor/PyEditor_Settings.h b/src/PyEditor/PyEditor_Settings.h deleted file mode 100644 index d7b11d8ea..000000000 --- a/src/PyEditor/PyEditor_Settings.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (C) 2015-2016 OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// File : PyEditor_Settings.h -// Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com) -// - -#ifndef PYEDITOR_SETTINGS_H -#define PYEDITOR_SETTINGS_H - -#include -#include "PyEditor.h" - -class QSettings; -class QtxResourceMgr; - -const char* const PY_EDITOR = "PythonEditor"; -const char* const HIGHLIGHT_CURRLINE = "HighlightCurrentLine"; -const char* const LINE_NUMBER_AREA = "LineNumberArea"; -const char* const TEXT_WRAP = "TextWrapping"; -const char* const CURSOR_SCROLL = "CenterCursorOnScroll"; -const char* const TAB_WHITESPACES = "TabSpaceVisible"; -const char* const TAB_SIZE = "TabSize"; -const char* const VERTICAL_EDGE = "VerticalEdge"; -const char* const NUM_COLUMNS = "NumberColumns"; -const char* const FONT_FAMILY = "FontFamily"; -const char* const FONT_SIZE = "FontSize"; - -class PYEDITOR_EXPORT PyEditor_Settings -{ -public: - PyEditor_Settings( QtxResourceMgr* = 0 , bool isSingle = true ); - - void readSettings(); - void writeSettings(); - - void fromSettings( const QString& ); - void toSettings( const QString& ) const; - - void readPreferences(); - void writePreferences(); - - bool isSingle(); - - // Display settings - bool p_HighlightCurrentLine; - bool p_TextWrapping; - bool p_CenterCursorOnScroll; - bool p_LineNumberArea; - - // Vertical edge settings - bool p_VerticalEdge; - int p_NumberColumns; - - // Tab settings - bool p_TabSpaceVisible; - int p_TabSize; - - // Font settings - QFont p_Font; - -private: - QSettings* m_Settings; - QtxResourceMgr* m_ResourceMgr; - bool m_Single; -}; - -#endif // PYEDITOR_SETTINGS_H diff --git a/src/PyEditor/PyEditor_SettingsDlg.cxx b/src/PyEditor/PyEditor_SettingsDlg.cxx deleted file mode 100644 index 47a519ffa..000000000 --- a/src/PyEditor/PyEditor_SettingsDlg.cxx +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright (C) 2015-2016 OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// File : PyEditor_SettingsDlg.cxx -// Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com) -// - -#include "PyEditor_SettingsDlg.h" - -#include "PyEditor_Editor.h" -#include "PyEditor_Settings.h" - -#include -#include -#include -#include -#include -#include -#include - -/*! - \class PyEditor_SettingsDlg - \brief Dialog settings for python editor. -*/ - -/*! - \brief Constructor. - \param theEditor widget that is used to edit and display text - \param theParent parent widget -*/ -PyEditor_SettingsDlg::PyEditor_SettingsDlg( PyEditor_Editor* theEditor, QWidget* theParent ) : - QDialog( theParent ), - my_Editor( theEditor ) -{ - setWindowTitle( tr("TIT_PY_PREF") ); - QVBoxLayout* aMainLayout = new QVBoxLayout( this ); - - // . Font settings - QGroupBox* aFontSetBox = new QGroupBox( tr( "GR_FONT_SET" ) ); - QHBoxLayout* aFontSetLayout = new QHBoxLayout( aFontSetBox ); - w_FontWidget = new QtxFontEdit( QtxFontEdit::Family|QtxFontEdit::Size|QtxFontEdit::UserSize, this ); - aFontSetLayout->addWidget( w_FontWidget ); - // . Font settings - - // . Display settings - QGroupBox* aDisplaySetBox = new QGroupBox( tr( "GR_DISP_SET" ) ); - QVBoxLayout* aDisplaySetLayout = new QVBoxLayout; - w_HighlightCurrentLine = new QCheckBox( tr( "LBL_CURRLINE_HIGHLIGHT" ) ); - w_TextWrapping = new QCheckBox( tr( "LBL_TEXT_WRAP" ) ); - w_CenterCursorOnScroll = new QCheckBox( tr( "LBL_CURSOR_SCROLL" ) ); - w_LineNumberArea = new QCheckBox( tr( "LBL_LINE_NUMBS_AREA" ) ); - aDisplaySetLayout->addWidget( w_HighlightCurrentLine ); - aDisplaySetLayout->addWidget( w_TextWrapping ); - aDisplaySetLayout->addWidget( w_CenterCursorOnScroll ); - aDisplaySetLayout->addWidget( w_LineNumberArea ); - aDisplaySetLayout->addStretch( 1 ); - aDisplaySetBox->setLayout( aDisplaySetLayout ); - // . Display settings - - QHBoxLayout* aTabVertEdgeLayout = new QHBoxLayout; - - // . Tab settings - QGroupBox* aTabSetBox = new QGroupBox( tr( "GR_TAB_SET" ) ); - QVBoxLayout* aTabSetLayout = new QVBoxLayout; - w_TabSpaceVisible = new QCheckBox( tr( "LBL_TAB_SPACES" ) ); - QHBoxLayout* aTabSizeLayout = new QHBoxLayout; - QLabel* aTabSizeLabel = new QLabel( tr( "LBL_TAB_SIZE" ) ); - w_TabSize = new QSpinBox; - w_TabSize->setMinimum( 0 ); - w_TabSize->setSingleStep( 1 ); - aTabSizeLayout->addWidget( aTabSizeLabel ); - aTabSizeLayout->addWidget( w_TabSize ); - aTabSizeLayout->addStretch( 1 ); - aTabSetLayout->addWidget( w_TabSpaceVisible ); - aTabSetLayout->addLayout( aTabSizeLayout ); - aTabSetBox->setLayout( aTabSetLayout ); - // . Tab settings - - // . Vertical edge settings - QGroupBox* aVertEdgeSetBox = new QGroupBox( tr( "GR_VERT_EDGE_SET" ) ); - QVBoxLayout* aVertEdgeLayout = new QVBoxLayout; - w_VerticalEdge = new QCheckBox( tr( "LBL_VERT_EDGE" ) ); - QHBoxLayout* aNumberColLayout = new QHBoxLayout; - lbl_NumColumns = new QLabel( tr( "LBL_NUM_COLUMNS" ) ); - w_NumberColumns = new QSpinBox; - w_NumberColumns->setMinimum( 0 ); - w_NumberColumns->setSingleStep( 1 ); - aNumberColLayout->addWidget( lbl_NumColumns ); - aNumberColLayout->addWidget( w_NumberColumns ); - aNumberColLayout->addStretch( 1 ); - aVertEdgeLayout->addWidget( w_VerticalEdge ); - aVertEdgeLayout->addLayout( aNumberColLayout ); - aVertEdgeSetBox->setLayout( aVertEdgeLayout ); - connect( w_VerticalEdge, SIGNAL( clicked( bool ) ), - this, SLOT( onVerticalEdgeChecked( bool ) ) ); - // . Vertical edge settings - - aTabVertEdgeLayout->addWidget( aTabSetBox ); - aTabVertEdgeLayout->addWidget( aVertEdgeSetBox ); - - // . "Set as default" check box - w_DefaultCheck = new QCheckBox( tr( "WDG_SET_AS_DEFAULT_CHECK" ), this ); - - aMainLayout->addWidget( aFontSetBox ); - aMainLayout->addWidget( aDisplaySetBox ); - aMainLayout->addLayout( aTabVertEdgeLayout ); - aMainLayout->addWidget( w_DefaultCheck ); - aMainLayout->addStretch( 1 ); - - myOkBtn = new QPushButton( tr( "BUT_OK" ), this ); - myOkBtn->setAutoDefault( true ); - myOkBtn->setDefault( true ); - myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this ); - myCancelBtn->setAutoDefault( true ); - myHelpBtn = new QPushButton( tr( "BUT_HELP" ), this ); - myHelpBtn->setAutoDefault( true ); - QHBoxLayout* aButtonLayout = new QHBoxLayout; - aButtonLayout->addWidget( myOkBtn ); - aButtonLayout->addStretch(); - aButtonLayout->addWidget( myCancelBtn ); - aButtonLayout->addWidget( myHelpBtn ); - aMainLayout->addLayout( aButtonLayout ); - - connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) ); - connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) ); - connect( myHelpBtn, SIGNAL( clicked() ), this, SLOT( onHelp() ) ); - - settingsToGui(); -} - -/*! - \brief Get "Set settings as default" check box value. - \return \c true if "Set settings as default" check box is on -*/ -bool PyEditor_SettingsDlg::isSetAsDefault() -{ - return w_DefaultCheck->isChecked(); -} - -/*! - SLOT: Changes the widget visibility depending on the set theState flag. - \param theState flag of visibility - */ -void PyEditor_SettingsDlg::onVerticalEdgeChecked( bool theState ) -{ - lbl_NumColumns->setEnabled( theState ); - w_NumberColumns->setEnabled( theState ); -} - -/*! - \brief Sets settings from preferences dialog. - */ -void PyEditor_SettingsDlg::settingsFromGui() -{ - my_Editor->settings()->p_HighlightCurrentLine = w_HighlightCurrentLine->isChecked(); - my_Editor->settings()->p_TextWrapping = w_TextWrapping->isChecked(); - my_Editor->settings()->p_CenterCursorOnScroll = w_CenterCursorOnScroll->isChecked(); - my_Editor->settings()->p_LineNumberArea = w_LineNumberArea->isChecked(); - my_Editor->settings()->p_TabSpaceVisible = w_TabSpaceVisible->isChecked(); - my_Editor->settings()->p_TabSize = w_TabSize->value(); - my_Editor->settings()->p_VerticalEdge = w_VerticalEdge->isChecked(); - my_Editor->settings()->p_NumberColumns = w_NumberColumns->value(); - my_Editor->settings()->p_Font = w_FontWidget->currentFont(); -} - -/*! - \brief Sets settings into preferences dialog. - */ -void PyEditor_SettingsDlg::settingsToGui() -{ - w_HighlightCurrentLine->setChecked( my_Editor->settings()->p_HighlightCurrentLine ); - w_TextWrapping->setChecked( my_Editor->settings()->p_TextWrapping ); - w_CenterCursorOnScroll->setChecked( my_Editor->settings()->p_CenterCursorOnScroll ); - w_LineNumberArea->setChecked( my_Editor->settings()->p_LineNumberArea ); - w_TabSpaceVisible->setChecked( my_Editor->settings()->p_TabSpaceVisible ); - w_TabSize->setValue( my_Editor->settings()->p_TabSize ); - w_VerticalEdge->setChecked( my_Editor->settings()->p_VerticalEdge ); - w_NumberColumns->setValue( my_Editor->settings()->p_NumberColumns ); - w_FontWidget->setCurrentFont( my_Editor->settings()->p_Font ); - w_FontWidget->setSizes(); - - onVerticalEdgeChecked( my_Editor->settings()->p_VerticalEdge ); -} - -/*! - \brief Sets settings into the setting resources or file - if the flag is set as default is true. - */ -void PyEditor_SettingsDlg::setSettings() -{ - if ( isSetAsDefault() ) - my_Editor->settings()->writeSettings(); - - my_Editor->updateStatement(); -} - -/*! - Slot, called when user clicks "OK" button -*/ -void PyEditor_SettingsDlg::onOk() -{ - settingsFromGui(); - setSettings(); - accept(); -} - -/*! - Slot, called when user clicks "Help" button. -*/ -void PyEditor_SettingsDlg::onHelp() -{ - emit onHelpClicked(); -} diff --git a/src/PyEditor/resources/translations/PyEditor_msg_en.ts b/src/PyEditor/resources/translations/PyEditor_msg_en.ts deleted file mode 100644 index 047f66180..000000000 --- a/src/PyEditor/resources/translations/PyEditor_msg_en.ts +++ /dev/null @@ -1,71 +0,0 @@ - - - - - PyEditor_SettingsDlg - - TIT_PY_PREF - Preferences - - - GR_FONT_SET - Font settings - - - LBL_FONT_FAM - Family: - - - LBL_FONT_SIZE - Size: - - - GR_DISP_SET - Display settings - - - LBL_CURRLINE_HIGHLIGHT - Enable current line highlight - - - LBL_TEXT_WRAP - Enable text wrapping - - - LBL_CURSOR_SCROLL - Center cursor on scroll - - - LBL_LINE_NUMBS_AREA - Display line numbers area - - - GR_TAB_SET - Tab settings - - - LBL_TAB_SPACES - Display tab white spaces - - - LBL_TAB_SIZE - Tab size: - - - GR_VERT_EDGE_SET - Vertical edge settings - - - LBL_VERT_EDGE - Display vertical edge - - - LBL_NUM_COLUMNS - Number of columns: - - - WDG_SET_AS_DEFAULT_CHECK - Save settings as default - - - diff --git a/src/PyEditor/resources/translations/PyEditor_msg_fr.ts b/src/PyEditor/resources/translations/PyEditor_msg_fr.ts deleted file mode 100644 index 3a2fcfb01..000000000 --- a/src/PyEditor/resources/translations/PyEditor_msg_fr.ts +++ /dev/null @@ -1,71 +0,0 @@ - - - - - PyEditor_SettingsDlg - - TIT_PY_PREF - Préférences - - - GR_FONT_SET - Paramètres de la fonte - - - LBL_FONT_FAM - Famille: - - - LBL_FONT_SIZE - Taille: - - - GR_DISP_SET - Paramètres d'affichage - - - LBL_CURRLINE_HIGHLIGHT - Met en surbrillance de la ligne actuelle - - - LBL_TEXT_WRAP - Retour à la ligne dynamique - - - LBL_CURSOR_SCROLL - Centre le curseur lors du scroll - - - LBL_LINE_NUMBS_AREA - Affiche les numéros de ligne - - - GR_TAB_SET - Indentation - - - LBL_TAB_SPACES - Affiche les guides d'indentation - - - LBL_TAB_SIZE - Largeur d'intentation: - - - GR_VERT_EDGE_SET - Marqueur de retour à la ligne - - - LBL_VERT_EDGE - Afficher la ligne verticale - - - LBL_NUM_COLUMNS - Nombre de colonnes: - - - WDG_SET_AS_DEFAULT_CHECK - Sauver en tant que paramètres par défaut - - - diff --git a/src/PyEditor/resources/translations/PyEditor_msg_ja.ts b/src/PyEditor/resources/translations/PyEditor_msg_ja.ts deleted file mode 100644 index 4b3280184..000000000 --- a/src/PyEditor/resources/translations/PyEditor_msg_ja.ts +++ /dev/null @@ -1,71 +0,0 @@ - - - - - PyEditor_SettingsDlg - - TIT_PY_PREF - 環境設定 - - - GR_FONT_SET - フォント設定 - - - LBL_FONT_FAM - Family: - - - LBL_FONT_SIZE - Size: - - - GR_DISP_SET - 表示設定 - - - LBL_CURRLINE_HIGHLIGHT - カレントラインのハイライト有効 - - - LBL_TEXT_WRAP - テキストラッピングの有効 - - - LBL_CURSOR_SCROLL - スクロール上の中心カーソル - - - LBL_LINE_NUMBS_AREA - ライン番号エリアの表示 - - - GR_TAB_SET - タブ設定 - - - LBL_TAB_SPACES - タブ空白の表示 - - - LBL_TAB_SIZE - Tab size: - - - GR_VERT_EDGE_SET - 垂直エッジ設定 - - - LBL_VERT_EDGE - 垂直エッジの表示 - - - LBL_NUM_COLUMNS - 列数: - - - WDG_SET_AS_DEFAULT_CHECK - デフォルトとして設定を保存 - - - diff --git a/src/PyViewer/CMakeLists.txt b/src/PyViewer/CMakeLists.txt index 90c645fc6..bc4fbe352 100644 --- a/src/PyViewer/CMakeLists.txt +++ b/src/PyViewer/CMakeLists.txt @@ -21,12 +21,14 @@ INCLUDE(UseQtExt) +# --- options --- + # additional include directories INCLUDE_DIRECTORIES( ${QT_INCLUDES} ${PROJECT_SOURCE_DIR}/src/Qtx ${PROJECT_SOURCE_DIR}/src/SUIT - ${PROJECT_SOURCE_DIR}/src/PyEditor + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src ) # additional preprocessor / compiler flags @@ -35,6 +37,8 @@ ADD_DEFINITIONS(${QT_DEFINITIONS}) # libraries to link to SET(_link_LIBRARIES ${PLATFORM_LIBS} ${QT_LIBRARIES} qtx suit PyEditor) +# --- headers --- + # header files / to be processed by moc SET(_moc_HEADERS PyViewer_ViewManager.h @@ -45,33 +49,46 @@ SET(_moc_HEADERS # header files / no moc processing SET(_other_HEADERS PyViewer.h + PyViewer_Settings.h ) # header files / to install SET(PyViewer_HEADERS ${_moc_HEADERS} ${_other_HEADERS}) -# resource files / to be processed by lrelease -SET(RESOURCES_PATH resources) +# --- resources --- SET(_ts_RESOURCES - ${RESOURCES_PATH}/translations/PyViewer_msg_en.ts - ${RESOURCES_PATH}/translations/PyViewer_msg_fr.ts - ${RESOURCES_PATH}/translations/PyViewer_msg_ja.ts + resources/PyViewer_msg_en.ts + resources/PyViewer_msg_fr.ts + resources/PyViewer_msg_ja.ts + resources/PyViewer_images.ts ) -# resource files / to be processed by rcc -SET(_rcc_RESOURCES ${RESOURCES_PATH}/PyEditor.qrc) +# resource files / static +SET(_other_RESOURCES + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src/resources/images/py_copy.png + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src/resources/images/py_cut.png + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src/resources/images/py_delete.png + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src/resources/images/py_help.png + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src/resources/images/py_new.png + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src/resources/images/py_open.png + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src/resources/images/py_paste.png + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src/resources/images/py_preferences.png + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src/resources/images/py_redo.png + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src/resources/images/py_save.png + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src/resources/images/py_save_as.png + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src/resources/images/py_select_all.png + ${PROJECT_SOURCE_DIR}/tools/PyEditor/src/resources/images/py_undo.png +) # --- sources --- # sources / moc wrappings QT_WRAP_MOC(_moc_SOURCES ${_moc_HEADERS}) -# sources / rcc wrappings -QT_ADD_RESOURCES(_rcc_SOURCES ${_rcc_RESOURCES}) - # sources / static SET(_other_SOURCES + PyViewer_Settings.cxx PyViewer_ViewManager.cxx PyViewer_ViewModel.cxx PyViewer_ViewWindow.cxx @@ -81,14 +98,11 @@ SET(_other_SOURCES SET(PyViewer_SOURCES ${_other_SOURCES} ${_moc_SOURCES}) # --- rules --- -ADD_LIBRARY(PyViewer ${PyViewer_SOURCES} ${_rcc_SOURCES}) + +ADD_LIBRARY(PyViewer ${PyViewer_SOURCES}) TARGET_LINK_LIBRARIES(PyViewer ${_link_LIBRARIES}) INSTALL(TARGETS PyViewer EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) -ADD_EXECUTABLE(DummyPyEditor PyViewer.cxx) -SET_TARGET_PROPERTIES(DummyPyEditor PROPERTIES OUTPUT_NAME "PyEditor") -TARGET_LINK_LIBRARIES(DummyPyEditor ${_link_LIBRARIES} PyEditor PyViewer) -INSTALL(TARGETS DummyPyEditor EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_BINS}) - INSTALL(FILES ${PyViewer_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) QT_INSTALL_TS_RESOURCES("${_ts_RESOURCES}" "${SALOME_GUI_INSTALL_RES_DATA}") +INSTALL(FILES ${_other_RESOURCES} DESTINATION ${SALOME_GUI_INSTALL_RES_DATA}) diff --git a/src/PyViewer/PyViewer.cxx b/src/PyViewer/PyViewer.cxx deleted file mode 100644 index 81062889b..000000000 --- a/src/PyViewer/PyViewer.cxx +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (C) 2015-2016 OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// File : PyViewer.cxx -// Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com) -// - -#include -#include -#include -#include - -#include "PyViewer_ViewWindow.h" - -#include - -int main( int argc, char *argv[] ) -{ - QApplication anApplication( argc, argv ); - - // Load translations - QtxTranslator aTranslatorEd , aTranslatorVi, aTranslatorQt; - QString aLanguage = QLocale::system().name().split('_', QString::SkipEmptyParts)[0]; - if ( !aLanguage.isEmpty() ) - { - if ( aTranslatorQt.load( QString( "qt_%1" ).arg( aLanguage ), QLibraryInfo::location( QLibraryInfo::TranslationsPath ) ) ) - anApplication.installTranslator( &aTranslatorQt ); - - QDir appDir = QApplication::applicationDirPath(); - appDir.cdUp(); appDir.cdUp(); - - if ( aTranslatorEd.load( QString( "PyEditor_msg_%1" ).arg( aLanguage ), appDir.filePath( "share/salome/resources/gui" ) ) ) - anApplication.installTranslator( &aTranslatorEd ); - - if ( aTranslatorVi.load( QString( "PyViewer_msg_%1" ).arg( aLanguage ), appDir.filePath( "share/salome/resources/gui" ) ) ) - anApplication.installTranslator( &aTranslatorVi ); - } - - PyViewer_ViewWindow aViewWin; - aViewWin.resize( 650, 700 ); - aViewWin.show(); - - return anApplication.exec(); -} diff --git a/src/PyViewer/PyViewer_Settings.cxx b/src/PyViewer/PyViewer_Settings.cxx new file mode 100644 index 000000000..d86c8373e --- /dev/null +++ b/src/PyViewer/PyViewer_Settings.cxx @@ -0,0 +1,68 @@ +// Copyright (C) 2015-2016 OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : PyViewer_Settings.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#include "PyViewer_Settings.h" + +#include + +PyViewer_Settings::PyViewer_Settings( QtxResourceMgr* resMgr ) : + myResMgr( resMgr ) +{ + load(); +} + +PyViewer_Settings::PyViewer_Settings( QtxResourceMgr* resMgr, const QString& group ) : + myResMgr( resMgr ), + myGroup( group ) +{ + load(); +} + +void PyViewer_Settings::load() +{ + if ( !myResMgr ) return; + QString group = myGroup.isEmpty() ? option( snEditor ) : myGroup; + setHighlightCurrentLine( myResMgr->booleanValue( group, option( snHighlightCurrentLine ), highlightCurrentLine() ) ); + setTextWrapping( myResMgr->booleanValue( group, option( snTextWrapping ), textWrapping() ) ); + setCenterCursorOnScroll( myResMgr->booleanValue( group, option( snCenterCursorOnScroll ), centerCursorOnScroll() ) ); + setLineNumberArea( myResMgr->booleanValue( group, option( snLineNumberArea ), lineNumberArea() ) ); + setVerticalEdge( myResMgr->booleanValue( group, option( snVerticalEdge ), verticalEdge() ) ); + setNumberColumns( myResMgr->integerValue( group, option( snNumberColumns ), numberColumns() ) ); + setTabSpaceVisible( myResMgr->booleanValue( group, option( snTabSpaceVisible ), tabSpaceVisible() ) ); + setTabSize( myResMgr->integerValue( group, option( snTabSize ), tabSize() ) ); + setFont( myResMgr->fontValue( group, option( snFont ), font() ) ); +} + +void PyViewer_Settings::save() +{ + if ( !myResMgr ) return; + QString group = myGroup.isEmpty() ? option( snEditor ) : myGroup; + myResMgr->setValue( group, option( snHighlightCurrentLine ), highlightCurrentLine() ); + myResMgr->setValue( group, option( snTextWrapping ), textWrapping() ); + myResMgr->setValue( group, option( snCenterCursorOnScroll ), centerCursorOnScroll() ); + myResMgr->setValue( group, option( snLineNumberArea ), lineNumberArea() ); + myResMgr->setValue( group, option( snVerticalEdge ), verticalEdge() ); + myResMgr->setValue( group, option( snNumberColumns ), numberColumns() ); + myResMgr->setValue( group, option( snTabSpaceVisible ), tabSpaceVisible() ); + myResMgr->setValue( group, option( snTabSize ), tabSize() ); + myResMgr->setValue( group, option( snFont ), font() ); +} diff --git a/src/PyViewer/PyViewer_Settings.h b/src/PyViewer/PyViewer_Settings.h new file mode 100644 index 000000000..2e09552d7 --- /dev/null +++ b/src/PyViewer/PyViewer_Settings.h @@ -0,0 +1,45 @@ +// Copyright (C) 2015-2016 OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : PyViewer_Settings.h +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#ifndef PYVIEWER_SETTINGS_H +#define PYVIEWER_SETTINGS_H + +#include "PyViewer.h" +#include "PyEditor_Settings.h" + +class QtxResourceMgr; + +class PYVIEWER_EXPORT PyViewer_Settings : public PyEditor_Settings +{ +public: + PyViewer_Settings( QtxResourceMgr* ); + PyViewer_Settings( QtxResourceMgr*, const QString& ); + + void load(); + void save(); + +private: + QtxResourceMgr* myResMgr; + QString myGroup; +}; + +#endif // PYVIEWER_SETTINGS_H diff --git a/src/PyViewer/PyViewer_ViewModel.cxx b/src/PyViewer/PyViewer_ViewModel.cxx index c0360da68..1e0be87de 100644 --- a/src/PyViewer/PyViewer_ViewModel.cxx +++ b/src/PyViewer/PyViewer_ViewModel.cxx @@ -21,8 +21,11 @@ // #include "PyViewer_ViewModel.h" - #include "PyViewer_ViewWindow.h" +#include "PyViewer_Settings.h" + +#include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" /*! \class PyViewer_Viewer @@ -34,6 +37,8 @@ */ PyViewer_Viewer::PyViewer_Viewer() : SUIT_ViewModel() { + if ( !PyEditor_Settings::settings() ) + PyEditor_Settings::setSettings( new PyViewer_Settings( SUIT_Session::session()->resourceMgr(), "PyEditor" ) ); } /*! @@ -49,17 +54,5 @@ PyViewer_Viewer::~PyViewer_Viewer() */ SUIT_ViewWindow* PyViewer_Viewer::createView( SUIT_Desktop* theDesktop ) { - PyViewer_ViewWindow* aPyViewer = new PyViewer_ViewWindow( theDesktop, this ); - initView( aPyViewer ); - return aPyViewer; -} - -/*! - Start initialization of view window - \param view - view window to be initialized -*/ -void PyViewer_Viewer::initView( PyViewer_ViewWindow* theViewModel ) -{ - if ( theViewModel ) - theViewModel->initLayout(); + return new PyViewer_ViewWindow( theDesktop ); } diff --git a/src/PyViewer/PyViewer_ViewModel.h b/src/PyViewer/PyViewer_ViewModel.h index 830a16c45..1a519b817 100644 --- a/src/PyViewer/PyViewer_ViewModel.h +++ b/src/PyViewer/PyViewer_ViewModel.h @@ -43,9 +43,6 @@ public: virtual QString getType() const { return Type(); } static QString Type() { return "PyViewer"; } - -protected: - void initView( PyViewer_ViewWindow* theViewModel ); }; #endif // PYVIEWER_VIEWMODEL_H diff --git a/src/PyViewer/PyViewer_ViewWindow.cxx b/src/PyViewer/PyViewer_ViewWindow.cxx index 5d68c48fb..f7c37be7e 100644 --- a/src/PyViewer/PyViewer_ViewWindow.cxx +++ b/src/PyViewer/PyViewer_ViewWindow.cxx @@ -23,22 +23,17 @@ #include "PyViewer_ViewWindow.h" #include "PyEditor_Editor.h" -#include "PyEditor_Settings.h" #include "PyEditor_SettingsDlg.h" -#include -#include +#include "SUIT_Session.h" +#include "SUIT_ResourceMgr.h" -#include -#include -#include +#include "QtxAction.h" +#include "QtxActionToolMgr.h" -#include +#include #include #include -#include -#include -#include #include /*! @@ -48,291 +43,220 @@ /*! \brief Constructor. - \param theParent parent widget + \param desktop SALOME desktop window */ -PyViewer_ViewWindow::PyViewer_ViewWindow( SUIT_Desktop* theDesktop , PyViewer_Viewer* theModel ) : - SUIT_ViewWindow(theDesktop), - myModel(theModel) -{ - my_IsExternal = (theDesktop == NULL); - - if( isExternal() ) - initLayout(); -} - -void PyViewer_ViewWindow::initLayout() +PyViewer_ViewWindow::PyViewer_ViewWindow( SUIT_Desktop* desktop ) : + SUIT_ViewWindow( desktop ) { - my_TextEditor = new PyEditor_Editor( my_IsExternal ,SUIT_Session::session()->resourceMgr(), this ); - setCentralWidget( my_TextEditor ); - - createActions(); - createToolBar(); + // Create editor and set it as a central widget. + myTextEditor = new PyEditor_Editor( this ); + setCentralWidget( myTextEditor ); + + // Create actions. + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + QtxAction* action; + + // . New + action = new QtxAction( tr( "TTP_NEW" ), + resMgr->loadPixmap( "PyViewer", tr( "ICON_NEW" ) ), + tr( "ACT_NEW" ), 0, this ); + action->setStatusTip( tr( "DSC_NEW" ) ); + action->setShortcut( QKeySequence::New ); + connect( action, SIGNAL( triggered( bool ) ), this, SLOT( onNew() ) ); + toolMgr()->registerAction( action, NewId ); + + // . Open + action = new QtxAction( tr( "TTP_OPEN" ), + resMgr->loadPixmap( "PyViewer", tr( "ICON_OPEN" ) ), + tr( "ACT_OPEN" ), 0, this ); + action->setStatusTip( tr( "DSC_OPEN" ) ); + action->setShortcut( QKeySequence::Open ); + connect( action, SIGNAL( triggered( bool ) ), this, SLOT( onOpen() ) ); + toolMgr()->registerAction( action, OpenId ); + + // . Save + action = new QtxAction( tr( "TTP_SAVE" ), + resMgr->loadPixmap( "PyViewer", tr( "ICON_SAVE" ) ), + tr( "ACT_SAVE" ), 0, this ); + action->setStatusTip( tr( "DSC_SAVE" ) ); + action->setShortcut( QKeySequence::Save ); + connect( action, SIGNAL( triggered( bool ) ), this, SLOT( onSave() ) ); + action->setEnabled( false ); + connect( myTextEditor->document(), SIGNAL( modificationChanged( bool ) ), + action, SLOT( setEnabled( bool ) ) ); + toolMgr()->registerAction( action, SaveId ); + + // . SaveAs + action = new QtxAction( tr( "TTP_SAVEAS" ), + resMgr->loadPixmap( "PyViewer", tr( "ICON_SAVEAS" ) ), + tr( "ACT_SAVEAS" ), 0, this ); + action->setStatusTip( tr( "DSC_SAVEAS" ) ); + action->setShortcut( QKeySequence::SaveAs ); + connect( action, SIGNAL( triggered( bool ) ), this, SLOT( onSaveAs() ) ); + toolMgr()->registerAction( action, SaveAsId ); + + // . Undo + action = new QtxAction( tr( "TTP_UNDO" ), + resMgr->loadPixmap( "PyViewer", tr( "ICON_UNDO" ) ), + tr( "ACT_UNDO" ), 0, this ); + action->setStatusTip( tr( "DSC_UNDO" ) ); + action->setShortcut( QKeySequence::Undo ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( undo() ) ); + action->setEnabled( false ); + connect( myTextEditor->document(), SIGNAL( undoAvailable( bool ) ), + action, SLOT( setEnabled( bool ) ) ); + toolMgr()->registerAction( action, UndoId ); + + // . Redo + action = new QtxAction( tr( "TTP_REDO" ), + resMgr->loadPixmap( "PyViewer", tr( "ICON_REDO" ) ), + tr( "ACT_REDO" ), 0, this ); + action->setStatusTip( tr( "DSC_REDO" ) ); + action->setShortcut( QKeySequence::Redo ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( redo() ) ); + action->setEnabled( false ); + connect( myTextEditor->document(), SIGNAL( redoAvailable( bool ) ), + action, SLOT( setEnabled( bool ) ) ); + toolMgr()->registerAction( action, RedoId ); + + // . Cut + action = new QtxAction( tr( "TTP_CUT" ), + resMgr->loadPixmap( "PyViewer", tr( "ICON_CUT" ) ), + tr( "ACT_CUT" ), 0, this ); + action->setStatusTip( tr( "DSC_CUT" ) ); + action->setShortcut( QKeySequence::Cut ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( cut() ) ); + action->setEnabled( false ); + connect( myTextEditor, SIGNAL( copyAvailable( bool ) ), + action, SLOT( setEnabled( bool ) ) ); + toolMgr()->registerAction( action, CutId ); + + // . Copy + action = new QtxAction( tr( "TTP_COPY" ), + resMgr->loadPixmap( "PyViewer", tr( "ICON_COPY" ) ), + tr( "ACT_COPY" ), 0, this ); + action->setStatusTip( tr( "DSC_COPY" ) ); + action->setShortcut( QKeySequence::Copy ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( copy() ) ); + action->setEnabled( false ); + connect( myTextEditor, SIGNAL( copyAvailable( bool ) ), + action, SLOT( setEnabled( bool ) ) ); + toolMgr()->registerAction( action, CopyId ); + + // . Paste + action = new QtxAction( tr( "TTP_PASTE" ), + resMgr->loadPixmap( "PyViewer", tr( "ICON_PASTE" ) ), + tr( "ACT_PASTE" ), 0, this ); + action->setStatusTip( tr( "DSC_PASTE" ) ); + action->setShortcut( QKeySequence::Paste ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( paste() ) ); + toolMgr()->registerAction( action, PasteId ); + + // . Delete + action = new QtxAction( tr( "TTP_DELETE" ), + resMgr->loadPixmap( "PyViewer", tr( "ICON_DELETE" ) ), + tr( "ACT_DELETE" ), 0, this ); + action->setStatusTip( tr( "DSC_DELETE" ) ); + action->setShortcut( QKeySequence::Delete ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( deleteSelected() ) ); + action->setEnabled( false ); + connect( myTextEditor, SIGNAL( copyAvailable( bool ) ), + action, SLOT( setEnabled( bool ) ) ); + toolMgr()->registerAction( action, DeleteId ); + + // . SelectAll + action = new QtxAction( tr( "TTP_SELECT_ALL" ), + resMgr->loadPixmap( "PyViewer", tr( "ICON_SELECT_ALL" ) ), + tr( "ACT_SELECT_ALL" ), 0, this ); + action->setStatusTip( tr( "DSC_SELECT_ALL" ) ); + action->setShortcut( QKeySequence::SelectAll ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( selectAll() ) ); + toolMgr()->registerAction( action, SelectAllId ); + + // . Preferences + action = new QtxAction( tr( "TTP_PREFERENCES" ), + resMgr->loadPixmap( "PyViewer", tr( "ICON_PREFERENCES" ) ), + tr( "ACT_PREFERENCES" ), 0, this ); + action->setStatusTip( tr( "DSC_PREFERENCES" ) ); + connect( action, SIGNAL( triggered( bool ) ), this, SLOT( onPreferences() ) ); + toolMgr()->registerAction( action, PreferencesId ); + + // . Help + action = new QtxAction( tr( "TTP_HELP" ), + resMgr->loadPixmap( "PyViewer", tr( "ICON_HELP" ) ), + tr( "ACT_HELP" ), 0, this ); + action->setStatusTip( tr( "DSC_HELP" ) ); + connect( action, SIGNAL( triggered() ), this, SLOT( onHelp() ) ); + toolMgr()->registerAction( action, HelpId ); + + // Create toolbar. + int idTB = toolMgr()->createToolBar( tr("TOOLBAR_LABEL"), QString( "PythonEditor" ), false ); + toolMgr()->append( NewId, idTB ); + toolMgr()->append( OpenId, idTB ); + toolMgr()->append( SaveId, idTB ); + toolMgr()->append( SaveAsId, idTB ); + toolMgr()->append( toolMgr()->separator(), idTB ); + toolMgr()->append( UndoId, idTB ); + toolMgr()->append( RedoId, idTB ); + toolMgr()->append( toolMgr()->separator(), idTB ); + toolMgr()->append( CutId, idTB ); + toolMgr()->append( CopyId, idTB ); + toolMgr()->append( PasteId, idTB ); + toolMgr()->append( DeleteId, idTB ); + toolMgr()->append( SelectAllId, idTB ); + toolMgr()->append( toolMgr()->separator(), idTB ); + toolMgr()->append( PreferencesId, idTB ); + toolMgr()->append( toolMgr()->separator(), idTB ); + toolMgr()->append( HelpId, idTB ); + + // Set current file. setCurrentFile( QString() ); - - if ( isExternal() ) - { - connect( my_TextEditor->document(), SIGNAL( modificationChanged( bool ) ), - this, SLOT( setWindowModified( bool ) ) ); - - statusBar()->showMessage( tr("STS_READY") ); - } } /*! \brief Destructor. - */ -PyViewer_ViewWindow::~PyViewer_ViewWindow() -{ - my_CurrentFile.clear(); - delete my_TextEditor; -} - -/*! - \return \c true if the application is external - */ -bool PyViewer_ViewWindow::isExternal() -{ - return my_IsExternal; -} - -/*! - \brief Creates actions of Python view window. */ -void PyViewer_ViewWindow::createActions() -{ - QtxActionToolMgr* aMgr = toolMgr(); - QtxAction* anAction; - - // 1. File operations - // 1.1. Create New action - anAction = new QtxAction( tr( "MNU_PY_NEW" ), QIcon( ":/images/py_new.png" ), - tr( "MNU_PY_NEW" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_NEW" ) ); - anAction->setShortcuts( QKeySequence::New ); - connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onNew() ) ); - aMgr->registerAction( anAction, NewId ); - - // 1.2 Create Open action - anAction = new QtxAction( tr( "MNU_PY_OPEN" ), QIcon( ":/images/py_open.png" ), - tr( "MNU_PY_OPEN" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_OPEN" ) ); - anAction->setShortcuts( QKeySequence::Open ); - connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onOpen() ) ); - aMgr->registerAction( anAction, OpenId ); - - // 1.3. Create Save action - anAction = new QtxAction( tr( "MNU_PY_SAVE" ), QIcon( ":/images/py_save.png" ), - tr( "MNU_PY_SAVE" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_SAVE" ) ); - anAction->setShortcuts( QKeySequence::Save ); - connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onSave() ) ); - aMgr->registerAction( anAction, SaveId ); - // Set default statement for Save action - anAction->setEnabled( my_TextEditor->document()->isModified() ); - connect( my_TextEditor->document(), SIGNAL( modificationChanged( bool ) ), - anAction, SLOT( setEnabled( bool ) ) ); - - // 1.4. Create SaveAs action - anAction = new QtxAction( tr( "MNU_PY_SAVEAS" ), QIcon( ":/images/py_save_as.png" ), - tr( "MNU_PY_SAVEAS" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_SAVEAS" ) ); - anAction->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_S ); - connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onSaveAs() ) ); - aMgr->registerAction( anAction, SaveAsId ); - - // 1.5 Create multi-action for file operations - /*QtxMultiAction* aFileAction = new QtxMultiAction( this ); - aFileAction->insertAction( aMgr->action( NewId ) ); - aFileAction->insertAction( aMgr->action( OpenId ) ); - aFileAction->insertAction( aMgr->action( SaveId ) ); - aFileAction->insertAction( aMgr->action( SaveAsId ) ); - aMgr->registerAction( aFileAction, FileOpId );*/ - - // 1.6. Create Close action - if (isExternal()) - { - anAction = new QtxAction( tr( "MNU_PY_CLOSE" ), QIcon( ":/images/py_close.png" ), - tr( "MNU_PY_CLOSE" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_CLOSE" ) ); - anAction->setShortcut( Qt::CTRL + Qt::Key_Q ); - connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( close() ) ); - aMgr->registerAction( anAction, CloseId ); - } - - // 2. Edit operations - // 2.1. Create Undo action - anAction = new QtxAction( tr( "MNU_PY_UNDO" ), QIcon( ":/images/py_undo.png" ), - tr( "MNU_PY_UNDO" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_UNDO" ) ); - anAction->setShortcuts( QKeySequence::Undo ); - connect( anAction, SIGNAL( triggered( bool ) ), my_TextEditor, SLOT( undo() ) ); - aMgr->registerAction( anAction, UndoId ); - // Set default statement for Undo action - anAction->setEnabled( my_TextEditor->document()->isUndoAvailable() ); - connect( my_TextEditor->document(), SIGNAL( undoAvailable( bool ) ), - anAction, SLOT( setEnabled( bool ) ) ); - - // 2.2. Create Redo action - anAction = new QtxAction( tr( "MNU_PY_REDO" ), QIcon( ":/images/py_redo.png" ), - tr( "MNU_PY_REDO" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_REDO" ) ); - anAction->setShortcuts( QKeySequence::Redo ); - connect( anAction, SIGNAL( triggered( bool ) ), my_TextEditor, SLOT( redo() ) ); - aMgr->registerAction( anAction, RedoId ); - // Set default statement for Redo action - anAction->setEnabled( my_TextEditor->document()->isRedoAvailable() ); - connect( my_TextEditor->document(), SIGNAL( redoAvailable( bool ) ), - anAction, SLOT( setEnabled( bool ) ) ); - - // 2.3. Create Cut action - anAction = new QtxAction( tr( "MNU_PY_CUT" ), QIcon( ":/images/py_cut.png" ), - tr( "MNU_PY_CUT" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_CUT" ) ); - anAction->setShortcuts( QKeySequence::Cut ); - connect( anAction, SIGNAL( triggered( bool ) ), my_TextEditor, SLOT( cut() ) ); - aMgr->registerAction( anAction, CutId ); - // Set default statement for Cut action - anAction->setEnabled( false ); - connect( my_TextEditor, SIGNAL( copyAvailable( bool ) ), - anAction, SLOT( setEnabled( bool ) ) ); - - // 2.4. Create Copy action - anAction = new QtxAction( tr( "MNU_PY_COPY" ), QIcon( ":/images/py_copy.png" ), - tr( "MNU_PY_COPY" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_COPY" ) ); - anAction->setShortcuts( QKeySequence::Copy ); - connect( anAction, SIGNAL( triggered( bool ) ), my_TextEditor, SLOT( copy() ) ); - aMgr->registerAction( anAction, CopyId ); - // Set default statement for Copy action - anAction->setEnabled( false ); - connect( my_TextEditor, SIGNAL( copyAvailable( bool ) ), - anAction, SLOT( setEnabled( bool ) ) ); - - // 2.5. Create Paste action - anAction = new QtxAction( tr( "MNU_PY_PASTE" ), QIcon( ":/images/py_paste.png" ), - tr( "MNU_PY_PASTE" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_PASTE" ) ); - anAction->setShortcuts( QKeySequence::Paste ); - connect( anAction, SIGNAL( triggered( bool ) ), my_TextEditor, SLOT( paste() ) ); - aMgr->registerAction( anAction, PasteId ); - - // 2.6. Create Delete action - anAction = new QtxAction( tr( "MNU_PY_DELETE" ), QIcon( ":/images/py_delete.png" ), - tr( "MNU_PY_DELETE" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_DELETE" ) ); - anAction->setShortcuts( QKeySequence::Delete ); - connect( anAction, SIGNAL( triggered( bool ) ), my_TextEditor, SLOT( deleteSelected() ) ); - aMgr->registerAction( anAction, DeleteId ); - // Set default statement for Delete action - anAction->setEnabled( false ); - connect( my_TextEditor, SIGNAL( copyAvailable( bool ) ), - anAction, SLOT( setEnabled( bool ) ) ); - - // 2.7. Create SelectAll action - anAction = new QtxAction( tr( "MNU_PY_SELECTALL" ), QIcon( ":/images/py_select_all.png" ), - tr( "MNU_PY_SELECTALL" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_SELECT_ALL" ) ); - anAction->setShortcuts( QKeySequence::SelectAll ); - connect( anAction, SIGNAL( triggered( bool ) ), my_TextEditor, SLOT( selectAll() ) ); - aMgr->registerAction( anAction, SelectAllId ); - - // 2.8. Create multi-action for edit operations - /*QtxMultiAction* anEditAction = new QtxMultiAction( this ); - anEditAction->insertAction( aMgr->action( UndoId ) ); - anEditAction->insertAction( aMgr->action( RedoId ) ); - anEditAction->insertAction( aMgr->action( CutId ) ); - anEditAction->insertAction( aMgr->action( CopyId ) ); - anEditAction->insertAction( aMgr->action( PasteId ) ); - anEditAction->insertAction( aMgr->action( DeleteId ) ); - anEditAction->insertAction( aMgr->action( SelectAllId ) ); - aMgr->registerAction( anEditAction, EditOpId );*/ - - // 3. Create Preference action - anAction = new QtxAction( tr( "MNU_PY_PREFERENCES" ), QIcon( ":/images/py_preferences.png" ), - tr( "MNU_PY_PREFERENCES" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_PREFERENCES" ) ); - connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onPreferences() ) ); - aMgr->registerAction( anAction, PreferencesId ); - - // 4. Help operations - - // 4.1. Create Help action - anAction = new QtxAction( tr( "MNU_PY_BROWSER" ), QIcon( ":/images/py_browser.png" ), - tr( "MNU_PY_BROWSER" ), 0, this ); - anAction->setStatusTip( tr( "DSC_PY_BROWSER" ) ); - connect( anAction, SIGNAL( triggered() ), this, SLOT( onBrowser() ) ); - //aMgr->registerAction( anAction, BrowserId ); - - // 4.2. Create multi-action for help operations - /*QtxMultiAction* aHelpAction = new QtxMultiAction( this ); - aHelpAction->insertAction( aMgr->action( BrowserId ) ); - aMgr->registerAction( aHelpAction, HelpOpId );*/ -} - -/*! - \brief Create toolbar for the python view window. -*/ -void PyViewer_ViewWindow::createToolBar() +PyViewer_ViewWindow::~PyViewer_ViewWindow() { - QtxActionToolMgr* aMgr = toolMgr(); - int idTB = aMgr->createToolBar( tr("LBL_TOOLBAR_LABEL"), // title (language-dependent) - QString( "PyEditorOperations" ), // name (language-independent) - false ); // disable floatable toolbar - aMgr->append( NewId, idTB ); - aMgr->append( OpenId, idTB ); - aMgr->append( SaveId, idTB ); - aMgr->append( SaveAsId, idTB ); - if ( isExternal() ) - aMgr->append( CloseId, idTB ); - aMgr->append( aMgr->separator(), idTB ); - aMgr->append( UndoId, idTB ); - aMgr->append( RedoId, idTB ); - aMgr->append( aMgr->separator(), idTB ); - aMgr->append( CutId, idTB ); - aMgr->append( CopyId, idTB ); - aMgr->append( PasteId, idTB ); - aMgr->append( DeleteId, idTB ); - aMgr->append( SelectAllId, idTB ); - aMgr->append( aMgr->separator(), idTB ); - aMgr->append( PreferencesId, idTB ); - aMgr->append( aMgr->separator(), idTB ); - aMgr->append( BrowserId, idTB ); - } /*! - \brief Reimplemented class is to receive a window close request. - \param theEvent event + \brief Manage window close request. + \param event close event */ -void PyViewer_ViewWindow::closeEvent( QCloseEvent* theEvent ) +void PyViewer_ViewWindow::closeEvent( QCloseEvent* event ) { if ( whetherSave() ) - theEvent->accept(); + event->accept(); else - theEvent->ignore(); + event->ignore(); } /*! - SLOT: Creates a new document - */ + SLOT: Create new document +*/ void PyViewer_ViewWindow::onNew() { if ( whetherSave() ) { - my_TextEditor->clear(); + myTextEditor->clear(); setCurrentFile( QString() ); } } /*! - SLOT: Open an existing python file - */ + SLOT: Open existing Python file +*/ void PyViewer_ViewWindow::onOpen() { if ( whetherSave() ) { - QString aFilePath = QFileDialog::getOpenFileName( - this, tr( "TIT_DLG_OPEN" ), QDir::currentPath(), "Python Files (*.py)" ); + QString filter = tr( "TIT_PY_FILES" ); + filter += " (*.py)"; + QString aFilePath = QFileDialog::getOpenFileName( this, + tr( "TIT_DLG_OPEN" ), + QDir::currentPath(), + filter ); if ( !aFilePath.isEmpty() ) loadFile( aFilePath ); @@ -340,24 +264,29 @@ void PyViewer_ViewWindow::onOpen() } /*! - SLOT: Save the current file - */ + SLOT: Save current document +*/ bool PyViewer_ViewWindow::onSave() { - if ( my_CurrentFile.isEmpty() ) + if ( myURL.isEmpty() ) return onSaveAs(); else - return saveFile( my_CurrentFile ); + return saveFile( myURL ); } /*! - SLOT: Save the current file under a new name - */ + SLOT: Save current document under a new name +*/ bool PyViewer_ViewWindow::onSaveAs() { - QString aFilePath = QFileDialog::getSaveFileName( - this, tr( "TIT_DLG_SAVEAS" ), QDir::currentPath(), "Python Files (*.py)" ); + QString filter = tr( "TIT_PY_FILES" ); + filter += " (*.py)"; + QString url = myURL.isEmpty() ? defaultName() : myURL; + QString aFilePath = QFileDialog::getSaveFileName( this, + tr( "TIT_DLG_SAVE" ), + url, + filter ); if ( !aFilePath.isEmpty() ) return saveFile( aFilePath ); @@ -367,143 +296,120 @@ bool PyViewer_ViewWindow::onSaveAs() /*! SLOT: Open preferences dialog - */ +*/ void PyViewer_ViewWindow::onPreferences() { - PyEditor_SettingsDlg* aPage = new PyEditor_SettingsDlg( my_TextEditor, this ); - connect( aPage, SIGNAL( onHelpClicked() ), - this, SLOT( onHelp() ) ); - aPage->exec(); - delete aPage; + PyEditor_SettingsDlg dlg( myTextEditor, true, this ); + connect( &dlg, SIGNAL( help() ), this, SLOT( onHelp() ) ); + dlg.exec(); } /*! - \brief Set preferece values for view. - */ -void PyViewer_ViewWindow::setPreferences() + \brief Associate \a filePath with the current document + \param filePath document's file path +*/ +void PyViewer_ViewWindow::setCurrentFile( const QString& filePath ) { - my_TextEditor->settings()->readSettings(); - my_TextEditor->updateStatement(); + myURL = filePath; + myTextEditor->document()->setModified( false ); } /*! - \brief Associates the theFilePath with the python view. - \param theFilePath file path - */ -void PyViewer_ViewWindow::setCurrentFile( const QString &theFilePath ) -{ - my_CurrentFile = theFilePath; - my_TextEditor->document()->setModified( false ); - - if ( isExternal() ) - { - setWindowModified( false ); - - QString aShownName = my_CurrentFile; - if ( my_CurrentFile.isEmpty() ) - aShownName = "untitled.py"; - setWindowFilePath( aShownName ); - - // Set window title with associated file path - QFileInfo anInfo( aShownName ); - setWindowTitle( "Python Viewer - " + anInfo.fileName() + "[*]" ); - } -} - -/*! - \brief Checks whether the file is modified. + \brief Check whether the file is modified. If it has the modifications then ask the user to save it. \return true if the document is saved. - */ +*/ bool PyViewer_ViewWindow::whetherSave() { - if ( my_TextEditor->document()->isModified() ) + if ( myTextEditor->document()->isModified() ) { - QMessageBox::StandardButton aReturn; - aReturn = QMessageBox::warning( - this, tr( "TIT_DLG_SAVE" ),tr( "WRN_PY_SAVE_FILE" ), - QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel ); - - if ( aReturn == QMessageBox::Save ) + QMessageBox::StandardButton answer = QMessageBox::warning( this, + tr( "NAME_PYEDITOR" ), + tr( "WRN_SAVE_FILE" ), + QMessageBox::Save | + QMessageBox::Discard | + QMessageBox::Cancel ); + switch( answer ) + { + case QMessageBox::Save: return onSave(); - else if ( aReturn == QMessageBox::Cancel ) + case QMessageBox::Cancel: return false; + default: + break; + } } return true; } /*! - \brief Opens file. - \param theFilePath file path - */ -void PyViewer_ViewWindow::loadFile( const QString &theFilePath ) + \brief Open file. + \param filePath file path +*/ +void PyViewer_ViewWindow::loadFile( const QString& filePath ) { - QFile aFile( theFilePath ); + QFile aFile( filePath ); if ( !aFile.open(QFile::ReadOnly | QFile::Text) ) { QMessageBox::warning( this, tr( "NAME_PYEDITOR" ), - tr( "WRN_PY_READ_FILE" ).arg( theFilePath ).arg( aFile.errorString() ) ); + tr( "WRN_READ_FILE" ).arg( filePath ).arg( aFile.errorString() ) ); return; } QTextStream anInput( &aFile ); QApplication::setOverrideCursor( Qt::WaitCursor ); - my_TextEditor->setPlainText( anInput.readAll() ); + myTextEditor->setPlainText( anInput.readAll() ); QApplication::restoreOverrideCursor(); - setCurrentFile( theFilePath ); + setCurrentFile( filePath ); aFile.close(); - if ( isExternal() ) - statusBar()->showMessage( tr( "STS_F_LOADED" ), 2000 ); + } /*! \brief Saves file. \param theFilePath file path - */ -bool PyViewer_ViewWindow::saveFile( const QString &theFilePath ) +*/ +bool PyViewer_ViewWindow::saveFile( const QString& filePath ) { - QFile aFile( theFilePath ); + QFile aFile( filePath ); if ( !aFile.open( QFile::WriteOnly | QFile::Text ) ) { QMessageBox::warning( this, tr( "NAME_PYEDITOR" ), - tr( "WRN_PY_WRITE_FILE" ).arg( theFilePath ).arg( aFile.errorString() ) ); + tr( "WRN_WRITE_FILE" ).arg( filePath ).arg( aFile.errorString() ) ); return false; } QTextStream anOutput( &aFile ); QApplication::setOverrideCursor( Qt::WaitCursor ); - anOutput << my_TextEditor->toPlainText(); + anOutput << myTextEditor->toPlainText(); QApplication::restoreOverrideCursor(); - setCurrentFile( theFilePath ); + setCurrentFile( filePath ); aFile.close(); - if ( isExternal() ) - statusBar()->showMessage( tr( "STS_F_SAVED" ), 2000 ); - return true; } /*! - \brief Opens help browser with python view help information. - */ -void PyViewer_ViewWindow::onBrowser() + Slot, called when user clicks "Help" button in "Preferences" dialog box. +*/ +void PyViewer_ViewWindow::onHelp() { - QDir appDir = QApplication::applicationDirPath(); - QStringList parameters; - parameters << QString( "--file=%1" ).arg( appDir.filePath( "pyeditor.html" ) ); - QProcess::startDetached( "HelpBrowser", parameters ); + SUIT_Application* app = SUIT_Session::session()->activeApplication(); + if ( app ) { + QString page = "python_viewer_page.html"; + if ( qobject_cast( sender() ) ) + page += "#custom_python_preferences"; + app->onHelpContextModule( "GUI", page ); + } } /*! - Slot, called when user clicks "Help" button in "Preferences" dialog box. + Get default name for Python file + \return default name */ -void PyViewer_ViewWindow::onHelp() +QString PyViewer_ViewWindow::defaultName() const { -#ifndef NO_SUIT - SUIT_Application* app = SUIT_Session::session()->activeApplication(); - if ( app ) - app->onHelpContextModule( "GUI", "python_viewer_page.html", "custom_python_preferences" ); -#endif + return tr( "NONAME" ); } diff --git a/src/PyViewer/PyViewer_ViewWindow.h b/src/PyViewer/PyViewer_ViewWindow.h index c7c207f13..b96ea8b2c 100644 --- a/src/PyViewer/PyViewer_ViewWindow.h +++ b/src/PyViewer/PyViewer_ViewWindow.h @@ -28,25 +28,19 @@ #include class PyEditor_Editor; -class PyViewer_Viewer; class PYVIEWER_EXPORT PyViewer_ViewWindow : public SUIT_ViewWindow { Q_OBJECT public: - enum { NewId, OpenId, SaveId, SaveAsId, CloseId, FileOpId, - UndoId, RedoId, CutId, CopyId, PasteId, DeleteId, SelectAllId, EditOpId, - PreferencesId, BrowserId, HelpOpId }; + enum { NewId, OpenId, SaveId, SaveAsId, + UndoId, RedoId, CutId, CopyId, PasteId, DeleteId, SelectAllId, + PreferencesId, HelpId }; - PyViewer_ViewWindow( SUIT_Desktop* theDesktop = 0, PyViewer_Viewer* theModel = 0 ); + PyViewer_ViewWindow( SUIT_Desktop* = 0 ); ~PyViewer_ViewWindow(); - virtual void initLayout(); - - bool isExternal(); - void setPreferences(); - protected: virtual void closeEvent( QCloseEvent* ); @@ -56,7 +50,6 @@ private Q_SLOTS: bool onSave(); bool onSaveAs(); void onPreferences(); - void onBrowser(); void onHelp(); private: @@ -65,16 +58,11 @@ private: void setCurrentFile( const QString& ); bool whetherSave(); + QString defaultName() const; private: - void createActions(); - void createToolBar(); - -private: - PyViewer_Viewer* myModel; - PyEditor_Editor* my_TextEditor; - QString my_CurrentFile; - bool my_IsExternal; + PyEditor_Editor* myTextEditor; + QString myURL; }; #endif // PYVIEWER_VIEWWINDOW_H diff --git a/src/PyViewer/resources/PyViewer_images.ts b/src/PyViewer/resources/PyViewer_images.ts new file mode 100644 index 000000000..639f1b584 --- /dev/null +++ b/src/PyViewer/resources/PyViewer_images.ts @@ -0,0 +1,59 @@ + + + + + PyViewer_ViewWindow + + ICON_NEW + py_new.png + + + ICON_OPEN + py_open.png + + + ICON_SAVE + py_save.png + + + ICON_SAVEAS + py_save_as.png + + + ICON_UNDO + py_undo.png + + + ICON_REDO + py_redo.png + + + ICON_CUT + py_cut.png + + + ICON_COPY + py_copy.png + + + ICON_PASTE + py_paste.png + + + ICON_DELETE + py_delete.png + + + ICON_SELECT_ALL + py_select_all.png + + + ICON_PREFERENCES + py_preferences.png + + + ICON_HELP + py_help.png + + + diff --git a/src/PyViewer/resources/PyViewer_msg_en.ts b/src/PyViewer/resources/PyViewer_msg_en.ts new file mode 100644 index 000000000..0f4355ee3 --- /dev/null +++ b/src/PyViewer/resources/PyViewer_msg_en.ts @@ -0,0 +1,206 @@ + + + + + PyViewer_ViewManager + + PYVIEWER_VIEW_TITLE + Python viewer:%M - viewer:%V + + + + PyViewer_ViewWindow + + NAME_PYEDITOR + Python Editor + + + ACT_NEW + &New + + + TTP_NEW + New + + + DSC_NEW + Create new document + + + ACT_OPEN + &Open... + + + TTP_OPEN + Open + + + DSC_OPEN + Open an existing document + + + ACT_SAVE + &Save + + + TTP_SAVE + Save + + + DSC_SAVE + Save the document to a file + + + ACT_SAVEAS + Save &As... + + + TTP_SAVEAS + Save As + + + DSC_SAVEAS + Save the document to a file with the new name + + + ACT_UNDO + &Undo + + + TTP_UNDO + Undo + + + DSC_UNDO + Undo last operation + + + ACT_REDO + &Redo + + + TTP_REDO + Redo + + + DSC_REDO + Redo last undone operation + + + ACT_CUT + Cu&t + + + TTP_CUT + Cut + + + DSC_CUT + Cut the current selection's contents to the clipboard + + + ACT_COPY + &Copy + + + TTP_COPY + Copy + + + DSC_COPY + Copy the current selection's contents to the clipboard + + + ACT_PASTE + &Paste + + + TTP_PASTE + Paste + + + DSC_PASTE + Paste the clipboard's contents into the current selection + + + ACT_DELETE + &Delete + + + TTP_DELETE + Delete + + + DSC_DELETE + Delete the current selection's contents + + + ACT_SELECT_ALL + Select &All + + + TTP_SELECT_ALL + Select All + + + DSC_SELECT_ALL + Select all the contents + + + ACT_PREFERENCES + Pre&ferences + + + TTP_PREFERENCES + Preferences + + + DSC_PREFERENCES + Show the Preferences dialog + + + ACT_HELP + &Help + + + TTP_HELP + Help + + + DSC_HELP + Show the help on the Python Editor + + + TOOLBAR_LABEL + Edit Operations + + + TIT_PY_FILES + Python files + + + TIT_DLG_OPEN + Open file + + + TIT_DLG_SAVE + Save file + + + WRN_SAVE_FILE + The document has been modified.<br>Do you want to save changes? + + + WRN_READ_FILE + Cannot read file %1:\n%2. + + + WRN_WRITE_FILE + Cannot write file %1:\n%2. + + + NONAME + Noname.py + + + diff --git a/src/PyViewer/resources/PyViewer_msg_fr.ts b/src/PyViewer/resources/PyViewer_msg_fr.ts new file mode 100644 index 000000000..c0fc973cd --- /dev/null +++ b/src/PyViewer/resources/PyViewer_msg_fr.ts @@ -0,0 +1,206 @@ + + + + + PyViewer_ViewManager + + PYVIEWER_VIEW_TITLE + Editeur Python:%M - visualiseur:%V + + + + PyViewer_ViewWindow + + NAME_PYEDITOR + Editeur python + + + ACT_NEW + Nouveau + + + TTP_NEW + Nouveau + + + DSC_NEW + Crée un nouveau fichier python + + + ACT_OPEN + Ouvrir + + + TTP_OPEN + Ouvrir + + + DSC_OPEN + Ouvre un fichier python existant + + + ACT_SAVE + Enregistrer + + + TTP_SAVE + Enregistrer + + + DSC_SAVE + Enregistre le fichier python sur le système de fichiers + + + ACT_SAVEAS + Enregistrer sous... + + + TTP_SAVEAS + Enregistrer sous... + + + DSC_SAVEAS + >Enregistre le fichier python sous un nouveau nom + + + ACT_UNDO + Annuler + + + TTP_UNDO + Annuler + + + DSC_UNDO + Annule la dernière opération + + + ACT_REDO + Refaire + + + TTP_REDO + Refaire + + + DSC_REDO + Répète la dernière opération + + + ACT_CUT + Coupe + + + TTP_CUT + Coupe + + + DSC_CUT + Coupe le contenu de la sélection vers le presse-papier + + + ACT_COPY + Copier + + + TTP_COPY + Copier + + + DSC_COPY + Copie le contenu de la sélection vers le presse-papier + + + ACT_PASTE + Coller + + + TTP_PASTE + Coller + + + DSC_PASTE + Colle le contenu de la sélection vers le presse-papier + + + ACT_DELETE + Supprime + + + TTP_DELETE + Supprime + + + DSC_DELETE + Supprime le contenu de la sélection + + + ACT_SELECT_ALL + Sélectionner tout + + + TTP_SELECT_ALL + Sélectionner tout + + + DSC_SELECT_ALL + Sélectionne tout le contenu + + + ACT_PREFERENCES + Préférences + + + TTP_PREFERENCES + Préférences + + + DSC_PREFERENCES + Affiche la boîte de dialogue des préférences + + + ACT_HELP + Aide + + + TTP_HELP + Aide + + + DSC_HELP + Afficher l'aide + + + TOOLBAR_LABEL + Opérations d'édition + + + TIT_PY_FILES + Fichiers Python + + + TIT_DLG_OPEN + Ouvrir le fichier + + + TIT_DLG_SAVE + Enregistrer le fichier + + + WRN_SAVE_FILE + Le document a été modifié.<br>Voulez-vous sauvegarder vos changements? + + + WRN_READ_FILE + Impossible de lire le fichier %1:\n%2. + + + WRN_WRITE_FILE + Impossible d'écrire le fichier %1:\n%2. + + + NONAME + Noname.py + + + diff --git a/src/PyViewer/resources/translations/PyViewer_msg_ja.ts b/src/PyViewer/resources/PyViewer_msg_ja.ts similarity index 57% rename from src/PyViewer/resources/translations/PyViewer_msg_ja.ts rename to src/PyViewer/resources/PyViewer_msg_ja.ts index 4747251bf..38c7a5a54 100644 --- a/src/PyViewer/resources/translations/PyViewer_msg_ja.ts +++ b/src/PyViewer/resources/PyViewer_msg_ja.ts @@ -12,159 +12,195 @@ PyViewer_ViewWindow NAME_PYEDITOR - Python Viewer + Python Editor - LBL_TOOLBAR_LABEL - 操作の編集 + ACT_NEW + 新規 - MNU_PY_NEW + TTP_NEW 新規 - DSC_PY_NEW + DSC_NEW 新規 python ファイルの作成 - MNU_PY_OPEN + ACT_OPEN + 開く + + + TTP_OPEN 開く - DSC_PY_OPEN + DSC_OPEN 存在する python ファイルを開く - MNU_PY_SAVE + ACT_SAVE + 保存 + + + TTP_SAVE 保存 - DSC_PY_SAVE + DSC_SAVE python ドキュメントをディスクに保存 - MNU_PY_SAVEAS + ACT_SAVEAS 別名保存 - DSC_PY_SAVEAS - 新しい名前で python ドキュメントを保存 + TTP_SAVEAS + 別名保存 - MNU_PY_CLOSE - 閉じる + DSC_SAVEAS + 新しい名前で python ドキュメントを保存 - DSC_PY_CLOSE - python ドキュメントを閉じる + ACT_UNDO + 元に戻す - MNU_PY_UNDO + TTP_UNDO 元に戻す - DSC_PY_UNDO + DSC_UNDO 最後の操作を元に戻す - MNU_PY_REDO + ACT_REDO やり直し - DSC_PY_REDO + TTP_REDO + やり直し + + + DSC_REDO 最後の操作をやり直す - MNU_PY_CUT + ACT_CUT + カット + + + TTP_CUT カット - DSC_PY_CUT + DSC_CUT 現在選択中の内容をクリップボードにカット - MNU_PY_COPY + ACT_COPY コピー - DSC_PY_COPY + TTP_COPY + コピー + + + DSC_COPY 現在選択中の内容をクリップボードにコピー - MNU_PY_PASTE + ACT_PASTE + ペースト + + + TTP_PASTE ペースト - DSC_PY_PASTE + DSC_PASTE クリップボードの内容を現在の選択にペースト - MNU_PY_DELETE + ACT_DELETE 削除 - DSC_PY_DELETE + TTP_DELETE + 削除 + + + DSC_DELETE 現在選択中の内容を削除 - MNU_PY_SELECTALL + ACT_SELECT_ALL + すべて選択 + + + TTP_SELECT_ALL すべて選択 - DSC_PY_SELECT_ALL + DSC_SELECT_ALL すべての内容を選択 - MNU_PY_PREFERENCES + ACT_PREFERENCES 環境設定 - DSC_PY_PREFERENCES + TTP_PREFERENCES + 環境設定 + + + DSC_PREFERENCES 環境設定ボックスの表示 - MNU_PY_BROWSER - ヘルプブラウザ + ACT_HELP + ヘルプ - DSC_PY_BROWSER - ヘルプブラウザの表示 + TTP_HELP + ヘルプ - WRN_PY_READ_FILE - Cannot read file %1:\n%2. + DSC_HELP + ヘルプ - WRN_PY_WRITE_FILE - Cannot write file %1:\n%2. + TOOLBAR_LABEL + 操作の編集 - WRN_PY_SAVE_FILE - ドキュメントは修正済みです。<br>変更を保存しますか? + TIT_PY_FILES + ã..ã.¡ã.¤ã.« Python - TIT_DLG_SAVE - ファイルを保存 + TIT_DLG_OPEN + ファイルを開く - TIT_DLG_SAVEAS - 別名でファイルを保存 + TIT_DLG_SAVE + ファイルを保存 - TIT_DLG_OPEN - ファイルを開く + WRN_SAVE_FILE + ドキュメントは修正済みです。<br>変更を保存しますか? - STS_READY - 準備 + WRN_READ_FILE + Cannot read file %1:\n%2. - STS_F_LOADED - ファイルは読み込まれました + WRN_WRITE_FILE + Cannot write file %1:\n%2. - STS_F_SAVED - ファイルは保存されました + NONAME + Noname.py diff --git a/src/PyViewer/resources/translations/PyViewer_msg_en.ts b/src/PyViewer/resources/translations/PyViewer_msg_en.ts deleted file mode 100644 index 26a70613c..000000000 --- a/src/PyViewer/resources/translations/PyViewer_msg_en.ts +++ /dev/null @@ -1,170 +0,0 @@ - - - - - PyViewer_ViewManager - - PYVIEWER_VIEW_TITLE - Python viewer:%M - viewer:%V - - - - PyViewer_ViewWindow - - NAME_PYEDITOR - Python Viewer - - - LBL_TOOLBAR_LABEL - Edit Operations - - - MNU_PY_NEW - New - - - DSC_PY_NEW - Create a new python file - - - MNU_PY_OPEN - Open - - - DSC_PY_OPEN - Open an existing python file - - - MNU_PY_SAVE - Save - - - DSC_PY_SAVE - Save the python document to disk - - - MNU_PY_SAVEAS - Save As... - - - DSC_PY_SAVEAS - Save the python document under a new name - - - MNU_PY_CLOSE - Close - - - DSC_PY_CLOSE - Close the python document - - - MNU_PY_UNDO - Undo - - - DSC_PY_UNDO - Undoes the last operation - - - MNU_PY_REDO - Redo - - - DSC_PY_REDO - Redoes the last operation - - - MNU_PY_CUT - Cut - - - DSC_PY_CUT - Cut the current selection's contents to the clipboard - - - MNU_PY_COPY - Copy - - - DSC_PY_COPY - Copy the current selection's contents to the clipboard - - - MNU_PY_PASTE - Paste - - - DSC_PY_PASTE - Paste the clipboard's contents into the current selection - - - MNU_PY_DELETE - Delete - - - DSC_PY_DELETE - Delete the current selection's contents - - - MNU_PY_SELECTALL - Select All - - - DSC_PY_SELECT_ALL - Select all the contents - - - MNU_PY_PREFERENCES - Preferences - - - DSC_PY_PREFERENCES - Show the Preferences box - - - MNU_PY_BROWSER - Help Browser - - - DSC_PY_BROWSER - Show the Help browser - - - WRN_PY_READ_FILE - Cannot read file %1:\n%2. - - - WRN_PY_WRITE_FILE - Cannot write file %1:\n%2. - - - WRN_PY_SAVE_FILE - The document has been modified.<br>Do you want to save your changes? - - - TIT_DLG_SAVE - Save file - - - TIT_DLG_SAVEAS - Save file as - - - TIT_DLG_OPEN - Open file - - - STS_READY - Ready - - - STS_F_LOADED - File is loaded - - - STS_F_SAVED - File is saved - - - diff --git a/src/PyViewer/resources/translations/PyViewer_msg_fr.ts b/src/PyViewer/resources/translations/PyViewer_msg_fr.ts deleted file mode 100644 index 117b51784..000000000 --- a/src/PyViewer/resources/translations/PyViewer_msg_fr.ts +++ /dev/null @@ -1,170 +0,0 @@ - - - - - PyViewer_ViewManager - - PYVIEWER_VIEW_TITLE - Editeur Python:%M - visualiseur:%V - - - - PyViewer_ViewWindow - - NAME_PYEDITOR - Editeur python - - - LBL_TOOLBAR_LABEL - Opérations d'édition - - - MNU_PY_NEW - Nouveau - - - DSC_PY_NEW - Crée un nouveau fichier python - - - MNU_PY_OPEN - Ouvrir - - - DSC_PY_OPEN - Ouvre un fichier python existant - - - MNU_PY_SAVE - Enregistrer - - - DSC_PY_SAVE - Enregistre le fichier python sur le système de fichiers - - - MNU_PY_SAVEAS - Enregistrer sous... - - - DSC_PY_SAVEAS - >Enregistre le fichier python sous un nouveau nom - - - MNU_PY_CLOSE - Fermer - - - DSC_PY_CLOSE - Ferme le fichier python - - - MNU_PY_UNDO - Annuler - - - DSC_PY_UNDO - Annule la dernière opération - - - MNU_PY_REDO - Refaire - - - DSC_PY_REDO - Répète la dernière opération - - - MNU_PY_CUT - Coupe - - - DSC_PY_CUT - Coupe le contenu de la sélection vers le presse-papier - - - MNU_PY_COPY - Copier - - - DSC_PY_COPY - Copie le contenu de la sélection vers le presse-papier - - - MNU_PY_PASTE - Coller - - - DSC_PY_PASTE - Colle le contenu de la sélection vers le presse-papier - - - MNU_PY_DELETE - Supprime - - - DSC_PY_DELETE - Supprime le contenu de la sélection - - - MNU_PY_SELECTALL - Sélectionner tout - - - DSC_PY_SELECT_ALL - Sélectionne tout le contenu - - - MNU_PY_PREFERENCES - Préférences - - - DSC_PY_PREFERENCES - Affiche la boîte de dialogue des préférences - - - MNU_PY_BROWSER - Aide - - - DSC_PY_BROWSER - Afficher l'aide - - - WRN_PY_READ_FILE - Impossible de lire le fichier %1:\n%2. - - - WRN_PY_WRITE_FILE - Impossible d'écrire le fichier %1:\n%2. - - - WRN_PY_SAVE_FILE - Le document a été modifié.<br>Voulez-vous sauvegarder vos changements? - - - TIT_DLG_SAVE - Enregistrer le fichier - - - TIT_DLG_SAVEAS - Enregistrer le fichier sous - - - TIT_DLG_OPEN - Ouvrir le fichier - - - STS_READY - Prêt - - - STS_F_LOADED - Le fichier est chargé - - - STS_F_SAVED - Le fichier est sauvé - - - diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 8013abd2d..8d608b708 100755 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -26,14 +26,26 @@ ENDIF() ## # Python-based packages, part 1 (generic) ## + IF(SALOME_USE_PYCONSOLE) # Include sub-project PyConsole: SET(TOOLS_EXPORT_NAME ${PROJECT_NAME}) SET(PYCONSOLE_INSTALL_LIBS "${SALOME_INSTALL_LIBS}" CACHE PATH "") SET(PYCONSOLE_INSTALL_HEADERS "${SALOME_INSTALL_HEADERS}" CACHE PATH "") SET(PYCONSOLE_INSTALL_RES "${SALOME_GUI_INSTALL_RES_DATA}" CACHE PATH "") - OPTION(PYCONSOLE_BUILD_WITH_QT5 "Build PYCONSOLE with Qt 5" ${SALOME_BUILD_WITH_QT5}) + OPTION(PYCONSOLE_BUILD_WITH_QT5 "Build PyConsole with Qt 5" ${SALOME_BUILD_WITH_QT5}) ADD_SUBDIRECTORY(../tools/PyConsole) # will bring in PyInterp automatically ENDIF(SALOME_USE_PYCONSOLE) +IF(SALOME_USE_PYVIEWER) + # Include sub-project PyEditor: + SET(TOOLS_EXPORT_NAME ${PROJECT_NAME}) + SET(PYEDITOR_INSTALL_BINS "${SALOME_INSTALL_BINS}" CACHE PATH "") + SET(PYEDITOR_INSTALL_LIBS "${SALOME_INSTALL_LIBS}" CACHE PATH "") + SET(PYEDITOR_INSTALL_HEADERS "${SALOME_INSTALL_HEADERS}" CACHE PATH "") + SET(PYEDITOR_INSTALL_RES "${SALOME_GUI_INSTALL_RES_DATA}" CACHE PATH "") + OPTION(PYEDITOR_BUILD_WITH_QT5 "Build PyEditor with Qt 5" ${SALOME_BUILD_WITH_QT5}) + ADD_SUBDIRECTORY(PyEditor) +ENDIF(SALOME_USE_PYVIEWER) + diff --git a/tools/PyEditor/CMakeLists.txt b/tools/PyEditor/CMakeLists.txt new file mode 100644 index 000000000..3a7f37867 --- /dev/null +++ b/tools/PyEditor/CMakeLists.txt @@ -0,0 +1,104 @@ +# Copyright (C) 2015-2016 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR) +PROJECT(PyEditor C CXX) + +# Versioning +# =========== +# Project name, upper case +STRING(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UC) + +# To be changed once externalized CMake procedure: +################### +SET(KERNEL_ROOT_DIR $ENV{KERNEL_ROOT_DIR} CACHE PATH "Path to the Salome KERNEL") +IF(EXISTS ${KERNEL_ROOT_DIR}) + LIST(APPEND CMAKE_MODULE_PATH "${KERNEL_ROOT_DIR}/salome_adm/cmake_files") + INCLUDE(SalomeMacros) +ELSE(EXISTS ${KERNEL_ROOT_DIR}) + MESSAGE(FATAL_ERROR "We absolutely need a Salome KERNEL, please define KERNEL_ROOT_DIR") +ENDIF(EXISTS ${KERNEL_ROOT_DIR}) +# From GUI - again to be changed once externalized: +LIST(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../../adm_local/cmake_files") +################### + +# Platform setup +# ============== +INCLUDE(SalomeSetupPlatform) + +# Options +# ======= +OPTION(PYEDITOR_BUILD_WITH_QT5 "Build PyEditor with Qt 5" ON) +OPTION(PYEDITOR_BUILD_SHARED_LIBS "Build shared libraries for PyEditor" ON) +OPTION(PYEDITOR_BUILD_EXE "Build PyEditor's executable" ON) +OPTION(PYEDITOR_BUILD_PYTHON "Build Python wrapping for PyEditor" ON) + +# +# Set list of prerequisites +# ========================= + +IF(PYEDITOR_BUILD_SHARED_LIBS) + SET(BUILD_SHARED_LIBS TRUE) +ELSE(PYEDITOR_BUILD_SHARED_LIBS) + SET(BUILD_SHARED_LIBS FALSE) +ENDIF(PYEDITOR_BUILD_SHARED_LIBS) + +# Qt +IF(NOT PYEDITOR_BUILD_WITH_QT5) + FIND_PACKAGE(SalomeQt4 REQUIRED) +ELSE() + FIND_PACKAGE(SalomeQt5 REQUIRED) +ENDIF() + +IF(PYEDITOR_BUILD_PYTHON) + # Python + FIND_PACKAGE(SalomePythonInterp REQUIRED) + FIND_PACKAGE(SalomePythonLibs REQUIRED) + SALOME_LOG_OPTIONAL_PACKAGE(SalomePythonInterp PYEDITOR_BUILD_PYTHON) + SALOME_LOG_OPTIONAL_PACKAGE(SalomePythonLibs PYEDITOR_BUILD_PYTHON) + # Sip + FIND_PACKAGE(SalomeSIP REQUIRED) # should come after Python and before PyQt + SALOME_LOG_OPTIONAL_PACKAGE(SalomeSIP PYEDITOR_BUILD_PYTHON) + # PyQt + IF (NOT PYEDITOR_BUILD_WITH_QT5) + FIND_PACKAGE(SalomePyQt4 REQUIRED) + SALOME_LOG_OPTIONAL_PACKAGE(SalomePyQt4 PYEDITOR_BUILD_PYTHON) + ELSE() + FIND_PACKAGE(SalomePyQt5 REQUIRED) + SALOME_LOG_OPTIONAL_PACKAGE(SalomePyQt5 PYEDITOR_BUILD_PYTHON) + ENDIF() +ENDIF(PYEDITOR_BUILD_PYTHON) + +# Detection report +SALOME_PACKAGE_REPORT_AND_CHECK() + +# Directories +# +# Directories have to be given after prerequisites (to be able to use +# Python version string for example). +# =========== +SET(PYEDITOR_INSTALL_BINS bin CACHE PATH "Install path: PyEditor binaries") +SET(PYEDITOR_INSTALL_LIBS lib CACHE PATH "Install path: PyEditor libraries") +SET(PYEDITOR_INSTALL_HEADERS include CACHE PATH "Install path: PyEditor headers") +SET(PYEDITOR_INSTALL_RES share/resources CACHE PATH "Install path: PyEditor resources") + +# Sources +# ======== +ADD_SUBDIRECTORY(src) + diff --git a/src/PyEditor/CMakeLists.txt b/tools/PyEditor/src/CMakeLists.txt similarity index 60% rename from src/PyEditor/CMakeLists.txt rename to tools/PyEditor/src/CMakeLists.txt index be15881f7..b8e10e409 100644 --- a/src/PyEditor/CMakeLists.txt +++ b/tools/PyEditor/src/CMakeLists.txt @@ -21,19 +21,22 @@ INCLUDE(UseQtExt) +IF(PYEDITOR_BUILD_PYTHON) + ADD_SUBDIRECTORY(python) +ENDIF(PYEDITOR_BUILD_PYTHON) + # --- options --- # additional include directories INCLUDE_DIRECTORIES( ${QT_INCLUDES} - ${PROJECT_SOURCE_DIR}/src/Qtx ) # additional preprocessor / compiler flags ADD_DEFINITIONS(${QT_DEFINITIONS}) # libraries to link to -SET(_link_LIBRARIES ${PLATFORM_LIBS} ${QT_LIBRARIES} qtx) +SET(_link_LIBRARIES ${PLATFORM_LIBS} ${QT_LIBRARIES}) # --- headers --- @@ -43,12 +46,14 @@ SET(_moc_HEADERS PyEditor_LineNumberArea.h PyEditor_PyHighlighter.h PyEditor_SettingsDlg.h + PyEditor_Window.h ) # header files / no moc processing SET(_other_HEADERS PyEditor.h PyEditor_Settings.h + PyEditor_StdSettings.h ) # header files / to install @@ -57,17 +62,23 @@ SET(PyEditor_HEADERS ${_moc_HEADERS} ${_other_HEADERS}) # --- resources --- # resource files / to be processed by lrelease -SET(RESOURCES_PATH resources) - SET(_ts_RESOURCES - ${RESOURCES_PATH}/translations/PyEditor_msg_en.ts - ${RESOURCES_PATH}/translations/PyEditor_msg_fr.ts - ${RESOURCES_PATH}/translations/PyEditor_msg_ja.ts + resources/translations/PyEditor_msg_en.ts + resources/translations/PyEditor_msg_fr.ts + resources/translations/PyEditor_msg_ja.ts ) +# resource files / to be processed by rcc +SET(_rcc_RESOURCES resources/PyEditor.qrc) + +# --- sources --- + # sources / moc wrappings QT_WRAP_MOC(_moc_SOURCES ${_moc_HEADERS}) +# sources / rcc wrappings +QT_ADD_RESOURCES(_rcc_SOURCES ${_rcc_RESOURCES}) + # sources / static SET(_other_SOURCES PyEditor_Editor.cxx @@ -75,15 +86,28 @@ SET(_other_SOURCES PyEditor_PyHighlighter.cxx PyEditor_Settings.cxx PyEditor_SettingsDlg.cxx + PyEditor_StdSettings.cxx + PyEditor_Window.cxx ) # sources / to compile -SET(PyEditor_SOURCES ${_other_SOURCES} ${_moc_SOURCES}) +# - for library +SET(PyEditor_SOURCES ${_other_SOURCES} ${_moc_SOURCES} ${_rcc_SOURCES}) +# - for executable +SET(pyeditorexe_SOURCES ${PyEditor_SOURCES} PyEditor.cxx) # --- rules --- + ADD_LIBRARY(PyEditor ${PyEditor_SOURCES}) TARGET_LINK_LIBRARIES(PyEditor ${_link_LIBRARIES}) -INSTALL(TARGETS PyEditor EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) +INSTALL(TARGETS PyEditor EXPORT ${TOOLS_EXPORT_NAME}TargetGroup DESTINATION ${PYEDITOR_INSTALL_LIBS}) + +IF(PYEDITOR_BUILD_EXE) + ADD_EXECUTABLE(pyeditorexe ${pyeditorexe_SOURCES}) + SET_TARGET_PROPERTIES(pyeditorexe PROPERTIES OUTPUT_NAME "pyeditor") + TARGET_LINK_LIBRARIES(pyeditorexe ${_link_LIBRARIES}) + INSTALL(TARGETS pyeditorexe EXPORT ${TOOLS_EXPORT_NAME}TargetGroup DESTINATION ${PYEDITOR_INSTALL_BINS}) +ENDIF(PYEDITOR_BUILD_EXE) -INSTALL(FILES ${PyEditor_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) -QT_INSTALL_TS_RESOURCES("${_ts_RESOURCES}" "${SALOME_GUI_INSTALL_RES_DATA}") +INSTALL(FILES ${PyEditor_HEADERS} DESTINATION ${PYEDITOR_INSTALL_HEADERS}) +QT_INSTALL_TS_RESOURCES("${_ts_RESOURCES}" "${PYEDITOR_INSTALL_RES}") diff --git a/tools/PyEditor/src/PyEditor.cxx b/tools/PyEditor/src/PyEditor.cxx new file mode 100644 index 000000000..03a29b8e9 --- /dev/null +++ b/tools/PyEditor/src/PyEditor.cxx @@ -0,0 +1,109 @@ +// Copyright (C) 2015-2016 OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : PyEditor.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#include "PyEditor_Window.h" +#include "PyEditor_StdSettings.h" + +#include +#include +#include +#include +#include +#include + +QString qtTrDir() +{ + const char* vars[] = { "QT5_ROOT_DIR", "QT_ROOT_DIR", "QTDIR" }; + QString qtPath; + for ( uint i = 0; i < sizeof( vars ) / sizeof( vars[0] ) && qtPath.isEmpty(); i++ ) + qtPath = qgetenv( vars[i] ); + if ( !qtPath.isEmpty() ) + qtPath = QDir( qtPath ).absoluteFilePath( "translations" ); + return qtPath; +} + +QString resourceDir() +{ + // Try standalone application's dir. + QDir appDir = QApplication::applicationDirPath(); + appDir.cdUp(); + QFileInfo resFile( appDir.filePath( "share/resources/PyEditor_msg_en.qm" ) ); + if ( resFile.exists() ) + return resFile.absolutePath(); + + // Try salome dir. + appDir = QApplication::applicationDirPath(); + appDir.cdUp(); appDir.cdUp(); + resFile.setFile( appDir.filePath( "share/salome/resources/gui/PyEditor_msg_en.qm" ) ); + if ( resFile.exists() ) + return resFile.absolutePath(); + + return QString(); +} + +int main( int argc, char *argv[] ) +{ + QApplication app( argc, argv ); + app.setOrganizationName( "salome" ); + app.setOrganizationDomain( "www.salome-platform.org" ); + app.setApplicationName( "pyeditor" ); + + PyEditor_StdSettings* settings = new PyEditor_StdSettings(); + PyEditor_Settings::setSettings( settings ); + + QString language = settings->language(); + + // Load Qt translations. + QString qtDirTrSet = QLibraryInfo::location( QLibraryInfo::TranslationsPath ); + QString qtDirTrEnv = qtTrDir(); + + QStringList qtTrFiles; + qtTrFiles << "qt" << "qtbase"; + QStringList qtTrDirs; + qtTrDirs << QLibraryInfo::location( QLibraryInfo::TranslationsPath ); + qtTrDirs << qtTrDir(); + + foreach( QString qtTrFile, qtTrFiles ) { + foreach ( QString qtTrDir, qtTrDirs ) { + QTranslator* translator = new QTranslator; + if ( translator->load( QString("%1_%2").arg( qtTrFile ).arg( language ), qtTrDir ) ) { + app.installTranslator( translator ); + break; + } + else { + delete translator; + } + } + } + + // Load application's translations. + QTranslator translator; + if ( translator.load( QString( "PyEditor_msg_%1" ).arg( language ), resourceDir() ) ) + app.installTranslator( &translator ); + + PyEditor_Window window; + window.setWindowIcon( QIcon( ":/images/py_editor.png" ) ); + window.resize( 650, 700 ); + window.show(); + + return app.exec(); +} diff --git a/src/PyEditor/PyEditor.h b/tools/PyEditor/src/PyEditor.h similarity index 100% rename from src/PyEditor/PyEditor.h rename to tools/PyEditor/src/PyEditor.h diff --git a/src/PyEditor/PyEditor_Editor.cxx b/tools/PyEditor/src/PyEditor_Editor.cxx similarity index 69% rename from src/PyEditor/PyEditor_Editor.cxx rename to tools/PyEditor/src/PyEditor_Editor.cxx index 141d7ee9d..fff2e0425 100644 --- a/src/PyEditor/PyEditor_Editor.cxx +++ b/tools/PyEditor/src/PyEditor_Editor.cxx @@ -20,47 +20,43 @@ // Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com) // -//Local includes #include "PyEditor_Editor.h" #include "PyEditor_LineNumberArea.h" #include "PyEditor_PyHighlighter.h" #include "PyEditor_Settings.h" -//Qtx includes -#include - -//Qt includes #include #include /*! \class PyEditor_Editor - \brief Viewer/Editor is used to edit and show advanced plain text. + \brief Widget to show / edit Python scripts. */ /*! \brief Constructor. - \param isSingle flag determined single application or reccesed. - \param theParent parent widget + \param parent parent widget */ -PyEditor_Editor::PyEditor_Editor( bool isSingle, QtxResourceMgr* theMgr, QWidget* theParent ) - : QPlainTextEdit( theParent ) +PyEditor_Editor::PyEditor_Editor( QWidget* parent ) + : QPlainTextEdit( parent ) { - my_Settings = new PyEditor_Settings( theMgr, isSingle ); + // Set up line number area + myLineNumberArea = new PyEditor_LineNumberArea( this ); + myLineNumberArea->setMouseTracking( true ); - // Create line number area - my_LineNumberArea = new PyEditor_LineNumberArea( this ); - my_LineNumberArea->setMouseTracking( true ); + // Set up syntax highighter + mySyntaxHighlighter = new PyEditor_PyHighlighter( this->document() ); - my_SyntaxHighlighter = new PyEditor_PyHighlighter( this->document() ); + // Set-up settings + PyEditor_Settings* settings = PyEditor_Settings::settings(); + if ( settings ) + setSettings( *settings ); - // Signals and slots + // Connect signals connect( this, SIGNAL( blockCountChanged( int ) ), this, SLOT( updateLineNumberAreaWidth( int ) ) ); connect( this, SIGNAL( updateRequest( QRect, int ) ), this, SLOT( updateLineNumberArea( QRect, int ) ) ); connect( this, SIGNAL( cursorPositionChanged() ), this, SLOT( updateHighlightCurrentLine() ) ); connect( this, SIGNAL( cursorPositionChanged() ), this, SLOT( matchParentheses() ) ); - - updateStatement(); } /*! @@ -71,24 +67,36 @@ PyEditor_Editor::~PyEditor_Editor() } /*! - Updates editor. - */ -void PyEditor_Editor::updateStatement() + \brief Get editor settings. + \return settings object +*/ +const PyEditor_Settings& PyEditor_Editor::settings() const { - //Set font size + return mySettings; +} + +/*! + \brief Set editor settings. + \param settings new settings +*/ +void PyEditor_Editor::setSettings( const PyEditor_Settings& settings ) +{ + mySettings.copyFrom( settings ); + + // Set font size QFont aFont = font(); - aFont.setFamily( settings()->p_Font.family() ); - aFont.setPointSize( settings()->p_Font.pointSize() ); + aFont.setFamily( mySettings.font().family() ); + aFont.setPointSize( mySettings.font().pointSize() ); setFont( aFont ); // Set line wrap mode - setLineWrapMode( settings()->p_TextWrapping ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap ); + setLineWrapMode( mySettings.textWrapping() ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap ); // Center the cursor on screen - setCenterOnScroll( settings()->p_CenterCursorOnScroll ); + setCenterOnScroll( mySettings.centerCursorOnScroll() ); // Set size white spaces - setTabStopWidth( settings()->p_TabSize * 10 ); + setTabStopWidth( mySettings.tabSize() * 10 ); // Update current line highlight updateHighlightCurrentLine(); @@ -96,13 +104,13 @@ void PyEditor_Editor::updateStatement() // Update line numbers area updateLineNumberAreaWidth( 0 ); - my_SyntaxHighlighter->rehighlight(); + mySyntaxHighlighter->rehighlight(); viewport()->update(); } /*! - SLOT: Delete the current selection's contents - */ + Delete current selection contents. +*/ void PyEditor_Editor::deleteSelected() { QTextCursor aCursor = textCursor(); @@ -112,16 +120,17 @@ void PyEditor_Editor::deleteSelected() } /*! - \brief Reimplemented calss is to receive key press events for the plain text widget. - \param theEvent event - */ -void PyEditor_Editor::keyPressEvent( QKeyEvent* theEvent ) + \brief Process key press event. + Reimplemented from QPlainTextEdit. + \param event key press event +*/ +void PyEditor_Editor::keyPressEvent( QKeyEvent* event ) { - if ( theEvent->type() == QEvent::KeyPress ) + if ( event->type() == QEvent::KeyPress ) { - int aKey = theEvent->key(); - Qt::KeyboardModifiers aCtrl = theEvent->modifiers() & Qt::ControlModifier; - Qt::KeyboardModifiers aShift = theEvent->modifiers() & Qt::ShiftModifier; + int aKey = event->key(); + Qt::KeyboardModifiers aCtrl = event->modifiers() & Qt::ControlModifier; + Qt::KeyboardModifiers aShift = event->modifiers() & Qt::ShiftModifier; if ( aKey == Qt::Key_Tab || ( aKey == Qt::Key_Backtab || ( aKey == Qt::Key_Tab && aShift ) ) ) { @@ -129,7 +138,7 @@ void PyEditor_Editor::keyPressEvent( QKeyEvent* theEvent ) aCursor.beginEditBlock(); tabIndentation( aKey == Qt::Key_Backtab ); aCursor.endEditBlock(); - theEvent->accept(); + event->accept(); } else if ( aKey == Qt::Key_Enter || aKey == Qt::Key_Return ) { @@ -137,19 +146,19 @@ void PyEditor_Editor::keyPressEvent( QKeyEvent* theEvent ) aCursor.beginEditBlock(); if ( lineIndent() == 0 ) { - QPlainTextEdit::keyPressEvent( theEvent ); + QPlainTextEdit::keyPressEvent( event ); } aCursor.endEditBlock(); - theEvent->accept(); + event->accept(); } - else if ( theEvent == QKeySequence::MoveToStartOfLine || theEvent == QKeySequence::SelectStartOfLine ) + else if ( event == QKeySequence::MoveToStartOfLine || event == QKeySequence::SelectStartOfLine ) { QTextCursor aCursor = this->textCursor(); if ( QTextLayout* aLayout = aCursor.block().layout() ) { if ( aLayout->lineForTextPosition( aCursor.position() - aCursor.block().position() ).lineNumber() == 0 ) { - handleHome( theEvent == QKeySequence::SelectStartOfLine ); + handleHome( event == QKeySequence::SelectStartOfLine ); } } } @@ -187,40 +196,40 @@ void PyEditor_Editor::keyPressEvent( QKeyEvent* theEvent ) setTextCursor( aCursor ); } } - QPlainTextEdit::keyPressEvent( theEvent ); + QPlainTextEdit::keyPressEvent( event ); } else { - QPlainTextEdit::keyPressEvent( theEvent ); + QPlainTextEdit::keyPressEvent( event ); } } } /*! - \brief Reimplemented calss is to receive plain text widget resize events - which are passed in the event parameter. - \param theEvent event - */ -void PyEditor_Editor::resizeEvent( QResizeEvent* theEvent ) + \brief Handle resize event. + Reimplemented from QPlainTextEdit. + \param event resize event +*/ +void PyEditor_Editor::resizeEvent( QResizeEvent* event ) { - QPlainTextEdit::resizeEvent( theEvent ); + QPlainTextEdit::resizeEvent( event ); // Change size geometry of line number area QRect aContentsRect = contentsRect(); - my_LineNumberArea->setGeometry( - QRect( aContentsRect.left(), - aContentsRect.top(), - lineNumberAreaWidth(), - aContentsRect.height() ) ); + myLineNumberArea->setGeometry( QRect( aContentsRect.left(), + aContentsRect.top(), + lineNumberAreaWidth(), + aContentsRect.height() ) ); } /*! - \brief Reimplemented calss is to receive paint events passed in theEvent. - \param theEvent event - */ -void PyEditor_Editor::paintEvent( QPaintEvent* theEvent ) + \brief Paint event. + Reimplemented from QPlainTextEdit. + \param event paint event +*/ +void PyEditor_Editor::paintEvent( QPaintEvent* event ) { - QPlainTextEdit::paintEvent( theEvent ); + QPlainTextEdit::paintEvent( event ); QTextBlock aBlock( firstVisibleBlock() ); QPointF anOffset( contentOffset() ); @@ -229,12 +238,12 @@ void PyEditor_Editor::paintEvent( QPaintEvent* theEvent ) int aTabSpaces = this->tabStopWidth() / 10; // Visualization tab spaces - if ( settings()->p_TabSpaceVisible ) + if ( mySettings.tabSpaceVisible() ) { qreal aTop = blockBoundingGeometry( aBlock ).translated( anOffset ).top(); - while ( aBlock.isValid() && aTop <= theEvent->rect().bottom() ) + while ( aBlock.isValid() && aTop <= event->rect().bottom() ) { - if ( aBlock.isVisible() && blockBoundingGeometry( aBlock ).translated( anOffset ).toRect().intersects( theEvent->rect() ) ) + if ( aBlock.isVisible() && blockBoundingGeometry( aBlock ).translated( anOffset ).toRect().intersects( event->rect() ) ) { QString aText = aBlock.text(); if ( aText.contains( QRegExp( "\\w+" ) ) ) @@ -267,28 +276,20 @@ void PyEditor_Editor::paintEvent( QPaintEvent* theEvent ) } // Vertical edge line - if ( settings()->p_VerticalEdge ) + if ( mySettings.verticalEdge() ) { - const QRect aRect = theEvent->rect(); + const QRect aRect = event->rect(); const QFont aFont = currentCharFormat().font(); - int aNumberColumn = QFontMetrics( aFont ).averageCharWidth() * settings()->p_NumberColumns + anOffset.x() + document()->documentMargin(); + int aNumberColumn = QFontMetrics( aFont ).averageCharWidth() * mySettings.numberColumns() + anOffset.x() + document()->documentMargin(); aPainter.setPen( QPen( Qt::lightGray, 1, Qt::SolidLine ) ); aPainter.drawLine( aNumberColumn, aRect.top(), aNumberColumn, aRect.bottom() ); } } /*! - \return manager of setting values. - */ -PyEditor_Settings* PyEditor_Editor::settings() -{ - return my_Settings; -} - -/*! - \brief Indenting and tabbing of the text - \param isShift flag defines reverse tab - */ + \brief Indent and tab text. + \param isShift flag defines reverse tab direction +*/ void PyEditor_Editor::tabIndentation( bool isShift ) { QTextCursor aCursor = textCursor(); @@ -329,9 +330,9 @@ void PyEditor_Editor::tabIndentation( bool isShift ) } /*! - \brief Indenting and tabbing of the selected text - \param isShift flag defines reverse tab - */ + \brief Indent and tab selected text. + \param isShift flag defines reverse tab direction +*/ void PyEditor_Editor::indentSelection( bool isShift ) { QTextCursor aCursor = this->textCursor(); @@ -378,16 +379,16 @@ void PyEditor_Editor::indentSelection( bool isShift ) } /*! - \brief Finds the first non-white sapce in theText. - \param theText string - \return index of the first non-white space - */ -int PyEditor_Editor::findFirstNonSpace( const QString& theText ) + \brief Find first non white-space symbol in text. + \param text input text + \return index of first non white-space symbol +*/ +int PyEditor_Editor::findFirstNonSpace( const QString& text ) { int i = 0; - while ( i < theText.size() ) + while ( i < text.size() ) { - if ( !theText.at(i).isSpace() ) + if ( !text.at(i).isSpace() ) return i; ++i; } @@ -395,9 +396,9 @@ int PyEditor_Editor::findFirstNonSpace( const QString& theText ) } /*! - \brief Auto line indenting + \brief Indent line. \return error code - */ +*/ int PyEditor_Editor::lineIndent() { int aTabSpaces = this->tabStopWidth() / 10; @@ -481,7 +482,8 @@ int PyEditor_Editor::lineIndent() /*! \brief Set text cursor on home position. - */ + \param isExtendLine \c true to keep current anchor position +*/ void PyEditor_Editor::handleHome( bool isExtendLine ) { QTextCursor aCursor = textCursor(); @@ -510,12 +512,12 @@ void PyEditor_Editor::handleHome( bool isExtendLine ) } /*! - SLOT: Updates the highlight current line. - */ + \brief Update current line highlighting. +*/ void PyEditor_Editor::updateHighlightCurrentLine() { QList anExtraSelections; - if ( !isReadOnly() && settings()->p_HighlightCurrentLine ) + if ( !isReadOnly() && mySettings.highlightCurrentLine() ) { QTextEdit::ExtraSelection selection; @@ -531,13 +533,13 @@ void PyEditor_Editor::updateHighlightCurrentLine() } /*! - \brief Creates line number area. - \param theEvent event for paint events. - */ -void PyEditor_Editor::lineNumberAreaPaintEvent( QPaintEvent* theEvent ) + \brief Draw linne number area. + \param event paint event +*/ +void PyEditor_Editor::lineNumberAreaPaintEvent( QPaintEvent* event ) { - QPainter aPainter( my_LineNumberArea ); - aPainter.fillRect( theEvent->rect(), QColor( Qt::lightGray ).lighter( 125 ) ); + QPainter aPainter( myLineNumberArea ); + aPainter.fillRect( event->rect(), QColor( Qt::lightGray ).lighter( 125 ) ); QTextBlock aBlock = firstVisibleBlock(); int aBlockNumber = aBlock.blockNumber(); @@ -548,9 +550,9 @@ void PyEditor_Editor::lineNumberAreaPaintEvent( QPaintEvent* theEvent ) QFont aFont = aPainter.font(); aPainter.setPen( this->palette().color( QPalette::Text ) ); - while ( aBlock.isValid() && aTop <= theEvent->rect().bottom() ) + while ( aBlock.isValid() && aTop <= event->rect().bottom() ) { - if ( aBlock.isVisible() && aBottom >= theEvent->rect().top() ) + if ( aBlock.isVisible() && aBottom >= event->rect().top() ) { if ( aBlockNumber == aCurrentLine ) { @@ -565,7 +567,7 @@ void PyEditor_Editor::lineNumberAreaPaintEvent( QPaintEvent* theEvent ) aPainter.setFont( aFont ); } QString aNumber = QString::number( aBlockNumber + 1 ); - aPainter.drawText( 0, aTop, my_LineNumberArea->width(), fontMetrics().height(), Qt::AlignRight, aNumber ); + aPainter.drawText( 0, aTop, myLineNumberArea->width(), fontMetrics().height(), Qt::AlignRight, aNumber ); } aBlock = aBlock.next(); @@ -576,8 +578,9 @@ void PyEditor_Editor::lineNumberAreaPaintEvent( QPaintEvent* theEvent ) } /*! + \brief Get with of line number area. \return width of line number area - */ +*/ int PyEditor_Editor::lineNumberAreaWidth() { int aSpace = 0; @@ -590,38 +593,40 @@ int PyEditor_Editor::lineNumberAreaWidth() ++aDigits; } - if ( settings()->p_LineNumberArea ) + if ( mySettings.lineNumberArea() ) aSpace += 5 + fontMetrics().width( QLatin1Char( '9' ) ) * aDigits; return aSpace; } /*! - SLOT: Updates the width of line number area. - */ -void PyEditor_Editor::updateLineNumberAreaWidth( int /*theNewBlockCount*/ ) + \brief Update width of the line number area. + \param newBlockCount (not used) +*/ +void PyEditor_Editor::updateLineNumberAreaWidth( int /*newBlockCount*/ ) { setViewportMargins( lineNumberAreaWidth(), 0, 0, 0 ); } /*! - SLOT: When the editor viewport has been scrolled. - */ -void PyEditor_Editor::updateLineNumberArea( const QRect& theRect, int theDY ) + \brief Update line number area (when editor viewport is scrolled). + \param rect area being updated + \param dy scroll factor +*/ +void PyEditor_Editor::updateLineNumberArea( const QRect& rect, int dy ) { - if ( theDY ) - my_LineNumberArea->scroll( 0, theDY ); + if ( dy ) + myLineNumberArea->scroll( 0, dy ); else - my_LineNumberArea->update( 0, theRect.y(), my_LineNumberArea->width(), theRect.height() ); + myLineNumberArea->update( 0, rect.y(), myLineNumberArea->width(), rect.height() ); - if ( theRect.contains( viewport()->rect() ) ) + if ( rect.contains( viewport()->rect() ) ) updateLineNumberAreaWidth( 0 ); } /*! - \brief Parenthesis management. - SLOT: Walk through and check that we don't exceed 80 chars per line. - */ + \brief Manage parentheses. +*/ void PyEditor_Editor::matchParentheses() { PyEditor_PyHighlighter::TextBlockData* data = @@ -667,93 +672,93 @@ void PyEditor_Editor::matchParentheses() } /*! - \brief Matches the left brackets. - \param theCurrentBlock text block - \param theI index - \param theNumLeftParentheses number of left parentheses + \brief Match left brackets. + \param currentBlock text block + \param idx index + \param numLeftParentheses number of left parentheses \return \c true if the left match - */ -bool PyEditor_Editor::matchLeftParenthesis( - const QTextBlock& theCurrentBlock, int theI, int theNumLeftParentheses ) +*/ +bool PyEditor_Editor::matchLeftParenthesis( const QTextBlock& currentBlock, + int idx, int numLeftParentheses ) { PyEditor_PyHighlighter::TextBlockData* data = - static_cast( theCurrentBlock.userData() ); + static_cast( currentBlock.userData() ); QVector infos = data->parentheses(); - int docPos = theCurrentBlock.position(); - for ( ; theI < infos.size(); ++theI ) + int docPos = currentBlock.position(); + for ( ; idx < infos.size(); ++idx ) { - PyEditor_PyHighlighter::ParenthesisInfo* info = infos.at(theI); + PyEditor_PyHighlighter::ParenthesisInfo* info = infos.at( idx ); if ( isLeftBrackets( info->character ) ) { - ++theNumLeftParentheses; + ++numLeftParentheses; continue; } - if ( isRightBrackets( info->character ) && theNumLeftParentheses == 0 ) + if ( isRightBrackets( info->character ) && numLeftParentheses == 0 ) { createParenthesisSelection( docPos + info->position ); return true; } else - --theNumLeftParentheses; + --numLeftParentheses; } - QTextBlock nextBlock = theCurrentBlock.next(); + QTextBlock nextBlock = currentBlock.next(); if ( nextBlock.isValid() ) - return matchLeftParenthesis( nextBlock, 0, theNumLeftParentheses ); + return matchLeftParenthesis( nextBlock, 0, numLeftParentheses ); return false; } /*! - \brief Matches the right brackets. - \param theCurrentBlock text block - \param theI index - \param theNumRightParentheses number of right parentheses + \brief Match right brackets. + \param currentBlock text block + \param idx index + \param numRightParentheses number of right parentheses \return \c true if the right match - */ -bool PyEditor_Editor::matchRightParenthesis( const QTextBlock& theCurrentBlock, int theI, int theNumRightParentheses ) +*/ +bool PyEditor_Editor::matchRightParenthesis( const QTextBlock& currentBlock, + int idx, int numRightParentheses ) { - PyEditor_PyHighlighter::TextBlockData* data = static_cast( theCurrentBlock.userData() ); + PyEditor_PyHighlighter::TextBlockData* data = static_cast( currentBlock.userData() ); QVector parentheses = data->parentheses(); - int docPos = theCurrentBlock.position(); - for ( ; theI > -1 && parentheses.size() > 0; --theI ) + int docPos = currentBlock.position(); + for ( ; idx > -1 && parentheses.size() > 0; --idx ) { - PyEditor_PyHighlighter::ParenthesisInfo* info = parentheses.at(theI); + PyEditor_PyHighlighter::ParenthesisInfo* info = parentheses.at( idx ); if ( isRightBrackets( info->character ) ) { - ++theNumRightParentheses; + ++numRightParentheses; continue; } - if ( isLeftBrackets( info->character ) && theNumRightParentheses == 0 ) + if ( isLeftBrackets( info->character ) && numRightParentheses == 0 ) { createParenthesisSelection( docPos + info->position ); return true; } else - --theNumRightParentheses; + --numRightParentheses; } - QTextBlock prevBlock = theCurrentBlock.previous(); + QTextBlock prevBlock = currentBlock.previous(); if ( prevBlock.isValid() ) { PyEditor_PyHighlighter::TextBlockData* data = static_cast( prevBlock.userData() ); QVector parentheses = data->parentheses(); - return matchRightParenthesis( prevBlock, parentheses.size() - 1, theNumRightParentheses ); + return matchRightParenthesis( prevBlock, parentheses.size() - 1, numRightParentheses ); } return false; } /*! - \brief Creates brackets selection. - \param thePosition position - */ -// Create brackets -void PyEditor_Editor::createParenthesisSelection( int thePosition ) + \brief Create brackets selection. + \param position cursor position +*/ +void PyEditor_Editor::createParenthesisSelection( int position ) { QList selections = extraSelections(); @@ -765,7 +770,7 @@ void PyEditor_Editor::createParenthesisSelection( int thePosition ) selection.format = format; QTextCursor cursor = textCursor(); - cursor.setPosition( thePosition ); + cursor.setPosition( position ); cursor.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor ); selection.cursor = cursor; @@ -774,31 +779,48 @@ void PyEditor_Editor::createParenthesisSelection( int thePosition ) } /*! - return true whether the left bracket - */ -bool PyEditor_Editor::isLeftBrackets( QChar theSymbol ) + \brief Check if symbol is a left bracket. + \param symbol text symbol + \return \c true if symbol is any left bracket +*/ +bool PyEditor_Editor::isLeftBrackets( QChar symbol ) +{ + return symbol == '(' || symbol == '{' || symbol == '['; +} + +/*! + \brief Check if symbol is a right bracket. + \param symbol text symbol + \return \c true if symbol is any right bracket +*/ +bool PyEditor_Editor::isRightBrackets( QChar symbol ) { - return theSymbol == '(' || theSymbol == '{' || theSymbol == '['; + return symbol == ')' || symbol == '}' || symbol == ']'; } /*! - Appends a new paragraph with text to the end of the text edit. - */ -void PyEditor_Editor::append( const QString & text ) { - QPlainTextEdit::appendPlainText(text); + \brief Append new paragraph to the end of the editor's text. + \param text paragraph text +*/ +void PyEditor_Editor::append( const QString& text ) +{ + appendPlainText( text ); } /*! - Sets the text edit's text. + \brief Set text to the editor. + \param text new text */ -void PyEditor_Editor::setText( const QString & text ) { - QPlainTextEdit::appendPlainText(text); +void PyEditor_Editor::setText( const QString& text ) +{ + setPlainText( text ); } /*! - return true whether the right bracket - */ -bool PyEditor_Editor::isRightBrackets( QChar theSymbol ) + \brief Get current editor's content. + \return current text +*/ +QString PyEditor_Editor::text() const { - return theSymbol == ')' || theSymbol == '}' || theSymbol == ']'; + return toPlainText(); } diff --git a/src/PyEditor/PyEditor_Editor.h b/tools/PyEditor/src/PyEditor_Editor.h similarity index 83% rename from src/PyEditor/PyEditor_Editor.h rename to tools/PyEditor/src/PyEditor_Editor.h index 518e56838..026635673 100644 --- a/src/PyEditor/PyEditor_Editor.h +++ b/tools/PyEditor/src/PyEditor_Editor.h @@ -23,31 +23,30 @@ #ifndef PYEDITOR_EDITOR_H #define PYEDITOR_EDITOR_H -#include #include "PyEditor.h" +#include "PyEditor_Settings.h" + +#include class PyEditor_PyHighlighter; -class PyEditor_Settings; -class QtxResourceMgr; class PYEDITOR_EXPORT PyEditor_Editor : public QPlainTextEdit { Q_OBJECT public: - PyEditor_Editor( bool isSingle = false, QtxResourceMgr* = 0, QWidget* = 0 ); + PyEditor_Editor( QWidget* = 0 ); virtual ~PyEditor_Editor(); - void lineNumberAreaPaintEvent( QPaintEvent* ); - int lineNumberAreaWidth(); - - void updateStatement(); - PyEditor_Settings* settings(); + void setSettings( const PyEditor_Settings& ); + const PyEditor_Settings& settings() const; + QString text() const; public Q_SLOTS: void deleteSelected(); - void append ( const QString & ); - void setText ( const QString & text ); + void append( const QString& ); + void setText( const QString& text ); + protected: virtual void keyPressEvent( QKeyEvent* ); virtual void resizeEvent( QResizeEvent* ); @@ -66,7 +65,9 @@ private: void createParenthesisSelection( int ); bool isLeftBrackets( QChar ); bool isRightBrackets( QChar ); - + void lineNumberAreaPaintEvent( QPaintEvent* ); + int lineNumberAreaWidth(); + void handleHome( bool ); int lineIndent(); void tabIndentation( bool ); @@ -74,9 +75,11 @@ private: int findFirstNonSpace( const QString& ); - QWidget* my_LineNumberArea; - PyEditor_PyHighlighter* my_SyntaxHighlighter; - PyEditor_Settings* my_Settings; + QWidget* myLineNumberArea; + PyEditor_PyHighlighter* mySyntaxHighlighter; + PyEditor_Settings mySettings; + + friend class PyEditor_LineNumberArea; }; #endif // PYEDITOR_EDITOR_H diff --git a/src/PyEditor/PyEditor_LineNumberArea.cxx b/tools/PyEditor/src/PyEditor_LineNumberArea.cxx similarity index 90% rename from src/PyEditor/PyEditor_LineNumberArea.cxx rename to tools/PyEditor/src/PyEditor_LineNumberArea.cxx index 0a47c9f5f..066ad4e55 100644 --- a/src/PyEditor/PyEditor_LineNumberArea.cxx +++ b/tools/PyEditor/src/PyEditor_LineNumberArea.cxx @@ -36,16 +36,16 @@ PyEditor_LineNumberArea::PyEditor_LineNumberArea( PyEditor_Editor* theCodeEditor ) : QWidget( theCodeEditor ) { - my_CodeEditor = theCodeEditor; + myCodeEditor = theCodeEditor; } QSize PyEditor_LineNumberArea::sizeHint() const { - return QSize( my_CodeEditor->lineNumberAreaWidth(), 0 ); + return QSize( myCodeEditor->lineNumberAreaWidth(), 0 ); } void PyEditor_LineNumberArea::paintEvent( QPaintEvent* theEvent ) { - my_CodeEditor->lineNumberAreaPaintEvent( theEvent ); + myCodeEditor->lineNumberAreaPaintEvent( theEvent ); QWidget::paintEvent( theEvent ); } diff --git a/src/PyEditor/PyEditor_LineNumberArea.h b/tools/PyEditor/src/PyEditor_LineNumberArea.h similarity index 97% rename from src/PyEditor/PyEditor_LineNumberArea.h rename to tools/PyEditor/src/PyEditor_LineNumberArea.h index e1b9e3040..e0092698e 100644 --- a/src/PyEditor/PyEditor_LineNumberArea.h +++ b/tools/PyEditor/src/PyEditor_LineNumberArea.h @@ -40,7 +40,7 @@ protected: void paintEvent( QPaintEvent* ); private: - PyEditor_Editor* my_CodeEditor; + PyEditor_Editor* myCodeEditor; }; #endif // PYEDITOR_LINENUMBERAREA_H diff --git a/src/PyEditor/PyEditor_PyHighlighter.cxx b/tools/PyEditor/src/PyEditor_PyHighlighter.cxx similarity index 97% rename from src/PyEditor/PyEditor_PyHighlighter.cxx rename to tools/PyEditor/src/PyEditor_PyHighlighter.cxx index 73ea030ec..70ff0186a 100644 --- a/src/PyEditor/PyEditor_PyHighlighter.cxx +++ b/tools/PyEditor/src/PyEditor_PyHighlighter.cxx @@ -37,16 +37,16 @@ PyEditor_PyHighlighter::TextBlockData::TextBlockData() QVector PyEditor_PyHighlighter::TextBlockData::parentheses() { - return my_Parentheses; + return myParentheses; } void PyEditor_PyHighlighter::TextBlockData::insert( PyEditor_PyHighlighter::ParenthesisInfo* theInfo ) { int i = 0; - while ( i < my_Parentheses.size() && theInfo->position > my_Parentheses.at(i)->position ) + while ( i < myParentheses.size() && theInfo->position > myParentheses.at(i)->position ) ++i; - my_Parentheses.insert( i, theInfo ); + myParentheses.insert( i, theInfo ); } /*! @@ -61,7 +61,7 @@ PyEditor_PyHighlighter::PyEditor_PyHighlighter( QTextDocument* theDocument ) /*! \brief Initialization rules. - */ +*/ void PyEditor_PyHighlighter::initialize() { HighlightingRule aRule; @@ -69,7 +69,7 @@ void PyEditor_PyHighlighter::initialize() // Keywords keywordFormat.setForeground( Qt::blue ); QStringList aKeywords = keywords(); - foreach ( const QString &keyword, aKeywords ) + foreach ( const QString& keyword, aKeywords ) { aRule.pattern = QRegExp( QString( "\\b%1\\b" ).arg( keyword ) ); aRule.format = keywordFormat; @@ -80,7 +80,7 @@ void PyEditor_PyHighlighter::initialize() // Special keywords specialFromat.setForeground( Qt::magenta ); QStringList aSpecialKeywords = specialKeywords(); - foreach ( const QString &keyword, aSpecialKeywords ) + foreach ( const QString& keyword, aSpecialKeywords ) { aRule.pattern = QRegExp( QString( "\\b%1\\b" ).arg( keyword ) ); aRule.format = specialFromat; @@ -190,7 +190,7 @@ QStringList PyEditor_PyHighlighter::keywords() /*! \return string list of special Python keywords. - */ +*/ QStringList PyEditor_PyHighlighter::specialKeywords() { QStringList aSpecialKeywords; diff --git a/src/PyEditor/PyEditor_PyHighlighter.h b/tools/PyEditor/src/PyEditor_PyHighlighter.h similarity index 98% rename from src/PyEditor/PyEditor_PyHighlighter.h rename to tools/PyEditor/src/PyEditor_PyHighlighter.h index 1256813dd..961616fa2 100644 --- a/src/PyEditor/PyEditor_PyHighlighter.h +++ b/tools/PyEditor/src/PyEditor_PyHighlighter.h @@ -48,7 +48,7 @@ public: void insert( ParenthesisInfo* ); private: - QVector my_Parentheses; + QVector myParentheses; }; public: diff --git a/tools/PyEditor/src/PyEditor_Settings.cxx b/tools/PyEditor/src/PyEditor_Settings.cxx new file mode 100644 index 000000000..d9fd52fd1 --- /dev/null +++ b/tools/PyEditor/src/PyEditor_Settings.cxx @@ -0,0 +1,283 @@ +// Copyright (C) 2015-2016 OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : PyEditor_Settings.cxx +// Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com) +// + +#include "PyEditor_Settings.h" + +/*! + \class PyEditor_Settings + \brief Manager of setting values. +*/ + +PyEditor_Settings* PyEditor_Settings::myGlobalSettings = 0; + +/*! + Get global settings. + \return reference to global settings object +*/ +PyEditor_Settings* PyEditor_Settings::settings() +{ + return myGlobalSettings; +} + +/*! + Set global settings. + \param settings reference to global settings object +*/ +void PyEditor_Settings::setSettings( PyEditor_Settings* settings ) +{ + if ( myGlobalSettings ) + delete myGlobalSettings; + myGlobalSettings = settings; +} + +/*! + \brief Constructor. +*/ +PyEditor_Settings::PyEditor_Settings() + : myHighlightCurrentLine( true ), + myTextWrapping( false ), + myCenterCursorOnScroll( true ), + myLineNumberArea( true ), + myVerticalEdge( true ), + myNumberColumns( 80 ), + myTabSpaceVisible( true ), + myTabSize( 4 ), + myFont( "Courier", 10 ) +{ +} + +/*! + \brief Set "highlight current line" option. + \param on option value +*/ +void PyEditor_Settings::setHighlightCurrentLine( bool on ) +{ + myHighlightCurrentLine = on; +} + +/*! + \brief Get "highlight current line" option. + \return option value +*/ +bool PyEditor_Settings::highlightCurrentLine() const +{ + return myHighlightCurrentLine; +} + +/*! + \brief Set "text wrapping" option. + \param on option value +*/ +void PyEditor_Settings::setTextWrapping( bool on ) +{ + myTextWrapping = on; +} + +/*! + \brief Get "text wrapping line" option. + \return option value +*/ +bool PyEditor_Settings::textWrapping() const +{ + return myTextWrapping; +} + +/*! + \brief Set "center cursor on scroll" option. + \param on option value +*/ +void PyEditor_Settings::setCenterCursorOnScroll( bool on ) +{ + myCenterCursorOnScroll = on; +} + +/*! + \brief Get "center cursor on scroll" option. + \return option value +*/ +bool PyEditor_Settings::centerCursorOnScroll() const +{ + return myCenterCursorOnScroll; +} + +/*! + \brief Set "show line number area" option. + \param on option value +*/ +void PyEditor_Settings::setLineNumberArea( bool on ) +{ + myLineNumberArea = on; +} + +/*! + \brief Get "show line number area" option. + \return option value +*/ +bool PyEditor_Settings::lineNumberArea() const +{ + return myLineNumberArea; +} + +/*! + \brief Set "show vertical edge" option. + \param on option value +*/ +void PyEditor_Settings::setVerticalEdge( bool on ) +{ + myVerticalEdge = on; +} + +/*! + \brief Get "show vertical edge" option. + \return option value +*/ +bool PyEditor_Settings::verticalEdge() const +{ + return myVerticalEdge; +} + +/*! + \brief Set "number of columns" option. + \param value option value +*/ +void PyEditor_Settings::setNumberColumns( int value ) +{ + myNumberColumns = value; +} + +/*! + \brief Get "number of columns" option. + \return option value +*/ +int PyEditor_Settings::numberColumns() const +{ + return myNumberColumns; +} + +/*! + \brief Set "show tab spaces" option. + \param on option value +*/ +void PyEditor_Settings::setTabSpaceVisible( bool on ) +{ + myTabSpaceVisible = on; +} + +/*! + \brief Get "show tab spaces" option. + \return option value +*/ +bool PyEditor_Settings::tabSpaceVisible() const +{ + return myTabSpaceVisible; +} + +/*! + \brief Set "tab size" option. + \param value option value +*/ +void PyEditor_Settings::setTabSize( int value ) +{ + myTabSize = value; +} + +/*! + \brief Get "tab size" option. + \return option value +*/ +int PyEditor_Settings::tabSize() const +{ + return myTabSize; +} + +/*! + \brief Set "font" option. + \param font option value +*/ +void PyEditor_Settings::setFont( const QFont& font ) +{ + myFont = font; +} + +/*! + \brief Get "font" option. + \return option value +*/ +QFont PyEditor_Settings::font() const +{ + return myFont; +} + +/*! + \brief Read settings from the persistence storage. + Base implementation does nothing; it should be reimplemented in successors. +*/ +void PyEditor_Settings::load() +{ +} + +/*! + \brief Write settings to the persistence storage. + Base implementation does nothing; it should be reimplemented in successors. +*/ +void PyEditor_Settings::save() +{ +} + +/*! + \brief Copy settings from another object. + \param other source settings object +*/ +void PyEditor_Settings::copyFrom( const PyEditor_Settings& other ) +{ + setHighlightCurrentLine( other.highlightCurrentLine() ); + setTextWrapping( other.textWrapping() ); + setCenterCursorOnScroll( other.centerCursorOnScroll() ); + setLineNumberArea( other.lineNumberArea() ); + setTabSpaceVisible( other.tabSpaceVisible() ); + setTabSize( other.tabSize() ); + setVerticalEdge( other.verticalEdge() ); + setNumberColumns( other.numberColumns() ); + setFont( other.font() ); + save(); +} + +/*! + \brief Get preference item's identifier. + \return string identifier +*/ +QString PyEditor_Settings::option( Option option ) +{ + static const char* options[] = { + "PythonEditor", + "HighlightCurrentLine", + "TextWrapping", + "CenterCursorOnScroll", + "LineNumberArea", + "VerticalEdge", + "NumberColumns", + "TabSpaceVisible", + "TabSize", + "Font", + }; + return option >= 0 && option <= snFont ? options[option] : "Unknown"; +} diff --git a/tools/PyEditor/src/PyEditor_Settings.h b/tools/PyEditor/src/PyEditor_Settings.h new file mode 100644 index 000000000..2f1c9be6c --- /dev/null +++ b/tools/PyEditor/src/PyEditor_Settings.h @@ -0,0 +1,106 @@ +// Copyright (C) 2015-2016 OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : PyEditor_Settings.h +// Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com) +// + +#ifndef PYEDITOR_SETTINGS_H +#define PYEDITOR_SETTINGS_H + +#include "PyEditor.h" + +#include + +class PYEDITOR_EXPORT PyEditor_Settings +{ +protected: + enum Option { snEditor, + snHighlightCurrentLine, + snTextWrapping, + snCenterCursorOnScroll, + snLineNumberArea, + snVerticalEdge, + snNumberColumns, + snTabSpaceVisible, + snTabSize, + snFont }; + +public: + static PyEditor_Settings* settings(); + static void setSettings( PyEditor_Settings* ); + + PyEditor_Settings(); + + void setHighlightCurrentLine( bool ); + bool highlightCurrentLine() const; + + void setTextWrapping( bool ); + bool textWrapping() const; + + void setCenterCursorOnScroll( bool ); + bool centerCursorOnScroll() const; + + void setLineNumberArea( bool ); + bool lineNumberArea() const; + + void setVerticalEdge( bool ); + bool verticalEdge() const; + + void setNumberColumns( int ); + int numberColumns() const; + + void setTabSpaceVisible( bool ); + bool tabSpaceVisible() const; + + void setTabSize( int ); + int tabSize() const; + + void setFont( const QFont& ); + QFont font() const; + + virtual void load(); + virtual void save(); + + void copyFrom( const PyEditor_Settings& ); + +protected: + QString option( Option ); + +private: + // Display settings + bool myHighlightCurrentLine; + bool myTextWrapping; + bool myCenterCursorOnScroll; + bool myLineNumberArea; + + // Vertical edge settings + bool myVerticalEdge; + int myNumberColumns; + + // Tab settings + bool myTabSpaceVisible; + int myTabSize; + + // Font settings + QFont myFont; + + static PyEditor_Settings* myGlobalSettings; +}; + +#endif // PYEDITOR_SETTINGS_H diff --git a/tools/PyEditor/src/PyEditor_SettingsDlg.cxx b/tools/PyEditor/src/PyEditor_SettingsDlg.cxx new file mode 100644 index 000000000..fc2c94b64 --- /dev/null +++ b/tools/PyEditor/src/PyEditor_SettingsDlg.cxx @@ -0,0 +1,326 @@ +// Copyright (C) 2015-2016 OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : PyEditor_SettingsDlg.cxx +// Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com) +// + +#include "PyEditor_SettingsDlg.h" + +#include "PyEditor_Editor.h" +#include "PyEditor_Settings.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +/*! + \class PyEditor_SettingsDlg + \brief Dialog settings for python editor. +*/ + +/*! + \brief Constructor. + \param theEditor widget that is used to edit and display text + \param theParent parent widget +*/ +PyEditor_SettingsDlg::PyEditor_SettingsDlg( PyEditor_Editor* theEditor, + bool showHelp, QWidget* theParent ) : + QDialog( theParent ), + myEditor( theEditor ) +{ + setWindowTitle( tr("TIT_PREFERENCES") ); + QVBoxLayout* aMainLayout = new QVBoxLayout( this ); + + // . Font settings + QGroupBox* aFontSetBox = new QGroupBox( tr( "GR_FONT_SET" ), this ); + QHBoxLayout* aFontSetLayout = new QHBoxLayout( aFontSetBox ); + myFontFamily = new QFontComboBox( aFontSetBox ); + myFontFamily->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); + myFontSize = new QComboBox( aFontSetBox ); + myFontSize->setInsertPolicy( QComboBox::NoInsert ); + myFontSize->setEditable( true ); + myFontSize->setValidator( new QIntValidator( 1, 250, myFontSize ) ); + myFontSize->setSizeAdjustPolicy( QComboBox::AdjustToContents ); + myFontSize->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ); + aFontSetLayout->addWidget( myFontFamily ); + aFontSetLayout->addWidget( myFontSize ); + connect( myFontFamily, SIGNAL( currentFontChanged( QFont ) ), + this, SLOT( onFontChanged() ) ); + aMainLayout->addWidget( aFontSetBox ); + // . Font settings + + // . Display settings + QGroupBox* aDisplaySetBox = new QGroupBox( tr( "GR_DISP_SET" ), this ); + QVBoxLayout* aDisplaySetLayout = new QVBoxLayout( aDisplaySetBox ); + myHighlightCurrentLine = new QCheckBox( tr( "LBL_CURRLINE_HIGHLIGHT" ), aDisplaySetBox ); + myTextWrapping = new QCheckBox( tr( "LBL_TEXT_WRAP" ), aDisplaySetBox ); + myCenterCursorOnScroll = new QCheckBox( tr( "LBL_CURSOR_SCROLL" ), aDisplaySetBox ); + myLineNumberArea = new QCheckBox( tr( "LBL_LINE_NUMBS_AREA" ), aDisplaySetBox ); + aDisplaySetLayout->addWidget( myHighlightCurrentLine ); + aDisplaySetLayout->addWidget( myTextWrapping ); + aDisplaySetLayout->addWidget( myCenterCursorOnScroll ); + aDisplaySetLayout->addWidget( myLineNumberArea ); + aDisplaySetLayout->addStretch( 1 ); + aMainLayout->addWidget( aDisplaySetBox ); + // . Display settings + + // . Tab settings + QGroupBox* aTabSetBox = new QGroupBox( tr( "GR_TAB_SET" ), this ); + QVBoxLayout* aTabSetLayout = new QVBoxLayout( aTabSetBox ); + myTabSpaceVisible = new QCheckBox( tr( "LBL_TAB_SPACES" ), aTabSetBox ); + QHBoxLayout* aTabSizeLayout = new QHBoxLayout; + QLabel* aTabSizeLabel = new QLabel( tr( "LBL_TAB_SIZE" ), aTabSetBox ); + myTabSize = new QSpinBox( aTabSetBox ); + myTabSize->setMinimum( 0 ); + myTabSize->setSingleStep( 1 ); + aTabSizeLayout->addWidget( aTabSizeLabel ); + aTabSizeLayout->addWidget( myTabSize ); + aTabSizeLayout->addStretch( 1 ); + aTabSetLayout->addWidget( myTabSpaceVisible ); + aTabSetLayout->addLayout( aTabSizeLayout ); + // . Tab settings + + // . Vertical edge settings + QGroupBox* aVertEdgeSetBox = new QGroupBox( tr( "GR_VERT_EDGE_SET" ), this ); + QVBoxLayout* aVertEdgeLayout = new QVBoxLayout( aVertEdgeSetBox ); + myVerticalEdge = new QCheckBox( tr( "LBL_VERT_EDGE" ), aVertEdgeSetBox ); + QHBoxLayout* aNumberColLayout = new QHBoxLayout; + myNumberColumnsLbl = new QLabel( tr( "LBL_NUM_COLUMNS" ), aVertEdgeSetBox ); + myNumberColumns = new QSpinBox( aVertEdgeSetBox ); + myNumberColumns->setMinimum( 0 ); + myNumberColumns->setSingleStep( 1 ); + aNumberColLayout->addWidget( myNumberColumnsLbl ); + aNumberColLayout->addWidget( myNumberColumns ); + aNumberColLayout->addStretch( 1 ); + aVertEdgeLayout->addWidget( myVerticalEdge ); + aVertEdgeLayout->addLayout( aNumberColLayout ); + connect( myVerticalEdge, SIGNAL( clicked( bool ) ), + this, SLOT( onVerticalEdgeChecked() ) ); + // . Vertical edge settings + + QHBoxLayout* aTabVertEdgeLayout = new QHBoxLayout; + aTabVertEdgeLayout->addWidget( aTabSetBox ); + aTabVertEdgeLayout->addWidget( aVertEdgeSetBox ); + aMainLayout->addLayout( aTabVertEdgeLayout ); + + // . "Set as default" check box + if ( PyEditor_Settings::settings() ) + { + myDefaultCheck = new QCheckBox( tr( "WDG_SET_AS_DEFAULT_CHECK" ), this ); + aMainLayout->addWidget( myDefaultCheck ); + } + else + { + myDefaultCheck = 0; + } + // . "Set as default" check box + + // . Control buttons + QHBoxLayout* aButtonLayout = new QHBoxLayout; + + QPushButton* okBtn = new QPushButton( tr( "BUT_OK" ), this ); + okBtn->setAutoDefault( true ); + okBtn->setDefault( true ); + connect( okBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) ); + aButtonLayout->addWidget( okBtn ); + + if ( PyEditor_Settings::settings() ) + { + QPushButton* defBtn = new QPushButton( tr( "BUT_DEFAULTS" ), this ); + defBtn->setAutoDefault( true ); + connect( defBtn, SIGNAL( clicked() ), this, SLOT( onDefault() ) ); + aButtonLayout->addStretch(); + aButtonLayout->addWidget( defBtn ); + } + + QPushButton* cancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this ); + cancelBtn->setAutoDefault( true ); + connect( cancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) ); + aButtonLayout->addStretch(); + aButtonLayout->addWidget( cancelBtn ); + + if ( showHelp ) + { + QPushButton* helpBtn = new QPushButton( tr( "BUT_HELP" ), this ); + helpBtn->setAutoDefault( true ); + connect( helpBtn, SIGNAL( clicked() ), this, SLOT( onHelp() ) ); + aButtonLayout->addWidget( helpBtn ); + } + aMainLayout->addStretch( 1 ); + aMainLayout->addLayout( aButtonLayout ); + // . Control buttons + + settingsToGui(); +} + +/*! + Destructor. +*/ +PyEditor_SettingsDlg::~PyEditor_SettingsDlg() +{ +} + +/*! + SLOT: Changes the widget visibility depending on the set theState flag. + \param theState flag of visibility + */ +void PyEditor_SettingsDlg::onVerticalEdgeChecked() +{ + myNumberColumnsLbl->setEnabled( myVerticalEdge->isChecked() ); + myNumberColumns->setEnabled( myVerticalEdge->isChecked() ); +} + +/*! + SLOT: Fills font sizesc combo-box with available values depending on the + chosen font family. + */ +void PyEditor_SettingsDlg::onFontChanged() +{ + bool blocked = myFontSize->blockSignals( true ); + + QString oldSize = myFontSize->currentText(); + + QList szList = QFontDatabase().pointSizes( myFontFamily->currentFont().family() ); + QStringList sizes; + foreach ( int size, szList ) + sizes.append( QString::number( size ) ); + + myFontSize->clear(); + myFontSize->addItems( sizes ); + setFontSize( oldSize ); + + myFontSize->blockSignals( blocked ); +} + +/*! + \brief Sets settings from preferences dialog. + */ +void PyEditor_SettingsDlg::settingsFromGui() +{ + const PyEditor_Settings& oldSettings = myEditor->settings(); + PyEditor_Settings settings; + + QFont font = oldSettings.font(); + font.setFamily( myFontFamily->currentFont().family() ); + bool ok; + int size = myFontSize->currentText().toInt( &ok ); + if ( ok ) + font.setPointSize( size ); + + settings.setHighlightCurrentLine( myHighlightCurrentLine->isChecked() ); + settings.setTextWrapping( myTextWrapping->isChecked() ); + settings.setCenterCursorOnScroll( myCenterCursorOnScroll->isChecked() ); + settings.setLineNumberArea( myLineNumberArea->isChecked() ); + settings.setTabSpaceVisible( myTabSpaceVisible->isChecked() ); + settings.setTabSize( myTabSize->value() ); + settings.setVerticalEdge( myVerticalEdge->isChecked() ); + settings.setNumberColumns( myNumberColumns->value() ); + settings.setFont( font ); + myEditor->setSettings(settings); // updateContent() + + PyEditor_Settings* globals = PyEditor_Settings::settings(); + if ( globals && myDefaultCheck && myDefaultCheck->isChecked() ) + globals->copyFrom( settings ); +} + +/*! + \brief Sets settings into preferences dialog. + */ +void PyEditor_SettingsDlg::settingsToGui() +{ + const PyEditor_Settings& settings = myEditor->settings(); + + myHighlightCurrentLine->setChecked( settings.highlightCurrentLine() ); + myTextWrapping->setChecked( settings.textWrapping() ); + myCenterCursorOnScroll->setChecked( settings.centerCursorOnScroll() ); + myLineNumberArea->setChecked( settings.lineNumberArea() ); + myTabSpaceVisible->setChecked( settings.tabSpaceVisible() ); + myTabSize->setValue( settings.tabSize() ); + myVerticalEdge->setChecked( settings.verticalEdge() ); + myNumberColumns->setValue( settings.numberColumns() ); + myFontFamily->setCurrentFont( settings.font() ); + setFontSize( QString::number( settings.font().pointSize() ) ); + + onVerticalEdgeChecked(); + onFontChanged(); +} + +/*! + \brief Set font size value to the combo box. + \param size new size value +*/ +void PyEditor_SettingsDlg::setFontSize( const QString& size ) +{ + int idx = myFontSize->findText( size ); + if ( idx != -1 ) + myFontSize->setCurrentIndex( idx ); + else + myFontSize->setEditText( size ); +} + +/*! + Slot, called when user clicks "OK" button +*/ +void PyEditor_SettingsDlg::onOk() +{ + settingsFromGui(); + accept(); +} + +/*! + Slot, called when user clicks "Defaults" button +*/ +void PyEditor_SettingsDlg::onDefault() +{ + PyEditor_Settings* settings = PyEditor_Settings::settings(); + if ( settings ) + { + settings->load(); // to reload from the resources + + QFont font = settings->font(); + + myHighlightCurrentLine->setChecked( settings->highlightCurrentLine() ); + myTextWrapping->setChecked( settings->textWrapping() ); + myCenterCursorOnScroll->setChecked( settings->centerCursorOnScroll() ); + myLineNumberArea->setChecked( settings->lineNumberArea() ); + myTabSpaceVisible->setChecked( settings->tabSpaceVisible() ); + myTabSize->setValue( settings->tabSize() ); + myVerticalEdge->setChecked( settings->verticalEdge() ); + myNumberColumns->setValue( settings->numberColumns() ); + myFontFamily->setCurrentFont( font ); + setFontSize( QString::number( font.pointSize() ) ); + + onVerticalEdgeChecked(); + onFontChanged(); + } +} + +/*! + Slot, called when user clicks "Help" button. + Emits help() signal. +*/ +void PyEditor_SettingsDlg::onHelp() +{ + emit help(); +} diff --git a/src/PyEditor/PyEditor_SettingsDlg.h b/tools/PyEditor/src/PyEditor_SettingsDlg.h similarity index 65% rename from src/PyEditor/PyEditor_SettingsDlg.h rename to tools/PyEditor/src/PyEditor_SettingsDlg.h index 9c486c45a..9f3dfa986 100644 --- a/src/PyEditor/PyEditor_SettingsDlg.h +++ b/tools/PyEditor/src/PyEditor_SettingsDlg.h @@ -28,54 +28,52 @@ class PyEditor_Editor; class QCheckBox; +class QComboBox; +class QFontComboBox; class QLabel; -class QPushButton; class QSpinBox; -class QtxFontEdit; class PYEDITOR_EXPORT PyEditor_SettingsDlg : public QDialog { Q_OBJECT public: - PyEditor_SettingsDlg( PyEditor_Editor*, QWidget* = 0 ); - - bool isSetAsDefault(); + PyEditor_SettingsDlg( PyEditor_Editor*, bool = false, QWidget* = 0 ); + ~PyEditor_SettingsDlg(); private Q_SLOTS: - void onVerticalEdgeChecked( bool ); + void onVerticalEdgeChecked(); + void onFontChanged(); void onOk(); + void onDefault(); void onHelp(); Q_SIGNALS: - void onHelpClicked(); + void help(); private: void settingsToGui(); void settingsFromGui(); - void setSettings(); + void setFontSize( const QString& ); - QCheckBox* w_HighlightCurrentLine; - QCheckBox* w_TextWrapping; - QCheckBox* w_CenterCursorOnScroll; - QCheckBox* w_LineNumberArea; - - QCheckBox* w_TabSpaceVisible; - QSpinBox* w_TabSize; + QCheckBox* myHighlightCurrentLine; + QCheckBox* myTextWrapping; + QCheckBox* myCenterCursorOnScroll; + QCheckBox* myLineNumberArea; - QCheckBox* w_VerticalEdge; - QSpinBox* w_NumberColumns; - QLabel* lbl_NumColumns; + QCheckBox* myTabSpaceVisible; + QSpinBox* myTabSize; - QtxFontEdit* w_FontWidget; + QCheckBox* myVerticalEdge; + QSpinBox* myNumberColumns; + QLabel* myNumberColumnsLbl; - QCheckBox* w_DefaultCheck; + QFontComboBox* myFontFamily; + QComboBox* myFontSize; - QPushButton* myOkBtn; - QPushButton* myCancelBtn; - QPushButton* myHelpBtn; + QCheckBox* myDefaultCheck; - PyEditor_Editor* my_Editor; + PyEditor_Editor* myEditor; }; #endif // PYEDITOR_SETTINGSDLG_H diff --git a/tools/PyEditor/src/PyEditor_StdSettings.cxx b/tools/PyEditor/src/PyEditor_StdSettings.cxx new file mode 100644 index 000000000..816db3653 --- /dev/null +++ b/tools/PyEditor/src/PyEditor_StdSettings.cxx @@ -0,0 +1,92 @@ +// Copyright (C) 2015-2016 OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : PyEditor_StdSettings.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#include "PyEditor_StdSettings.h" + +PyEditor_StdSettings::PyEditor_StdSettings() : + myLanguage( "en" ) +{ + load(); +} + +PyEditor_StdSettings::PyEditor_StdSettings( const QString& group ) : + myGroup( group ), + myLanguage( "en" ) +{ + load(); +} + +PyEditor_StdSettings::PyEditor_StdSettings( const QString& group, + const QString& filename, + QSettings::Format format ) : + mySettings( filename, format ), + myGroup( group ), + myLanguage( "en" ) +{ + load(); +} + +void PyEditor_StdSettings::setLanguage( const QString& language ) +{ + myLanguage = language; +} + +QString PyEditor_StdSettings::language() const +{ + return myLanguage; +} + +void PyEditor_StdSettings::load() +{ + mySettings.beginGroup( myGroup.isEmpty() ? option( snEditor ) : myGroup ); + + setHighlightCurrentLine( mySettings.value( option( snHighlightCurrentLine ), highlightCurrentLine() ).toBool() ); + setTextWrapping( mySettings.value( option( snTextWrapping ), textWrapping() ).toBool() ); + setCenterCursorOnScroll( mySettings.value( option( snCenterCursorOnScroll ), centerCursorOnScroll() ).toBool() ); + setLineNumberArea( mySettings.value( option( snLineNumberArea ), lineNumberArea() ).toBool() ); + setVerticalEdge( mySettings.value( option( snVerticalEdge ), verticalEdge() ).toBool() ); + setNumberColumns( mySettings.value( option( snNumberColumns ), numberColumns() ).toInt() ); + setTabSpaceVisible( mySettings.value( option( snTabSpaceVisible ), tabSpaceVisible() ).toBool() ); + setTabSize( mySettings.value( option( snTabSize ), tabSize() ).toInt() ); + setFont( mySettings.value( option( snFont ), font() ).value() ); + setLanguage( mySettings.value( "language", language() ).toString() ); + + mySettings.endGroup(); +} + +void PyEditor_StdSettings::save() +{ + mySettings.beginGroup( myGroup.isEmpty() ? option( snEditor ) : myGroup ); + + mySettings.setValue( option( snHighlightCurrentLine ), highlightCurrentLine() ); + mySettings.setValue( option( snTextWrapping ), textWrapping() ); + mySettings.setValue( option( snCenterCursorOnScroll ), centerCursorOnScroll() ); + mySettings.setValue( option( snLineNumberArea ), lineNumberArea() ); + mySettings.setValue( option( snVerticalEdge ), verticalEdge() ); + mySettings.setValue( option( snNumberColumns ), numberColumns() ); + mySettings.setValue( option( snTabSpaceVisible ), tabSpaceVisible() ); + mySettings.setValue( option( snTabSize ), tabSize() ); + mySettings.setValue( option( snFont ), font() ); + mySettings.setValue( "language", language() ); + + mySettings.endGroup(); +} diff --git a/tools/PyEditor/src/PyEditor_StdSettings.h b/tools/PyEditor/src/PyEditor_StdSettings.h new file mode 100644 index 000000000..dc102fd96 --- /dev/null +++ b/tools/PyEditor/src/PyEditor_StdSettings.h @@ -0,0 +1,50 @@ +// Copyright (C) 2015-2016 OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : PyEditor_StdSettings.h +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#ifndef PYEDITOR_STDSETTINGS_H +#define PYEDITOR_STDSETTINGS_H + +#include "PyEditor.h" +#include "PyEditor_Settings.h" + +#include + +class PYEDITOR_EXPORT PyEditor_StdSettings : public PyEditor_Settings +{ +public: + PyEditor_StdSettings(); + PyEditor_StdSettings( const QString& ); + PyEditor_StdSettings( const QString&, const QString&, QSettings::Format = QSettings::IniFormat ); + + void setLanguage( const QString& ); + QString language() const; + + void load(); + void save(); + +private: + QSettings mySettings; + QString myGroup; + QString myLanguage; +}; + +#endif // PYEDITOR_STDSETTINGS_H diff --git a/tools/PyEditor/src/PyEditor_Window.cxx b/tools/PyEditor/src/PyEditor_Window.cxx new file mode 100644 index 000000000..74c0be042 --- /dev/null +++ b/tools/PyEditor/src/PyEditor_Window.cxx @@ -0,0 +1,467 @@ +// Copyright (C) 2015-2016 OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : PyEditor_Window.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#include "PyEditor_Window.h" +#include "PyEditor_Editor.h" +#include "PyEditor_Settings.h" +#include "PyEditor_SettingsDlg.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +/*! + \class PyEditor_Window + \brief Python view window. +*/ + +/*! + \brief Constructor. + \param parent parent widget +*/ +PyEditor_Window::PyEditor_Window( QWidget* parent ) : + QMainWindow( parent ) +{ + Q_INIT_RESOURCE( PyEditor ); + + // Create editor and set it as a central widget. + myTextEditor = new PyEditor_Editor( this ); + setCentralWidget( myTextEditor ); + + // Create actions. + QAction* action; + + // . New + action = new QAction( QIcon( ":/images/py_new.png" ), + tr( "ACT_NEW" ), this ); + action->setToolTip( tr( "TTP_NEW" ) ); + action->setStatusTip( tr( "DSC_NEW" ) ); + action->setShortcut( QKeySequence::New ); + connect( action, SIGNAL( triggered( bool ) ), this, SLOT( onNew() ) ); + myActions[ NewId ] = action; + + // . Open + action = new QAction( QIcon( ":/images/py_open.png" ), + tr( "ACT_OPEN" ), this ); + action->setToolTip( tr( "TTP_OPEN" ) ); + action->setStatusTip( tr( "DSC_OPEN" ) ); + action->setShortcut( QKeySequence::Open ); + connect( action, SIGNAL( triggered( bool ) ), this, SLOT( onOpen() ) ); + myActions[ OpenId ] = action; + + // . Save + action = new QAction( QIcon( ":/images/py_save.png" ), + tr( "ACT_SAVE" ), this ); + action->setToolTip( tr( "TTP_SAVE" ) ); + action->setStatusTip( tr( "DSC_SAVE" ) ); + action->setShortcut( QKeySequence::Save ); + connect( action, SIGNAL( triggered( bool ) ), this, SLOT( onSave() ) ); + action->setEnabled( false ); + connect( myTextEditor->document(), SIGNAL( modificationChanged( bool ) ), + action, SLOT( setEnabled( bool ) ) ); + myActions[ SaveId ] = action; + + // . SaveAs + action = new QAction( QIcon( ":/images/py_save_as.png" ), + tr( "ACT_SAVEAS" ), this ); + action->setToolTip( tr( "TTP_SAVEAS" ) ); + action->setStatusTip( tr( "DSC_SAVEAS" ) ); + action->setShortcut( QKeySequence::SaveAs ); + connect( action, SIGNAL( triggered( bool ) ), this, SLOT( onSaveAs() ) ); + myActions[ SaveAsId ] = action; + + // . Exit + action = new QAction( QIcon( ":/images/py_exit.png" ), + tr( "ACT_EXIT" ), this ); + action->setToolTip( tr( "TTP_EXIT" ) ); + action->setStatusTip( tr( "DSC_EXIT" ) ); + action->setShortcut( QKeySequence::Quit ); + connect( action, SIGNAL( triggered( bool ) ), this, SLOT( close() ) ); + myActions[ ExitId ] = action; + + // . Undo + action = new QAction( QIcon( ":/images/py_undo.png" ), + tr( "ACT_UNDO" ), this ); + action->setToolTip( tr( "TTP_UNDO" ) ); + action->setStatusTip( tr( "DSC_UNDO" ) ); + action->setShortcut( QKeySequence::Undo ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( undo() ) ); + action->setEnabled( false ); + connect( myTextEditor->document(), SIGNAL( undoAvailable( bool ) ), + action, SLOT( setEnabled( bool ) ) ); + myActions[ UndoId ] = action; + + // . Redo + action = new QAction( QIcon( ":/images/py_redo.png" ), + tr( "ACT_REDO" ), this ); + action->setToolTip( tr( "TTP_REDO" ) ); + action->setStatusTip( tr( "DSC_REDO" ) ); + action->setShortcut( QKeySequence::Redo ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( redo() ) ); + action->setEnabled( false ); + connect( myTextEditor->document(), SIGNAL( redoAvailable( bool ) ), + action, SLOT( setEnabled( bool ) ) ); + myActions[ RedoId ] = action; + + // . Cut + action = new QAction( QIcon( ":/images/py_cut.png" ), + tr( "ACT_CUT" ), this ); + action->setToolTip( tr( "TTP_CUT" ) ); + action->setStatusTip( tr( "DSC_CUT" ) ); + action->setShortcut( QKeySequence::Cut ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( cut() ) ); + action->setEnabled( false ); + connect( myTextEditor, SIGNAL( copyAvailable( bool ) ), + action, SLOT( setEnabled( bool ) ) ); + myActions[ CutId ] = action; + + // . Copy + action = new QAction( QIcon( ":/images/py_copy.png" ), + tr( "ACT_COPY" ), this ); + action->setToolTip( tr( "TTP_COPY" ) ); + action->setStatusTip( tr( "DSC_COPY" ) ); + action->setShortcut( QKeySequence::Copy ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( copy() ) ); + action->setEnabled( false ); + connect( myTextEditor, SIGNAL( copyAvailable( bool ) ), + action, SLOT( setEnabled( bool ) ) ); + myActions[ CopyId ] = action; + + // . Paste + action = new QAction( QIcon( ":/images/py_paste.png" ), + tr( "ACT_PASTE" ), this ); + action->setToolTip( tr( "TTP_PASTE" ) ); + action->setStatusTip( tr( "DSC_PASTE" ) ); + action->setShortcut( QKeySequence::Paste ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( paste() ) ); + myActions[ PasteId ] = action; + + // . Delete + action = new QAction( QIcon( ":/images/py_delete.png" ), + tr( "ACT_DELETE" ), this ); + action->setToolTip( tr( "TTP_DELETE" ) ); + action->setStatusTip( tr( "DSC_DELETE" ) ); + action->setShortcut( QKeySequence::Delete ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( deleteSelected() ) ); + action->setEnabled( false ); + connect( myTextEditor, SIGNAL( copyAvailable( bool ) ), + action, SLOT( setEnabled( bool ) ) ); + myActions[ DeleteId ] = action; + + // . SelectAll + action = new QAction( QIcon( ":/images/py_select_all.png" ), + tr( "ACT_SELECT_ALL" ), this ); + action->setToolTip( tr( "TTP_SELECT_ALL" ) ); + action->setStatusTip( tr( "DSC_SELECT_ALL" ) ); + action->setShortcut( QKeySequence::SelectAll ); + connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( selectAll() ) ); + myActions[ SelectAllId ] = action; + + // . Preferences + action = new QAction( QIcon( ":/images/py_preferences.png" ), + tr( "ACT_PREFERENCES" ), this ); + action->setToolTip( tr( "TTP_PREFERENCES" ) ); + action->setStatusTip( tr( "DSC_PREFERENCES" ) ); + connect( action, SIGNAL( triggered( bool ) ), this, SLOT( onPreferences() ) ); + myActions[ PreferencesId ] = action; + + // . Help + action = new QAction( QIcon( ":/images/py_help.png" ), + tr( "ACT_HELP" ), this ); + action->setToolTip( tr( "TTP_HELP" ) ); + action->setStatusTip( tr( "DSC_HELP" ) ); + connect( action, SIGNAL( triggered() ), this, SLOT( onHelp() ) ); + myActions[ HelpId ] = action; + + // Create menu. + QMenu* menu = menuBar()->addMenu( tr( "MNU_FILE" ) ); + menu->addAction( myActions[ NewId ] ); + menu->addAction( myActions[ OpenId ] ); + menu->addSeparator(); + menu->addAction( myActions[ SaveId ] ); + menu->addAction( myActions[ SaveAsId ] ); + menu->addSeparator(); + menu->addAction( myActions[ ExitId ] ); + + menu = menuBar()->addMenu( tr( "MNU_EDIT" ) ); + menu->addAction( myActions[ UndoId ] ); + menu->addAction( myActions[ RedoId ] ); + menu->addSeparator(); + menu->addAction( myActions[ CutId ] ); + menu->addAction( myActions[ CopyId ] ); + menu->addAction( myActions[ PasteId ] ); + menu->addAction( myActions[ DeleteId ] ); + menu->addSeparator(); + menu->addAction( myActions[ SelectAllId ] ); + menu->addSeparator(); + menu->addAction( myActions[ PreferencesId ] ); + + menu = menuBar()->addMenu( tr( "MNU_HELP" ) ); + menu->addAction( myActions[ HelpId ] ); + + // Create toolbar. + QToolBar* toolbar = addToolBar( tr( "TOOLBAR_LABEL" ) ); + toolbar->setObjectName("PythonEditor"); + toolbar->addAction( myActions[ NewId ] ); + toolbar->addAction( myActions[ OpenId ] ); + toolbar->addAction( myActions[ SaveId ] ); + toolbar->addAction( myActions[ SaveAsId ] ); + toolbar->addSeparator(); + toolbar->addAction( myActions[ ExitId ] ); + toolbar->addSeparator(); + toolbar->addAction( myActions[ UndoId ] ); + toolbar->addAction( myActions[ RedoId ] ); + toolbar->addSeparator(); + toolbar->addAction( myActions[ CutId ] ); + toolbar->addAction( myActions[ CopyId ] ); + toolbar->addAction( myActions[ PasteId ] ); + toolbar->addAction( myActions[ DeleteId ] ); + toolbar->addAction( myActions[ SelectAllId ] ); + toolbar->addSeparator(); + toolbar->addAction( myActions[ PreferencesId ] ); + toolbar->addSeparator(); + toolbar->addAction( myActions[ HelpId ] ); + + // Set current file. + setCurrentFile( QString() ); + + // Additional set-up for main window. + connect( myTextEditor->document(), SIGNAL( modificationChanged( bool ) ), + this, SLOT( setWindowModified( bool ) ) ); + + // Initialize status bar. + statusBar()->showMessage( tr( "STS_READY" ) ); +} + +/*! + \brief Destructor. +*/ +PyEditor_Window::~PyEditor_Window() +{ +} + +/*! + \brief Manage window close request. + \param event close event +*/ +void PyEditor_Window::closeEvent( QCloseEvent* event ) +{ + if ( whetherSave() ) + event->accept(); + else + event->ignore(); +} + +/*! + SLOT: Create new document +*/ +void PyEditor_Window::onNew() +{ + if ( whetherSave() ) + { + myTextEditor->clear(); + setCurrentFile( QString() ); + } +} + +/*! + SLOT: Open existing Python file +*/ +void PyEditor_Window::onOpen() +{ + if ( whetherSave() ) + { + QString filter = tr( "TIT_PY_FILES" ); + filter += " (*.py)"; + QString aFilePath = QFileDialog::getOpenFileName( this, + tr( "TIT_DLG_OPEN" ), + QDir::currentPath(), + filter ); + + if ( !aFilePath.isEmpty() ) + loadFile( aFilePath ); + } +} + +/*! + SLOT: Save current document +*/ +bool PyEditor_Window::onSave() +{ + if ( myURL.isEmpty() ) + return onSaveAs(); + else + return saveFile( myURL ); +} + + +/*! + SLOT: Save current document under a new name +*/ +bool PyEditor_Window::onSaveAs() +{ + QString filter = tr( "TIT_PY_FILES" ); + filter += " (*.py)"; + QString url = myURL.isEmpty() ? defaultName() : myURL; + QString aFilePath = QFileDialog::getSaveFileName( this, + tr( "TIT_DLG_SAVE" ), + url, + filter ); + + if ( !aFilePath.isEmpty() ) + return saveFile( aFilePath ); + + return false; +} + +/*! + SLOT: Open preferences dialog +*/ +void PyEditor_Window::onPreferences() +{ + PyEditor_SettingsDlg dlg( myTextEditor, true, this ); + connect( &dlg, SIGNAL( help() ), this, SLOT( onHelp() ) ); + dlg.exec(); +} + +/*! + \brief Associate \a filePath with the current document + \param filePath document's file path +*/ +void PyEditor_Window::setCurrentFile( const QString& filePath ) +{ + myURL = filePath; + myTextEditor->document()->setModified( false ); + + setWindowModified( false ); + + setWindowFilePath( myURL.isEmpty() ? defaultName() : myURL ); +} + +/*! + \brief Check whether the file is modified. + If it has the modifications then ask the user to save it. + \return true if the document is saved. +*/ +bool PyEditor_Window::whetherSave() +{ + if ( myTextEditor->document()->isModified() ) + { + QMessageBox::StandardButton answer = QMessageBox::warning( this, + tr( "NAME_PYEDITOR" ), + tr( "WRN_SAVE_FILE" ), + QMessageBox::Save | + QMessageBox::Discard | + QMessageBox::Cancel ); + switch( answer ) + { + case QMessageBox::Save: + return onSave(); + case QMessageBox::Cancel: + return false; + default: + break; + } + } + return true; +} + +/*! + \brief Open file. + \param filePath file path +*/ +void PyEditor_Window::loadFile( const QString& filePath ) +{ + QFile aFile( filePath ); + if ( !aFile.open(QFile::ReadOnly | QFile::Text) ) + { + QMessageBox::warning( this, tr( "NAME_PYEDITOR" ), + tr( "WRN_READ_FILE" ).arg( filePath ).arg( aFile.errorString() ) ); + return; + } + + QTextStream anInput( &aFile ); + QApplication::setOverrideCursor( Qt::WaitCursor ); + myTextEditor->setPlainText( anInput.readAll() ); + QApplication::restoreOverrideCursor(); + + setCurrentFile( filePath ); + aFile.close(); + + statusBar()->showMessage( tr( "STS_F_LOADED" ), 2000 ); +} + +/*! + \brief Save file. + \param filePath file path +*/ +bool PyEditor_Window::saveFile( const QString& filePath ) +{ + QFile aFile( filePath ); + if ( !aFile.open( QFile::WriteOnly | QFile::Text ) ) + { + QMessageBox::warning( this, tr( "NAME_PYEDITOR" ), + tr( "WRN_WRITE_FILE" ).arg( filePath ).arg( aFile.errorString() ) ); + return false; + } + + QTextStream anOutput( &aFile ); + QApplication::setOverrideCursor( Qt::WaitCursor ); + anOutput << myTextEditor->toPlainText(); + QApplication::restoreOverrideCursor(); + + setCurrentFile( filePath ); + aFile.close(); + + statusBar()->showMessage( tr( "STS_F_SAVED" ), 2000 ); + + return true; +} + +/*! + Slot, called when user clicks "Help" button in "Preferences" dialog box. +*/ +void PyEditor_Window::onHelp() +{ + QWidget* w = qobject_cast( sender() ); + if ( !w ) w = this; + QFile file(":/about.txt"); + file.open(QFile::ReadOnly | QFile::Text); + QTextStream stream( &file ); + QString about = stream.readAll(); + file.close(); + QMessageBox::about( w, tr( "NAME_PYEDITOR" ), about ); +} + +/*! + Get default name for Python file + \return default name +*/ +QString PyEditor_Window::defaultName() const +{ + return tr( "NONAME" ); +} diff --git a/tools/PyEditor/src/PyEditor_Window.h b/tools/PyEditor/src/PyEditor_Window.h new file mode 100644 index 000000000..209739e77 --- /dev/null +++ b/tools/PyEditor/src/PyEditor_Window.h @@ -0,0 +1,71 @@ +// Copyright (C) 2015-2016 OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : PyEditor_Window.h +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#ifndef PYEDITOR_WINDOW_H +#define PYEDITOR_WINDOW_H + +#include "PyEditor.h" + +#include +#include + +class QAction; +class PyEditor_Editor; + +class PYEDITOR_EXPORT PyEditor_Window : public QMainWindow +{ + Q_OBJECT + +public: + enum { NewId, OpenId, SaveId, SaveAsId, ExitId, + UndoId, RedoId, CutId, CopyId, PasteId, DeleteId, SelectAllId, + PreferencesId, HelpId }; + + PyEditor_Window( QWidget* = 0 ); + ~PyEditor_Window(); + +protected: + virtual void closeEvent( QCloseEvent* ); + +private Q_SLOTS: + void onNew(); + void onOpen(); + bool onSave(); + bool onSaveAs(); + void onPreferences(); + void onHelp(); + +private: + void loadFile( const QString& ); + bool saveFile( const QString& ); + + void setCurrentFile( const QString& ); + bool whetherSave(); + QString defaultName() const; + +private: + PyEditor_Editor* myTextEditor; + QString myURL; + QMap myActions; +}; + +#endif // PYEDITOR_WINDOW_H diff --git a/tools/PyEditor/src/python/CMakeLists.txt b/tools/PyEditor/src/python/CMakeLists.txt new file mode 100644 index 000000000..fcde6e16a --- /dev/null +++ b/tools/PyEditor/src/python/CMakeLists.txt @@ -0,0 +1,62 @@ +# Copyright (C) 2015-2016 OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +# + +INCLUDE(UseQtExt) +INCLUDE(UsePyQt) + +# --- options --- + +# additional include directories +INCLUDE_DIRECTORIES( + $(QT_INCLUDES) + ${PYTHON_INCLUDE_DIRS} + ${SIP_INCLUDE_DIR} + ${PROJECT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/.. +) + +# additional preprocessor / compiler flags +ADD_DEFINITIONS(${QT_DEFINITIONS}) + +# libraries to link to +SET(_link_LIBRARIES ${QT_LIBRARIES} ${PYTHON_LIBRARIES} PyEditor) + +# --- sources --- + +# sip files / to be processed by sip +SET(_sip_files PyEditorPy.sip) + +# sources / sip wrappings +PYQT_WRAP_SIP(_sip_SOURCES ${_sip_files}) + +# sources / to compile +SET(PyEditorPy_SOURCES ${_sip_SOURCES}) + +# --- rules --- + +ADD_LIBRARY(PyEditorPy ${PyEditorPy_SOURCES}) +IF(WIN32) + SET_TARGET_PROPERTIES(PyEditorPy PROPERTIES SUFFIX ".pyd" DEBUG_OUTPUT_NAME PyEditorPy_d RELEASE_OUTPUT_NAME PyEditorPy) +ELSE() + SET_TARGET_PROPERTIES(PyEditorPy PROPERTIES PREFIX "") +ENDIF() +TARGET_LINK_LIBRARIES(PyEditorPy ${_link_LIBRARIES}) +INSTALL(TARGETS PyEditorPy EXPORT ${TOOLS_EXPORT_NAME}TargetGroup DESTINATION ${PYEDITOR_INSTALL_LIBS}) diff --git a/tools/PyEditor/src/python/PyEditorPy.sip b/tools/PyEditor/src/python/PyEditorPy.sip new file mode 100644 index 000000000..372cc2898 --- /dev/null +++ b/tools/PyEditor/src/python/PyEditorPy.sip @@ -0,0 +1,98 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : SalomePyQt.sip +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +%Module PyEditorPy + +%Import QtCore/QtCoremod.sip +%Import QtGui/QtGuimod.sip +%If (Qt_5_0_0 -) +%Import QtWidgets/QtWidgetsmod.sip +%End + +class PyEditor_Settings +{ +%TypeHeaderCode +#include +%End + +public: + PyEditor_Settings(); + + void setHighlightCurrentLine( bool ); + bool highlightCurrentLine() const; + + void setTextWrapping( bool ); + bool textWrapping() const; + + void setCenterCursorOnScroll( bool ); + bool centerCursorOnScroll() const; + + void setLineNumberArea( bool ); + bool lineNumberArea() const; + + void setVerticalEdge( bool ); + bool verticalEdge() const; + + void setNumberColumns( int ); + int numberColumns() const; + + void setTabSpaceVisible( bool ); + bool tabSpaceVisible() const; + + void setTabSize( int ); + int tabSize() const; + + void setFont( const QFont& ); + QFont font() const; +}; + +class PyEditor_Editor : QPlainTextEdit +{ +%TypeHeaderCode +#include +%End + +public: + explicit PyEditor_Editor( QWidget* /TransferThis/ = 0 ); + virtual ~PyEditor_Editor(); + + void setSettings( const PyEditor_Settings& ); + const PyEditor_Settings& settings() const; + QString text() const; + +public slots: + void deleteSelected(); + void append( const QString& ); + void setText( const QString& text ); + +protected: + virtual void keyPressEvent( QKeyEvent* ); + virtual void resizeEvent( QResizeEvent* ); + virtual void paintEvent( QPaintEvent* ); + +private: + PyEditor_Editor( const PyEditor_Editor& ); + PyEditor_Editor& operator=( const PyEditor_Editor& ); +}; diff --git a/src/PyViewer/resources/PyEditor.qrc b/tools/PyEditor/src/resources/PyEditor.qrc similarity index 79% rename from src/PyViewer/resources/PyEditor.qrc rename to tools/PyEditor/src/resources/PyEditor.qrc index 2f703f92c..7df3d3208 100644 --- a/src/PyViewer/resources/PyEditor.qrc +++ b/tools/PyEditor/src/resources/PyEditor.qrc @@ -1,10 +1,11 @@ - images/py_browser.png - images/py_close.png images/py_copy.png images/py_cut.png images/py_delete.png + images/py_editor.png + images/py_exit.png + images/py_help.png images/py_new.png images/py_open.png images/py_paste.png @@ -14,5 +15,6 @@ images/py_save_as.png images/py_select_all.png images/py_undo.png + about.txt diff --git a/tools/PyEditor/src/resources/about.txt b/tools/PyEditor/src/resources/about.txt new file mode 100644 index 000000000..8fe8dc6d9 --- /dev/null +++ b/tools/PyEditor/src/resources/about.txt @@ -0,0 +1,36 @@ +Python Editor +
+ +Python Editor is a simple program for writing Python scripts. +Program provides standard editing operations like copy/cut/paste, undo/redo, select all, delete, etc. +Also it supports syntax highlighting and auto-indentation of Python code. + +Most often used editing operations are available via the toolbar: +
    +
  • New: creates new document.
  • +
  • Open: opens existing Python script for editing.
  • +
  • Save: saves current document to a file.
  • +
  • Save As: allows saving current document with a new name.
  • +
  • Exit: quits application.
  • +
  • Undo: undoes the last operation.
  • +
  • Redo: redoes the previously undone operation.
  • +
  • Cut: cuts selected text into the clipboard.
  • +
  • Copy: copies selected text into the clipboard.
  • +
  • Paste: pastes text from the clipboard into the current cursor position.
  • +
  • Delete: removes selected text.
  • +
  • Select All: selects the whole text in the editor.
  • +
  • Preferences: opens Preferences dialog that allows specifying advanced parameters for the program.
  • +
  • Help: shows this help information.
  • +
+ +The behavior of the editor can be customized via the Preferences dialog. The following options can be customized: +
    +
  • Font settings: choose the font.
  • +
  • Enable current line highlight: switches on background coloring of the line under the cursor.
  • +
  • Enable text wrapping: allows wrapping text at the border of the editor's window.
  • +
  • Center cursor on scroll: allows scrolling the script vertically to make the cursor visible at the center of the viewer.
  • +
  • Display line numbers area: shows line numbers at the left border of the editor.
  • +
  • Vertical edge settings: draws vertical line at the specified column of the viewer.
  • +
  • Display tab white spaces: displays tab indentations at a given number of white spaces.
  • +
  • Save settings as default: saves chosen options as a default ones. These settings will be restored after application restart.
  • +
diff --git a/src/PyViewer/resources/images/py_copy.png b/tools/PyEditor/src/resources/images/py_copy.png similarity index 100% rename from src/PyViewer/resources/images/py_copy.png rename to tools/PyEditor/src/resources/images/py_copy.png diff --git a/src/PyViewer/resources/images/py_cut.png b/tools/PyEditor/src/resources/images/py_cut.png similarity index 100% rename from src/PyViewer/resources/images/py_cut.png rename to tools/PyEditor/src/resources/images/py_cut.png diff --git a/src/PyViewer/resources/images/py_delete.png b/tools/PyEditor/src/resources/images/py_delete.png similarity index 100% rename from src/PyViewer/resources/images/py_delete.png rename to tools/PyEditor/src/resources/images/py_delete.png diff --git a/tools/PyEditor/src/resources/images/py_editor.png b/tools/PyEditor/src/resources/images/py_editor.png new file mode 100644 index 0000000000000000000000000000000000000000..183e1390d6d08fb69600c515d2e68b3fe304d840 GIT binary patch literal 4164 zcmcIn2~<;O7Je~6PB+b9~Jpo9@Y1Ok;MK?qtf(FLaN7qgF8$aI z*RtT1<^cbAdlAekCQ_K1j z=)9NR4gMSJo~(P2*|qGL7td9rI&|*^gbnul4Ne#JLSr5~Zg=S4qK`Hxxb!*8dSQRO z$7M~27GSbCYiyLT!Y8C0nNXt5b3!q;z@oDAlH_;!@MI1vTSrIzd3BHnf}2WSj$%P#ntm zhmQ!2zV4r`7xg>X7kNo~u;iY{Kzc$fXzy;l$v`@(sKPddZ9-}a?qO@BGlR5OrV71B zkGxwa+B*Y|VUU|oFgP;|vZz0{Bo`TdCR6s3tuU9)5E!kEs)M>lIYgVOUi{2+a8A#r zW-$P)>8SzC?`2?x(y?3jXJ#~&`Z&~}OPPnHm%fYLsHQZST?e?u1Y3_J;iJyp@sD)0 zgEsYE1I+K1j&<~2o=ZB-xUy$OGyn2x5un*KawR)(ez>DiRe7$hF+d9#9Xd>4xbO=K zkZd$-5|3c3mg`DS>|707?p7qD^)gJB0ivk;qKRQP$V9Yc;o6Tybgm=xgkWJ9!{+%c%7_mttWIK;N#_Ij^3+KGuXDfI!B6|q z@vytR0ZZC^9?IL!a;4itJVUcs9BS9fncl3vNPU*Tu7<2f0<4Ce-1@^*vV>rARrT_n zgK?Ng{998+cg>A2`;9kQ%8Lo=G}45pBs&+0oC#Q?D{XxJ(r00jl9Id``nkp2_^Hsz z5Tc625(?-+<#?N^0?vD!Nga~8#2c80iL0PnE#}N(RKvIfkxFki26Uy7y~kCYG9z9z z)BV?rHu!O7R1d;c<`z268Gi9*x$_HR!?>X4y6OJs7Dh`2=&J`kI{}t9puP*1Z$@M7 ze^ctJ;@+1e0FG#&BkE0MVm4mJvBJJ1Y9ioU1ek0jEN|^si2zvM>+qI*Mq`dW0i=mJ zm~cv|hpF$7nSoMN5`O>C5ziF#v*EGWaju;ilI3NTa>I=$={n1hmY(h^_O$T$SajpE z$K=0k`2K)5KEKi5pZNhF-kQ9^1*?dO)PTZMHT|@s&g&z-d`?-b=y2OU1=58K&!vaes zzF+-sobX`+ct;3Khs(HS;P6?yhB$9$kAixBQ_@{hzwLlyT_T9u{9Ss5MJO%oFXMa* zlpC*Mx&&!8Pex5C3X|?)LrySw0sxx z71us6#;bQKnDYdA_qyD34SU2t_7CvmyYT#eN`*~!bXIHk@py1u@;zef>ICk-{%c*7 z-HlE&Lxs_%`cPiVqNsd1=FS&{jHn>AZ`mGMWT5Osux|Y65p&)a(WMUWimj|)qoLmz z`oHtwEll3^0YMI7=a`jLQ$Ha~t?PBypBxty*!5<lY8Ug1`Z$f9b*YHyR`kLC&d{qHc@kY=)G6~Uq>y5HW+?*;4B!d;E1 z9^8PVf&)kDZ_d`jaJ%)`Sf${Y+&?p8q^^*I)R^(r$79rU`aYZ*zcoT{p#RS?`FGib z0!D-HsT|yx`a!c!vKZmojq{9|Q(V|JZ6MwAPs;sZCq@?z0 z+R1HI+8c385xVx|f9hv$=8{vckmJ@HojbM4UQWY^8qcb)PfMVjE%hnfs;W}pw@ z<2>PpDcE;MPJeNhAXo)v^`;9U-{1hG!tM3c+LJ%ShM0z$Y)M#f^hIrCQh8zFaMs$@ zB6^`*=wY2>dg@2#%%T#qmE0Zt?rO(5xOX?Cf_(w*wU*EvmD6qt-7X2FZquZ+zlvQ8 zp|a+`0CRHBus5}2W|fJa(gpd$65@lSS>a{_jh|ELf-e8pJ$22_CGAZ^;QaBhfxA^W z=n8>RdIvpL22U29Ii6hGDpI@}zGb zTG4R3=N#@fz+#ZWZyS~~*@?cKgv2nC2Z||wnm5eA%QkHU>co%AQ(KSXQA~?%C5iY7 z?&SX1Ot`o7nQ)iLSb|8q79$>F`nkg)>Yi01v4cnICy>#^VIX60!EbzEc8qy7c|M5# z3B*V?WZt=19EIxaWq126S`xTq#EzDuUvdUkN+ad_L9#dixTn2VKICBGTag|}rLTj& z5|e;?)fod?mLl{y1qmxROEwOgo+L=z=zDICrR_e`y|%VJP|dh3)iXAsNO1MUk8s$G zqq=Rb??GL=YGN_4g3X_U-x&J4U9eN~%JMP=1DbDiWZ@u9WA0W7R?JM6K#QH0#d%n#8 literal 0 HcmV?d00001 diff --git a/src/PyViewer/resources/images/py_close.png b/tools/PyEditor/src/resources/images/py_exit.png similarity index 100% rename from src/PyViewer/resources/images/py_close.png rename to tools/PyEditor/src/resources/images/py_exit.png diff --git a/src/PyViewer/resources/images/py_browser.png b/tools/PyEditor/src/resources/images/py_help.png similarity index 100% rename from src/PyViewer/resources/images/py_browser.png rename to tools/PyEditor/src/resources/images/py_help.png diff --git a/src/PyViewer/resources/images/py_new.png b/tools/PyEditor/src/resources/images/py_new.png similarity index 100% rename from src/PyViewer/resources/images/py_new.png rename to tools/PyEditor/src/resources/images/py_new.png diff --git a/src/PyViewer/resources/images/py_open.png b/tools/PyEditor/src/resources/images/py_open.png similarity index 100% rename from src/PyViewer/resources/images/py_open.png rename to tools/PyEditor/src/resources/images/py_open.png diff --git a/src/PyViewer/resources/images/py_paste.png b/tools/PyEditor/src/resources/images/py_paste.png similarity index 100% rename from src/PyViewer/resources/images/py_paste.png rename to tools/PyEditor/src/resources/images/py_paste.png diff --git a/src/PyViewer/resources/images/py_preferences.png b/tools/PyEditor/src/resources/images/py_preferences.png similarity index 100% rename from src/PyViewer/resources/images/py_preferences.png rename to tools/PyEditor/src/resources/images/py_preferences.png diff --git a/src/PyViewer/resources/images/py_redo.png b/tools/PyEditor/src/resources/images/py_redo.png similarity index 100% rename from src/PyViewer/resources/images/py_redo.png rename to tools/PyEditor/src/resources/images/py_redo.png diff --git a/src/PyViewer/resources/images/py_save.png b/tools/PyEditor/src/resources/images/py_save.png similarity index 100% rename from src/PyViewer/resources/images/py_save.png rename to tools/PyEditor/src/resources/images/py_save.png diff --git a/src/PyViewer/resources/images/py_save_as.png b/tools/PyEditor/src/resources/images/py_save_as.png similarity index 100% rename from src/PyViewer/resources/images/py_save_as.png rename to tools/PyEditor/src/resources/images/py_save_as.png diff --git a/src/PyViewer/resources/images/py_select_all.png b/tools/PyEditor/src/resources/images/py_select_all.png similarity index 100% rename from src/PyViewer/resources/images/py_select_all.png rename to tools/PyEditor/src/resources/images/py_select_all.png diff --git a/src/PyViewer/resources/images/py_undo.png b/tools/PyEditor/src/resources/images/py_undo.png similarity index 100% rename from src/PyViewer/resources/images/py_undo.png rename to tools/PyEditor/src/resources/images/py_undo.png diff --git a/tools/PyEditor/src/resources/translations/PyEditor_msg_en.ts b/tools/PyEditor/src/resources/translations/PyEditor_msg_en.ts new file mode 100644 index 000000000..ed2e32172 --- /dev/null +++ b/tools/PyEditor/src/resources/translations/PyEditor_msg_en.ts @@ -0,0 +1,310 @@ + + + + + PyEditor_SettingsDlg + + TIT_PREFERENCES + Preferences + + + GR_FONT_SET + Font settings + + + GR_DISP_SET + Display settings + + + LBL_CURRLINE_HIGHLIGHT + Enable current line highlight + + + LBL_TEXT_WRAP + Enable text wrapping + + + LBL_CURSOR_SCROLL + Center cursor on scroll + + + LBL_LINE_NUMBS_AREA + Display line numbers area + + + GR_TAB_SET + Tab settings + + + LBL_TAB_SPACES + Display tab white spaces + + + LBL_TAB_SIZE + Tab size: + + + GR_VERT_EDGE_SET + Vertical edge settings + + + LBL_VERT_EDGE + Display vertical edge + + + LBL_NUM_COLUMNS + Number of columns: + + + WDG_SET_AS_DEFAULT_CHECK + Save settings as default + + + BUT_OK + &OK + + + BUT_DEFAULTS + &Defaults + + + BUT_CANCEL + &Cancel + + + BUT_HELP + &Help + + + + PyEditor_Window + + NAME_PYEDITOR + Python Editor + + + ACT_NEW + &New + + + TTP_NEW + New + + + DSC_NEW + Create new document + + + ACT_OPEN + &Open... + + + TTP_OPEN + Open + + + DSC_OPEN + Open an existing document + + + ACT_SAVE + &Save + + + TTP_SAVE + Save + + + DSC_SAVE + Save the document to a file + + + ACT_SAVEAS + Save &As... + + + TTP_SAVEAS + Save As + + + DSC_SAVEAS + Save the document to a file with the new name + + + ACT_EXIT + E&xit + + + TTP_EXIT + Exit + + + DSC_EXIT + Exit application + + + ACT_UNDO + &Undo + + + TTP_UNDO + Undo + + + DSC_UNDO + Undo last operation + + + ACT_REDO + &Redo + + + TTP_REDO + Redo + + + DSC_REDO + Redo last undone operation + + + ACT_CUT + Cu&t + + + TTP_CUT + Cut + + + DSC_CUT + Cut the current selection's contents to the clipboard + + + ACT_COPY + &Copy + + + TTP_COPY + Copy + + + DSC_COPY + Copy the current selection's contents to the clipboard + + + ACT_PASTE + &Paste + + + TTP_PASTE + Paste + + + DSC_PASTE + Paste the clipboard's contents into the current selection + + + ACT_DELETE + &Delete + + + TTP_DELETE + Delete + + + DSC_DELETE + Delete the current selection's contents + + + ACT_SELECT_ALL + Select &All + + + TTP_SELECT_ALL + Select All + + + DSC_SELECT_ALL + Select all the contents + + + ACT_PREFERENCES + Pre&ferences + + + TTP_PREFERENCES + Preferences + + + DSC_PREFERENCES + Show the Preferences dialog + + + ACT_HELP + &Help + + + TTP_HELP + Help + + + DSC_HELP + Show the help on the Python Editor + + + MNU_FILE + &File + + + MNU_EDIT + &Edit + + + MNU_HELP + &Help + + + TOOLBAR_LABEL + Edit Operations + + + TIT_PY_FILES + Python files + + + TIT_DLG_OPEN + Open file + + + TIT_DLG_SAVE + Save file + + + WRN_SAVE_FILE + The document has been modified.<br>Do you want to save changes? + + + WRN_READ_FILE + Cannot read file %1:\n%2. + + + WRN_WRITE_FILE + Cannot write file %1:\n%2. + + + STS_READY + Ready + + + STS_F_LOADED + Document is loaded + + + STS_F_SAVED + Document is saved + + + NONAME + Noname.py + + + diff --git a/tools/PyEditor/src/resources/translations/PyEditor_msg_fr.ts b/tools/PyEditor/src/resources/translations/PyEditor_msg_fr.ts new file mode 100644 index 000000000..96cd1e001 --- /dev/null +++ b/tools/PyEditor/src/resources/translations/PyEditor_msg_fr.ts @@ -0,0 +1,310 @@ + + + + + PyEditor_SettingsDlg + + TIT_PREFERENCES + Préférences + + + GR_FONT_SET + Paramètres de la fonte + + + GR_DISP_SET + Paramètres d'affichage + + + LBL_CURRLINE_HIGHLIGHT + Met en surbrillance de la ligne actuelle + + + LBL_TEXT_WRAP + Retour à la ligne dynamique + + + LBL_CURSOR_SCROLL + Centre le curseur lors du scroll + + + LBL_LINE_NUMBS_AREA + Affiche les numéros de ligne + + + GR_TAB_SET + Indentation + + + LBL_TAB_SPACES + Affiche les guides d'indentation + + + LBL_TAB_SIZE + Largeur d'intentation: + + + GR_VERT_EDGE_SET + Marqueur de retour à la ligne + + + LBL_VERT_EDGE + Afficher la ligne verticale + + + LBL_NUM_COLUMNS + Nombre de colonnes: + + + WDG_SET_AS_DEFAULT_CHECK + Sauver en tant que paramètres par défaut + + + BUT_OK + &OK + + + BUT_DEFAULTS + Défauts + + + BUT_CANCEL + &Annuler + + + BUT_HELP + A&ide + + + + PyEditor_Window + + NAME_PYEDITOR + Editeur python + + + ACT_NEW + Nouveau + + + TTP_NEW + Nouveau + + + DSC_NEW + Crée un nouveau fichier python + + + ACT_OPEN + Ouvrir + + + TTP_OPEN + Ouvrir + + + DSC_OPEN + Ouvre un fichier python existant + + + ACT_SAVE + Enregistrer + + + TTP_SAVE + Enregistrer + + + DSC_SAVE + Enregistre le fichier python sur le système de fichiers + + + ACT_SAVEAS + Enregistrer sous... + + + TTP_SAVEAS + Enregistrer sous... + + + DSC_SAVEAS + >Enregistre le fichier python sous un nouveau nom + + + ACT_EXIT + Fermer + + + TTP_EXIT + Fermer + + + DSC_EXIT + Ferme le fichier python + + + ACT_UNDO + Annuler + + + TTP_UNDO + Annuler + + + DSC_UNDO + Annule la dernière opération + + + ACT_REDO + Refaire + + + TTP_REDO + Refaire + + + DSC_REDO + Répète la dernière opération + + + ACT_CUT + Coupe + + + TTP_CUT + Coupe + + + DSC_CUT + Coupe le contenu de la sélection vers le presse-papier + + + ACT_COPY + Copier + + + TTP_COPY + Copier + + + DSC_COPY + Copie le contenu de la sélection vers le presse-papier + + + ACT_PASTE + Coller + + + TTP_PASTE + Coller + + + DSC_PASTE + Colle le contenu de la sélection vers le presse-papier + + + ACT_DELETE + Supprime + + + TTP_DELETE + Supprime + + + DSC_DELETE + Supprime le contenu de la sélection + + + ACT_SELECT_ALL + Sélectionner tout + + + TTP_SELECT_ALL + Sélectionner tout + + + DSC_SELECT_ALL + Sélectionne tout le contenu + + + ACT_PREFERENCES + Préférences + + + TTP_PREFERENCES + Préférences + + + DSC_PREFERENCES + Affiche la boîte de dialogue des préférences + + + ACT_HELP + Aide + + + TTP_HELP + Aide + + + DSC_HELP + Afficher l'aide + + + MNU_FILE + Fic&hier + + + MNU_EDIT + &Edition + + + MNU_HELP + A&ide + + + TOOLBAR_LABEL + Opérations d'édition + + + TIT_PY_FILES + Fichiers Python + + + TIT_DLG_OPEN + Ouvrir le fichier + + + TIT_DLG_SAVE + Enregistrer le fichier + + + WRN_SAVE_FILE + Le document a été modifié.<br>Voulez-vous sauvegarder vos changements? + + + WRN_READ_FILE + Impossible de lire le fichier %1:\n%2. + + + WRN_WRITE_FILE + Impossible d'écrire le fichier %1:\n%2. + + + STS_READY + Prêt + + + STS_F_LOADED + Le fichier est chargé + + + STS_F_SAVED + Le fichier est sauvé + + + NONAME + Noname.py + + + diff --git a/tools/PyEditor/src/resources/translations/PyEditor_msg_ja.ts b/tools/PyEditor/src/resources/translations/PyEditor_msg_ja.ts new file mode 100644 index 000000000..6851ed722 --- /dev/null +++ b/tools/PyEditor/src/resources/translations/PyEditor_msg_ja.ts @@ -0,0 +1,310 @@ + + + + + PyEditor_SettingsDlg + + TIT_PREFERENCES + 環境設定 + + + GR_FONT_SET + フォント設定 + + + GR_DISP_SET + 表示設定 + + + LBL_CURRLINE_HIGHLIGHT + カレントラインのハイライト有効 + + + LBL_TEXT_WRAP + テキストラッピングの有効 + + + LBL_CURSOR_SCROLL + スクロール上の中心カーソル + + + LBL_LINE_NUMBS_AREA + ライン番号エリアの表示 + + + GR_TAB_SET + タブ設定 + + + LBL_TAB_SPACES + タブ空白の表示 + + + LBL_TAB_SIZE + Tab size: + + + GR_VERT_EDGE_SET + 垂直エッジ設定 + + + LBL_VERT_EDGE + 垂直エッジの表示 + + + LBL_NUM_COLUMNS + 列数: + + + WDG_SET_AS_DEFAULT_CHECK + デフォルトとして設定を保存 + + + BUT_OK + &OK + + + BUT_DEFAULTS + デフォルト(&D) + + + BUT_CANCEL + キャンセル(&C) + + + BUT_HELP + ヘルプ(&H) + + + + PyEditor_Window + + NAME_PYEDITOR + Python Editor + + + ACT_NEW + 新規 + + + TTP_NEW + 新規 + + + DSC_NEW + 新規 python ファイルの作成 + + + ACT_OPEN + 開く + + + TTP_OPEN + 開く + + + DSC_OPEN + 存在する python ファイルを開く + + + ACT_SAVE + 保存 + + + TTP_SAVE + 保存 + + + DSC_SAVE + python ドキュメントをディスクに保存 + + + ACT_SAVEAS + 別名保存 + + + TTP_SAVEAS + 別名保存 + + + DSC_SAVEAS + 新しい名前で python ドキュメントを保存 + + + ACT_EXIT + 終 + + + TTP_EXIT + 終 + + + DSC_EXIT + アプリケーションを終了 + + + ACT_UNDO + 元に戻す + + + TTP_UNDO + 元に戻す + + + DSC_UNDO + 最後の操作を元に戻す + + + ACT_REDO + やり直し + + + TTP_REDO + やり直し + + + DSC_REDO + 最後の操作をやり直す + + + ACT_CUT + カット + + + TTP_CUT + カット + + + DSC_CUT + 現在選択中の内容をクリップボードにカット + + + ACT_COPY + コピー + + + TTP_COPY + コピー + + + DSC_COPY + 現在選択中の内容をクリップボードにコピー + + + ACT_PASTE + ペースト + + + TTP_PASTE + ペースト + + + DSC_PASTE + クリップボードの内容を現在の選択にペースト + + + ACT_DELETE + 削除 + + + TTP_DELETE + 削除 + + + DSC_DELETE + 現在選択中の内容を削除 + + + ACT_SELECT_ALL + すべて選択 + + + TTP_SELECT_ALL + すべて選択 + + + DSC_SELECT_ALL + すべての内容を選択 + + + ACT_PREFERENCES + 環境設定 + + + TTP_PREFERENCES + 環境設定 + + + DSC_PREFERENCES + 環境設定ボックスの表示 + + + ACT_HELP + ヘルプ + + + TTP_HELP + ヘルプ + + + DSC_HELP + ヘルプ + + + MNU_FILE + ファイル(&F) + + + MNU_EDIT + 編集(&E) + + + MNU_HELP + ヘルプ(&H) + + + TOOLBAR_LABEL + 操作の編集 + + + TIT_PY_FILES + ã..ã.¡ã.¤ã.« Python + + + TIT_DLG_OPEN + ファイルを開く + + + TIT_DLG_SAVE + ファイルを保存 + + + WRN_SAVE_FILE + ドキュメントは修正済みです。<br>変更を保存しますか? + + + WRN_READ_FILE + Cannot read file %1:\n%2. + + + WRN_WRITE_FILE + Cannot write file %1:\n%2. + + + STS_READY + 準備 + + + STS_F_LOADED + ファイルは読み込まれました + + + STS_F_SAVED + ファイルは保存されました + + + NONAME + Noname.py + + + -- 2.39.2