00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 #include <gtk/gtk.h>
00320 #include "config.h"
00321 #include "gxsm/plugin.h"
00322
00323
00324
00325
00326
00327
00328
00329 #ifdef HAVE_PYTHON2_1_PYTHON_H
00330 #include <python2.1/Python.h>
00331 #endif
00332
00333 #ifdef HAVE_PYTHON2_2_PYTHON_H
00334 #include <python2.2/Python.h>
00335 #endif
00336
00337 #ifdef HAVE_PYTHON2_3_PYTHON_H
00338 #include <python2.3/Python.h>
00339 #endif
00340
00341 #ifdef HAVE_PYTHON2_4_PYTHON_H
00342 #include <python2.4/Python.h>
00343 #endif
00344
00345 #include <sys/types.h>
00346 #include <signal.h>
00347
00348 #include "action_id.h"
00349 #include "xsmtypes.h"
00350
00351
00352 #include "pyremote.h"
00353
00354
00355 static void pyremote_init( void );
00356 static void pyremote_about( void );
00357 static void pyremote_configure( void );
00358 static void pyremote_cleanup( void );
00359 static void pyremote_run(GtkWidget *w, void *data);
00360
00361
00362 GxsmPlugin pyremote_pi = {
00363 NULL,
00364 NULL,
00365 0,
00366 NULL,
00367
00368
00369
00370
00371 "Pyremote",
00372 NULL,
00373
00374 "Remote control",
00375
00376 "Stefan Schroeder",
00377
00378 "_Tools/",
00379
00380 N_("Pyremote"),
00381
00382 N_("Python Remote Control."),
00383
00384 "See Manual.",
00385 NULL,
00386 NULL,
00387
00388
00389 pyremote_init,
00390
00391
00392 NULL,
00393
00394
00395 pyremote_about,
00396
00397
00398 pyremote_configure,
00399
00400
00401 pyremote_run,
00402
00403
00404 pyremote_cleanup
00405 };
00406
00407
00408 static const char *about_text = N_("Gxsm Plugin\n\n"
00409 "Python Remote Control.");
00410
00411
00412 GxsmPlugin *get_gxsm_plugin_info ( void ){
00413 pyremote_pi.description = g_strdup_printf(N_("Gxsm pyremote plugin %s"), VERSION);
00414 return &pyremote_pi;
00415 }
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431 static void pyremote_init(void)
00432 {
00433
00434
00435 PI_DEBUG(DBG_L2, "pyremote Plugin Init");
00436 if (!getenv("PYTHONPATH")){
00437 PI_DEBUG(DBG_L2, "pyremote: PYTHONPATH is not set.");
00438 PI_DEBUG(DBG_L2, "pyremote: Setting to '.'");
00439 setenv("PYTHONPATH", ".", 0);
00440 }
00441 }
00442
00443
00444 static void pyremote_about(void)
00445 {
00446 const gchar *authors[] = { pyremote_pi.authors, NULL};
00447 gtk_widget_show(gnome_about_new ( pyremote_pi.name,
00448 VERSION,
00449 N_("(C) 2000 the Free Software Foundation"),
00450 about_text,
00451 authors,
00452 NULL,NULL,NULL
00453 ));
00454 }
00455
00456
00457 static void pyremote_configure(void)
00458 {
00459 if(pyremote_pi.app)
00460 pyremote_pi.app->message("Pyremote Plugin Configuration");
00461 }
00462
00463
00464 static void pyremote_cleanup(void)
00465 {
00466 PI_DEBUG(DBG_L2, "Pyremote Plugin Cleanup");
00467 }
00468
00469 #ifdef Py_PYTHON_H
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503 static void Check_ec(Gtk_EntryControl* ec, gpointer arglist){
00504 ec->CheckRemoteCmd((gchar **)arglist);
00505 };
00506
00507 static void CbAction_ra(remote_action_cb* ra, gpointer arglist){
00508 if(ra->cmd && ((gchar**)arglist)[1])
00509 if(! strcmp(((gchar**)arglist)[1], ra->cmd)){
00510
00511 (*ra->RemoteCb) (ra->widget, arglist);
00512
00513 }
00514 };
00515
00516 static PyObject* remote_set(PyObject *self, PyObject *args)
00517 {
00518 PI_DEBUG(DBG_L2, "pyremote: Setting ");
00519 gchar *parameter, *value;
00520
00521 if (!PyArg_ParseTuple(args, "ss", ¶meter, &value))
00522 return Py_BuildValue("i", -1);
00523
00524 PI_DEBUG(DBG_L2, parameter << " to " << value );
00525
00526 gchar *line3[] ={"set", parameter, value};
00527
00528 g_slist_foreach(gapp->RemoteEntryList, (GFunc) Check_ec, (gpointer)line3);
00529
00530 return Py_BuildValue("i", 0);
00531 }
00532
00533 static PyObject* remote_action(PyObject *self, PyObject *args)
00534 {
00535 PI_DEBUG(DBG_L2, "pyremote: Action ") ;
00536 gchar *parameter, *value = "5.0";
00537
00538 if (!PyArg_ParseTuple(args, "s|s", ¶meter, &value))
00539 return Py_BuildValue("i", -1);
00540
00541 PI_DEBUG(DBG_L2, parameter );
00542
00543 PI_DEBUG(DBG_L2, "value:" << value);
00544
00545 gchar *line3[] ={"action", parameter, value};
00546
00547 g_slist_foreach(gapp->RemoteActionList, (GFunc) CbAction_ra, (gpointer)line3);
00548
00549 return Py_BuildValue("i", 0);
00550 }
00551
00553
00554
00555
00556
00557
00558
00559
00560
00562
00563 static PyObject* remote_startscan(PyObject *self, PyObject *args)
00564 {
00565 PI_DEBUG(DBG_L2, "pyremote: Starting scan");
00566 gapp->action_toolbar_callback(NULL, (void*)"Toolbar_Scan_Start");
00567 return Py_BuildValue("i", 0);
00568 }
00569
00570 static PyObject* remote_stopscan(PyObject *self, PyObject *args)
00571 {
00572 PI_DEBUG(DBG_L2, "pyremote: Stopping scan");
00573 gapp->action_toolbar_callback(NULL, (void*)"Toolbar_Scan_Stop");
00574 return Py_BuildValue("i", 0);
00575 }
00576
00577 static PyObject* remote_waitscan(PyObject *self, PyObject *args)
00578 {
00579 PI_DEBUG(DBG_L2, "pyremote: Wait scan: commented out");
00580
00581
00582
00583
00584
00585
00586 return Py_BuildValue("i", 0);
00587 }
00588
00589 static PyObject* remote_scaninit(PyObject *self, PyObject *args)
00590 {
00591 PI_DEBUG(DBG_L2, "pyremote: Initializing scan");
00592 gapp->action_toolbar_callback(NULL, (void*)"Toolbar_Scan_Init");
00593 return Py_BuildValue("i", 0);
00594 }
00595
00596 static PyObject* remote_scanupdate(PyObject *self, PyObject *args)
00597 {
00598 PI_DEBUG(DBG_L2, "pyremote: Updating scan (hardware)");
00599 gapp->action_toolbar_callback(NULL, (void*)"Toolbar_Scan_UpdateParam");
00600 return Py_BuildValue("i", 0);
00601 }
00602
00603 static PyObject* remote_scanylookup(PyObject *self, PyObject *args)
00604 {
00605 PI_DEBUG(DBG_L2, "pyremote: Scanylookup");
00606 int value1 = 0;
00607 double value2 = 0.0;
00608 if (!PyArg_ParseTuple(args, "ld", &value1, &value2))
00609 return Py_BuildValue("i", -1);
00610 PI_DEBUG(DBG_L2, value1 << " and " << value2 );
00611 if(value1 && value2){
00612 gchar *cmd = NULL;
00613 cmd = g_strdup_printf ("2 %d %g", value1, value2);
00614 gapp->PutPluginData (cmd);
00615 gapp->action_toolbar_callback (NULL, (void*)"Toolbar_Scan_SetYLookup");
00616 g_free (cmd);
00617 }
00618 return Py_BuildValue("i", 0);
00619 }
00620
00621 static PyObject* remote_scanline(PyObject *self, PyObject *args)
00622 {
00623 PI_DEBUG(DBG_L2, "pyremote: Scan line");
00624 int value1 = 0, value2 = 0, value3 = 0;
00625 if (!PyArg_ParseTuple(args, "lll", &value1, &value2, &value3))
00626 return Py_BuildValue("i", -1);
00627 PI_DEBUG(DBG_L2, value1 << " and " << value2 << " and " << value3);
00628 PI_DEBUG(DBG_L2, "pyremote: Warning toolbar NYI");
00629 if(value1){
00630 gchar *cmd = NULL;
00631 if(value2 && value3){
00632 cmd = g_strdup_printf ("3 %d %d %d",
00633 value1,
00634 value2,
00635 value3);
00636 gapp->PutPluginData (cmd);
00637 gapp->action_toolbar_callback (NULL,(void*)"Toolbar_Scan_Partial_Line");
00638 }
00639 else{
00640 cmd = g_strdup_printf ("d %d",
00641 value1);
00642 gapp->PutPluginData (cmd);
00643 gapp->action_toolbar_callback (NULL, (void*)"Toolbar_Scan_Line");
00644 }
00645 g_free (cmd);
00646 }
00647 return Py_BuildValue("i", 0);
00648 }
00649
00651
00652
00653
00654
00655
00656
00657
00659
00660 static PyObject* remote_save(PyObject *self, PyObject *args)
00661 {
00662 PI_DEBUG(DBG_L2, "pyremote: Save");
00663 gapp->xsm->save (TRUE);
00664 return Py_BuildValue("i", 0);
00665 }
00666
00667 static PyObject* remote_saveas(PyObject *self, PyObject *args)
00668 {
00669 PI_DEBUG(DBG_L2, "pyremote: Save As ");
00670 gchar* zeile;
00671 long channel = 0;
00672 if (!PyArg_ParseTuple(args, "sl", &zeile, &channel))
00673 return Py_BuildValue("i", -1);
00674 PI_DEBUG(DBG_L2, zeile << " to Channel " << channel );
00675 if(zeile && channel)
00676 gapp->xsm->save(TRUE, zeile, channel);
00677 return Py_BuildValue("i", 0);
00678 }
00679
00680 static PyObject* remote_load(PyObject *self, PyObject *args)
00681 {
00682 PI_DEBUG(DBG_L2, "pyremote: Loading ");
00683 gchar* zeile;
00684 long channel = 0;
00685 if (!PyArg_ParseTuple(args, "si", &zeile, &channel))
00686 return Py_BuildValue("i", -1);;
00687 PI_DEBUG(DBG_L2, zeile << " to Channel " << channel );
00688 if(zeile && channel){
00689 gapp->xsm->ActivateChannel( channel );
00690 gapp->xsm->load( zeile );
00691 }
00692 return Py_BuildValue("i", 0);
00693 }
00694
00695 static PyObject* remote_import(PyObject *self, PyObject *args)
00696 {
00697 PI_DEBUG(DBG_L2, "pyremote: Importing ");
00698 gchar* zeile;
00699 long channel = 0;
00700 if (!PyArg_ParseTuple(args, "sl", &zeile, &channel))
00701 return Py_BuildValue("i", -1);
00702 PI_DEBUG(DBG_L2, zeile << " to Channel " << channel);
00703 if(zeile && channel){
00704 gapp->xsm->ActivateChannel( channel );
00705 gapp->xsm->load( zeile );
00706 }
00707 return Py_BuildValue("i", 0);
00708 }
00709
00710 static PyObject* remote_export(PyObject *self, PyObject *args)
00711 {
00712 PI_DEBUG(DBG_L2, "pyremote: Exporting ");
00713 gchar* zeile;
00714 long channel = 0;
00715 if (!PyArg_ParseTuple(args, "sl", &zeile, &channel))
00716 return Py_BuildValue("i", -1);
00717 PI_DEBUG(DBG_L2, zeile << " to Channel " << channel);
00718 if(zeile && channel){
00719 gapp->xsm->ActivateChannel( channel );
00720 gapp->xsm->gnuexport( zeile );
00721 }
00722
00723 return Py_BuildValue("i", 0);
00724 }
00725
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00741
00742 static PyObject* remote_autodisplay(PyObject *self, PyObject *args)
00743 {
00744 PI_DEBUG(DBG_L2, "pyremote: Autodisplay");
00745 gapp->xsm->AutoDisplay();
00746 return Py_BuildValue("i", 0);
00747 }
00748
00749 static PyObject* remote_chmodea(PyObject *self, PyObject *args)
00750 {
00751 PI_DEBUG(DBG_L2, "pyremote: Chmode a ");
00752 long channel = 0;
00753 if (!PyArg_ParseTuple(args, "l", &channel))
00754 return Py_BuildValue("i", -1);
00755 PI_DEBUG(DBG_L2, channel);
00756 if (channel)
00757 gapp->xsm->ActivateChannel( channel );
00758 return Py_BuildValue("i", 0);
00759 }
00760
00761 static PyObject* remote_chmodex(PyObject *self, PyObject *args)
00762 {
00763 PI_DEBUG(DBG_L2, "pyremote: Chmode x ");
00764 long channel = 0;
00765 if (!PyArg_ParseTuple(args, "l", &channel))
00766 return Py_BuildValue("i", -1);
00767 PI_DEBUG(DBG_L2, channel );
00768 if (channel)
00769 gapp->xsm->SetMode( channel, ID_CH_M_X );
00770 return Py_BuildValue("i", 0);
00771 }
00772
00773 static PyObject* remote_chmodem(PyObject *self, PyObject *args)
00774 {
00775 PI_DEBUG(DBG_L2, "pyremote: Chmode m ");
00776 long channel = 0;
00777 if (!PyArg_ParseTuple(args, "l", &channel))
00778 return Py_BuildValue("i", -1);
00779 PI_DEBUG(DBG_L2, channel );
00780 if (channel)
00781 gapp->xsm->SetMode( channel, ID_CH_M_MATH );
00782 return Py_BuildValue("i", 0);
00783 }
00784
00785 static PyObject* remote_chmoden(PyObject *self, PyObject *args)
00786 {
00787 PI_DEBUG(DBG_L2, "pyremote: Chmode n ");
00788 long channel = 0;
00789 long mode = 0;
00790 if (!PyArg_ParseTuple(args, "ll", &channel, &mode))
00791 return Py_BuildValue("i", -1);
00792 PI_DEBUG(DBG_L2, channel << " to " << mode );
00793 if (channel && mode)
00794 gapp->xsm->SetMode(channel, ID_CH_M_X+mode);
00795 return Py_BuildValue("i", 0);
00796 }
00797
00798 static PyObject* remote_chmodeno(PyObject *self, PyObject *args)
00799 {
00800 PI_DEBUG(DBG_L2, "pyremote: Chmode no ");
00801 long channel = 0;
00802 if (!PyArg_ParseTuple(args, "l", &channel))
00803 return Py_BuildValue("i", -1);
00804 PI_DEBUG(DBG_L2, channel );
00805 if (channel)
00806 gapp->xsm->SetView( channel, ID_CH_V_NO );
00807 return Py_BuildValue("i", 0);
00808 }
00809
00810 static PyObject* remote_chview1d(PyObject *self, PyObject *args)
00811 {
00812 PI_DEBUG(DBG_L2, "pyremote: Chview 1d.");
00813 long channel;
00814 if (!PyArg_ParseTuple(args, "l", &channel))
00815 return Py_BuildValue("i", -1);
00816 PI_DEBUG(DBG_L2, channel );
00817 if (channel)
00818 gapp->xsm->SetView( channel, ID_CH_V_PROFILE );
00819 return Py_BuildValue("i", 0);
00820 }
00821
00822 static PyObject* remote_chview2d(PyObject *self, PyObject *args)
00823 {
00824 PI_DEBUG(DBG_L2, "pyremote: Chview 2d");
00825 long channel;
00826 if (!PyArg_ParseTuple(args, "l", &channel))
00827 return Py_BuildValue("i", -1);
00828 PI_DEBUG(DBG_L2, channel );
00829 if (channel)
00830 gapp->xsm->SetView( channel, ID_CH_V_GREY );
00831 return Py_BuildValue("i", 0);
00832 }
00833
00834 static PyObject* remote_chview3d(PyObject *self, PyObject *args)
00835 {
00836 PI_DEBUG(DBG_L2, "pyremote: Chview 3d.");
00837 long channel;
00838 if (!PyArg_ParseTuple(args, "l", &channel))
00839 return Py_BuildValue("i", -1);
00840 PI_DEBUG(DBG_L2, channel );
00841 if (channel)
00842 gapp->xsm->SetView( channel, ID_CH_V_SURFACE );
00843 return Py_BuildValue("i", 0);
00844 }
00845
00846 static PyObject* remote_quick(PyObject *self, PyObject *args)
00847 {
00848 PI_DEBUG(DBG_L2, "pyremote: Quick");
00849 gapp->xsm->SetVM(SCAN_V_QUICK);
00850 return Py_BuildValue("i", 0);
00851 }
00852
00853 static PyObject* remote_direct(PyObject *self, PyObject *args)
00854 {
00855 PI_DEBUG(DBG_L2, "pyremote: Direkt");
00856 gapp->xsm->SetVM(SCAN_V_DIRECT);
00857 return Py_BuildValue("i", 0);
00858 }
00859
00860 static PyObject* remote_log(PyObject *self, PyObject *args)
00861 {
00862 PI_DEBUG(DBG_L2, "pyremote: Log");
00863 gapp->xsm->SetVM(SCAN_V_LOG);
00864 return Py_BuildValue("i", 0);
00865 }
00866
00868
00869
00870
00871
00872
00874
00875 static PyObject* remote_unitbz(PyObject *self, PyObject *args)
00876 {
00877 PI_DEBUG(DBG_L2, "pyremote: unitbz");
00878 gapp->xsm->SetModeFlg(MODE_BZUNIT);
00879 gapp->xsm->ClrModeFlg(MODE_VOLTUNIT);
00880 return Py_BuildValue("i", 0);
00881 }
00882 static PyObject* remote_unitvolt(PyObject *self, PyObject *args)
00883 {
00884 PI_DEBUG(DBG_L2, "pyremote: unitvolt");
00885 gapp->xsm->SetModeFlg(MODE_VOLTUNIT);
00886 gapp->xsm->ClrModeFlg(MODE_BZUNIT);
00887 return Py_BuildValue("i", 0);
00888 }
00889 static PyObject* remote_unitev(PyObject *self, PyObject *args)
00890 {
00891 PI_DEBUG(DBG_L2, "pyremote: unitev");
00892 gapp->xsm->SetModeFlg(MODE_ENERGY_EV);
00893 gapp->xsm->ClrModeFlg(MODE_ENERGY_S);
00894 return Py_BuildValue("i", 0);
00895 }
00896 static PyObject* remote_units(PyObject *self, PyObject *args)
00897 {
00898 PI_DEBUG(DBG_L2, "pyremote: units");
00899 gapp->xsm->SetModeFlg(MODE_ENERGY_S);
00900 gapp->xsm->ClrModeFlg(MODE_ENERGY_EV);
00901 return Py_BuildValue("i", 0);
00902 }
00903
00905
00906
00907
00908
00909
00910
00912
00913 static PyObject* remote_echo(PyObject *self, PyObject *args)
00914 {
00915
00916 PI_DEBUG(DBG_L2, "pyremote: Echo.");
00917 gchar* line1;
00918 if (!PyArg_ParseTuple(args, "s", &line1))
00919 return Py_BuildValue("i", -1);
00920
00921 PI_DEBUG(DBG_EVER, line1 );
00922 return Py_BuildValue("i", 0);
00923 }
00924
00925 static PyObject* remote_logev(PyObject *self, PyObject *args)
00926 {
00927
00928 PI_DEBUG(DBG_L2, "pyremote: Log ev.");
00929 gchar* zeile;
00930 if (!PyArg_ParseTuple(args, "s", &zeile))
00931 return Py_BuildValue("i", -1);
00932 if(zeile){
00933 gapp->monitorcontrol->LogEvent("RemoteLogEv", zeile);
00934 }else{
00935 gapp->monitorcontrol->LogEvent("RemoteLogEv", "--");
00936 }
00937 return Py_BuildValue("i", 0);
00938 }
00939
00940 static PyObject* remote_da0(PyObject *self, PyObject *args)
00941 {
00942
00943 PI_DEBUG(DBG_L2, "pyremote: da0 ");
00944 double channel;
00945 if (!PyArg_ParseTuple(args, "d", &channel))
00946 return Py_BuildValue("i", -1);
00947 if (channel){
00948 PI_DEBUG(DBG_L2, "Commented out.");
00949
00950 }
00951 return Py_BuildValue("i", 0);
00952 }
00953
00954 static PyObject* remote_menupath(PyObject *self, PyObject *args)
00955 {
00956
00957 PI_DEBUG(DBG_L2, "pyremote: Searching menupath ");
00958 gchar *menu1;
00959 if (!PyArg_ParseTuple(args, "s", &menu1))
00960 return Py_BuildValue("i", -1);
00961 PI_DEBUG(DBG_L2, menu1 );
00962 GtkWidget *menushell;
00963 GtkWidget *menuitem;
00964 gint pos;
00965 menushell = gnome_app_find_menu_pos (gapp->gxsmmenu, menu1, &pos);
00966 --pos;
00967 if (!menushell)
00968 return 0;
00969 PI_DEBUG(DBG_L2, "pyremote: Menu Shell Found: " << pos << " Item=" << menushell);
00970
00971 menuitem = (GtkWidget*)g_list_nth_data(GTK_MENU_SHELL (menushell) -> children, pos);
00972
00973 if (!menuitem)
00974 return 0;
00975 PI_DEBUG(DBG_L2, "pyremote: Menu Item Found: " << menuitem);
00976
00977 GdkEvent event;
00978 gint return_val;
00979 gtk_signal_emit (GTK_OBJECT(GTK_MENU_ITEM (menuitem) ),
00980 gtk_signal_lookup ("activate", GTK_OBJECT_TYPE (GTK_OBJECT(menuitem))),
00981 &event, &return_val);
00982
00983
00984
00985 return Py_BuildValue("i", 0);
00986 }
00987
00988
00989
00990
00991 static gboolean busy_sleep;
00992 gint ret_false()
00993 {
00994 gtk_main_quit();
00995 return FALSE;
00996 }
00997
00998 void sleep_ms(int ms)
00999 {
01000 if (busy_sleep) return;
01001 busy_sleep=TRUE;
01002 gtk_timeout_add(ms,(GtkFunction)ret_false,0);
01003 gtk_main();
01004 busy_sleep=FALSE;
01005 }
01006
01007 static PyObject* remote_sleep(PyObject *self, PyObject *args)
01008 {
01009 PI_DEBUG(DBG_L2, "pyremote: Sleep ");
01010 long l;
01011 if (!PyArg_ParseTuple(args, "l", &l))
01012 return Py_BuildValue("i", -1);
01013 if (l){
01014 sleep_ms(l*100);
01015 }
01016 return Py_BuildValue("i", 0);
01017 }
01018
01020
01021 static PyMethodDef EmbMethods[] = {
01022
01023 {"set", remote_set, METH_VARARGS, "Set."},
01024 {"action", remote_action, METH_VARARGS, "Action."},
01025
01026
01027 {"startscan", remote_startscan, METH_VARARGS, "Start Scan."},
01028 {"stopscan", remote_stopscan, METH_VARARGS, "Stop Scan."},
01029 {"waitscan", remote_waitscan, METH_VARARGS, "Wait Scan."},
01030 {"scaninit", remote_scaninit, METH_VARARGS, "Scaninit."},
01031 {"scanupdate", remote_scanupdate, METH_VARARGS, "Scanupdate."},
01032 {"scanylookup", remote_scanylookup, METH_VARARGS, "Scanylookup."},
01033 {"scanline", remote_scanline, METH_VARARGS, "Scan line."},
01034
01035
01036 {"save", remote_save, METH_VARARGS, "Save."},
01037 {"saveas", remote_saveas, METH_VARARGS, "Save As."},
01038 {"load", remote_load, METH_VARARGS, "Load."},
01039 {"gnuexport", remote_export, METH_VARARGS, "Export."},
01040 {"gnuimport", remote_import, METH_VARARGS, "Import."},
01041
01042
01043 {"autodisplay", remote_autodisplay, METH_VARARGS, "Autodisplay."},
01044 {"chmodea", remote_chmodea, METH_VARARGS, "Chmode A."},
01045 {"chmodex", remote_chmodex, METH_VARARGS, "Chmode X."},
01046 {"chmodem", remote_chmodem, METH_VARARGS, "Chmode M."},
01047 {"chmoden", remote_chmoden, METH_VARARGS, "Chmode N."},
01048 {"chmodeno", remote_chmodeno, METH_VARARGS, "Chmode No."},
01049 {"chview1d", remote_chview1d, METH_VARARGS, "Chview 1d."},
01050 {"chview2d", remote_chview2d, METH_VARARGS, "Chview 2d."},
01051 {"chview3d", remote_chview3d, METH_VARARGS, "Chview 3d."},
01052 {"quick", remote_quick, METH_VARARGS, "Quick."},
01053 {"direct", remote_direct, METH_VARARGS, "Direct."},
01054 {"log", remote_log, METH_VARARGS, "Log."},
01055
01056
01057 {"unitbz", remote_unitbz, METH_VARARGS, "UnitBZ."},
01058 {"unitvolt", remote_unitvolt, METH_VARARGS, "UnitVolt."},
01059 {"unitev", remote_unitev, METH_VARARGS, "UniteV."},
01060 {"units", remote_units, METH_VARARGS, "UnitS."},
01061
01062
01063 {"echo", remote_echo, METH_VARARGS, "Echo. "},
01064 {"logev", remote_logev, METH_VARARGS, "Logev. "},
01065 {"da0", remote_da0, METH_VARARGS, "Da0. "},
01066 {"menupath", remote_menupath, METH_VARARGS, "Menupath. "},
01067 {"sleep", remote_sleep, METH_VARARGS, "Sleep. "},
01068
01069 {NULL, NULL, 0, NULL}
01070 };
01071
01072
01073 int ok_button_callback( GtkWidget *widget, gpointer data)
01074 {
01075
01076 kill (getpid(), SIGINT);
01077
01078 return 0;
01079 }
01080
01081
01083 GtkWidget* create_gui_elements()
01084 {
01085 GtkWidget *mywin;
01086
01087 GtkWidget *button1;
01088
01089
01090 GtkWidget *label1;
01091
01092 mywin = gtk_dialog_new();
01093 gtk_window_set_title(GTK_WINDOW (mywin), "Press to Interrupt Python Script");
01094 label1 = gtk_label_new ("Press button to interrupt after current script-command.");
01095 button1 = gtk_button_new_with_label ("Interrupt");
01096
01097 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(mywin)->action_area),button1);
01098 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(mywin)->vbox),label1);
01099 gtk_signal_connect (GTK_OBJECT (button1), "clicked",GTK_SIGNAL_FUNC (ok_button_callback), NULL);
01100 gtk_signal_connect_object (GTK_OBJECT (button1), "clicked",
01101 GTK_SIGNAL_FUNC (gtk_widget_destroy),
01102 GTK_OBJECT (mywin));
01103 gtk_widget_show_all (mywin);
01104
01105 return(mywin);
01106 }
01108
01109
01110
01111
01112 static void pyremote_run( GtkWidget *w, void *data )
01113 {
01114 GtkWidget *remote_window;
01115 remote_window = create_gui_elements();
01116
01117 PyObject *pName, *pModule;
01118
01119 Py_Initialize();
01120 Py_InitModule("emb", EmbMethods);
01121
01122 pName = PyString_FromString("remote");
01123
01124 pModule = PyImport_Import(pName);
01125 Py_DECREF(pName);
01126
01127 if (pModule == NULL) {
01128 PyErr_Print();
01129 fprintf(stderr, "Failed to execute Module. \n");
01130 }
01131
01132 Py_Finalize();
01133 gtk_widget_destroy(remote_window);
01134 return;
01135 }
01136 #endif
01137
01138 #ifndef Py_PYTHON_H
01139 static void pyremote_run( GtkWidget *w, void *data )
01140 {
01141 PI_DEBUG_ERROR(DBG_L1, "Python is not available on your system, sorry.");
01142 return;
01143 }
01144 #endif