• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • scripting
script-common.cc
Go to the documentation of this file.
1 // Copyright (C) 2004 Pino Toscano <toscano.pino@tiscali.it>
2 
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17 
18 #include "script-common.h"
19 #include "../objects/text_imp.h"
20 
21 #include <qstring.h>
22 
23 #include <kdebug.h>
24 #include <klocale.h>
25 
26 struct script_prop
27 {
28  const char* fillCodeStatement;
29  const char* icon;
30  const char* highlightStyle;
31 };
32 
33 static const script_prop scripts_properties[] =
34 {
35  { I18N_NOOP( "Now fill in the code:" ), "application-x-thoshellscript", 0 },
36  { I18N_NOOP( "Now fill in the Python code:" ), "text-x-python", "Python-Kig" }
37 };
38 
39 QString ScriptType::fillCodeStatement( ScriptType::Type type )
40 {
41  return i18n( scripts_properties[type].fillCodeStatement );
42 }
43 
44 QString ScriptType::templateCode( ScriptType::Type type, std::list<ObjectHolder*> args )
45 {
46  if ( type == Python )
47  {
48  QString tempcode = QString::fromLatin1( "def calc( " );
49  bool firstarg = true;
50  KLocalizedString temparg = ki18nc( "Note to translators: this should be a default "
51  "name for an argument in a Python function. The "
52  "default is \"arg%1\" which would become arg1, "
53  "arg2, etc. Give something which seems "
54  "appropriate for your language.", "arg%1" );
55 
56  uint id = 1;
57  for ( std::list<ObjectHolder*>::const_iterator i = args.begin(); i != args.end(); ++i )
58  {
59  if ( !firstarg ) tempcode += ", ";
60  else firstarg = false;
61  QString n = ( *i )->name();
62  tempcode += n.isEmpty() ? temparg.subs( id ).toString() : n;
63  id++;
64  };
65  tempcode +=
66  " ):\n"
67  "\t# Calculate whatever you want to show here, and return it.\n";
68  if ( args.empty() )
69  {
70  tempcode +=
71  "\t# For example, to return the number pi, you would put\n"
72  "\t# this code here:\n"
73  "\t#\treturn DoubleObject( 4*atan(1.0) )\n";
74  } else {
75  if ( ! args.empty() && (*args.begin())->imp()->inherits( NumericTextImp::stype() ) )
76  {
77  tempcode +=
78  "\t# For example, to return one half of the input number,\n"
79  "\t# you would put this code here:\n"
80  "\t#\treturn DoubleObject( arg1.value()/ 2 )\n";
81  } else if ( ! args.empty() && (*args.begin())->imp()->inherits( BoolTextImp::stype() ) )
82  {
83  tempcode +=
84  "\t# For example, to return a string based on the test result,\n"
85  "\t# you would put this code here:\n"
86  "\t#\tif arg1.value():\n"
87  "\t#\t\treturn StringObject( \"TRUE!\" )\n"
88  "\t#\telse:\n"
89  "\t#\t\treturn StringObject( \"FALSE!\" )\n";
90  } else {
91  tempcode +=
92  "\t# For example, to implement a mid point, you would put\n"
93  "\t# this code here:\n"
94  "\t#\treturn Point( ( arg1.coordinate() + arg2.coordinate() ) / 2 )\n";
95  }
96  }
97  tempcode +=
98  "\t# Please refer to the manual for more information.\n"
99  "\n";
100  return tempcode;
101  }
102 
103  kDebug() << "No such script type: " << type;
104  return "";
105 }
106 
107 const char* ScriptType::icon( ScriptType::Type type )
108 {
109  return scripts_properties[type].icon;
110 }
111 
112 QString ScriptType::highlightStyle( ScriptType::Type type )
113 {
114  return scripts_properties[type].highlightStyle
115  ? QString::fromLatin1( scripts_properties[type].highlightStyle )
116  : QString();
117 }
118 
119 ScriptType::Type ScriptType::intToType( int type )
120 {
121  if ( type == 1 )
122  return Python;
123 
124  return Unknown;
125 }
scripts_properties
static const script_prop scripts_properties[]
Definition: script-common.cc:33
ScriptType::icon
static const char * icon(ScriptType::Type type)
Returns the icon's name for a script language.
Definition: script-common.cc:107
ScriptType::Type
Type
This enum represents all the script language types actually in Kig.
Definition: script-common.h:36
ScriptType::intToType
static ScriptType::Type intToType(int type)
Converts an int to a ScriptType::Type.
Definition: script-common.cc:119
ScriptType::Python
Definition: script-common.h:36
script-common.h
ScriptType::fillCodeStatement
static QString fillCodeStatement(ScriptType::Type type)
Returns an i18n'ed statement like 'Now fill in the code:' with the name of the script language...
Definition: script-common.cc:39
ScriptType::templateCode
static QString templateCode(ScriptType::Type type, std::list< ObjectHolder * > args)
Returns a template code for a script language.
Definition: script-common.cc:44
NumericTextImp::stype
static const ObjectImpType * stype()
Definition: text_imp.cc:189
ScriptType::highlightStyle
static QString highlightStyle(ScriptType::Type type)
Returns the Kate highlight stytle name for a script language.
Definition: script-common.cc:112
ScriptType::Unknown
Definition: script-common.h:36
uint
unsigned int uint
Definition: object_imp.h:87
BoolTextImp::stype
static const ObjectImpType * stype()
Definition: text_imp.cc:281
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal