Exemplo n.º 1
0
// python.exec function: execute a python command through a maxscript string
Value*
exec_cf( Value** arg_list, int count ) {
    // Step 1: make sure the arguments supplied are correct in count
    check_arg_count( python.exec, 1, count );

    // Step 2: protect the maxscript memory
    MXS_PROTECT(one_value_local(mxs_command));
    MXS_EVAL( arg_list[0], vl.mxs_command );

    // Step 2: create a python file based on the filename
    const MCHAR* command	= NULL;
    try {
        command	= vl.mxs_command->to_string();
    }
    MXS_CATCHERRORS();

    // Step 3: check to make sure the command is valid
    if ( !command ) {
        MXS_CLEANUP();
        return &false_value;
    }

    {
        MCharToPyString ascii(command);
        if( ascii.pyString() )
            PyRun_SimpleString( ascii.data() );

        PY_ERROR_PROPAGATE_MXS_CLEANUP();
    }

    // Step 5: cleanup the memory
    MXS_CLEANUP();

    return &ok;
}
Exemplo n.º 2
0
BOOL
FooControl::handle_message(Rollout *ro, UINT message, WPARAM wParam, LPARAM lParam)
{
	if (message == CC_SPINNER_CHANGE)
	{
		one_value_local(arg);
		/* handle CC_SPINNER_CHANGE message received for this control - call my _T('changed') event handler with
		 * with the current spinner value as the argument */
		if (spin_type == EDITTYPE_INT)
		{
			value = (float)((ISpinnerControl *)lParam)->GetIVal();
			vl.arg = Integer::intern((int)value);
		}
		else
			vl.arg = Float::intern(value = ((ISpinnerControl *)lParam)->GetFVal()); 
		try
		{
			call_event_handler(ro, n_changed, &vl.arg, 1);
		}
		catch (...)
		{
   			SendMessage(GetDlgItem(ro->page, control_ID), WM_LBUTTONUP, 0, 0); // on error, force a buttonup to release the spinner
			throw;
		}
		pop_value_locals();
		return TRUE;
	}
	return FALSE;
}
Exemplo n.º 3
0
// ============================================================================
void AngleControl::CallChangedHandler()
{
   init_thread_locals();
   push_alloc_frame();
   one_value_local(arg);
   vl.arg = Float::intern(m_degrees);
   run_event_handler(parent_rollout, n_changed, &vl.arg, 1);
   pop_value_locals();
   pop_alloc_frame();
}
Exemplo n.º 4
0
// __getattr__: get an item from the maxscript globals hash table
static PyObject*
mxs_getattro( PyObject* self, PyObject* key ) {
	// Step 1: convert the key to a name
	//mprintf( _T("mxs_getattro entered\n") );
	MXS_PROTECT(one_value_local(name));
	PyStringToMCHAR mkey(key);
	vl.name = Name::intern( mkey.mchar() );
	// Step 2: collect the PyObject* instance
	PyObject * output = ObjectWrapper::py_intern( globals->get( vl.name ) );
	MXS_CLEANUP();
	//mprintf( _T("mxs_getattro leaving\n") );

	return output;
}
Exemplo n.º 5
0
// python.reload function: reload an existing module in maxscript
Value*
reload_cf( Value** arg_list, int count ) {
    // Step 1: make sure the arguments supplied are correct in count
    check_arg_count( python.reload, 1, count );

    // Step 2: evaluate the input item
    MXS_PROTECT(one_value_local(mxs_check));
    MXS_EVAL( arg_list[0], vl.mxs_check );

    // Step 3: make sure the item is a proper type
    if ( is_objectwrapper(vl.mxs_check) ) {
        PyImport_ReloadModule( ((ObjectWrapper*) vl.mxs_check)->object() );
        PY_ERROR_PROPAGATE_MXS_CLEANUP();
    }
    else {
        mprintf( _T("python.reload() error: you need to supply a valid python module to reload\n") );
    }

    MXS_CLEANUP();
    return &ok;
}
Exemplo n.º 6
0
// python.run function: run a python file from maxscript
Value*
run_cf( Value** arg_list, int count ) {
    // Step 1: make sure the arguments supplied are correct in count
    check_arg_count( python.run, 1, count );

    // Step 2: protect the maxscript memory
    MXS_PROTECT(one_value_local(mxs_filename));
    MXS_EVAL( arg_list[0], vl.mxs_filename );

    // Step 2: create a python file based on the filename
    const MCHAR * filename	= vl.mxs_filename->to_string();
    //mprintf( _T("Got Filename to run: %s\n"), filename );

    MCharToPyString pys(filename);
    PyObject* args = PyTuple_New(2);
    PyTuple_SET_ITEM(args,0,pys.pyStringRef());
    PyTuple_SET_ITEM(args,1,PyString_FromString("r"));
    //mprintf( _T("Arg tuple created, creating python file object\n") );

    PyObject* py_file = PyObject_Call((PyObject*)&PyFile_Type, args, NULL);
    Py_DECREF(args);
    if( !py_file ) {
        mprintf( _T("Call to python file object creation failed\n") );
        PY_ERROR_PROPAGATE_MXS_CLEANUP();
        return &false_value;
    }

    //mprintf( _T("File opened, calling PyRun_SimpleFile\n") );
    // Step 4: run the file
    PyRun_SimpleFile( PyFile_AsFile(py_file), pys.data() );

    //mprintf( _T("File ran, cleaning up\n") );
    // Step 5: cleanup the memory
    Py_DECREF( py_file );
    PY_ERROR_PROPAGATE_MXS_CLEANUP();

    return &true_value;
}
Exemplo n.º 7
0
LRESULT CALLBACK ish3_ProgressBar::WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
   // Get back at our stored class pointer
   ish3_ProgressBar *UGC = DLGetWindowLongPtr<ish3_ProgressBar*>(hWnd);
   if(UGC == NULL && message != WM_CREATE)
      return DefWindowProc(hWnd, message, wParam, lParam);

   switch ( message ) {
   
      case WM_CREATE:
         {
            LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
            UGC = (ish3_ProgressBar*)lpcs->lpCreateParams;
            DLSetWindowLongPtr(hWnd, UGC);
            break;
         }

      case WM_MOUSEMOVE:
         {
         if(wParam && MK_LBUTTON)
         {
            init_thread_locals();
            push_alloc_frame();
            one_value_local(arg);
            // work out a positional click value and fire a 'clicked' event
            int xPos = LOWORD(lParam);
            int yPos = HIWORD(lParam);
            Rect rect;
            GetClientRect(hWnd,&rect);
            float fDelta = 0.0f;

            if(UGC->type==TYPE_HORIZ)
            {
               int rWide = (rect.right-1)-(rect.left+2);

               float Delta = 100.0f/rWide;
               fDelta = Delta*xPos;
            }
            if(UGC->type==TYPE_VERT)
            {
               int rHigh = (rect.bottom)-(rect.top);

               float Delta = 100.0f/rHigh;
               fDelta = Delta*(rHigh-yPos);
            }
            
            vl.arg = Integer::intern((int)fDelta);
            UGC->run_event_handler(UGC->parent_rollout, n_clicked, &vl.arg, 1);
            pop_value_locals();
            pop_alloc_frame();
         }

         if(UGC->enabled)
            SetCursor(LoadCursor(NULL, IDC_ARROW));
         }
      break;

      case WM_LBUTTONDOWN:
         {
            init_thread_locals();
            push_alloc_frame();
            one_value_local(arg);
            // ditto - just wanted to handle first time clicks
            int xPos = LOWORD(lParam);
            int yPos = HIWORD(lParam);
            Rect rect;
            GetClientRect(hWnd,&rect);
            float fDelta = 0.0f;

            if(UGC->type==TYPE_HORIZ)
            {
               int rWide = (rect.right-1)-(rect.left+2);

               float Delta = 100.0f/rWide;
               fDelta = Delta*xPos;
            }
            if(UGC->type==TYPE_VERT)
            {
               int rHigh = (rect.bottom)-(rect.top);

               float Delta = 100.0f/rHigh;
               fDelta = Delta*(rHigh-yPos);
            }
            
            vl.arg = Integer::intern((int)fDelta);
            UGC->run_event_handler(UGC->parent_rollout, n_clicked, &vl.arg, 1);
            pop_value_locals();
            pop_alloc_frame();
         }
         break;

	  case WM_RBUTTONUP:
		  UGC->call_event_handler(UGC->parent_rollout, n_rightClick, NULL, 0);
		  break;

      case WM_PAINT:
         {
            // begin paint cycle
            PAINTSTRUCT ps;
            HDC hdc;
            hdc = BeginPaint( hWnd, &ps );

            Rect rect;
            GetClientRect(hWnd,&rect);


            // Setup pens, brushes and colours
            SetBkColor( hdc, GetCustSysColor( COLOR_BTNFACE ) );
            SetBkMode( hdc, TRANSPARENT );   
            HPEN hLight = CreatePen( PS_SOLID, 0, GetCustSysColor( COLOR_BTNHIGHLIGHT ) );
            HPEN hBlack = (HPEN)GetStockObject(BLACK_PEN);
            HPEN hDark  = CreatePen( PS_SOLID, 0, GetCustSysColor( COLOR_BTNSHADOW ) );   

            // setup the progress bar colour, taking enabled flag into account
            HBRUSH hProgress;
            if(UGC->enabled)
             hProgress = CreateSolidBrush( UGC->colorPro );
            else hProgress = CreatePatternBrush( LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_DISABLED)) );

            HPEN hPP;
            if(UGC->enabled)
               hPP = CreatePen( PS_SOLID, 0, UGC->colorPro );
            else hPP = CreatePen( PS_SOLID, 0, GetCustSysColor( COLOR_BTNFACE ) );

            // the 'blanker' definition
            HBRUSH hProgressTerm = CreateSolidBrush( GetCustSysColor( COLOR_BTNFACE ) );
            HPEN hPT = CreatePen( PS_SOLID, 0, GetCustSysColor( COLOR_BTNFACE ) );


            // Do some 3D control drawing (frame)
            SelectObject(hdc, hDark);

            MoveToEx(hdc, rect.right-1, 0, NULL);
            LineTo  (hdc, 0, 0);
            LineTo  (hdc, 0, rect.bottom-1);

            SelectObject(hdc, hBlack);

            MoveToEx(hdc, rect.right-2, 1, NULL);
            LineTo  (hdc, 1, 1);
            LineTo  (hdc, 1, rect.bottom-2);

            SelectObject(hdc, hLight);

            MoveToEx(hdc, 0, rect.bottom-1, NULL);
            LineTo  (hdc, rect.right-1, rect.bottom-1);
            LineTo  (hdc, rect.right-1, 0 );

      // HORIZONTAL DRAW
      if(UGC->type==TYPE_HORIZ)
      {

            // prepare progress bar
            float delta = (float)((rect.right-rect.left)-1)/100.0f;
            int amt     = UGC->value;
            int draw = (int)(amt*delta);

            // handle extremities
            if(amt==100)   draw = ((rect.right-rect.left)-1);
            if(amt==0)     draw = rect.left+1;
            if(draw<=2) draw=2;


            // blit out unused to background
            if(amt!=100)
            {

               HGDIOBJ hOldPen = SelectObject(hdc, hPT);
               HGDIOBJ hOldBrush = SelectObject(hdc, hProgressTerm);
               Rectangle(hdc,draw,2,rect.right-1,rect.bottom-2);
			   SelectObject(hdc, hOldPen);
			   SelectObject(hdc, hOldBrush);
          }

            // draw progress bar
            if(amt>0)
            {
               HGDIOBJ hOldPen = SelectObject(hdc, hPP);
               HGDIOBJ hOldBrush = SelectObject(hdc, hProgress);
               Rectangle(hdc,2,2,draw,rect.bottom-2);
			   SelectObject(hdc, hOldPen);
			   SelectObject(hdc, hOldBrush);
            }
      }
      // VERTICAL DRAW
      if(UGC->type==TYPE_VERT)
      {

            // prepare progress bar
            float delta = (float)((rect.bottom-rect.top)-4)/100.0f;
            int amt     = UGC->value;
            int draw = (int)(amt*delta);

            // handle extremities
            if(amt==100)   draw = ((rect.bottom-rect.top)-4);
            if(amt==0)     draw = 0;//rect.bottom-2;

            
            // blit out unused to background
            if(amt!=100)
            {
               HGDIOBJ hOldPen = SelectObject(hdc, hPT);
               HGDIOBJ hOldBrush = SelectObject(hdc, hProgressTerm);
               Rectangle(hdc,2,rect.top+2,rect.right-2,(rect.bottom-2)-draw);
			   SelectObject(hdc, hOldPen);
			   SelectObject(hdc, hOldBrush);
            }

            // draw progress bar
            if(amt>0)
            {
               HGDIOBJ hOldPen = SelectObject(hdc, hPP);
               HGDIOBJ hOldBrush = SelectObject(hdc, hProgress);
               Rectangle(hdc,2,rect.bottom-2,rect.right-2,(rect.bottom-2)-draw);
			   SelectObject(hdc, hOldPen);
			   SelectObject(hdc, hOldBrush);
            }
      }

            DeleteObject(hLight);
            DeleteObject(hDark);
            DeleteObject(hBlack);
            DeleteObject(hPP);
            DeleteObject(hPT);
            DeleteObject(hProgress);
            DeleteObject(hProgressTerm);

            // end paint cycle
            EndPaint( hWnd, &ps );
            return 0;
         }

   }

   return TRUE;
}