Warning, /frameworks/kross/autotests/qtstest.es is written in an unsupported language. File is not indexed.
0001 // #!/usr/bin/env kross 0002 0003 /* 0004 This function does print some general information about 0005 Kross to stdout. 0006 */ 0007 function printInfos() 0008 { 0009 function inspect(v) { 0010 var items = new Array(); 0011 for(i in v) 0012 items.push(i); 0013 return items; 0014 } 0015 0016 // print the items the Kross object provides 0017 print(Kross + " [" + inspect(Kross) + "]\n"); 0018 0019 // print the items the Kross.self object provides 0020 //print(Kross.self + " [" + inspect(Kross.self) + "]\n"); 0021 0022 // print the list of supported interpreters 0023 print("interpreters=" + Kross.interpreters() + "\n"); 0024 } 0025 0026 /* 0027 This function does execute Python scripting code using 0028 the Kross Scripting Framework. 0029 */ 0030 function executePythonCode(PythonScriptCode) 0031 { 0032 // create an action-instance which is our script 0033 var action = Kross.action("MyPythonScript"); 0034 // publish our action instance as "MyAction" 0035 action.addQObject(action, "MyAction"); 0036 // set the name of the used interpreter. 0037 action.setInterpreter("python"); 0038 0039 // set the python scripting code we like to execute. 0040 //action.setCode( Kross.QByteArray(PythonScriptCode) ); 0041 action.setCode( PythonScriptCode ); 0042 0043 // finally execute the script 0044 action.trigger(); 0045 } 0046 0047 /* 0048 This function does execute a Python scripting file using 0049 the Kross Scripting Framework. 0050 */ 0051 function executePythonFile(PythonFileName) 0052 { 0053 // create an action-instance which is our script 0054 var action = Kross.action(PythonFileName); 0055 // publish our action instance as "MyAction" 0056 action.addQObject(action, "MyAction"); 0057 // set the scripting file that should be executed 0058 action.setFile(PythonFileName); 0059 // finally execute the script 0060 action.trigger(); 0061 } 0062 0063 /* 0064 This function does show a dialog using the Kross forms-module 0065 shipped together with kross in kdelibs. The forms module does 0066 provide us some high-level functionality like KPageDialog, 0067 KFileWidget and the UI-loader. All the functionality provided 0068 within that module is accessible from within all supported 0069 scripting languages. 0070 */ 0071 function showKrossForms() 0072 { 0073 var krossforms = Kross.module("forms"); 0074 var dialog = krossforms.createDialog("My Dialog"); 0075 dialog.setButtons("Ok|Cancel"); 0076 dialog.setFaceType("List"); //Auto Plain List Tree Tabbed 0077 var mypage = dialog.addPage("My Page","This is my page","document-save"); 0078 var lst = new QListWidget(mypage); 0079 var btn = new QPushButton(mypage); 0080 dialog.exec_loop(); 0081 } 0082 0083 /* 0084 This function does show a dialog using the QtScript 0085 functionality. 0086 */ 0087 function showDialog() 0088 { 0089 var dialog = new QDialog(); 0090 layout = new QVBoxLayout(dialog); 0091 0092 var otherlayout = new QHBoxLayout(); 0093 var brw = new QTextBrowser(dialog); 0094 brw.html = "Some <b>HTML</b> text"; 0095 otherlayout.addWidget(brw); 0096 var lst = new QListWidget(dialog); 0097 otherlayout.addWidget(lst); 0098 layout.addLayout(otherlayout); 0099 0100 var gridlayout = new QGridLayout(); 0101 var lbl = new QLabel(dialog); 0102 lbl.text = "First Label"; 0103 gridlayout.addWidget(lbl, 0, 0); 0104 var btn = new QPushButton(dialog); 0105 btn.text = "First Button"; 0106 gridlayout.addWidget(btn, 0, 1); 0107 var lbl = new QLabel(dialog); 0108 lbl.text = "Second Label"; 0109 gridlayout.addWidget(lbl, 1, 0); 0110 var btn = new QPushButton(dialog); 0111 btn.text = "Second Button"; 0112 gridlayout.addWidget(btn, 1, 1); 0113 layout.addLayout(gridlayout); 0114 0115 dialog.exec(); 0116 } 0117 0118 printInfos(); 0119 executePythonCode("import MyAction ; print 'This is Python. name=>',MyAction.name()"); 0120 //executePythonFile("/home/kde4/svn/_src/kdelibs/kross/ext/test.py"); 0121 showKrossForms(); 0122 //showDialog();