On 28/06/2013 at 09:16, xxxxxxxx wrote:
Here's a script that shows how to Get & Set the cursor position in a text field.
When you press the period key on your keyboard. A popup list opens.
After you make a choice, it adds it to the text field. And then automatically moves the cursor to the end of the text. It's one of my favorite R13 SDK additions.
import c4d
from c4d import gui
GROUP1 = 1000 #GROUP1 id
TEXTBOX= 1001 #TEXTBOX id
BUTTON = 1002 #BUTTON1 id
class ExampleDlg(gui.GeDialog) :
def CreateLayout(self) :
self.SetTitle("Simple Dialog")
self.GroupBegin(GROUP1, c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 0, 0, "Press The Period Key", c4d.BFH_SCALEFIT)
self.GroupBorder(c4d.BORDER_BLACK)
self.AddEditText(TEXTBOX, c4d.BFH_SCALEFIT)
self.AddButton(BUTTON, c4d.BFH_SCALE, name="Close")
self.GroupEnd()
return True
def InitValues(self) :
#initiate the gadgets with values
self.SetString(TEXTBOX, "value")
return True
def Command(self, id, msg) :
if id==BUTTON: self.Close()
if id==TEXTBOX:
text = self.GetString(TEXTBOX)
bc = c4d.BaseContainer(c4d.BFM_EDITFIELD_GETCURSORPOS) #R13+ flag
pos = dlg.SendMessage(TEXTBOX, bc) #Returns the current index position on the cursor in the text
if pos > 0 and text[pos-1]=='.' :
entries = c4d.BaseContainer()
entries.SetString(c4d.FIRST_POPUP_ID+0, "first") #The &d& code is used to grey out the entry
entries.SetString(c4d.FIRST_POPUP_ID+1, "second")
entries.SetString(c4d.FIRST_POPUP_ID+2, "Third")
entries.SetString(c4d.FIRST_POPUP_ID+3, "Fourth")
entries.SetString(c4d.FIRST_POPUP_ID+4, "Fifth") #The &c& code is used to add a checkmark to the entry
mypopup = gui.ShowPopupDialog(cd=None, bc=entries, x=600, y=200)
text += entries.GetString(mypopup)
self.SetString(TEXTBOX, text)
bc = c4d.BaseContainer(c4d.BFM_EDITFIELD_SETCURSORPOS) #R13+ flag
bc.SetLong(1, len(text)) #Puts the cursor at the end of the text
pos = dlg.SendMessage(TEXTBOX, bc) #Execute the cursor position code
return True
dlg = ExampleDlg()
dlg.Open(c4d.DLG_TYPE_ASYNC, defaultw=300, defaulth=50)
-ScottA