UltraScan III
us_rasmol_control.cpp
Go to the documentation of this file.
1 #include <QApplication>
3 
4 #include "us_rasmol_control.h"
5 #include "us_gui_settings.h"
6 #include "us_settings.h"
7 #include "us_license_t.h"
8 #include "us_license.h"
9 
11 // the class US_RasmolControl.
12 
13 int main( int argc, char* argv[] )
14 {
15  QApplication application( argc, argv );
16 
17 #include "main1.inc"
18 
20  w.show();
21  return application.exec();
22 }
23 
25 {
26  setWindowTitle( tr( "Interface with RasMol Instances" ) );
27  setPalette( US_GuiSettings::frameColor() );
29  winmsgs = new US_WindowMessage( );
30 
31  // Main layout
32  QGridLayout* mainLayout = new QGridLayout( this );
33  mainLayout->setSpacing ( 2 );
34  mainLayout->setContentsMargins ( 2, 2, 2, 2 );
35 
36  // Lay out the controls
37  QLabel* lb_intname = us_label( tr( "Interp Name:" ) );
39  cb_intname->addItem( "rasmol-pdb" );
40  cb_intname->addItem( "rasmol-bead" );
41  cb_intname->addItem( "(other)" );
42 
43  pb_sendcmd = us_pushbutton( tr( "Send Command:" ) );
44  le_sendcmd = us_lineedit( "reset", -1, false );
45  QLabel* lb_commcmd = us_label( tr( "Send Common Command:" ) );
47  cb_commcmd->addItem( "reset" );
48  cb_commcmd->addItem( "background black" );
49  cb_commcmd->addItem( "wireframe on" );
50  cb_commcmd->addItem( "wireframe off" );
51  cb_commcmd->addItem( "backbone on" );
52  cb_commcmd->addItem( "backbone off" );
53  cb_commcmd->addItem( "spacefill on" );
54  cb_commcmd->addItem( "spacefill off" );
55  cb_commcmd->addItem( "ribbons on" );
56  cb_commcmd->addItem( "ribbons off" );
57  cb_commcmd->addItem( "strands on" );
58  cb_commcmd->addItem( "strands off" );
59  cb_commcmd->addItem( "cartoons on" );
60  cb_commcmd->addItem( "cartoons off" );
61  cb_commcmd->addItem( "set shadow on" );
62  cb_commcmd->addItem( "set shadow off" );
63 
64  QLabel* lb_results = us_label( tr( "Command Results:" ) );
66  us_setReadOnly( te_status, true );
67 
68  pb_listints = us_pushbutton( tr( "List Interps" ) );
69  pb_close = us_pushbutton( tr( "Close" ) );
70 
71  connect( cb_commcmd, SIGNAL( activated ( const QString& ) ),
72  this, SLOT( choose_command( const QString& ) ) );
73  connect( pb_sendcmd, SIGNAL( clicked() ),
74  this, SLOT ( send_command() ) );
75  connect( pb_listints, SIGNAL( clicked() ),
76  this, SLOT ( list_interps() ) );
77  connect( pb_close, SIGNAL( clicked() ),
78  this, SLOT ( close() ) );
79 
80  // Do detailed layout of the controls
81  int row = 0;
82  mainLayout->addWidget( lb_intname, row, 0, 1, 2 );
83  mainLayout->addWidget( cb_intname, row++, 2, 1, 2 );
84  mainLayout->addWidget( lb_commcmd, row, 0, 1, 2 );
85  mainLayout->addWidget( cb_commcmd, row++, 2, 1, 2 );
86  mainLayout->addWidget( pb_sendcmd, row, 0, 1, 1 );
87  mainLayout->addWidget( le_sendcmd, row++, 1, 1, 3 );
88  mainLayout->addWidget( lb_results, row++, 0, 1, 4 );
89  mainLayout->addWidget( te_status, row++, 0, 1, 4 );
90  mainLayout->addWidget( pb_listints, row, 0, 1, 2 );
91  mainLayout->addWidget( pb_close, row++, 2, 1, 2 );
92 
93  resize( 400, 300 );
94 
95  list_interps(); // Get the initial list of live interpreters
96 }
97 
98 // Execute a Send command
100 {
101  QString scmnd = le_sendcmd->text();
102  QString iname = cb_intname->currentText();
103 DbgLv(1) << "SCMD: command" << scmnd << "iname" << iname;
104 
105 #if 1
106  int errcd = winmsgs->sendMessage( iname, scmnd );
107 
108  te_status->setPlainText( errcd == 0 ?
109  tr( "Successful Send to \"%1\"\n of command \"%2\"." )
110  .arg( iname ).arg( scmnd ) :
111  winmsgs->lastSendResult() );
112 #endif
113 #if 0
114  QString resp = winmsgs->sendQuery( iname, scmnd );
115  te_status->setPlainText( resp );
116 #endif
117 }
118 
119 // Execute a chosen Send command
120 void US_RasmolControl::choose_command( const QString& scmnd )
121 {
122 DbgLv(1) << "CHCMD: command" << scmnd;
123  le_sendcmd->setText( scmnd );
124  send_command();
125 }
126 
127 // Get and list interp names
129 {
131  cb_intname->clear();
132 
133  QList< ulong > w_ids;
134  QStringList w_inames;
135 
136  int nids = winmsgs->interpIDs ( w_ids );
137  int nnames = winmsgs->interpNames( w_inames );
138 
139  if ( nids != nnames )
140  {
141  qDebug() << "*ERROR* Number of IDs does not match number of Names"
142  << nids << nnames;
143  return;
144  }
145 
146  else if ( nids == 0 )
147  {
148  te_status->setPlainText( QString( "(none)" ) );
149  return;
150  }
151 
152  QString namtext;
153 
154  for ( int ii = 0; ii < nids; ii++ )
155  {
156  if ( ii != 0 )
157  namtext += "\n";
158 
159  QString iname = w_inames[ ii ];
160  QString ientry = QString().sprintf( "%lx : ", w_ids[ ii ] ) + iname;
161 
162  cb_intname->addItem( iname ); // Add name to combo box list
163  namtext += ientry; // Add line to status text
164  }
165 
166  QStringList zombies;
167  int nzomb = winmsgs->zombieList( zombies );
168 
169  if ( nzomb > 0 )
170  { // If zombies exist, list them in the status box
171  namtext += tr( "\n\nZombie Interpreters:" );
172 
173  for ( int ii = 0; ii < nzomb; ii++ )
174  {
175  namtext += "\n" + zombies[ ii ];
176  }
177  }
178 
179  // Populate command result list
180  te_status->setPlainText( namtext ); // Pure results in status box
181 
182 }
183