Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorWillian Padovani Germano <wpgermano@gmail.com>2004-06-16 05:18:57 +0400
committerWillian Padovani Germano <wpgermano@gmail.com>2004-06-16 05:18:57 +0400
commitddec3db89d10ac84f1e2c3cdd7a2fcd5134b46f2 (patch)
treec97e11db3a2c57719d5c449cecd387bdc2fe00a4 /source
parent23165676b7cfa91c6e4b4a2e4975b09623659e79 (diff)
- New Blender.Draw method by Campbell Barton (Cam / ideasman):
PupStrInput, a wrapper for the Blender String popup (thanks!) - Fixed bug #1374 reported by Gabriel Beloin (gabio, thanks too): http://projects.blender.org/tracker/?func=detail&atid=125&aid=1374&group_id=9 There was a minor mistake in the import menu: vrml called dxf and vice-versa and shortcuts were wrong (removed them). - Doc updates, minor updates elsewhere.
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/api2_2x/Draw.c73
-rw-r--r--source/blender/python/api2_2x/Draw.h4
-rw-r--r--source/blender/python/api2_2x/Sys.c14
-rw-r--r--source/blender/python/api2_2x/doc/Draw.py39
-rw-r--r--source/blender/python/api2_2x/doc/Sys.py2
-rw-r--r--source/blender/src/header_info.c8
6 files changed, 106 insertions, 34 deletions
diff --git a/source/blender/python/api2_2x/Draw.c b/source/blender/python/api2_2x/Draw.c
index f22f9b7aeae..0a7d7e6f0da 100644
--- a/source/blender/python/api2_2x/Draw.c
+++ b/source/blender/python/api2_2x/Draw.c
@@ -45,6 +45,7 @@
#include "BLI_winstuff.h"
#endif
+#include "BLI_blenlib.h"
#include "MEM_guardedalloc.h"
#include "BMF_Api.h"
@@ -107,9 +108,10 @@ static PyObject *Method_String (PyObject * self, PyObject * args);
static PyObject *Method_GetStringWidth (PyObject * self, PyObject * args);
static PyObject *Method_Text (PyObject * self, PyObject * args);
static PyObject *Method_PupMenu (PyObject * self, PyObject * args);
-/* next two by Campbell: */
+/* next three by Campbell: */
static PyObject *Method_PupIntInput (PyObject * self, PyObject * args);
static PyObject *Method_PupFloatInput (PyObject * self, PyObject * args);
+static PyObject *Method_PupStrInput (PyObject * self, PyObject * args);
static uiBlock *Get_uiBlock (void);
static void py_slider_update (void *butv, void *data2_unused);
@@ -150,7 +152,8 @@ static char Method_Button_doc[] =
(event) The event number to pass to the button event function when activated\n\
(x, y) The lower left coordinate of the button\n\
(width, height) The button width and height\n\
-[tooltip=] The button's tooltip";
+[tooltip=] The button's tooltip\n\n\
+This function can be called as Button() or PushButton().";
static char Method_Menu_doc[] =
"(name, event, x, y, width, height, default, [tooltip]) - Create a new Menu \
@@ -251,18 +254,25 @@ Ex: Draw.PupMenu('OK?%t|QUIT BLENDER') # should be familiar ...";
static char Method_PupIntInput_doc[] =
"(text, default, min, max) - Display an int pop-up input.\n\
-(text) - text string to display at the button;\n\
+(text) - text string to display on the button;\n\
(default, min, max) - the default, min and max int values for the button;\n\
-Return the value selected or None";
+Return the user input value or None on user exit";
static char Method_PupFloatInput_doc[] =
"(text, default, min, max, clickStep, floatLen) - Display a float pop-up input.\n\
-(text) - text string to display at the button;\n\
+(text) - text string to display on the button;\n\
(default, min, max) - the default, min and max float values for the button;\n\
(clickStep) - float increment/decrement for each click on the button arrows;\n\
(floatLen) - an integer defining the precision (number of decimal places) of \n\
the float value show.\n\
-Return the value selected or None";
+Return the user input value or None on user exit";
+
+static char Method_PupStrInput_doc[] =
+"(text, default, max = 20) - Display a float pop-up input.\n\
+(text) - text string to display on the button;\n\
+(default) - the initial string to display (truncated to 'max' chars);\n\
+(max = 20) - The maximum number of chars the user can input;\n\
+Return the user input value or None on user exit";
static char Method_Exit_doc[] = "() - Exit the windowing interface";
@@ -293,10 +303,12 @@ static struct PyMethodDef Draw_methods[] = {
MethodDef (PupMenu),
MethodDef (PupIntInput),
MethodDef (PupFloatInput),
+ MethodDef (PupStrInput),
MethodDef (Exit),
MethodDef (Redraw),
MethodDef (Draw),
MethodDef (Register),
+ {"PushButton", Method_Button, METH_VARARGS, Method_Button_doc},
{NULL, NULL,0,NULL}
};
@@ -356,7 +368,7 @@ static int Button_setattr (PyObject *self, char *name, PyObject *v)
/* if the length of the new string is the same as */
/* the old one, just copy, else delete and realloc. */
if (but->slen == strlen (newstr)) {
- strncpy (but->val.asstr, newstr, but->slen);
+ BLI_strncpy (but->val.asstr, newstr, but->slen);
}
else {
MEM_freeN (but->val.asstr);
@@ -1084,10 +1096,10 @@ static PyObject *Method_PupMenu (PyObject *self, PyObject *args)
static PyObject *Method_PupIntInput (PyObject *self, PyObject *args)
{
- char *text;
- int min, max;
- short var;
- PyObject *ret;
+ char *text = NULL;
+ int min = 0, max = 1;
+ short var = 0;
+ PyObject *ret = NULL;
if (!PyArg_ParseTuple (args, "s|hii", &text, &var, &min, &max))
return EXPP_ReturnPyObjError (PyExc_TypeError,
@@ -1105,9 +1117,9 @@ static PyObject *Method_PupIntInput (PyObject *self, PyObject *args)
static PyObject *Method_PupFloatInput (PyObject *self, PyObject *args)
{
- char *text;
- float min, max, var, a1, a2;
- PyObject *ret;
+ char *text = NULL;
+ float min = 0, max = 1, var = 0, a1 = 10, a2 = 2;
+ PyObject *ret = NULL;
if (!PyArg_ParseTuple (args, "s|fffff", &text, &var, &min, &max, &a1, &a2))
return EXPP_ReturnPyObjError (PyExc_TypeError,
@@ -1123,6 +1135,39 @@ static PyObject *Method_PupFloatInput (PyObject *self, PyObject *args)
return EXPP_ReturnPyObjError (PyExc_MemoryError, "couldn't create a PyFloat");
}
+static PyObject *Method_PupStrInput (PyObject *self, PyObject *args)
+{
+ char *text = NULL, *textMsg = NULL;
+ char tmp[101];
+ char max = 20;
+ PyObject *ret = NULL;
+
+ if (!PyArg_ParseTuple (args, "ss|b", &textMsg, &text, &max))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected 2 strings and 1 int");
+
+ if ((max <= 0) || (max > 100))
+ return EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "max string length value must be in the range [1, 100].");
+
+ /* copying the text string handles both cases:
+ * max < strlen(text) (by truncating) and
+ * max > strlen(text) (by expanding to strlen(tmp)) */
+ BLI_strncpy(tmp, text, max);
+
+ if (sbutton (tmp, 0, max, textMsg) == 0) {
+ Py_INCREF (Py_None);
+ return Py_None;
+ }
+
+ ret = Py_BuildValue ("s", tmp);
+
+ if (ret) return ret;
+
+ return EXPP_ReturnPyObjError(PyExc_MemoryError, "couldn't create a PyString");
+}
+
+
PyObject *Draw_Init (void)
{
PyObject *submodule, *dict;
diff --git a/source/blender/python/api2_2x/Draw.h b/source/blender/python/api2_2x/Draw.h
index b04fb5eb0ef..fbf2fb85c0e 100644
--- a/source/blender/python/api2_2x/Draw.h
+++ b/source/blender/python/api2_2x/Draw.h
@@ -56,8 +56,8 @@ void initDraw (void);
typedef struct _Button
{
PyObject_VAR_HEAD /* required Py Macro */
- int type; /*@ 1 == int, 2 == float, 3 == string */
- int slen; /*@ length of string (if type == 3) */
+ int type; /*@ 1 == int, 2 == float, 3 == string */
+ unsigned int slen; /*@ length of string (if type == 3) */
union
{
int asint;
diff --git a/source/blender/python/api2_2x/Sys.c b/source/blender/python/api2_2x/Sys.c
index b2c133d6881..a7356d39639 100644
--- a/source/blender/python/api2_2x/Sys.c
+++ b/source/blender/python/api2_2x/Sys.c
@@ -158,7 +158,7 @@ static PyObject *M_sys_basename (PyObject *self, PyObject *args)
if (n > FILE_MAXFILE)
return EXPP_ReturnPyObjError(PyExc_RuntimeError, "path too long");
- strncpy(basename, p+1, n); /* + 1 to skip the sep */
+ BLI_strncpy(basename, p+1, n); /* + 1 to skip the sep */
basename[n] = '\0';
return Py_BuildValue("s", basename);
}
@@ -190,7 +190,7 @@ static PyObject *M_sys_dirname (PyObject *self, PyObject *args)
if (n > FILE_MAXDIR)
return EXPP_ReturnPyObjError (PyExc_RuntimeError, "path too long");
- strncpy(dirname, name, n);
+ BLI_strncpy(dirname, name, n);
dirname[n] = '\0';
return Py_BuildValue("s", dirname);
}
@@ -233,9 +233,9 @@ static PyObject *M_sys_splitext (PyObject *self, PyObject *args)
if (n > FILE_MAXFILE || (len - n ) > FILE_MAXFILE)
EXPP_ReturnPyObjError(PyExc_RuntimeError, "path too long");
- strncpy(ext, dot, n);
+ BLI_strncpy(ext, dot, n);
ext[n] = '\0';
- strncpy(path, name, dot - name);
+ BLI_strncpy(path, name, dot - name);
path[dot - name] = '\0';
return Py_BuildValue("ss", path, ext);
@@ -271,11 +271,11 @@ static PyObject *M_sys_makename(PyObject *self, PyObject *args, PyObject *kw)
if (p && strip) {
n = path + len - p - 1; /* - 1 because we don't want the sep */
- strncpy(basename, p+1, n); /* + 1 to skip the sep */
+ BLI_strncpy(basename, p+1, n); /* + 1 to skip the sep */
basename[n] = 0;
}
else {
- strncpy(basename, path, len);
+ BLI_strncpy(basename, path, len);
n = len;
basename[n] = '\0';
}
@@ -291,7 +291,7 @@ static PyObject *M_sys_makename(PyObject *self, PyObject *args, PyObject *kw)
if (dot) n = dot - basename;
else n = strlen(basename);
- strncpy(basename + n, ext, lenext);
+ BLI_strncpy(basename + n, ext, lenext);
basename[n+lenext] = '\0';
}
}
diff --git a/source/blender/python/api2_2x/doc/Draw.py b/source/blender/python/api2_2x/doc/Draw.py
index 363104f43ea..aa95dbb2337 100644
--- a/source/blender/python/api2_2x/doc/Draw.py
+++ b/source/blender/python/api2_2x/doc/Draw.py
@@ -6,6 +6,8 @@ The Blender.Draw submodule.
Draw
====
+B{New}: L{PupIntInput}, L{PupFloatInput}, L{PupStrInput}.
+
This module provides access to a B{windowing interface} in Blender. Its widgets
include many kinds of buttons: push, toggle, menu, number, string, slider,
scrollbar, plus support for text drawing. It also includes keyboard keys and
@@ -73,6 +75,8 @@ not necessary to re-register the callbacks, they will stay until Draw.Exit
is called. It's enough to redraw the screen when a relevant event is caught.
Apologies for the confusion.
+@note: function Button has a new alias: L{PushButton}.
+
@warn: Inside the windowing loop (after Draw.Register() has been executed and
before Draw.Exit() is called), don't use the redraw functions from other
modules (Blender and Window). The Draw submodule has its own Draw.Redraw() and
@@ -124,11 +128,9 @@ def Create(value):
@return: The Button created.
"""
-def Button_(name, event, x, y, width, height, tooltip = None):
+def PushButton(name, event, x, y, width, height, tooltip = None):
"""
- Create a new (push) Button object. Please note there is no '_' character at the end of 'Button'.
- This is due to a bug in our doc generation program. Use Button(....) instead.
- And stop laughing.
+ Create a new (push) Button object.
@type name: string
@param name: The string to display on the button.
@type event: int
@@ -145,6 +147,10 @@ def Button_(name, event, x, y, width, height, tooltip = None):
@type tooltip: string
@param tooltip: The button's tooltip (the string that appears when the mouse
is kept over the button).
+ @note: This function used to be called only "Button". We added an
+ alternative alias to avoid a name clash with the L{Button} class/type that
+ caused trouble in this documentation's generation. The old name shouldn't
+ be deprecated, use Button or PushButton (better) at your choice.
"""
def PupMenu(name, maxrow = None):
@@ -193,7 +199,7 @@ def PupIntInput(text, default, min, max):
@type text: string
@param text: The text that is displayed in the popup.
@type default: int
- @param default: The value that the popup is set to initialy.
+ @param default: The value that the popup is set to initially.
@type min: int
@param min: The lowest value the popup will allow.
@type max: int
@@ -225,7 +231,7 @@ def PupFloatInput(text, default, min, max, clickStep, floatLen):
@type text: string
@param text: The text that is displayed in the popup.
@type default: float
- @param default: The value that the popup is set to initialy.
+ @param default: The value that the popup is set to initially.
@type min: float
@param min: The lowest value the popup will allow.
@type max: float
@@ -238,6 +244,27 @@ def PupFloatInput(text, default, min, max, clickStep, floatLen):
@return: the number chosen or None if none was chosen.
"""
+def PupStrInput(text, default, max = 20):
+ """
+ Create a string input pop-up.
+
+ This allows python to use Blender's string popup input.
+
+ Example::
+ Blender.Draw.PupStrInput("Name:", "untitled", 25)
+
+ @type text: string
+ @param text: The text that is displayed in the popup.
+ @type default: string
+ @param default: The value that the popup is set to initially. If it's longer
+ then 'max', it's truncated.
+ @type max: int
+ @param max: The most characters the popup input will allow. If not given
+ it defaults to 20 chars. It should be in the range [1, 100].
+ @rtype: string
+ @return: The text entered by the user or None if none was chosen.
+ """
+
def Menu(name, event, x, y, width, height, default, tooltip = None):
"""
Create a new Menu Button object.
diff --git a/source/blender/python/api2_2x/doc/Sys.py b/source/blender/python/api2_2x/doc/Sys.py
index d969fe545b4..9792d3fd278 100644
--- a/source/blender/python/api2_2x/doc/Sys.py
+++ b/source/blender/python/api2_2x/doc/Sys.py
@@ -6,7 +6,7 @@ The Blender.sys submodule.
sys
===
-B{New}: L{exists}
+B{New}: L{exists}, L{makename}.
This module provides a minimal set of helper functions and data. Its purpose
is to avoid the need for the standard Python module 'os', in special 'os.path',
diff --git a/source/blender/src/header_info.c b/source/blender/src/header_info.c
index 49b87cf7f66..84efce73579 100644
--- a/source/blender/src/header_info.c
+++ b/source/blender/src/header_info.c
@@ -715,11 +715,11 @@ static uiBlock *info_file_importmenu(void *arg_unused)
uiBlockSetButmFunc(block, do_info_file_importmenu, NULL);
//uiBlockSetXOfs(block, -50); // offset to parent button
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VRML 1.0...|Ctrl F2",
- 0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "DXF...|Shift F2",
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VRML 1.0...",
0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VideoScape...|Alt W",
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "DXF...",
+ 0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, "");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VideoScape...",
0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "STL...",
0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 3, "");