r14630 by cbradney - Add functionality to new prefs pane for scripter (though I think the colour stuff is b0rken in the original anyway)

scribus-commit scribus-commit at lists.scribus.net
Tue Feb 2 23:40:23 CET 2010


Revision: 14630
Author: cbradney
Date: 2010-02-02T22:37:56.983554Z
Commit message: Add functionality to new prefs pane for scripter (though I think the colour stuff is b0rken in the original anyway)

Changeset: 
M  /trunk/Scribus/scribus/plugins/scriptplugin/prefs_scripter.cpp
M  /trunk/Scribus/scribus/plugins/scriptplugin/prefs_scripter.h
M  /trunk/Scribus/scribus/plugins/scriptplugin/prefs_scripterbase.ui

Diffs:
Index: scribus/plugins/scriptplugin/prefs_scripter.h
===================================================================
--- scribus/plugins/scriptplugin/prefs_scripter.h	(revision 14629)
+++ scribus/plugins/scriptplugin/prefs_scripter.h	(revision 14630)
@@ -10,9 +10,8 @@
 
 #include "ui_prefs_scripterbase.h"
 #include "ui/prefs_pane.h"
-#include "scribusapi.h"
 
-class SCRIBUS_API Prefs_Scripter : public Prefs_Pane, Ui::Prefs_Scripter
+class Prefs_Scripter : public Prefs_Pane, Ui::Prefs_Scripter
 {
 	Q_OBJECT
 
@@ -26,6 +25,17 @@
 		void languageChange();
 		//! \brief Apply changes to prefs. Auto connected.
 		void apply();
+
+
+	protected:
+		void setupSyntaxColors();
+
+	protected slots:
+		/*! \brief All requests for color change are handled here.
+		\author Petr Vanek
+		\warning I'm trying to handle multiple signals via single slot here. sender() Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise the return value is undefined. This function will return something apparently correct in other cases as well. However, its value may change during any function call, depending on what signal-slot connections are activated during that call. In Qt 3.0 the value will change more often than in 2.x. This function violates the object-oriented principle of modularity. However, getting access to the sender might be useful when many signals are connected to a single slot. The sender is undefined if the slot is called as a normal C++ function. */
+		void setColor();
+		void changeStartupScript();
 };
 
 #endif // PREFS_SCRIPTER_H
Index: scribus/plugins/scriptplugin/prefs_scripterbase.ui
===================================================================
--- scribus/plugins/scriptplugin/prefs_scripterbase.ui	(revision 14629)
+++ scribus/plugins/scriptplugin/prefs_scripterbase.ui	(revision 14630)
@@ -46,7 +46,7 @@
         <x>0</x>
         <y>0</y>
         <width>742</width>
-        <height>537</height>
+        <height>538</height>
        </rect>
       </property>
       <layout class="QVBoxLayout" name="verticalLayout">
@@ -72,7 +72,7 @@
         </widget>
        </item>
        <item>
-        <widget class="QCheckBox" name="checkBox">
+        <widget class="QCheckBox" name="extensionScriptsChk">
          <property name="text">
           <string>Enable Extension Scripts</string>
          </property>
@@ -88,10 +88,10 @@
           </widget>
          </item>
          <item>
-          <widget class="QLineEdit" name="lineEdit"/>
+          <widget class="QLineEdit" name="startupScriptEdit"/>
          </item>
          <item>
-          <widget class="QPushButton" name="pushButton">
+          <widget class="QPushButton" name="startupScriptChangeButton">
            <property name="text">
             <string>Change...</string>
            </property>
@@ -151,7 +151,7 @@
             </widget>
            </item>
            <item row="0" column="1">
-            <widget class="QPushButton" name="pushButton_2">
+            <widget class="QPushButton" name="textButton">
              <property name="text">
               <string/>
              </property>
@@ -165,7 +165,7 @@
             </widget>
            </item>
            <item row="1" column="1">
-            <widget class="QPushButton" name="pushButton_3">
+            <widget class="QPushButton" name="commentButton">
              <property name="text">
               <string/>
              </property>
@@ -179,7 +179,7 @@
             </widget>
            </item>
            <item row="2" column="1">
-            <widget class="QPushButton" name="pushButton_7">
+            <widget class="QPushButton" name="keywordButton">
              <property name="text">
               <string/>
              </property>
@@ -193,7 +193,7 @@
             </widget>
            </item>
            <item row="3" column="1">
-            <widget class="QPushButton" name="pushButton_4">
+            <widget class="QPushButton" name="signButton">
              <property name="text">
               <string/>
              </property>
@@ -207,7 +207,7 @@
             </widget>
            </item>
            <item row="4" column="1">
-            <widget class="QPushButton" name="pushButton_8">
+            <widget class="QPushButton" name="errorButton">
              <property name="text">
               <string/>
              </property>
@@ -221,7 +221,7 @@
             </widget>
            </item>
            <item row="5" column="1">
-            <widget class="QPushButton" name="pushButton_6">
+            <widget class="QPushButton" name="stringButton">
              <property name="text">
               <string/>
              </property>
@@ -235,7 +235,7 @@
             </widget>
            </item>
            <item row="6" column="1">
-            <widget class="QPushButton" name="pushButton_5">
+            <widget class="QPushButton" name="numberButton">
              <property name="text">
               <string/>
              </property>
