Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Public Slots | Signals | Public Member Functions | Public Attributes | Protected Slots | Protected Member Functions | Protected Attributes
PythonConsole Class Reference

This is simple "IDE"/python console for interactive commands execution. More...

#include <pconsole.h>

List of all members.

Public Slots

virtual void slot_runScript ()
 menu operations
virtual void slot_runScriptAsConsole ()
virtual void slot_open ()
virtual void slot_save ()
virtual void slot_saveAs ()
virtual void slot_saveOutput ()
virtual void slot_quit ()
virtual void commandEdit_cursorPositionChanged (int para, int pos)
 Slot processed after user change cursor postion in "programmer's editor".

Signals

void paletteShown (bool)
 Menu indication trigger.
void runCommand ()
 Scripter Core launcher.

Public Member Functions

 PythonConsole (QWidget *parent=0)
 ~PythonConsole ()
void setFonts ()
QString command ()
 The command string.
void closeEvent (QCloseEvent *)
 Close event for turning the action off.

Public Attributes

QString filename
 File name for saving the contents.
QTextEdit * commandEdit
 Programmer's editor ;)
QTextEdit * outputEdit
 Results viewer.

Protected Slots

virtual void languageChange ()

Protected Member Functions

void parsePythonString ()
 prepare Python "script" from GUI widget

Protected Attributes

QGridLayout * gridLayout
QVBoxLayout * editorsLayout
QMenuBar * menuBar
QStatusBar * statusBar
QString m_command
 String with the script to run (part of the all text)

Detailed Description

This is simple "IDE"/python console for interactive commands execution.

It's used e.g. like Tora (SQLnavigator) console. Sample: highlight some code, press F9, then see the results.

Author:
Petr Vanek petr@.nosp@m.yarp.nosp@m.en.cz

Definition at line 39 of file pconsole.h.


Constructor & Destructor Documentation

PythonConsole::PythonConsole ( QWidget *  parent = 0)

Definition at line 43 of file pconsole.cpp.

       : QWidget( parent, "PythonConsole", WType_TopLevel )
{
       setIcon(loadIcon("AppIcon.png"));

       // setup the menu
       menuBar = new QMenuBar(this, "menuBar");
       QPopupMenu *fileMenu = new QPopupMenu(this);
       fileMenu->insertItem(loadIcon("16/document-open.png"), tr("&Open..."), this, SLOT(slot_open()), CTRL+Key_O);
       fileMenu->insertItem(loadIcon("16/document-save.png"), tr("&Save"), this, SLOT(slot_save()), CTRL+Key_S);
       fileMenu->insertItem(loadIcon("16/document-save-as.png"), tr("Save &As..."), this, SLOT(slot_saveAs()));
       fileMenu->insertSeparator();
       fileMenu->insertItem(loadIcon("exit.png"), tr("&Exit"), this, SLOT(slot_quit()));
       menuBar->insertItem( tr("&File"), fileMenu);
       QPopupMenu *scriptMenu = new QPopupMenu(this);
       scriptMenu->insertItem(loadIcon("ok.png"), tr("&Run"), this, SLOT(slot_runScript()), Key_F9);
       scriptMenu->insertItem( tr("Run As &Console"), this, SLOT(slot_runScriptAsConsole()), CTRL+Key_F9);
       scriptMenu->insertItem( tr("&Save Output..."), this, SLOT(slot_saveOutput()));
       menuBar->insertItem( tr("&Script"), scriptMenu);

       gridLayout = new QGridLayout( this, 0, 0, 1, 6, "gridLayout");
       gridLayout->setMenuBar(menuBar);

       editorsLayout = new QVBoxLayout( 0, 0, 6, "editorsLayout");

       QSplitter *splitter = new QSplitter(Qt::Vertical, this, "splitter");
       editorsLayout->addWidget(splitter);

       commandEdit = new QTextEdit(splitter, "commandEdit" );
       commandEdit->setTextFormat(Qt::PlainText);
       commandEdit->setFocus();
       commandEdit->setTabStopWidth(commandEdit->pointSize() * 4);
       QSizePolicy commandEditSize( commandEdit->sizePolicy() );
       commandEditSize.setVerStretch(4);
       commandEditSize.setVerData(QSizePolicy::Preferred);
       commandEdit->setSizePolicy(commandEditSize);
       // install syntax highlighter.
       SyntaxHighlighter *sxHigh = new SyntaxHighlighter(commandEdit);
       //remove that unused warning!
       sxHigh->currentParagraph();

       outputEdit = new QTextEdit(splitter, "outputEdit" );
       outputEdit->setTextFormat(Qt::PlainText);
       outputEdit->setReadOnly(true);
       QSizePolicy outputEditSize( outputEdit->sizePolicy() );
       outputEditSize.setVerStretch(10);
       outputEditSize.setVerData(QSizePolicy::Expanding);
       outputEdit->setSizePolicy(outputEditSize);

       statusBar = new QStatusBar(this, "statusBar");
       statusBar->setSizeGripEnabled(true);
       commandEdit_cursorPositionChanged(0, 0);
       editorsLayout->addWidget(statusBar);
       
       gridLayout->addLayout( editorsLayout, 0, 0 );
       languageChange();
       resize(QSize(640, 480).expandedTo(minimumSizeHint()));
       clearWState( WState_Polished );

       // welcome note
       QString welcomeText("\"\"\"");
       welcomeText += tr("Scribus Python Console");
       welcomeText += "\n\n";
       welcomeText += tr(
                     "This is derived from standard Python console "
                     "so it contains some limitations esp. in the "
                     "case of whitespaces. Please consult Scribus "
                     "manual for more informations.");
       welcomeText += "\"\"\"\n";
       commandEdit->setText(welcomeText);
       commandEdit->selectAll(true);

       connect(commandEdit, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(commandEdit_cursorPositionChanged(int, int)));
}

