~ubuntu-branches/ubuntu/lucid/blender/lucid

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Draw.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-08-06 22:32:19 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806223219-8z4eej1u8levu4pz
Tags: 2.49a+dfsg-0ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: Build-depend on python-2.6 rather than python-2.5.
  - debian/misc/*.desktop: Add Spanish translation to .desktop 
    files.
  - debian/pyversions: 2.6.
  - debian/rules: Clean *.o of source/blender/python/api2_2x/
* New upstream release (LP: #382153).
* Refreshed patches:
  - 01_sanitize_sys.patch
  - 02_tmp_in_HOME
  - 10_use_systemwide_ftgl
  - 70_portability_platform_detection
* Removed patches merged upstream:
  - 30_fix_python_syntax_warning
  - 90_ubuntu_ffmpeg_52_changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
2
 
 * $Id: Draw.c 17171 2008-10-22 08:21:43Z campbellbarton $
 
2
 * $Id: Draw.c 20017 2009-05-01 14:19:56Z campbellbarton $
3
3
 *
4
4
 * ***** BEGIN GPL LICENSE BLOCK *****
5
5
 *
258
258
[tooltip=] The button's tooltip";
259
259
 
260
260
static char Method_Number_doc[] =
261
 
        "(name, event, x, y, width, height, initial, min, max, [tooltip]) - Create a \
 
261
        "(name, event, x, y, width, height, initial, min, max, [tooltip], [callback], [clickstep], [precision]) - Create a \
262
262
new Number button\n\n\
263
263
(name) A string to display on the button\n\
264
264
(event) The event number to pass to the button event function when activated\n\
266
266
(width, height) The button width and height\n\
267
267
(initial, min, max) Three values (int or float) specifying the initial and \
268
268
limit values.\n\
269
 
[tooltip=] The button's tooltip";
 
269
[tooltip=] The button's tooltip\n\
 
270
[callback=] The button's callback\n\
 
271
[clickstep=] Click step for the button\n\
 
272
[precision=] How many decimal places to maintain, if not given, it is calculated depending on range, otherwise 1,2,3 or 4. Larger values are clamped to 4";
270
273
 
271
274
static char Method_String_doc[] =
272
275
        "(name, event, x, y, width, height, initial, length, [tooltip]) - Create a \
611
614
 
612
615
        if( err ) {
613
616
                PyErr_Print(  );
 
617
                PyErr_Clear(  );
 
618
                PySys_SetObject("last_traceback", NULL);
 
619
                
614
620
                script->flags = 0;      /* mark script struct for deletion */
615
621
                SCRIPT_SET_NULL(script);
616
622
                script->scriptname[0] = '\0';
656
662
        }
657
663
 
658
664
        Py_XDECREF( result );
659
 
        Py_DECREF( args );
 
665
        Py_XDECREF( args );
660
666
}
661
667
 
662
668
/* BPY_spacescript_do_pywin_draw, the static spacescript_do_pywin_buttons and
685
691
                BPy_Set_DrawButtonsList(sc->but_refs);
686
692
                
687
693
                glPushAttrib( GL_ALL_ATTRIB_BITS );
688
 
                exec_callback( sc, script->py_draw, Py_BuildValue( "()" ) );
 
694
                exec_callback( sc, script->py_draw, NULL );
689
695
                glPopAttrib(  );
690
696
        } else {
691
697
                glClearColor( 0.4375, 0.4375, 0.4375, 0.0 );
835
841
        if (!result) {
836
842
                Py_DECREF(pyvalue);
837
843
                PyErr_Print(  );
 
844
                PyErr_Clear(  );
 
845
                PySys_SetObject("last_traceback", NULL);
838
846
                error_pyscript(  );
839
847
        }
840
848
        Py_XDECREF( result );
907
915
        exit_pydraw( sc, 0 );
908
916
 
909
917
        script = sc->script;
910
 
 
911
 
        /* remove our lock to the current namespace */
912
 
        script->flags &= ~SCRIPT_GUI;
913
 
        script->scriptname[0] = '\0';
914
 
        script->scriptarg[0] = '\0';
915
 
 
 
918
        if(script) { /* in very rare cases this can be NULL, (when saving and loading see bug #18654)*/
 
919
                /* remove our lock to the current namespace */
 
920
                script->flags &= ~SCRIPT_GUI;
 
921
                script->scriptname[0] = '\0';
 
922
                script->scriptarg[0] = '\0';
 
923
        }
