commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/forms/src/uidrivers/qt UILoginHandler.py U...


From: Jason Cater
Subject: gnue/forms/src/uidrivers/qt UILoginHandler.py U...
Date: Sat, 08 Mar 2003 00:11:29 -0500

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    03/03/08 00:11:27

Modified files:
        forms/src/uidrivers/qt: UILoginHandler.py UIdriver.py common.py 
        forms/src/uidrivers/qt/widgets: button.py entry.py 
        forms/src/uidrivers/qt/widgets/form: wrappers.py 

Log message:
        first stab at getting QT events working

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/src/uidrivers/qt/UILoginHandler.py.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/src/uidrivers/qt/UIdriver.py.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/src/uidrivers/qt/common.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/src/uidrivers/qt/widgets/button.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/src/uidrivers/qt/widgets/entry.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/src/uidrivers/qt/widgets/form/wrappers.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: gnue/forms/src/uidrivers/qt/UILoginHandler.py
diff -c gnue/forms/src/uidrivers/qt/UILoginHandler.py:1.3 
gnue/forms/src/uidrivers/qt/UILoginHandler.py:1.4
*** gnue/forms/src/uidrivers/qt/UILoginHandler.py:1.3   Thu Mar  6 18:01:48 2003
--- gnue/forms/src/uidrivers/qt/UILoginHandler.py       Sat Mar  8 00:11:22 2003
***************
*** 148,161 ****
          self.textctrlList[i].move(xPos + xSpacing, lastY)
          lastY = lastY + ySpacing
          self.textctrlList[i].show()
! 
        if errortext:
          errorField.move(
            dlgWidth/2 - errorField.width()/2,
                  lastY+3)
  
        # Set the focus to the first text entry field
! ##      self.textctrlList[0].SetFocus()
  
        # Create and position the logo
        img = QLabel(self.dlg)
--- 148,161 ----
          self.textctrlList[i].move(xPos + xSpacing, lastY)
          lastY = lastY + ySpacing
          self.textctrlList[i].show()
!         
        if errortext:
          errorField.move(
            dlgWidth/2 - errorField.width()/2,
                  lastY+3)
  
        # Set the focus to the first text entry field
!       self.textctrlList[0].setFocus()
  
        # Create and position the logo
        img = QLabel(self.dlg)
Index: gnue/forms/src/uidrivers/qt/UIdriver.py
diff -c gnue/forms/src/uidrivers/qt/UIdriver.py:1.5 
gnue/forms/src/uidrivers/qt/UIdriver.py:1.6
*** gnue/forms/src/uidrivers/qt/UIdriver.py:1.5 Thu Mar  6 01:51:20 2003
--- gnue/forms/src/uidrivers/qt/UIdriver.py     Sat Mar  8 00:11:22 2003
***************
*** 61,79 ****
  
  
    def initialize(self):
-     ################################################################
-     # WX Specifics
-     ################################################################
      self._qtapp = getQtApp()
        
- ##    self._qtapp.setFont(font)
- 
      font = QFont("Courier")
      font.setPointSize(int(gConfig('pointSize')))
      setWidgetBaseFont(font)
!         
! ##    self._qtapp.font().setFixedPitch(1)
! 
      #
      # SplashScreen
      #
--- 61,72 ----
  
  
    def initialize(self):
      self._qtapp = getQtApp()
        
      font = QFont("Courier")
      font.setPointSize(int(gConfig('pointSize')))
      setWidgetBaseFont(font)
!     
      #
      # SplashScreen
      #
Index: gnue/forms/src/uidrivers/qt/common.py
diff -c gnue/forms/src/uidrivers/qt/common.py:1.4 
gnue/forms/src/uidrivers/qt/common.py:1.5
*** gnue/forms/src/uidrivers/qt/common.py:1.4   Fri Mar  7 00:14:27 2003
--- gnue/forms/src/uidrivers/qt/common.py       Sat Mar  8 00:11:22 2003
***************
*** 97,251 ****
  #####################################################################
  
  def _setDefaultEventHandlers(newWidget, eventHandler, initialize, uiDriver):
