Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search

key in dialog [SOLVED]

Author
Message
  Topic Search Topic Search
conner View Drop Down
Member
Member


Joined: 2013 Apr 17
Online Status: Offline
Posts: 176
Direct Link To This Post Topic: key in dialog [SOLVED]
    Posted: 2015 Jan 18 at 5:51am
I try to get Keys within a dialog - with out success

def CreateLayout(self):
        self.SetTitle('Stage - Command Line')
        self.GroupBegin(GROUP, c4d.BFH_SCALEFIT, cols=1, title="Generator",)
        self.AddEditText(1001, c4d.BFH_SCALEFIT, editflags=c4d.EDITTEXT_HELPTEXT)
        self.SetString(id = 1001,value  = "enter a Stage command",flags = c4d.EDITTEXT_HELPTEXT)
       self.GroupEnd()
        return True

 def Command(self, id_, msg):
        if id_ == 1001:
            resultBaseContainer = c4d.BaseContainer()
            self.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.KEY_ENTER,resultBaseContainer)
            if resultBaseContainer[c4d.BFM_INPUT_VALUE]:
                print self.GetString(1001)
        bc = c4d.BaseContainer()
        ok = c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.KEY_TAB, bc)
        if bc[c4d.BFM_INPUT_VALUE] == 1:
            print "tab key"    
        bc = c4d.BaseContainer()
        ok = c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.KEY_ESC, bc)
        if bc[c4d.BFM_INPUT_VALUE] == 1:
            self.Close()
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1878
Direct Link To This Post Posted: 2015 Jan 20 at 3:02am
Hi conner,

I have demonstrated two ways in the following Message function.
Please be careful!
By default you need to call gui.GeDialog.Message(self, msg, result). If you fail to do so, C4D will probably freeze.
If you detect a keyboard input, you may return True, to avoid further processing of the key.
BUT, again be careful, especially with keys like Enter or Tab. The user expects certain behavior and may be disappointed, if he is no longer able to use the Tab key to switch between dialog elements.

def Message ( self, msg, result ):
        # Method A, querying a special key
        bc = c4d.BaseContainer()
        ok = c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_TAB, bc)
        if ok:
            if bc[c4d.BFM_INPUT_VALUE] == 1:
                print "tab key"
                return True # if you don't return here, the Tab key will still have the default influence on your dialog
                # This can get really confusing...
        ok = c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_ENTER, bc)
        if ok:
            if bc[c4d.BFM_INPUT_VALUE] == 1:
                print "enter"
                return True
        # Method B - processing the input message, works nicely for normal keys
        if msg.GetId() == c4d.BFM_INPUT:
            if msg.GetInt32(c4d.BFM_INPUT_DEVICE) == c4d.BFM_INPUT_KEYBOARD:
                print "KEYBOARD: "
                print msg.GetString(c4d.BFM_INPUT_ASC)
                return True  # return True ONLY on keys you want to process, otherwise standard commands won't work anymore, as long as your dialog is active
        return gui.GeDialog.Message(self, msg, result)

Cheers,
Andreas
SDK Support Engineer
Back to Top
conner View Drop Down
Member
Member


Joined: 2013 Apr 17
Online Status: Offline
Posts: 176
Direct Link To This Post Posted: 2015 Jan 21 at 1:57am
Many Thanks for the solution 
Back to Top

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.093 seconds.