Here is the call graph for this function:

Definition at line 121 of file pconsole.cpp.

{
       //delete the highlighter
       delete commandEdit->syntaxHighlighter();
}

Member Function Documentation

void PythonConsole::closeEvent ( QCloseEvent *  )

Close event for turning the action off.

Definition at line 136 of file pconsole.cpp.

{
       emit paletteShown(false);
}

Here is the call graph for this function:

QString PythonConsole::command ( ) [inline]

The command string.

Return values:
QStringwith prepared Python commands

Definition at line 51 of file pconsole.h.

{ return m_command; };

Here is the caller graph for this function:

void PythonConsole::commandEdit_cursorPositionChanged ( int  para,
int  pos 
) [virtual, slot]

Slot processed after user change cursor postion in "programmer's editor".

Parameters:
paranumber of the paragraph (0 = 1st...)
posposition in the text like (0 = 1st...)

Definition at line 141 of file pconsole.cpp.

{
       statusBar->message( tr("Line: %1 Column: %2").arg(para+1).arg(pos+1));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PythonConsole::languageChange ( ) [protected, virtual, slot]

Definition at line 146 of file pconsole.cpp.

{
       setCaption( tr("Script Console"));
       QToolTip::add(commandEdit, "<qt>" + tr("Write your commands here. A selection is processed as script") + "</qt>");
       QToolTip::add(outputEdit, "<qt>" + tr("Output of your script") + "</qt>");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PythonConsole::paletteShown ( bool  ) [signal]

Menu indication trigger.

Here is the caller graph for this function:

void PythonConsole::parsePythonString ( ) [protected]

prepare Python "script" from GUI widget

Definition at line 171 of file pconsole.cpp.

{
       if (commandEdit->hasSelectedText())
              m_command = commandEdit->selectedText();
       else
       {
              commandEdit->selectAll(true);
              m_command = commandEdit->selectedText();
              commandEdit->selectAll(false);
       }
       // prevent user's wrong selection
       m_command += '\n';
}

Here is the caller graph for this function:

void PythonConsole::runCommand ( ) [signal]

Scripter Core launcher.

Here is the caller graph for this function:

Definition at line 127 of file pconsole.cpp.

{
       QFont font = QFont("Fixed");
       font.setStyleHint(QFont::TypeWriter);
       font.setPointSize(PrefsManager::instance()->appPrefs.AppFontSize);
       commandEdit->setFont(font); 
       outputEdit->setFont(font);
}

Here is the caller graph for this function:

void PythonConsole::slot_open ( ) [virtual, slot]

Definition at line 188 of file pconsole.cpp.

{
       filename = QFileDialog::getOpenFileName(".",
                     tr("Python Scripts (*.py *.PY)"),
                     this,
                     "ofdialog",
                     tr("Open Python Script File"));
       if (filename.isNull())
              return;
       QFile file(filename);
       if (file.open(IO_ReadOnly))
       {
              QTextStream stream(&file);
              commandEdit->setText(stream.read());
              file.close();
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PythonConsole::slot_quit ( ) [virtual, slot]

Definition at line 274 of file pconsole.cpp.

{
       emit paletteShown(false);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PythonConsole::slot_runScript ( ) [virtual, slot]

menu operations

Definition at line 153 of file pconsole.cpp.

{
       outputEdit->clear();
       parsePythonString();
       emit runCommand();
       outputEdit->setCursorPosition(0, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PythonConsole::slot_runScriptAsConsole ( ) [virtual, slot]

Definition at line 161 of file pconsole.cpp.

{
       parsePythonString();
       commandEdit->clear();
       // content is destroyed. This is to prevent overwritting
       filename = QString::null;
       outputEdit->append("\n>>> " + m_command);
       emit runCommand();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PythonConsole::slot_save ( ) [virtual, slot]

Definition at line 206 of file pconsole.cpp.

{
       if (filename.isNull())
       {
              slot_saveAs();
              return;
       }
       QFile f(filename);
       if (f.open(IO_WriteOnly))
       {
              QTextStream stream(&f);
              stream << commandEdit->text();
              f.close();
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PythonConsole::slot_saveAs ( ) [virtual, slot]

Definition at line 222 of file pconsole.cpp.

{
       QString oldFname = filename;
       filename = QFileDialog::getSaveFileName(".",
                     tr("Python Scripts (*.py *.PY)"),
                     this,
                     "sfdialog",
                     tr("Save the Python Commands in File"));
       if (filename.isNull())
              return;
       QFile f(filename);
       if (f.exists())
       {
              QString fn = QDir::convertSeparators(filename);
              if (ScMessageBox::warning(this, CommonStrings::trWarning,
                     "<qt>" + tr(QString("File %1 already exists. Do you want to replace it?").arg(fn)) + "</qt>",
                     QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
              {
                     filename = oldFname;
                     return;
              }
       }
       slot_save();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PythonConsole::slot_saveOutput ( ) [virtual, slot]

Definition at line 247 of file pconsole.cpp.

{
       QString fname = QFileDialog::getSaveFileName(".",
                     tr("Text Files (*.txt)"),
                     this,
                     "sfdialog",
                     tr("Save Current Output"));
       if (fname == QString::null)
              return;
       QFile f(fname);
       if (!f.exists())
       {
              QString fn = QDir::convertSeparators(filename);
              if (QMessageBox::warning(this, CommonStrings::trWarning,
                     "<qt>" + tr(QString("File %1 already exists. Do you want to replace it?").arg(fn)) + "</qt>",
                     QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
                     return;
       }
       // save
       if (f.open(IO_WriteOnly))
       {
              QTextStream stream(&f);
              stream << outputEdit->text();
              f.close();
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Programmer's editor ;)

Definition at line 56 of file pconsole.h.

QVBoxLayout* PythonConsole::editorsLayout [protected]

Definition at line 88 of file pconsole.h.

File name for saving the contents.

Definition at line 51 of file pconsole.h.

QGridLayout* PythonConsole::gridLayout [protected]

Definition at line 87 of file pconsole.h.

QString PythonConsole::m_command [protected]

String with the script to run (part of the all text)

Definition at line 92 of file pconsole.h.

QMenuBar* PythonConsole::menuBar [protected]

Definition at line 89 of file pconsole.h.

Results viewer.

Definition at line 58 of file pconsole.h.

QStatusBar* PythonConsole::statusBar [protected]

Definition at line 90 of file pconsole.h.


The documentation for this class was generated from the following files: