Skip to content

Commit

Permalink
Docking, New Icons, Resources Changed
Browse files Browse the repository at this point in the history
  • Loading branch information
JaDogg committed Nov 30, 2014
1 parent 24b676a commit c87e6d4
Show file tree
Hide file tree
Showing 18 changed files with 657 additions and 568 deletions.
Binary file modified Icons/Add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Icons/Clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Icons/Load.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Icons/Open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Icons/PyRunImg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Icons/Remove.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Icons/Run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Icons/Save.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Icons/Snippets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion PyRun.pro
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ QMAKE_CXXFLAGS += -std=c++11 -Wpedantic
RESOURCES += \
PyRunResources.qrc

RC_FILE = WindowsResources/PyRun.rc
RC_FILE = WindowsResources/win_rsrc.rc


win32: LIBS += -L$$PWD/../Python34/libs/ -lpython34
Expand Down
71 changes: 50 additions & 21 deletions UI/mainview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
#include "PythonAccess/emb.h"
#include "UI/mainview.h"
#include "ui_mainview.h"
#include <QSettings>
#define SAVE_STATE_VERSION 1
#define KEY_DOCK_LOCATIONS "DOCK_LOCATIONS"
#define KEY_GEOMETRY "GEOMETRY"
#define KEY_INPUTBOX "INPUTBOX"
#define KEY_CODEBOX "CODEBOX"
#define KEY_OUTPUTBOX "OUTPUTBOX"
#define KEY_FONT "FONT"
#define KEY_FONTSIZE "FONTSIZE"

MainView::MainView(QWidget* parent)
: QMainWindow(parent)
Expand All @@ -11,40 +20,62 @@ MainView::MainView(QWidget* parent)
ui->setupUi(this);
SetupHighlighter();
LoadStartupScript();
LoadSettings();
}

void MainView::SetSnippets(Snippets* snip)
void MainView::LoadSettings()
{
m_snip = snip;
LoadSnippetsToCombo();
}

void MainView::SetupHighlighter()
{
m_highlighter = new PythonSyntaxHighlighter(ui->txtCode->document());
QSettings settings;
this->restoreState(settings.value(KEY_DOCK_LOCATIONS).toByteArray(), SAVE_STATE_VERSION);
this->restoreGeometry(settings.value(KEY_GEOMETRY).toByteArray());
this->SetCode(settings.value(KEY_CODEBOX, QString()).toString());
this->SetInput(settings.value(KEY_INPUTBOX, QString()).toString());
this->SetOutput(settings.value(KEY_OUTPUTBOX, QString()).toString());

int pos = ui->fntCombo->findText("Courier New");
QString font = settings.value(KEY_FONT, tr("Courier New")).toString();
int sizeIndex = settings.value(KEY_FONTSIZE, 6).toInt(); // select 12pt

int pos = ui->fntCombo->findText(font);
if (pos != -1) {
ui->fntCombo->setCurrentIndex(pos);
}
ui->cmbFontSize->setCurrentIndex(6); // select 12pt
if (sizeIndex >= 0){
ui->cmbFontSize->setCurrentIndex(sizeIndex);
}

ChangeFontSize(ui->fntCombo->currentFont(), ui->cmbFontSize->currentText().toInt());
}
void MainView::SetSnippets(Snippets* snip)
{
mSnippets = snip;
LoadSnippetsToCombo();
}

void MainView::SetupHighlighter()
{
mHighlighter = new PythonSyntaxHighlighter(ui->txtCode->document());
ui->txtCode->setFocus();
}

void MainView::LoadStartupScript()
{
bool success;
m_startme = LoadFile(":/data/startme.py", success);
mStartMe = LoadFile(":/data/startme.py", success);

if (!success) {
QMessageBox::warning(this, tr(APP_NAME), tr("Loading startup script failed"));
}
}
MainView::~MainView()
{
QSettings settings;
settings.setValue(KEY_DOCK_LOCATIONS, this->saveState(SAVE_STATE_VERSION));
settings.setValue(KEY_GEOMETRY, this->saveGeometry());
settings.setValue(KEY_CODEBOX, this->GetCode());
settings.setValue(KEY_INPUTBOX, this->GetInput());
settings.setValue(KEY_OUTPUTBOX, this->GetOutput());
settings.setValue(KEY_FONT, ui->fntCombo->currentText());
settings.setValue(KEY_FONTSIZE, ui->cmbFontSize->currentIndex());
delete ui;
}

Expand Down Expand Up @@ -147,16 +178,14 @@ void MainView::RunPythonCode(const QString& code)
Py_Initialize();
PyImport_ImportModule("emb");

emb::StdOutWriteType write = [](std::string s)
{
emb::StdOutWriteType write = [](std::string s) {
emb::getMainView()->WriteOutput(QString::fromStdString(s));
};

emb::SetStdout(write);
PyRun_SimpleString(m_startme.toStdString().c_str());
PyRun_SimpleString(mStartMe.toStdString().c_str());
PyRun_SimpleString(code.toStdString().c_str());
emb::ResetStdOut();
//}
Py_Finalize();
}

Expand Down Expand Up @@ -233,7 +262,7 @@ void MainView::on_btnCodeSave_clicked()
void MainView::on_btnCodeDatabase_clicked()
{
bool success;
m_snip->SaveSnippets(success);
mSnippets->SaveSnippets(success);
if (success) {
QMessageBox::information(this, tr(APP_NAME), tr("Snippets database saved."));
} else {
Expand All @@ -244,7 +273,7 @@ void MainView::on_btnCodeDatabase_clicked()
void MainView::on_btnRunSnippet_clicked()
{
bool success;
QString code = m_snip->GetSnippet(ui->cmbSnippets->currentText(), success);
QString code = mSnippets->GetSnippet(ui->cmbSnippets->currentText(), success);
if (success) {
RunPythonCode(code);
}
Expand All @@ -253,7 +282,7 @@ void MainView::on_btnRunSnippet_clicked()
void MainView::on_btnLoadSnippet_clicked()
{
bool success;
QString code = m_snip->GetSnippet(ui->cmbSnippets->currentText(), success);
QString code = mSnippets->GetSnippet(ui->cmbSnippets->currentText(), success);
if (success) {
ui->txtCode->setPlainText(code);
}
Expand All @@ -262,7 +291,7 @@ void MainView::on_btnLoadSnippet_clicked()
void MainView::on_btnRemoveSnippet_clicked()
{
bool success;
m_snip->RemoveSnippet(ui->cmbSnippets->currentText(), success);
mSnippets->RemoveSnippet(ui->cmbSnippets->currentText(), success);
if (success) {
QMessageBox::information(this, tr(APP_NAME), tr("Snippet removed."));
} else {
Expand All @@ -285,7 +314,7 @@ void MainView::on_btnAddSnippet_clicked()
return;
}

m_snip->AddSnippet(text, ui->txtCode->toPlainText(), ok);
mSnippets->AddSnippet(text, ui->txtCode->toPlainText(), ok);

if (ok) {
QMessageBox::information(this, tr(APP_NAME), tr("Snippet added."));
Expand All @@ -311,7 +340,7 @@ void MainView::LoadSnippetsToCombo()
{
ui->cmbSnippets->clear();
bool success;
QList<QString> keys = m_snip->GetKeys(success);
QList<QString> keys = mSnippets->GetKeys(success);
if (success) {
ui->cmbSnippets->addItems(QStringList(keys));
}
Expand Down
7 changes: 4 additions & 3 deletions UI/mainview.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ private slots:

private:
Ui::MainView* ui;
PythonSyntaxHighlighter* m_highlighter;
QString m_startme;
Snippets* m_snip;
PythonSyntaxHighlighter* mHighlighter;
QString mStartMe;
Snippets* mSnippets;
void ChangeFontSize(QFont font, int size);
void SetupHighlighter();
void SaveFile(CodeEditor* codeEditor);
Expand All @@ -69,6 +69,7 @@ private slots:
void LoadStartupScript();
void LoadSnippetsToCombo();
void RunPythonCode(const QString& code);
void LoadSettings();
};

#endif // MAINVIEW_H
Loading

0 comments on commit c87e6d4

Please sign in to comment.