GrxJythonPromptView.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 /*
11  * GrxJythonPromptView.java
12  *
13  * Copyright (C) 2007 GeneralRobotix, Inc.
14  * All Rights Reserved
15  *
16  * @author Yuichiro Kawasumi (General Robotix, Inc.)
17  */
18 
19 package com.generalrobotix.ui.view;
20 
21 
22 import java.awt.Frame;
23 import java.io.File;
24 import java.io.IOException;
25 import java.io.PrintWriter;
26 import java.io.Writer;
27 import java.net.URL;
28 import java.util.LinkedList;
29 import java.util.List;
30 
31 import javax.swing.JOptionPane;
32 
33 import org.eclipse.jface.action.Action;
34 import org.eclipse.jface.action.ActionContributionItem;
35 import org.eclipse.jface.action.IAction;
36 import org.eclipse.jface.action.IContributionItem;
37 import org.eclipse.jface.action.ICoolBarManager;
38 import org.eclipse.jface.action.IToolBarManager;
39 import org.eclipse.jface.action.ToolBarContributionItem;
40 import org.eclipse.jface.dialogs.MessageDialog;
41 import org.eclipse.jface.window.ApplicationWindow;
42 import org.eclipse.swt.SWT;
43 import org.eclipse.swt.awt.SWT_AWT;
44 import org.eclipse.swt.custom.StyledText;
45 import org.eclipse.swt.custom.VerifyKeyListener;
46 import org.eclipse.swt.events.SelectionEvent;
47 import org.eclipse.swt.events.SelectionListener;
48 import org.eclipse.swt.events.VerifyEvent;
49 import org.eclipse.swt.graphics.Image;
50 import org.eclipse.swt.layout.GridData;
51 import org.eclipse.swt.layout.GridLayout;
52 import org.eclipse.swt.widgets.Button;
53 import org.eclipse.swt.widgets.Composite;
54 import org.eclipse.swt.widgets.Display;
55 import org.eclipse.ui.IWorkbenchWindow;
56 import org.eclipse.ui.PlatformUI;
57 import org.python.core.Py;
58 import org.python.core.PyList;
59 import org.python.core.PyString;
60 import org.python.util.InteractiveInterpreter;
61 
70 
71 @SuppressWarnings("serial") //$NON-NLS-1$
75 public class GrxJythonPromptView extends GrxBaseView {
76  private InteractiveInterpreter interpreter_ = new InteractiveInterpreter();
77  private Thread thread_1_;
78  private Thread thread_2_;
79  private String prompt_ = ">>> "; //$NON-NLS-1$
80  private Display display_;
81  private Composite parent_;
82  private StyledText styledText_;
84  private Frame frame_;
85  private static final int HISTORY_SIZE = 50;
86  private List<String> history_ = new LinkedList<String>();
87  private int hpos_ = 0;
88  private String com_;
89  private Button btnExec_;
90  private Writer writer_;
92  private String message_;
93  private Object result_;
94 
95  private static final int KS_SHIFT = SWT.SHIFT;
96  private static final int KS_CONTROL = SWT.CTRL;
97  private static final int KS_CTRL_U = 'u' | SWT.CTRL;
98  private static final int KS_CTRL_A = 'a' | SWT.CTRL;
99  private static final int KS_CTRL_E = 'e' | SWT.CTRL;
100  private static final int KS_CTRL_F = 'f' | SWT.CTRL;
101  private static final int KS_CTRL_B = 'b' | SWT.CTRL;
102  private static final int KS_CTRL_N = 'n' | SWT.CTRL;
103  private static final int KS_CTRL_P = 'p' | SWT.CTRL;
104  private static final int KS_UP = SWT.ARROW_UP;
105  private static final int KS_DOWN = SWT.ARROW_DOWN;
106  private static final int KS_LEFT = SWT.ARROW_LEFT;
107  private static final int KS_RIGHT = SWT.ARROW_RIGHT;
108  private static final int KS_ENTER = SWT.CR;
109  private static final int KS_ENTER_ALT = SWT.CR | SWT.ALT;
110  private static final int KS_ENTER_CTRL = SWT.CR | SWT.CTRL;
111  private static final int KS_ENTER_SHIFT = SWT.CR | SWT.SHIFT;
112  private static final int KS_BACK_SPACE = SWT.BS;
113  private static final int KS_DELETE = SWT.DEL;
114 
115  private Image simScriptStartIcon_;
116  private Image simScriptStopIcon_;
118 
119  private static final int INTERVAL=100; // StyledText の更新間隔(ms) //
120 
128  public GrxJythonPromptView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent) {
129  super(name, manager, vp, parent);
130 
131  display_ = parent.getDisplay();
132  parent_ = parent;
133  composite_.setLayout(new GridLayout(1,false));
134  simScriptStartIcon_ = Activator.getDefault().getImage( "sim_script_start.png" ); //$NON-NLS-1$
135  simScriptStopIcon_ = Activator.getDefault().getImage( "sim_script_stop.png"); //$NON-NLS-1$
136  frame_ = SWT_AWT.new_Frame(new Composite(parent.getShell(),SWT.EMBEDDED));
137 
138  btnExec_ = new Button(composite_,SWT.TOGGLE);
139  btnExec_.setImage(simScriptStartIcon_);
140  btnExec_.setText(MessageBundle.get("GrxJythonPromptView.button.execute")); //$NON-NLS-1$
141  //btnExec_.setPreferredSize(GrxBaseView.getDefaultButtonSize());
142  //btnExec_.setMaximumSize(GrxBaseView.getDefaultButtonSize());
143  btnExec_.setEnabled(false);
144 
145  styledText_ = new StyledText(composite_,SWT.MULTI|SWT.V_SCROLL|SWT.WRAP);
146  styledText_.setEditable(false);
147  styledText_.setText(prompt_);
148  styledText_.addVerifyKeyListener(new ConsoleKeyListener());
149  styledText_.setEditable(true);
150  styledText_.setLayoutData(new GridData(GridData.FILL_BOTH));
151 
152  btnExec_.addSelectionListener(new SelectionListener(){
153 
154  public void widgetDefaultSelected(SelectionEvent e) {
155  }
156 
157  public void widgetSelected(SelectionEvent e) {
158  selectedExecBtn();
159  }
160 
161  });
162 
163 
164  stWriter_ = new StyledTextWriter();
165  writer_ = new PrintWriter(stWriter_);
166  interpreter_.setErr(writer_);
167  interpreter_.setOut(writer_);
168  interpreter_.set("uimanager", manager_); //$NON-NLS-1$
169  interpreter_.exec("import sys"); //$NON-NLS-1$
170  String dir = Activator.getDefault().getPreferenceStore().getString("JYTHON_LIB"); //$NON-NLS-1$
171  if(dir.equals("")) //$NON-NLS-1$
172  dir = System.getenv("JYTHON_LIB"); //$NON-NLS-1$
173  if(dir!=null){
174  String dirs[] = dir.split(":");
175  for (int i=0; i<dirs.length; i++){
176  File f = new File(dirs[i]);
177  if (f.exists()){
178  interpreter_.exec("sys.path.append('"+dirs[i]+"')"); //$NON-NLS-1$ //$NON-NLS-2$
179  File[] files = f.listFiles();
180  for (int j=0; j<files.length; j++){
181  if (files[j].getName().endsWith(".jar")){
182  interpreter_.exec("sys.path.append('"+files[j].getAbsolutePath()+"')"); //$NON-NLS-1$ //$NON-NLS-2$
183  }
184  }
185  }
186  }
187  }
188  dir = Activator.getDefault().getPreferenceStore().getString("PROJECT_DIR"); //$NON-NLS-1$
189  if(dir.equals("")) //$NON-NLS-1$
190  dir = System.getenv("PROJECT_DIR"); //$NON-NLS-1$
191  if(dir!=null)
192  dir += "/../script"; //$NON-NLS-1$
193  if(dir !=null && new File(dir).exists())
194  interpreter_.exec("sys.path.append('"+dir+"')"); //$NON-NLS-1$ //$NON-NLS-2$
195  URL[] urls = manager_.pluginLoader_.getURLs();
196  for (int i=0; i<urls.length; i++) {
197  interpreter_.exec("sys.path.append('"+urls[i].getPath()+"')"); //$NON-NLS-1$ //$NON-NLS-2$
198  interpreter_.exec("print \"sys.path.append(\'"+urls[i].getPath()+"\')\""); //$NON-NLS-1$ //$NON-NLS-2$
199  }
200  if(dir!=null && new File(dir).exists())
201  interpreter_.exec("import rbimporter"); //$NON-NLS-1$
202  interpreter_.exec("import __builtin__"); //$NON-NLS-1$
203 
204  interpreter_.set("view", this); //$NON-NLS-1$
205  interpreter_.exec("__builtin__.waitInput = view.waitInput"); //$NON-NLS-1$
206  interpreter_.exec("__builtin__.waitInputConfirm = view.waitInputConfirm"); //$NON-NLS-1$
207  interpreter_.exec("__builtin__.waitInputSelect = view.waitInputSelect"); //$NON-NLS-1$
208  interpreter_.exec("__builtin__.waitInputMessage = view.waitInputMessage"); //$NON-NLS-1$
209  interpreter_.exec("__builtin__.waitInputMenu = view.waitInputMenu"); //$NON-NLS-1$
210  interpreter_.exec("__builtin__.waitInputSetMessage = view.waitInputSetMessage"); //$NON-NLS-1$
211  interpreter_.exec("del view\n"); //$NON-NLS-1$
212  interpreter_.exec("del __builtin__"); //$NON-NLS-1$
213  history_.add(""); //$NON-NLS-1$
214  setNameService();
215 
216  setMenuItem(new InitPythonAction());
217  setScrollMinSize(SWT.DEFAULT,SWT.DEFAULT);
218 
219  setUp();
220  manager_.registerItemChangeListener(this, GrxPythonScriptItem.class);
221 
222  Runnable stringOutRun_ = new Runnable() {
223  public void run() {
224  if(composite_!=null && !composite_.isDisposed()){
225  Display display = composite_.getDisplay();
226  if (!display.isDisposed()){
227  display.timerExec(INTERVAL, this);
228  String string=stWriter_.read();
229  if(!string.equals("")){
230  styledText_.append(string);
231  styledText_.setCaretOffset(styledText_.getText().length());
232  styledText_.setTopIndex(styledText_.getLineCount());
233  }
234  if(btnExec_.isEnabled() && btnExec_.getSelection()){
235  if( (thread_1_==null || !thread_1_.isAlive()) && (thread_2_==null || !thread_2_.isAlive()) ){
236  btnExec_.setSelection(false);
237  styleExecBtn(false);
238  }
239  }
240  }
241  }
242  }
243  };
244  Display display = composite_.getDisplay();
245  if (!display.isDisposed())
246  display.timerExec(INTERVAL, stringOutRun_);
247 
248  updateEditerFont();
249  }
250 
251  public void setUp(){
252  currentItem_ = manager_.<GrxPythonScriptItem>getSelectedItem(GrxPythonScriptItem.class, null);
253  btnExec_.setEnabled(currentItem_ != null);
254  }
255 
256  private class InitPythonAction extends Action{
258  super("cleanup python",IAction.AS_PUSH_BUTTON); //$NON-NLS-1$
259  }
260  public void run(){
261  interpreter_.cleanup();
262  interpreter_.exec("rbimporter.refresh()"); //$NON-NLS-1$
263  }
264  }
265 
266  public void interrupt() {
267  if (thread_1_ != null)
268  interpreter_.interrupt(Py.getThreadState());
269  if (thread_2_ != null) {
270  interpreter_.interrupt(Py.getThreadState());
271  }
272  }
273 
274  private class ConsoleKeyListener implements VerifyKeyListener {
275 
276  public void verifyKey(VerifyEvent event) {
277  int ks = event.keyCode | event.stateMask;
278  int len = styledText_.getText().length();
279  int cp = styledText_.getCaretOffset();
280 
281  com_ = getCommand();
282  event.doit = false;
283  if (thread_1_ != null) {
284  return;
285  } else if (ks == KS_ENTER || ks == KS_ENTER_ALT
286  || ks == KS_ENTER_CTRL || ks == KS_ENTER_SHIFT) {
287  try {
288  if (com_.trim().length() <= 0){
289  styledText_.append("\n"+prompt_); //$NON-NLS-1$
290  styledText_.setCaretOffset(styledText_.getText().length());
291  styledText_.setTopIndex(styledText_.getLineCount());
292  }else{
293  styledText_.append("\n"); //$NON-NLS-1$
294  btnExec_.setSelection(true);
295  styleExecBtn(true);
296  final String com = com_.trim();
297  thread_1_ = new Thread() {
298  public void run() {
299  result_=null;
300  try{
301  if (com.startsWith("dir(")) { //$NON-NLS-1$
302  interpreter_.exec("__tmp__ = " +com); //$NON-NLS-1$
303  result_ = interpreter_.eval("__tmp__"); //$NON-NLS-1$
304  } else {
305  result_ = interpreter_.eval(com);
306  }
307  }catch (org.python.core.PyException e) {
308  try{
309  interpreter_.exec(com);
310  }catch( org.python.core.PyException exception ){
311  result_ = exception.toString();
312  }
313  }
314  history_.add(1, com);
315  if (history_.size() > HISTORY_SIZE)
316  history_.remove(HISTORY_SIZE-1);
317  if (result_ != null)
318  stWriter_.write(result_.toString()+"\n");
319  stWriter_.write(prompt_);
320  hpos_ = 0;
321  thread_1_ = null;
322  };
323  };
324  thread_1_.start();
325  }
326  } catch (Exception e) {
327  e.printStackTrace();
328  }
329  } else if (ks == KS_CTRL_U) {
330  styledText_.replaceTextRange(len - com_.length(), com_.length(),""); //$NON-NLS-1$
331  } else if (ks == KS_CTRL_A) {
332  styledText_.setCaretOffset(len - com_.length());
333  } else if (ks == KS_CTRL_E) {//Eclipseの標準キーバインド
334  styledText_.setCaretOffset(len);
335  } else if ((ks == KS_CTRL_F || ks == KS_RIGHT)) {//Eclipseの標準キーバインド
336  if (cp < len)
337  styledText_.setCaretOffset(cp + 1);
338  } else if ((ks == KS_CTRL_B || ks == KS_LEFT)) {//Eclipseの標準キーバインド
339  if (len - com_.length() < cp)
340  styledText_.setCaretOffset(cp - 1);
341  } else if (ks == KS_SHIFT) { // ignore input of shift key
342  } else if (ks == KS_CONTROL) { // and control key
343  } else if (ks == KS_BACK_SPACE) {
344  int p = styledText_.getText().lastIndexOf('\n') + prompt_.length() + 1;
345  if (p < cp) {
346  styledText_.replaceTextRange(cp - 1, 1,""); //$NON-NLS-1$
347  }
348  } else if (ks == KS_DELETE) {
349  if (cp < len) {
350  styledText_.replaceTextRange( cp,1,""); //$NON-NLS-1$
351  }
352  } else if (ks == KS_UP || ks == KS_CTRL_P) {
353  if (hpos_ < history_.size() - 1) {
354  int start = styledText_.getText().lastIndexOf('\n') + prompt_.length() + 1;
355  if (start <= len)
356  styledText_.replaceTextRange(start, len-start, history_.get(++hpos_));
357  styledText_.setCaretOffset(styledText_.getText().length());
358  }
359  } else if (ks == KS_DOWN || ks == KS_CTRL_N) {//KS_CTRL_N
360  styledText_.setCaretOffset(len);
361  if (hpos_ > 0) {
362  int start = styledText_.getText().lastIndexOf('\n') + prompt_.length() + 1;
363  if (start <= len)
364  styledText_.replaceTextRange(start, len-start,history_.get(--hpos_));
365  }
366  } else {
367  if (cp <styledText_.getText().lastIndexOf('\n')) {
368  cp = len;
369  styledText_.setCaretOffset(len);
370  }
371  event.doit = true;
372  }
373  }
374  }
375 
376  public void execFile() {
377  if (currentItem_ == null)
378  return;
379 
380  if (currentItem_.isEdited()) {
381  boolean ans = MessageDialog.openConfirm(parent_.getShell(), MessageBundle.get("GrxJythonPromptView.dialog.title.exec"), MessageBundle.get("GrxJythonPromptView.dialog.message.exec")); //$NON-NLS-1$ //$NON-NLS-2$
382  if (!ans || !currentItem_.save())
383  return;
384  }
385 
386  final String url = currentItem_.getURL(true);
387  execFile(url);
388  }
389 
390  public void execFile(final String url) {
391  setNameService();
392  File f = new File(url);
393  File p = f.getParentFile();
394  interpreter_.exec("import sys"); //$NON-NLS-1$
395  PyString pyStr = new PyString(p.getAbsolutePath());
396  PyList pathList = (PyList)interpreter_.eval("sys.path"); //$NON-NLS-1$
397  if (!pathList.__contains__(pyStr)) {
398  String com = "sys.path.append(\""+p.getAbsolutePath()+"\")"; //$NON-NLS-1$ //$NON-NLS-2$
399  interpreter_.exec("print '"+com+"'"); //$NON-NLS-1$ //$NON-NLS-2$
400  interpreter_.exec(com);
401  }
402 
403  thread_2_ = new Thread() {
404  public void run() {
405  try {
406  interpreter_.exec("print 'execfile("+url+")'"); //$NON-NLS-1$ //$NON-NLS-2$
407  interpreter_.execfile(url);
408  } catch (Exception e) {
409  e.printStackTrace();
410  }
411  stWriter_.write(prompt_);
412  hpos_ = 0;
413  }
414  };
415  thread_2_.start();
416  }
417 
418  private String getCommand() {
419  String com = styledText_.getText();
420  int idx = com.lastIndexOf('\n');
421  if (idx > 0)
422  com = com.substring(idx + 1);
423  return com.replaceFirst(prompt_, ""); //$NON-NLS-1$
424  }
425 
426  public void setNameService(){
427  String nsHost = manager_.getProjectProperty("nsHost"); //$NON-NLS-1$
428  String nsPort = manager_.getProjectProperty("nsPort"); //$NON-NLS-1$
429  if (nsHost == null)
430  nsHost = GrxCorbaUtil.nsHost();
431  if (nsPort == null){
432  Integer np = new Integer(GrxCorbaUtil.nsPort());
433  nsPort = np.toString();
434  }
435 
436  String NS_OPT = "-ORBInitRef NameService=corbaloc:iiop:"+nsHost+":"+nsPort+"/NameService"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
437  System.setProperty("NS_OPT", NS_OPT); //$NON-NLS-1$
438  interpreter_.cleanup();
439  interpreter_.exec("print 'NS_OPT="+NS_OPT+"'"); //$NON-NLS-1$ //$NON-NLS-2$
440  interpreter_.exec("print '"+prompt_+"rbimporter.refresh()'"); //$NON-NLS-1$ //$NON-NLS-2$
441  interpreter_.exec("rbimporter.refresh()"); //$NON-NLS-1$
442  String nameservice = "could not parse"; //$NON-NLS-1$
443  try {
444  nameservice = NS_OPT.split("=")[1]; //$NON-NLS-1$
445  } catch (Exception e) {
446  interpreter_.exec("print 'failed to connect NameService("+nameservice+")'"); //$NON-NLS-1$ //$NON-NLS-2$
447  }
448  }
449  /*
450  public void restoreProperties() {
451  super.restoreProperties();
452  setNameService();
453 
454  //TODO:UIスレッド以外から呼ばれることはないならはずしてもいい。
455  display_.asyncExec(new Thread(){
456  public void run(){
457  styledText_.setCaretOffset(styledText_.getText().length());
458  //area_.setMaximumRowCount(getInt("maxRowCount", DEFAULT_MAX_ROW));
459  }
460  });
461 
462  String defaultScript = System.getProperty("SCRIPT"); //$NON-NLS-1$
463  if (defaultScript != null) {
464  System.clearProperty("SCRIPT"); //$NON-NLS-1$
465  File f = new File(defaultScript);
466  String name = f.getName().replace(".py", ""); //$NON-NLS-1$ //$NON-NLS-2$
467  GrxBaseItem newItem = manager_.loadItem(GrxPythonScriptItem.class, name, f.getAbsolutePath());
468  if(newItem!=null){
469  manager_.itemChange(newItem, GrxPluginManager.ADD_ITEM);
470  manager_.setSelectedItem(newItem, true);
471  }
472  execFile();
473  }
474  }
475  */
476  public void registerItemChange(GrxBaseItem item, int event){
477  if(item instanceof GrxPythonScriptItem){
478  GrxPythonScriptItem pythonScriptItem = (GrxPythonScriptItem)item;
479  switch(event){
481  currentItem_ = pythonScriptItem;
482  btnExec_.setEnabled(true);
483  break;
486  currentItem_ = null;
487  btnExec_.setEnabled(false);
488  break;
489  default:
490  break;
491  }
492  }
493  }
494 
495  public void waitInput(final String msg) {
496  JOptionPane.showMessageDialog(frame_, msg);
497  }
498 
499  public void waitInputConfirm(final String msg) {
500  int ans = JOptionPane.showConfirmDialog(frame_,
501  msg,"waitInputConfirm", //$NON-NLS-1$
502  JOptionPane.OK_CANCEL_OPTION,
503  JOptionPane.INFORMATION_MESSAGE,
504  null);
505  if (ans != JOptionPane.OK_OPTION)
506  interrupt();
507  }
508 
509  public boolean waitInputSelect(final String msg) {
510  int ans = JOptionPane.showConfirmDialog(frame_,
511  msg,"waitInputSelect", //$NON-NLS-1$
512  JOptionPane.YES_NO_CANCEL_OPTION,
513  JOptionPane.INFORMATION_MESSAGE,
514  null);
515  if (ans == JOptionPane.YES_OPTION)
516  return true;
517  else if (ans != JOptionPane.NO_OPTION)
518  interrupt();
519  return false;
520  }
521 
522  public Object waitInputMessage(String msg) {
523  return JOptionPane.showInputDialog(frame_,
524  msg, "waitInputMessage", //$NON-NLS-1$
525  JOptionPane.INFORMATION_MESSAGE,
526  null,null,null);
527  }
528 
529  public void waitInputMenu(String[][] menuList) {
530  menuDialog = new MenuDialog(menuList, interpreter_, message_, stWriter_);
531  menuDialog.showDialog(frame_, currentItem_.getName(), false);
532  }
533  public void waitInputSetMessage(String msg) {
534  message_ = msg;
536  menuDialog.setMessage(msg);
537  }
538 
539  public class StyledTextWriter extends Writer {
540  private StringBuffer outString_ = null;
541 
542  public StyledTextWriter() {
543  outString_ = new StringBuffer();
544  }
545 
546  public void write(char[] cbuf, int off, int len) throws IOException {
547  synchronized (lock) {
548  if ((off < 0) || (off > cbuf.length) || (len < 0)
549  || ((off + len) > cbuf.length) || ((off + len) < 0)) {
550  throw new IndexOutOfBoundsException();
551  } else if (len == 0) {
552  }
553 
554  char[] c = new char[len];
555  System.arraycopy(cbuf, off, c, 0, len);
556  outString_.append(c);
557  }
558  }
559 
560  public void close() throws IOException {
561  synchronized (lock) {
562  }
563  }
564 
565  public void flush() throws IOException {
566  synchronized (lock) {
567  }
568  }
569 
570  public String read(){
571  synchronized(lock){
572  String str = outString_.toString();
573  outString_.delete(0, outString_.length());
574  return str;
575  }
576  }
577 
578  public void write(String str){
579  synchronized(lock){
580  outString_.append(str);
581  }
582  }
583 
584  }
585 
586  public void shutdown(){
587  manager_.removeItemChangeListener(this, GrxPythonScriptItem.class);
588  }
589 
590  public boolean getEnabledExecBtn(){
591  return btnExec_.getEnabled();
592  }
593 
594  public void selectExecBtn(){
595  btnExec_.setSelection(!btnExec_.getSelection());
596  selectedExecBtn();
597  }
598 
599  private void selectedExecBtn(){
600  if (btnExec_.getSelection()) {
601  styleExecBtn(true);
602  execFile();
603  } else {
604  styleExecBtn(false);
605  interrupt();
606  }
607  }
608 
609  private void styleExecBtn(boolean selected){
610  IAction action = getStartSimulationAction();
611  if(selected){
612  btnExec_.setImage(simScriptStopIcon_);
613  btnExec_.setToolTipText(MessageBundle.get("GrxJythonPromptView.text.interrupt"));
614  if(action != null){
615  action.setText("interrupt python threads");
616  action.setImageDescriptor(Activator.getDefault().getDescriptor("sim_script_stop.png"));
617  }
618  }
619  else{
620  btnExec_.setImage(simScriptStartIcon_);
621  btnExec_.setToolTipText(MessageBundle.get("GrxJythonPromptView.text.execute"));
622  styledText_.setEnabled(true);
623  if(action != null){
624  action.setToolTipText("Execute Script File");
625  action.setImageDescriptor(Activator.getDefault().getDescriptor("sim_script_start.png"));
626  }
627  }
628  }
629 
630  private IAction getStartSimulationAction()
631  {
632  IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
633  for(IWorkbenchWindow w : windows){
634  if(!(w instanceof ApplicationWindow))
635  continue;
636  ApplicationWindow window = (ApplicationWindow)w;
637  ICoolBarManager coolbar = window.getCoolBarManager2();
638  if(coolbar == null)
639  continue;
640  IContributionItem setitem = coolbar.find("com.generalrobotix.ui.actionSet");
641  if(setitem != null && setitem instanceof ToolBarContributionItem)
642  {
643  IToolBarManager toolbar = ((ToolBarContributionItem)setitem).getToolBarManager();
644  if(toolbar == null)
645  continue;
646  IContributionItem actitem = toolbar.find("com.generalrobotix.ui.actions.ExecuteScript");
647  if(actitem != null && actitem instanceof ActionContributionItem)
648  return ((ActionContributionItem)actitem).getAction();
649  }
650  }
651  return null;
652  }
653 
654  public void updateEditerFont(){
655  styledText_.setFont(Activator.getDefault().getFont("preference_editer"));
656  }
657 }
static final String get(String key)
int c
Definition: autoplay.py:16
void showDialog(Frame owner, String title, boolean modal)
#define null
our own NULL pointer
Definition: IceTypes.h:57
png_infop png_charpp name
Definition: png.h:2382
w
static String nsHost()
get hostname where naming server is running
png_uint_32 i
Definition: png.h:2735
static MenuDialog getCurrentMenuDialog()
def run(tree, args)
png_size_t start
Definition: png.h:1496
static int nsPort()
get port number where naming server is listening
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
org
GrxJythonPromptView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent)
constructor
void registerItemChange(GrxBaseItem item, int event)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:03