!     if initialize:
!       pass
!         # TODO: this should use one instance
! #FIX#        
newWidget.PushEventHandler(mouseEvtHandler(eventHandler,uiDriver))
! #FIX#        
newWidget.PushEventHandler(keyboardEvtHandler(eventHandler,uiDriver))
!       pass
!         
! #FIX#class uiBaseEvtHandler(wxEvtHandler):
! #FIX#    def __init__(self,eventList,eventProcessor, uiDriver):
! #FIX#        wxEvtHandler.__init__(self)
! #FIX#        self._eventProcessor = eventProcessor
! #FIX#        self._uiDriver = uiDriver
! #FIX#        for eventType in eventList:
! #FIX#            self.Connect(-1, -1, eventType,self._processEvent)
          
  
! #FIX#    def _processEvent(self,event):
! #FIX#        GDebug.printMesg(0,"uiBaseEvtHandler _processEvent was 
called?!?")
!       
! #
! # mouseEvtHandler
! #
! # Traps most mouse events and translates them into
! # GNUe events passed back to the form
! #
! #FIX#class mouseEvtHandler(uiBaseEvtHandler):
! #FIX#  def __init__(self,eventProcessor, uiDriver):
! #FIX#    eventList = [wxEVT_LEFT_DOWN]
! #FIX#    uiBaseEvtHandler.__init__(self, eventList, eventProcessor, uiDriver)
  
    #