916
924
        Py_RETURN_NONE;
917
925
}
918
926
 
1126
1134
        
1127
1135
        if (!result) {
1128
1136
                PyErr_Print(  );
 
1137
                PyErr_Clear(  );
 
1138
                PySys_SetObject("last_traceback", NULL);
1129
1139
                error_pyscript(  );
1130
1140
        } else {
1131
1141
                /* copied from do_clever_numbuts in toolbox.c */
1600
1610
        Button *but;
1601
1611
        PyObject *mino, *maxo, *inio;
1602
1612
        PyObject *callback=NULL;
 
1613
        PyObject *a1=NULL;
 
1614
        PyObject *a2=NULL;
1603
1615
        uiBut *ubut= NULL;
1604
1616
        
1605
1617
        if (G.background) {
1607
1619
                                              "Can't run Draw.Number() in background mode." );
1608
1620
        }
1609
1621
        
1610
 
        if( !PyArg_ParseTuple( args, "siiiiiOOO|sO", &name, &event,
1611
 
                               &x, &y, &w, &h, &inio, &mino, &maxo, &tip, &callback ) )
 
1622
        if( !PyArg_ParseTuple( args, "siiiiiOOO|sOOO", &name, &event,
 
1623
                               &x, &y, &w, &h, &inio, &mino, &maxo, &tip, &callback, &a1, &a2 ) )
1612
1624
                return EXPP_ReturnPyObjError( PyExc_TypeError,
1613
1625
                                              "expected a string, five ints, three PyObjects and\n\
1614
 
                        optionally string and callback arguments" );
 
1626
                        optionally string, callback, range and precision arguments" );
1615
1627
 
1616
1628
        UI_METHOD_ERRORCHECK;
1617
1629
 
1632
1644
                min = (float)PyFloat_AsDouble( mino );
1633
1645
                max = (float)PyFloat_AsDouble( maxo );
1634
1646
                
1635
 
                range= (float)fabs(max-min); /* Click step will be a 10th of the range. */
1636
 
                if (!range) range= 1.0f; /* avoid any odd errors */
 
1647
                if(a1 && PyNumber_Check(a1)) {
 
1648
                        if(PyFloat_Check(a1))
 
1649
                                range= (float)PyFloat_AsDouble(a1);
 
1650
                        else
 
1651
                                range= (float)PyInt_AsLong(a1);
 
1652
                } else {
 
1653
                        range= (float)fabs(max-min); /* Click step will be a 10th of the range. */
 
1654
                        if (!range) range= 1.0f; /* avoid any odd errors */
 
1655
                }
1637
1656
                
1638
 
                /* set the precission to display*/
1639
 
                if      (range>=1000.0f) precission=1.0f;
1640
 
                else if (range>=100.0f) precission=2.0f;
1641
 
                else if (range>=10.0f) precission=3.0f;
1642
 
                else precission=4.0f;
 
1657
                if(a2 && PyNumber_Check(a2)) {
 
1658
                        if(PyFloat_Check(a2))
 
1659
                                precission= (float)PyFloat_AsDouble(a2);
 
1660
                        else
 
1661
                                precission= (float)PyInt_AsLong(a2);
 
1662
                } else {
 
1663
                        /* set the precission to display*/
 
1664
                        if      (range>=1000.0f) precission=1.0f;
 
1665
                        else if (range>=100.0f) precission=2.0f;
 
1666
                        else if (range>=10.0f) precission=3.0f;
 
1667
                        else precission=4.0f;
 
1668
                        
 
1669
                        range *= 10;
 
1670
                }
1643
1671
                        
1644
1672
                but->type = BFLOAT_TYPE;
1645
1673
                but->val.asfloat = ini;
1647
1675
                
1648
1676
                if( block )
1649
1677
                        ubut= uiDefButF( block, NUM, event, name, (short)x, (short)y, (short)w, (short)h,
1650
 
                                   &but->val.asfloat, min, max, 10*range, precission, but->tooltip );
 
1678
                                   &but->val.asfloat, min, max, range, precission, but->tooltip );
1651
1679
        } else {
1652
1680
                int ini, min, max;
1653
1681