[pygtk] Whole-app cursor setting patch revisited

2000-10-27 Thread Stephan R.A. Deibel

Hi,

Here is a patch for pygtk that exposes some of the lower-level gdk_window
functionality (creation of a gdk_window, show, hide,  destroy) to Python.

The motivation for this was a need to use an INPUT_ONLY GDK window to set
the cursor on the entire surface of a window, and to block mouse and
keyboard interaction with that window during that time (as you would when
the GUI is going to be unresponsive for a while due to some more lengthy
syncronous operation).

This could be used for other things as well, wherever there is a need to
temporarily overlay an existing window with an event-trapping transparent
window.

With this patch, you can now say something like this to set up a watch
cursor on any gtk_window:

  gdk_window = my_gtkwindow.get_window()
  attribs = { 'wmclass': GDK.INPUT_ONLY,
  'window_type': GDK.WINDOW_CHILD,
  'event_mask': 0,
  'x': 0,
  'y': 0,
  'width': gtk.screen_width(),
  'height': gtk.screen_height() }
  cursor_win = gtk.gdk_window_new(gdk_window, attribs)
  gdk_cursor = gtk.cursor_new(GDK.WATCH)
  cursor_win.set_cursor(gdk_cursor)
  cursor_win._show()

To set things back to normal you do this:

  cursor_win._hide()

To show the watch again later:

  cursor_win._show()

And when you're done with the cursor-setting window you say:

  cursor_win.destroy()
  cursor_win = None

This patch replaces the one that was sent by me to this list on Fri, 20
Oct 2000 20:28:38 -0400 (EDT).  It is a cdiff based on a somewhat modified
pygtk 0.6.5, so may not apply automatically.  But hopefully it's not too
hard to figure out, since it's just a set of added functions in several
files.  The 'WINGIDE_EXTENSION' ifdefs and comments can of course be
removed.

Please let me know if you have any questions or run into any problems
with this.

I hope that it's something that can be considered for a future version
of pygtk.

Thanks,

- Stephan


Archaeopteryx Software, Inc.Wing IDE for Python 
www.archaeopteryx.com   Take Flight!


Index: GDK.py
===
RCS file: /home/cvs/src/ide/external/pygtk-0.6.5-wing/GDK.py,v
retrieving revision 1.1
diff -c -r1.1 GDK.py
*** GDK.py  2000/03/13 18:45:37 1.1
--- GDK.py  2000/10/27 15:04:30
***
*** 294,299 
--- 294,313 
  XTERM = 152
  CURSOR_IS_PIXMAP = -1
  
+ # WINGIDE_EXTENSIONS
+ # GdkWindowClass's
+ INPUT_OUTPUT = 0
+ INPUT_ONLY = 1
+ 
+ # GdkWindowType's
+ WINDOW_ROOT = 0
+ WINDOW_TOPLEVEL = 1
+ WINDOW_CHILD = 2
+ WINDOW_DIALOG = 3
+ WINDOW_TEMP = 4
+ WINDOW_PIXMAP = 5
+ WINDOW_FOREIGN = 6
+ # END WINGIDE_EXTENSIONS
  
  # these are the Key Symbols for GDK
  # they were created with sed -n 's/#define GDK)\([^ ]*\)/\1 =/p' gdkkeysyms.h
Index: gtk.py
===
RCS file: /home/cvs/src/ide/external/pygtk-0.6.5-wing/gtk.py,v
retrieving revision 1.8
diff -c -r1.8 gtk.py
*** gtk.py  2000/09/25 19:47:24 1.8
--- gtk.py  2000/10/27 15:04:41
***
*** 2738,2743 
--- 2738,2769 
  keyval_to_upper = _gtk.gdk_keyval_to_upper
  keyval_to_lower = _gtk.gdk_keyval_to_lower
  
+ # WINGIDE_EXTENSIONS
+ # Low-level function to create new gdk window
+ def gdk_window_new(parent, attribs):
+   """ Creates a new gdk window which must be destroyed with an
+   explicit call to the _destroy() method.  parent is the new 
+   window's parent PyGdkWindow or None if the window should be a 
+   child of the root window.  attribs must be a dictionary of 
+   attribute values for the window; the following attribs must 
+   be specified:
+ window_type -- GDK.WINDOW_TOPLEVEL, GDK.WINDOW_CHILD
+GDK.WINDOW_DIALOG, GDK.WINDOW_TEMP
+GDK.WINDOW_PIXMAP, or GDK.WINDOW_FOREIGN
+ event_mask -- the events to get
+ width -- width of window
+ height -- height of window
+   The following attributes are optional:
+ wmclass -- GDK.INPUT_OUTPUT or GDK.INPUT_ONLY
+ x -- x offset from parent
+ y -- y offset from parent
+ colormap -- PyGdkColormap to use to interpret colors
+ override_redirect -- see gdk / X documentation
+   """
+   
+   return _gtk.gdk_window_new(parent, attribs)
+ # END WINGIDE_EXTENSIONS
+ 
  # screen size
  def screen_width():