!   # The putzing about with the event timestamp is to
!   # allow us to process mouse click events twice. 
!   # The mouse handler is called before the cursor 
!   # position is updated so GetInsertionPoint returns 
!   # the position from the widget losing focus.
!   # setting the timestamp to zero is a flag to prevent
!   # infinate loops and allow us to avoid process that does 
!   # not need done twice.
! 
! #FIX#  def _processEvent(self,event):
! #FIX#    object = _eventObjTowxWindow(event)
! #FIX#
! #FIX#    id = object.GetId()
! #FIX#    gfObject     = self._uiDriver._IdToGFObj[id]
! #FIX#    screenWidget = self._uiDriver._IdToTkObj[id]
! #FIX#    count        = 
self._uiDriver._IdToUIObj[id].widgets.index(screenWidget)
! #FIX#
! #FIX#    if event.GetTimestamp():
! #FIX#      self._eventProcessor('requestFOCUS',gfObject,_form=gfObject._form)
! #FIX#      self._eventProcessor('requestJUMPRECORD',count - 
gfObject._visibleIndex,_form=gfObject._form)
! #FIX#
! #FIX#      if isinstance(screenWidget,wxTextCtrl):
! #FIX#        event.SetTimestamp(0)
! #FIX#        self.AddPendingEvent(event)
! #FIX#
! #FIX#    else:
! #FIX#      textObject= wxPyTypeCast(object, 'wxTextCtrl')
! #FIX#      cursorPosition = textObject.GetInsertionPoint()
! #FIX#      
self._eventProcessor('requestCURSORMOVE',position=cursorPosition,_form=gfObject._form)
! #FIX#
! #FIX#    event.Skip()
! 
! 
! #
! # keyboardEvtHandler
! #
! # Traps most keypress events and translates them into
! # GNUe events passed back to the form
! #
! # Note: wxEVT_KEY_DOWN event seems to only return uppercase chars so
! #       i don't trap it.
! #
! 
! #FIX#class keyboardEvtHandler(uiBaseEvtHandler):
! #FIX#  def __init__(self, eventProcessor, uiDriver):
! #FIX#    eventList = [wxEVT_CHAR]
! #FIX#    uiBaseEvtHandler.__init__(self, eventList, eventProcessor, uiDriver)
! #FIX#
! #FIX#  def _processEvent(self,event):
! #FIX#    action = None
! #FIX#    # hack for swig shortcomming needed by wxPython 2.2.x (2.3 does not 
need this)
! #FIX#    # compute the location of the character in the widget
! #FIX#    object = 
self._uiDriver._IdToGFObj[_eventObjTowxWindow(event).GetId()]
! #FIX#
! #FIX#    keycode = event.KeyCode()
! #FIX#
! #FIX#    #
! #FIX#    # Sigh... a hack for using <enter> in multiline entries
! #FIX#    #
! #FIX#    if  keycode == 13 and \
! #FIX#        not event.ShiftDown() and \
! #FIX#        not event.ControlDown() and \
! #FIX#        not event.AltDown() and \
! #FIX#        int (gConfigForms('enterIsNewLine')) and \
! #FIX#        (hasattr(object,'Char__height') and object.Char__height) > 1:
! #FIX#
! #FIX#      command = 'NEWLINE'
! #FIX#
! #FIX#    else:
! #FIX#
! #FIX#
! #FIX#      #
! #FIX#      # Get the event to process from the KeyMapper
! #FIX#      #
! #FIX#      command = GFKeyMapper.KeyMapper.getEvent(
! #FIX#        keycode,
! #FIX#        event.ShiftDown(),
! #FIX#        event.ControlDown(),
! #FIX#        event.AltDown())
! #FIX#
! #FIX#    if command == 'JUMPRECORD':
! #FIX#      global _PROMPTFORRECORD
! #FIX#      action = _PROMPTFORRECORD()
! #FIX#
! #FIX#    elif command == 'NEWLINE':
! #FIX#      action = events.Event('requestKEYPRESS', '\n',
! #FIX#                     text='\n',
! #FIX#                     code=10)
! #FIX#
! #FIX#    elif command:
! #FIX#      action = events.Event('request%s' % command)
! #FIX#
! #FIX#    elif object._type == 'GFButton':
! #FIX#      action = events.Event('buttonActivated',object)
! #FIX#
! #FIX#    elif object.style == 'checkbox' and object._type == 'GFEntry':
! #FIX#      # <space> <=> <click>
! #FIX#      if keycode == 32:
! #FIX#          action = events.Event('requestTOGGLECHKBOX')
! #FIX#      else:
! #FIX#          # maybe some background error message here
! #FIX#          pass
! #FIX#    else:
! #FIX#      try:
! #FIX#        char = chr(keycode)
! #FIX#        if char in string.printable or char == "\n" or \
! #FIX#           128 <= keycode <= 255:
! #FIX#          action = events.Event('requestKEYPRESS', char,
! #FIX#                         text=char,
! #FIX#                         code=keycode)
! #FIX#      except ValueError:
! #FIX#        pass 
! #FIX#
! #FIX#    if action:
! #FIX#      # Add the object's _form to the outgoing event
! #FIX#      # rather than every event in the function
! #FIX#      action.__dict__.update({'_form':object._form})
! #FIX#      self._eventProcessor(action)
  
                                                                
  #####################################################################
--- 97,209 ----
  #####################################################################
  
  def _setDefaultEventHandlers(newWidget, eventHandler, initialize, uiDriver):