Index: scribus/plugins/scriptplugin/prefs_scripter.cpp
===================================================================
--- scribus/plugins/scriptplugin/prefs_scripter.cpp	(revision 14629)
+++ scribus/plugins/scriptplugin/prefs_scripter.cpp	(revision 14630)
@@ -5,14 +5,42 @@
 for which a new license (GPL+exception) is in place.
 */
 
+// include the python header first because on OSX that uses the name "slots"
+#include "cmdvar.h"
+
+#include <QColorDialog>
+#include <QFileDialog>
+
 #include "prefs_scripter.h"
+#include "scriptercore.h"
+#include "pconsole.h"
 #include "prefsstructs.h"
 
 Prefs_Scripter::Prefs_Scripter(QWidget* parent)
 	: Prefs_Pane(parent)
 {
 	setupUi(this);
+	languageChange();
+	setupSyntaxColors();
 
+	// Set the state of the ext script enable checkbox
+	extensionScriptsChk->setChecked(scripterCore->extensionsEnabled());
+	// The startup script box should be disabled  if ext scripts are off
+	startupScriptEdit->setEnabled(extensionScriptsChk->isChecked());
+	connect(extensionScriptsChk, SIGNAL(toggled(bool)),
+			startupScriptEdit, SLOT(setEnabled(bool)));
+
+	// signals and slots connections
+	connect(extensionScriptsChk, SIGNAL(toggled(bool)), startupScriptEdit, SLOT(setEnabled(bool)));
+	// colors
+	connect(textButton, SIGNAL(clicked()), this, SLOT(setColor()));
+	connect(commentButton, SIGNAL(clicked()), this, SLOT(setColor()));
+	connect(keywordButton, SIGNAL(clicked()), this, SLOT(setColor()));
+	connect(errorButton, SIGNAL(clicked()), this, SLOT(setColor()));
+	connect(signButton, SIGNAL(clicked()), this, SLOT(setColor()));
+	connect(stringButton, SIGNAL(clicked()), this, SLOT(setColor()));
+	connect(numberButton, SIGNAL(clicked()), this, SLOT(setColor()));
+	connect(startupScriptChangeButton, SIGNAL(clicked()), this, SLOT(changeStartupScript()));
 }
 
 Prefs_Scripter::~Prefs_Scripter()
@@ -31,7 +59,65 @@
 {
 }
 
+// Apply changes to prefs. Auto connected.
 void Prefs_Scripter::apply()
 {
+	scripterCore->setExtensionsEnabled(extensionScriptsChk->isChecked());
+	scripterCore->setStartupScript(startupScriptEdit->text());
+	// colors
+	SyntaxColors *syntax = new SyntaxColors();
+	syntax->textColor = textButton->palette().color(QPalette::Window);
+	syntax->commentColor = commentButton->palette().color(QPalette::Window);
+	syntax->keywordColor = keywordButton->palette().color(QPalette::Window);
+	syntax->errorColor = errorButton->palette().color(QPalette::Window);
+	syntax->signColor = signButton->palette().color(QPalette::Window);
+	syntax->stringColor = stringButton->palette().color(QPalette::Window);
+	syntax->numberColor = numberButton->palette().color(QPalette::Window);
+	delete(syntax);
+}
 
+void Prefs_Scripter::setColor()
+{
+	QPalette palette;
+	QPushButton* button = (QPushButton*)sender();
+	QColor color = QColorDialog::getColor(button->palette().color(QPalette::Window), this);
+	if (color.isValid())
+	{
+		palette.setColor(button->backgroundRole(), color);
+ 		button->setPalette(palette);
+	}
 }
+
+void Prefs_Scripter::setupSyntaxColors()
+{
+	QPalette palette;
+	SyntaxColors *syntax = new SyntaxColors();
+	palette.setColor(textButton->backgroundRole(), syntax->textColor);
+ 	textButton->setPalette(palette);
+	palette.setColor(commentButton->backgroundRole(), syntax->commentColor);
+ 	commentButton->setPalette(palette);
+	palette.setColor(keywordButton->backgroundRole(), syntax->keywordColor);
+ 	keywordButton->setPalette(palette);
+	palette.setColor(errorButton->backgroundRole(), syntax->errorColor);
+ 	errorButton->setPalette(palette);
+	palette.setColor(signButton->backgroundRole(), syntax->signColor);
+ 	signButton->setPalette(palette);
+	palette.setColor(stringButton->backgroundRole(), syntax->stringColor);
+ 	stringButton->setPalette(palette);
+	palette.setColor(numberButton->backgroundRole(), syntax->numberColor);
+ 	numberButton->setPalette(palette);
+	delete(syntax);
+}
+
+void Prefs_Scripter::changeStartupScript()
+{
+	QString currentScript=startupScriptEdit->text();
+	QFileInfo fi(startupScriptEdit->text());
+	if (!fi.exists())
+		currentScript = QDir::homePath();
+
+	QString s = QFileDialog::getOpenFileName(this, tr("Locate Startup Script"), currentScript, "Python Scripts (*.py *.PY)");
+	if (!s.isEmpty())
+		startupScriptEdit->setText(s);
+}
+




More information about the scribus-commit mailing list