return _gtk.gdk_screen_width()
Index: gtkmodule.c
===
RCS file: /home/cvs/src/ide/external/pygtk-0.6.5-wing/gtkmodule.c,v
retrieving revision 1.10
diff -c -r1.10 gtkmodule.c
*** gtkmodule.c 2000/09/28 22:49:52 1.10
--- gtkmodule.c 2000/10/27 15:05:30
***
*** 1665,1670 
--- 

[pygtk] Re: Patch for easier whole-app cursor setting

2000-10-24 Thread Stephan R.A. Deibel

Last week I wrote:

 I've attached a patch that makes it much easier to set the cursor (e.g.,
 to a watch / wait cursor) on an entire pygtk app, as you might do before
 intensive processing that will lock up the entire gtk mainloop().

Turns out there are some refcount/deletion order problems with the patch.
We'll be send a new version later after testing it a bit more this time.
Sorry...

- Stephan


Archaeopteryx Software, Inc.Wing IDE for Python 
www.archaeopteryx.com   Take Flight!


___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



[pygtk] Patch for easier whole-app cursor setting

2000-10-20 Thread Stephan R.A. Deibel

Hi, James and others,

I've attached a patch that makes it much easier to set the cursor (e.g.,
to a watch / wait cursor) on an entire pygtk app, as you might do before
intensive processing that will lock up the entire gtk mainloop().

This both sets the cursor and prevents key clicks and pointer clicks from
entering any windows of the app, so it's really only for use when the
entire app is busy... it's much nicer for the user to use set_cursor() and
lock only a sub-part of the app instead, whenever possible.

Nevertheless, I needed this functionality and hope that some form of
it can be included in future versions of pygtk.

The patch is a cdiff based on a somewhat modified version of pygtk 0.6.5,
so I'm not sure whether it will apply automatically on later versions...
and in any case it's likely that you'll want to change how the
functionality is packaged.  But it's not very complicated; just a few
areas of added code.

The implementation is based on X windows FAQ item number 170.  However, it
doesn't actually make any X calls and uses only GDK.  I think it has a
reasonable chance of being portable to MS Windows if GDK there handles
input-only windows correctly... probably not hard to do but at this point
I have no idea what the actual status of this might be.

If you have any questions about this, let me know.

Thanks!

- Stephan


Archaeopteryx Software, Inc.Wing IDE for Python 
www.archaeopteryx.com   Take Flight!


--

Index: gtk.py
===
RCS file: /home/cvs/src/ide/external/pygtk-0.6.5-wing/gtk.py,v
retrieving revision 1.8
diff -c -r1.8 gtk.py
*** gtk.py  2000/09/25 19:47:24 1.8
--- gtk.py  2000/10/20 23:54:57
***
*** 876,881 
--- 876,891 
_gtk.gtk_window_set_default_size(self._o, width, height)
def set_modal(self, modal):
_gtk.gtk_window_set_modal(self._o, modal)
+   
+   # WINGIDE_EXTENSIONS
+   def block_with_cursor(self, cursor):
+   """ Block typing and pointer activity in given window and
+   show the given cursor.  This returns a GdkWindow.  Tossing
+   your reference to it ends the block.  This is primarily
+   useful for setting the wait cursor during busy times. """
+   gdk_window = self.get_window()
+   _gtk.gdk_window_block_with_cursor(gdk_window, cursor)
+   return gdk_window
  
  class GtkColorSelectionDialog(GtkWindow):
get_type = _gtk.gtk_color_selection_dialog_get_type
***
*** 2737,2742 
--- 2747,2756 
  keyval_is_lower = _gtk.gdk_keyval_is_lower
  keyval_to_upper = _gtk.gdk_keyval_to_upper
  keyval_to_lower = _gtk.gdk_keyval_to_lower