!   return 
! ##  if initialize:      
! ##    uiBaseEvtHandler(newWidget, eventHandler, uiDriver)
          
  
! ##
! ##
! ##
! class uiBaseEvtHandler: 
!   def __init__(self, event, uiwidget): 
!     self._eventHandler = event.eventHandler
!     self._uiwidget = uiwidget
!     self.setFocusPolicy(QWidget.NoFocus)
!     
!   #
!   # Over-ride events
!   #
!   def keyPressEvent(self, event):
!     action = None
!     
!     uiwidget = self._uiwidget
!     gfObject = uiwidget._gfObject
! 
!     keycode = event.key()
!     state = event.state()
!     shifted = state & QKeyEvent.ShiftButton
!     control = state & QKeyEvent.ControlButton
!     alt = state & QKeyEvent.AltButton
! 
!     #
!     # Sigh... a hack for using <enter> in multiline entries
!     #
!     if  keycode == 13 and \
!        not state and \
!         int (gConfigForms('enterIsNewLine')) and \
!         (hasattr(gfObject,'Char__height') and gfObject.Char__height) > 1:
! 
!       command = 'NEWLINE'
! 
!     else:
! 
! 
!       #
!       # Get the event to process from the KeyMapper
!       #
!       command = GFKeyMapper.KeyMapper.getEvent(
!         keycode,
!         shifted,
!         control,
!         alt)
! 
! 
!       if command == 'NEWLINE':
!         action = events.Event('requestKEYPRESS', '\n',
!                      text='\n',
!                      code=10)
! 
!       elif command:
!         action = events.Event('request%s' % command)
! 
! 
!       elif gfObject._type == 'GFButton':
!         self.animateClick()
! 
!       elif gfObject._type == 'GFEntry' and gfObject.style == 'checkbox':
!         # <space> <=> <click>
!         if keycode == 32:
!           action = events.Event('requestTOGGLECHKBOX')
!         else:
!             # maybe some background error message here
!           pass
!       elif not (control or alt):
!         char = "%s" % event.text()
!         if char: 
!           action = events.Event('requestKEYPRESS', char,
!                            text=char,
!                            code=keycode)
! 
!     if action:
!       # Add the object's _form to the outgoing event
!       # rather than every event in the function
!       action.__dict__.update({'_form':gfObject._form})
!       self._eventHandler(action)
  
    #
!   # Over-ride events
!   #
!   def mousePressEvent(self, event):
!     uiwidget = self._uiwidget
!     gfObject = uiwidget._gfObject
!     
!     if self.hasFocus():  
!       print "** Move cursor"
!     # Move cursor
! ##      cursorPosition = self.getInsertionPoint()
! ##      
self._eventHandler('requestCURSORMOVE',position=cursorPosition,_form=gfObject._form)
!     else: 
!     # Request Focus
!     
!       self._eventHandler('requestFOCUS',gfObject,_form=gfObject._form)
!       print "** Jump to Record"
!       
! ##      count = 
self._uiwidget._uiDriver._IdToUIObj[id(self)].widgets.index(uiwidget)
! ##      self._eventHandler('requestJUMPRECORD',count - 
gfObject._visibleIndex,_form=gfObject._form)
! 
! 
!     
  
                                                                
  #####################################################################
Index: gnue/forms/src/uidrivers/qt/widgets/button.py
diff -c gnue/forms/src/uidrivers/qt/widgets/button.py:1.4 
gnue/forms/src/uidrivers/qt/widgets/button.py:1.5
*** gnue/forms/src/uidrivers/qt/widgets/button.py:1.4   Fri Mar  7 00:14:28 2003
--- gnue/forms/src/uidrivers/qt/widgets/button.py       Sat Mar  8 00:11:26 2003
***************
*** 29,35 ****
  from qt import *
  
  from gnue.common import events
! from gnue.forms.uidrivers.qt.common import _setDefaultEventHandlers
  from gnue.forms.uidrivers.qt.common import _eventObjToQtWindow
  from gnue.forms.uidrivers.qt.widgets._base import UIHelper
  
--- 29,35 ----
  from qt import *
  
  from gnue.common import events
! from gnue.forms.uidrivers.qt.common import uiBaseEvtHandler as _Base
  from gnue.forms.uidrivers.qt.common import _eventObjToQtWindow
  from gnue.forms.uidrivers.qt.widgets._base import UIHelper
  
***************
*** 43,49 ****
      object = event.object
      
      # Create a button..
!     newWidget = QPushButton(event.container, 'button%s' % id(self))
      
      # .. set the label text..
      newWidget.setText(str(object.label))
--- 43,49 ----
      object = event.object
      
      # Create a button..
