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

Window.c « api2_2x « python « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6a7bba3f85110fe93f28766bbc83eae81d331f79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* 
 *
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version. The Blender
 * Foundation also sells licenses for use in proprietary software under
 * the Blender License.  See http://www.blender.org/BL/ for information
 * about this.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 * All rights reserved.
 *
 * This is a new part of Blender.
 *
 * Contributor(s): Willian P. Germano
 *
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
*/

#include "Window.h"

/* Many parts of the code here come from the older bpython implementation
 * (file opy_window.c) */

/*****************************************************************************/
/* Function:              M_Window_Redraw                                    */
/* Python equivalent:     Blender.Window.Redraw                              */
/*****************************************************************************/
PyObject *M_Window_Redraw(PyObject *self, PyObject *args)
{ /* not static so py_slider_update in Draw.[ch] can use it */
  ScrArea *tempsa, *sa;
  SpaceText *st;
  int wintype = SPACE_VIEW3D;
  short redraw_all = 0;

  if (!PyArg_ParseTuple(args, "|i", &wintype))
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
            "expected int argument (or nothing)"));

  if (wintype < 0)
    redraw_all = 1;

  if (!during_script()) { /* XXX check this */
    tempsa= curarea;
    sa = G.curscreen->areabase.first;

    while (sa) {

      if (sa->spacetype == wintype || redraw_all) {
        /* don't force-redraw Text window (Python GUI) when
           redraw is called out of a slider update */
        if (sa->spacetype == SPACE_TEXT) {
          st = sa->spacedata.first;
          if (st->text->flags & TXT_FOLLOW) /* follow cursor display */
            pop_space_text(st);
          if (EXPP_disable_force_draw) { /* from Draw.[ch] ... */
            scrarea_queue_redraw(sa);
          }


        } else {
          scrarea_do_windraw(sa);
          if (sa->headwin) scrarea_do_headdraw(sa);
        }
      }

      sa= sa->next;
    }

    if (curarea != tempsa) areawinset (tempsa->win);

    if (curarea->headwin) scrarea_do_headdraw (curarea);

    screen_swapbuffers();
  }

  Py_INCREF(Py_None);
  return Py_None;
}

/*****************************************************************************/
/* Function:              M_Window_RedrawAll                                 */
/* Python equivalent:     Blender.Window.RedrawAll                           */
/*****************************************************************************/
static PyObject *M_Window_RedrawAll(PyObject *self, PyObject *args)
{
  return M_Window_Redraw(self, Py_BuildValue("(i)", -1));
}

/*****************************************************************************/
/* Function:              M_Window_QRedrawAll                                */
/* Python equivalent:     Blender.Window.QRedrawAll                          */
/*****************************************************************************/
static PyObject *M_Window_QRedrawAll(PyObject *self, PyObject *args)
{
  allqueue(REDRAWALL, 0);

  Py_INCREF(Py_None);
  return Py_None;
}

/*****************************************************************************/
/* Function:              M_Window_FileSelector                              */
/* Python equivalent:     Blender.Window.FileSelector                        */
/*****************************************************************************/

/* This is the callback to "activate_fileselect" below.  It receives the
 * selected filename and (using it as argument) calls the Python callback
 * provided by the script writer and stored in EXPP_FS_PyCallback. */

static void getSelectedFile(char *name)
{
  if (EXPP_FS_PyCallback) {
	  SpaceText *st= curarea->spacedata.first;

    PyObject_CallFunction((PyObject *)EXPP_FS_PyCallback, "s", name);

		EXPP_FS_PyCallback = NULL;
		st->flags &= ST_CLEAR_NAMESPACE; /* free global dictionary */
  }
}

static PyObject *M_Window_FileSelector(PyObject *self, PyObject *args)
{
  char *title = "SELECT FILE";
	SpaceText *st = curarea->spacedata.first;

  if (!PyArg_ParseTuple(args, "O!|s",
                        &PyFunction_Type, &EXPP_FS_PyCallback, &title))
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
    "\nexpected a callback function (and optionally a string) as argument(s)"));

	st->flags &= ~ST_CLEAR_NAMESPACE; /* hold global dictionary */

  activate_fileselect(FILE_BLENDER, title, G.sce, getSelectedFile);

  Py_INCREF(Py_None);
  return Py_None;
}

static PyObject *M_Window_ImageSelector(PyObject *self, PyObject *args)
{
  char *title = "SELECT IMAGE";
	SpaceText *st = curarea->spacedata.first;

  if (!PyArg_ParseTuple(args, "O!|s",
                        &PyFunction_Type, &EXPP_FS_PyCallback, &title))
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
    "\nexpected a callback function (and optionally a string) as argument(s)"));

	st->flags &= ~ST_CLEAR_NAMESPACE; /* hold global dictionary */

  activate_imageselect(FILE_BLENDER, title, G.sce, getSelectedFile);

  Py_INCREF(Py_None);
  return Py_None;
}

/*****************************************************************************/
/* Function:              M_Window_DrawProgressBar                           */
/* Python equivalent:     Blender.Window.DrawProgressBar                     */
/*****************************************************************************/
static PyObject *M_Window_DrawProgressBar(PyObject *self, PyObject *args)
{
  float done;
  char *info = NULL;
  int retval;

  if(!PyArg_ParseTuple(args, "fs", &done, &info))
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
            "expected a float and a string as arguments"));

  retval = progress_bar(done, info);

  return Py_BuildValue("i", retval);
}

/*****************************************************************************/
/* Function:              Window_Init                                        */
/*****************************************************************************/
PyObject *Window_Init (void)
{
  PyObject  *submodule, *Types;

  submodule = Py_InitModule3("Blender.Window", M_Window_methods, M_Window_doc);

  Types = Py_BuildValue("{s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h}",
                  "VIEW3D", SPACE_VIEW3D, "IPO", SPACE_IPO, "OOPS", SPACE_OOPS,
                  "BUTS", SPACE_BUTS, "FILE", SPACE_FILE, "IMAGE", SPACE_IMAGE,
                  "INFO", SPACE_INFO, "SEQ", SPACE_SEQ, "IMASEL", SPACE_IMASEL,
                  "SOUND", SPACE_SOUND, "ACTION", SPACE_ACTION,
                  "TEXT", SPACE_TEXT, "NLA", SPACE_NLA);

  if (Types) PyModule_AddObject(submodule, "Types", Types);

  return submodule;
}