+ 
+ # WINGIDE_EXTENSIONS
+ # See GtkWindow.block_with_cursor
+ gdk_window_block_with_cursor = _gtk.gdk_window_block_with_cursor
  
  # screen size
  def screen_width():
Index: gtkmodule.c
===
RCS file: /home/cvs/src/ide/external/pygtk-0.6.5-wing/gtkmodule.c,v
retrieving revision 1.10
diff -c -r1.10 gtkmodule.c
*** gtkmodule.c 2000/09/28 22:49:52 1.10
--- gtkmodule.c 2000/10/20 23:55:23
***
*** 294,299 
--- 294,302 
if (self == NULL)
  return NULL;
self-obj = win;
+ #ifdef WINGIDE_EXTENSIONS
+   self-cursor_win = NULL;
+ #endif
gdk_window_ref(self-obj);
return (PyObject *)self;
  }
***
*** 1321,1326 
--- 1324,1337 
  gdk_pixmap_unref(self-obj);
else
  gdk_window_unref(self-obj);
+ #ifdef WINGIDE_EXTENSIONS
+   if (self-cursor_win != NULL) {
+ gdk_window_set_cursor(self-cursor_win-obj, NULL);
+ gdk_window_hide(self-cursor_win-obj);
+ Py_DECREF(self-cursor_win);
+ self-cursor_win = NULL;
+   }
+ #endif
PyMem_DEL(self);
  }
  
***
*** 6524,6529 
--- 6535,6601 
  return Py_BuildValue("i", lower_val);
  }
  
+ #ifdef WINGIDE_EXTENSIONS
+ // A function to start showing the given cursor on the entire given gdk window,
+ // regardless of what any sub-windows are doing, and to block all keyboard
+ // and other entry to windows.  The function returns a reference to a 
+ // GdkWindow and the cursor block will continue until that reference is
+ // discarded by the caller.
+ // This is based on X FAQ item number 170:  We install an INPUT_ONLY
+ // window as the child of the window given and set the cursor in it
+ // to the wait cursor
+ static PyObject *_wrap_gdk_window_block_with_cursor(PyObject *self, PyObject *args) {
+ PyObject *parent;
+ PyGdkWindow_Object *pygdkparent;
+ PyGdkWindow_Object *cursor_win;
+ GdkWindow *gdkparent;
+ GdkWindowAttr attr;
+ PyObject *cursor;
+ 
+ // Parse args
+ if (!PyArg_ParseTuple(args, 

[pygtk] Re: General python/pygtk question

2000-06-28 Thread Stephan R.A. Deibel

 Phillip Ezolt [EMAIL PROTECTED] wrote:

 Is there anyway to:
 1) Instantiate an Object
 2) Ask it all of the attributes  methods that it has? 

What you want to do is use the class not an instance of the class, like
this:

gtk.GtkText.__dict__

It would be easy to write a util to output that in more readable format.

You could go further for each thing in this dict with something like this:

method = gtk.GtkText.__dict__['get_text']
co = method.func_code
argcount = co.co_argcount
argnames = co.co_varnames[:argcount]

A great resource for python introspection is the Python Quick Ref:

http://starship.python.net/quick-ref1_5.html

See the "Special informative state attributes for some types" sub-section.

Hope that's helpful and sorry if this has been answered already today (I
get the digest).

- Stephan


Archaeopteryx Software, Inc.Wing IDE for Python
www.archaeopteryx.com   Take Flight!



___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] Possible alternative for GtkText

2000-05-25 Thread Stephan R.A. Deibel

For what it's worth, there is another editor called Scintilla for which
I've written a python binding:

http://www.archaeopteryx.com/opensource/pyscintilla.html

It's really designed as a source code editor and has features like syntax
hilighting, etc, but it works fine without enabling those and provides
fairly fine-grained control of behaviours.

Very likely heavier in weight that the ideal text widget but it's still 
pretty lightweight on the scale of things.

Only tried on Linux and although Scintilla works on Windows natively I'm
not sure if its gtk personality has been ported/tested there (but this is
not a huge leap).

- Stephan

-

On Thu, 25 May 2000, James Henstridge wrote:

 On Thu, 25 May 2000, Harry Henry Gebel wrote:
 
  How do I make a GtkText widget start a new line when the end of the current
  line is reached? I tried turning word wrap on, line wrap on, and word wrap
  and lone wrap both on, but all of these settings keep the text as one line;
  although some of them have the line drawn over two lines of the widget.
  
 The current GtkText widget is not very flexible, as you have found.  Havoc
 and Owen have been working on a new text widget for gtk+-1.4 (based on the
 Tk text widget, but with pango support and multi view).  Of course, this
 doesn't help too much right now.
 
 James.
 
 -- 
 Email: [EMAIL PROTECTED]
 WWW:   http://www.daa.com.au/~james/
 
 
 -
 To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]
 