!     newWidget = _Button(event, self)
      
      # .. set the label text..
      newWidget.setText(str(object.label))
***************
*** 56,82 ****
                            
(object.Char__y+spacer+(spacer*object._gap))*event.widgetHeight, 
                            self.itemWidth,self.itemHeight)
  
!     # TODO: we need to listen for "clicked()" slot
!     
      if event.initialize:
        QObject.connect(newWidget, SIGNAL("clicked()"), self.buttonHandler)
  
      return newWidget
  
    def buttonHandler(self):
!     print self._uiDriver._IdToGFObj
!     gfObject     = self._uiDriver._IdToGFObj[id(self)]
!     self._eventHandler('buttonActivated', gfObject)
! ##    if event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED:
! ##      action = None
! ##      object = _eventObjToQtWindow(event)
! ##      id = object.GetId()
! ##      gfObject     = self._uiDriver._IdToGFObj[id]
! ##      action = events.Event('buttonActivated',gfObject)
! ##      self._eventHandler(action)
! 
  
  
  configuration = {
      'baseClass'  : UIButton,
      'provides'   : 'GFButton',
--- 56,80 ----
                            
(object.Char__y+spacer+(spacer*object._gap))*event.widgetHeight, 
                            self.itemWidth,self.itemHeight)
  
!     # Attach the events to our button, and we can all go home...
      if event.initialize:
+       self._eventHandler = event.eventHandler
        QObject.connect(newWidget, SIGNAL("clicked()"), self.buttonHandler)
  
      return newWidget
  
+   #
+   #
    def buttonHandler(self):
!     self._eventHandler('buttonActivated', self._gfObject)
  
  
+ class _Button(_Base, QPushButton): 
+   def __init__(self, event, *args): 
+     QPushButton.__init__(self, event.container,'button%s' % id(self))
+     _Base.__init__(self, event, *args)
+     
+     
  configuration = {
      'baseClass'  : UIButton,
      'provides'   : 'GFButton',
Index: gnue/forms/src/uidrivers/qt/widgets/entry.py
diff -c gnue/forms/src/uidrivers/qt/widgets/entry.py:1.4 
gnue/forms/src/uidrivers/qt/widgets/entry.py:1.5
*** gnue/forms/src/uidrivers/qt/widgets/entry.py:1.4    Fri Mar  7 00:14:28 2003
--- gnue/forms/src/uidrivers/qt/widgets/entry.py        Sat Mar  8 00:11:26 2003
***************
*** 31,37 ****
  
  from gnue.forms.uidrivers.qt.widgets._base import UIHelper
  from gnue.forms.uidrivers.qt.common import _eventObjToQtWindow
! from gnue.forms.uidrivers.qt.common import _setDefaultEventHandlers
  
  #
  # UIEntry
--- 31,37 ----
  
  from gnue.forms.uidrivers.qt.widgets._base import UIHelper
  from gnue.forms.uidrivers.qt.common import _eventObjToQtWindow
! from gnue.forms.uidrivers.qt.common import uiBaseEvtHandler as _Base
  
  #
  # UIEntry
***************
*** 50,56 ****
        else:
          choices = [""]
  
!       newWidget = _ComboBox(event.container)
        newWidget.setInsertionPolicy(QComboBox.NoInsertion)
        
        if event.initialize:
--- 50,56 ----
        else:
          choices = [""]
  
!       newWidget = _ComboBox(event, self)
        newWidget.setInsertionPolicy(QComboBox.NoInsertion)
        
        if event.initialize:
***************
*** 67,73 ****
                
  
      elif style == 'checkbox':
!       newWidget = QCheckBox(event.container)
        
        if event.initialize:
          newWidget.setChecked(0)
--- 67,73 ----
                
  
      elif style == 'checkbox':
!       newWidget = _CheckBox(event, self)
        
        if event.initialize:
          newWidget.setChecked(0)
***************
*** 77,90 ****
  
      else: # Normal text box
        if hasattr(object,'Char__height') and object.Char__height > 1:
!         cls = QMultiLineEdit
        else: 
          # TODO: According to the QT 3 docs, we should probably switch
          # TODO: to QTextEdit.  However, I'm not sure how to check for
          # TODO: the QT version in use :)
!         cls = QLineEdit
  
!       newWidget = cls(event.container)
            
        # TODO: Capture textChanged, returnPressed, selectionChanged signals
        
--- 77,90 ----
  
      else: # Normal text box
        if hasattr(object,'Char__height') and object.Char__height > 1:
!         cls = _MultiLineEdit
        else: 
          # TODO: According to the QT 3 docs, we should probably switch
          # TODO: to QTextEdit.  However, I'm not sure how to check for
          # TODO: the QT version in use :)
!         cls = _SingleLineEdit
  
!       newWidget = cls(event, self)
            
        # TODO: Capture textChanged, returnPressed, selectionChanged signals
        
***************
*** 95,108 ****
                            self.itemWidth,self.itemHeight)
        
      