-
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]



Re: [pygtk] add_entries in MenuFactory

2000-05-08 Thread Stephan R.A. Deibel

Hi,

If you're using the gtk item factory, then I think you can just put an _
before the letter you want underscored.  E.g., send "_File".

I didn't write the code I'm looking at but it looks like we create a
GtkItemFactory like this:

  accel_group = gtk.GtkAccelGroup()
  self.fItemFactory = gtk.GtkItemFactory(gtk_type, 'tmp%s'%id(self),
 accel_group)

And then create the items like this:

  if defn.fLabel != None:
disp_path = '/' + RemoveSlash(defn.fLabel)
item_type = ''
  else:
disp_path = '/sep'
item_type = 'Separator'

  item = (disp_path, '', self.__CB_ItemActivate, 0, item_type)
  self.fItemFactory.create_items([item])

We access the item like this:

  menu_item = self.fItemFactory.get_widget(RemoveUnderscore(disp_path))

Where RemoveUnderscore are RemoveSlash are this:

def RemoveUnderscore(s):
  """ Remove any underscore chars from given string. """
  parts = string.split(s, '_')
  retval = parts[0]
  for part in parts[1:]:
retval = str(retval) + str(part)
  return retval

def RemoveSlash(s):
  """ Remove any underscore chars from given string. """
  parts = string.split(s, '/')
  return string.join(parts, '')

Hope that helps...

- Stephan

--

On Mon, 8 May 2000 [EMAIL PROTECTED] wrote:

 Greetings,
 
   Does anybody know how to put underscores under a selected letter
 of the items in a menu bar ? (You know the now traditional _File
 -underscore under F- means altF should pop-down the File menu...
 
 By the way I do not want to add an explicit accelerator which will yield
 to ALT+ Whaterver in the menu
 
 
 Thanks all 
 
 _
   
   LaBoufarikoise
 
 
 -
 To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]
 


-
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]



Re: [pygtk] How to prevent tab focus changes in H/VBoxes?

2000-01-27 Thread Stephan R.A. Deibel

On Thu, 27 Jan 2000, James Henstridge wrote:

 You may be able to do this like so:
 
 1) connect to the key_press_event of the GtkText widget.
 2) In the handler, if the key pressed was GDK.Tab, then insert a tab
character into the text widget, call the emit_stop_by_name method of
the text widget for key_press_event and return TRUE.  For other keys,
just return FALSE.

This solution works, thanks.

If you want the tab in the text you don't need to do anything other than
return gtk.TRUE.

Since I actually didn't want the tab in the text, I had to call
emit_stop_by_name and had to make sure I used connect() and not
connect_after() (which at first I was using).

Thanks!

- Stephan

To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]



[pygtk] GtkText bug of sorts

2000-01-26 Thread Stephan R.A. Deibel

Hi,

Although GtkText descends from GtkEditable and there is a method
insert_text() in GtkEditable, it doesn't work right to call this on an
instantiated GtkText:

Gtk-CRITICAL **: file gtktext.c: line 875 (gtk_text_set_point): assertion
`index = TEXT_LENGTH (text)' failed.

Using insert_defaults() instead, as defined in GtkText interface works, so
perhaps GtkText in gtk.py should override insert_text() to call
insert_defaults(), to avoid confusion?

- Stephan

To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]



[pygtk] How to prevent tab focus changes in H/VBoxes?

2000-01-26 Thread Stephan R.A. Deibel

Hi,

I have a GtkHBox with two GtkTexts in it and when I hit tab the focus is
shifted between texts instead of inserting a tab character into the text.

How do I turn this off?  I can't seem to find this at any level of the
abstractions involved...

Thanks,

- Stephan

To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]



[pygtk] Python module for Scintilla 1.1.1 text editor

1999-01-16 Thread Stephan R.A. Deibel

Hi,

In case anyone is interested, I've released a version of a Python module
that wraps the Scintilla 1.1.1 text editor widget.

This requires a pygtk 0.6.3 source distribution and a few other things.
See the README at the following URL for more info:

ftp://archaeopteryx.com/pub/scintilla/

- Stephan


To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]