! ##    self._eventHandler = event.eventHandler
! ##    _setDefaultEventHandlers(newWidget, event.eventHandler, 
event.initialize,self._uiDriver)
  
      
      return newWidget
  
  
! class _ComboBox (QComboBox): 
  
    def setChoices(self,choices): 
      self.__choices = choices
--- 95,130 ----
                            self.itemWidth,self.itemHeight)
        
      
! ##    # Attach the events to our entry and call it a night...
! ##    if event.initialize:
! ##      self._eventHandler = event.eventHandler
! ##      _setDefaultEventHandlers(newWidget, event.eventHandler, 
event.initialize,self._uiDriver)
  
      
      return newWidget
  
+     
+ ###########################################################
+ #
+ #  Our custom event-riddled QObjects
+ #
+ class _SingleLineEdit (_Base, QLineEdit): 
+   def __init__(self, event, uiwidget): 
+     QLineEdit.__init__(self, event.container)
+     _Base.__init__(self, event, uiwidget)
  
!     
! class _MultiLineEdit (_Base, QLineEdit): 
! 
!   def __init__(self, event, uiwidget): 
!     QLineEdit.__init__(self, event.container)
!     _Base.__init__(self, event, uiwidget)
! 
!     
! class _ComboBox (_Base, QComboBox): 
!   def __init__(self, event, uiwidget): 
!     QComboBox.__init__(self, event.container)
!     _Base.__init__(self, event, uiwidget)
  
    def setChoices(self,choices): 
      self.__choices = choices
***************
*** 111,119 ****
      
    def setText(self, text): 
      self.setCurrentItem(self.__choices.index(text))
      
!     
!     
  configuration = {
      'baseClass'  : UIEntry,
      'provides'   : 'GFEntry',
--- 133,143 ----
      
    def setText(self, text): 
      self.setCurrentItem(self.__choices.index(text))
+   
      
! #
! #
! #           
  configuration = {
      'baseClass'  : UIEntry,
      'provides'   : 'GFEntry',
Index: gnue/forms/src/uidrivers/qt/widgets/form/wrappers.py
diff -c gnue/forms/src/uidrivers/qt/widgets/form/wrappers.py:1.4 
gnue/forms/src/uidrivers/qt/widgets/form/wrappers.py:1.5
*** gnue/forms/src/uidrivers/qt/widgets/form/wrappers.py:1.4    Thu Mar  6 
18:01:54 2003
--- gnue/forms/src/uidrivers/qt/widgets/form/wrappers.py        Sat Mar  8 
00:11:27 2003
***************
*** 120,125 ****
--- 120,126 ----
      
      self._pageList.append(newWidget)
      self.pane.addTab(newWidget,hasattr(object,'caption') and object.caption 
or object.name)
+     self.pane.setFocusPolicy(QWidget.ClickFocus)
      
  ##    self.pane.SetClientSize(self.layoutSize)
  ##    self.fit()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]