def setup(self, label, range, value, orientation, *args, **kwargs): def updateField(widget, field, value): widget[field] = value def finalCommand(): val = self.slider['value'] updateField(self.slider, 'text', '%1.3f' % val) self.slider = DirectSlider(parent=self, relief=DGG.FLAT, range=range, value=value, orientation=orientation, scale=0.25, thumb_relief=DGG.FLAT, thumb_color=(0, 1, 1, 1), pos=(0, 0, 0), text='0.0', text_scale=0.20000000000000001, text_pos=(0, 0.10000000000000001, 0)) updateField(self.slider, 'command', finalCommand) width = 3 if orientation == DGG.HORIZONTAL: pos = (-0.27500000000000002 - width * 0.050000000000000003, 0, -0.02) else: pos = (-0.025000000000000001 * width, 0, -0.34999999999999998) self.min = DirectEntry(parent=self, initialText=` float(self.slider['range'][0]) `, scale=0.050000000000000003, width=width, pos=pos) updateField( self.min, 'command', lambda x: updateField(self.slider, 'range', (float(x), self.slider['range'][1]))) if orientation == DGG.HORIZONTAL: pos = (0.27500000000000002, 0, -0.02) else: pos = (-0.025000000000000001 * width, 0, 0.29999999999999999) self.max = DirectEntry(parent=self, initialText=` float(self.slider['range'][1]) `, scale=0.050000000000000003, width=width, pos=pos) updateField( self.max, 'command', lambda x: updateField(self.slider, 'range', (self.slider['range'][0], float(x)))) self.label = DirectLabel( parent=self, relief=None, text=label, text_scale=0.050000000000000003, text_pos=(0.029999999999999999 - 0.39500000000000002, 0.34999999999999998 - 0.23999999999999999, 0), text_align=TextNode.ALeft)
def __init__(self, parent=None, **kw): self.__qtd_conexao = 0 self.__frmAuth = DirectFrame(frameColor=(0, 0, 0, .3), frameSize=(-.5, .5, 0, 0.45), pos=(0, 0, -.1), enableEdit=1) self.__lblLogin = DirectLabel(text="Login: "******"Senha: ", scale=0.05, pos=(-0.3, 0, 0.2), frameColor=(0, 0, 0, 0), text_fg=(1, 1, 1, 1)) self.__etySenha = DirectEntry( scale=0.05, width=12, pos=(-.2, 0, 0.2), cursorKeys=1, obscured=1, focusInCommand=self.__command_clear_senha) self.__btnEntrar = DirectButton(frameColor=(0, 0, 0, 1), text="Entrar", scale=0.06, pos=(0.3, 0, 0.1), text_fg=(1, 1, 1, 1), rolloverSound=None, clickSound=None, command=self.__command_entrar) self.__lblLogin.reparentTo(self.__frmAuth) self.__etyLogin.reparentTo(self.__frmAuth) self.__lblSenha.reparentTo(self.__frmAuth) self.__etySenha.reparentTo(self.__frmAuth) self.__btnEntrar.reparentTo(self.__frmAuth) self.__etyLogin.set("viner") self.__etySenha.set("viner")
def __init__(self, _client): # Ref self.client = _client # create a host button self.btnConnect = DirectButton( # Scale and position scale=0.25, pos=(0, 0, 0), # Text text="Connect", # Frame # Functionality command=self.connect) # create the IP input field self.txtIP = DirectEntry( # scale and position pos=(0, 0, -.35), scale=0.25, width=9, # Text text="", text_align=TextNode.ACenter, initialText="127.0.0.1", numLines=1, # Functionality command=self.connect, focusInCommand=self.clearText) self.hide()
def enterSysMsgSection(self): geom = CIGlobals.getDefaultBtnGeom() self.infoLbl = OnscreenText( text="Inform all online players about something.", pos=(0, 0.45)) self.msgEntry = DirectEntry( initialText="System Message...", scale=0.055, width=15, numLines=4, command=self.sendSystemMessageCommand, focusInCommand=base.localAvatar.chatInput.disableKeyboardShortcuts, focusOutCommand=base.localAvatar.chatInput.enableKeyboardShortcuts, pos=(-0.4, 0, 0)) self.sendBtn = DirectButton( geom=geom, text_scale=0.04, relief=None, scale=1.0, text="Send", pos=(0, 0, -0.35), text_pos=(0, -0.01), command=self.sendSystemMessageCommand, ) self.cancelBtn = DirectButton(geom=geom, text_scale=0.04, relief=None, scale=1.0, text="Cancel", pos=(-0.45, 0.15, -0.55), text_pos=(0, -0.01), command=self.fsm.request, extraArgs=['basePage'])
def __init__(self, placeholder, pos, on_enter, focus=False, sort_order=0): """ Object of a simple entry field @param placeholder: text to appear in textbox automatically @type placeholder: string @param pos: where to place the textbox @type pos: (float, float, float) @param on_enter: function to call upon them submitting a response @type on_enter: function @param focus: Should the entry auto-focus? @type focus: bool @param sort_order: Where should Entry display? (Alert is at 1000) @type sort_order: int """ DirectObject.__init__(self) self.accept('mouse1', self.click_out) self.placeholder = placeholder self.on_enter = on_enter self.entry = DirectEntry(initialText=self.placeholder, scale=0.05, focus=focus, focusOutCommand=self.focus_out, focusInCommand=self.focus_in, pos=pos, sortOrder=sort_order)
def terminarPartida(self): # Solicita al usuario un nombre para la tabla de puntuaciones self.entrada = DirectEntry(width = 15, numLines = 1, scale = 0.07, cursorKeys = 1, frameSize = (0, 15, 0, 1), command = self.almacenarPuntuacion, pos = (-0.3, 0, 0.1), focus = True, text_pos = (0.2, 0.2)) self.puntos = self.ship.puntos self.ship.ship.detachNode() self.ship.ship.remove() taskMgr.remove("Mover Nave") taskMgr.remove("Generar Enemigos") taskMgr.remove("Comprobar Impactos") taskMgr.remove("Actualizar Puntuacion") taskMgr.remove("Explosionar*") self.mostrarFinPartida() # Libera los recursos de la partida que ha terminado self.ship.eliminarObjetos() del self.ship del self.menuGraphics del self.menu self.marcadorNP.detachNode() self.marcadorNP.remove() self.barraEnergia.destroy() del self.marcador del self.barraEnergia
def create_text_entry(self, frame, param): entry = DirectEntry(parent=frame, initialText=str(param.get_param()), numLines=1, width=10, command=self.do_update, extraArgs=[None, param], text_scale=self.font_size, text_align=TextNode.A_left, suppressKeys=1) widget = SizerWidget(entry) return widget
def add_entry(self, name='', text = "" , pos = (0, 0, 0), scale=1, command = None, initialText="", width = 15, numLines = 1, focus=1): """ docstring for add_entry """ if name == '': name = generate_hash(self) self[name] = DirectEntry(text = text, pos = pos, scale = scale, command = command, initialText = initialText, width = width, numLines = numLines, focus = focus) return self[name]
def open_query(self, owner): self.owner = owner bg_color = LColor(*self.color) bg_color[3] = 0.2 scale3 = LVector3(self.scale[0], 1.0, self.scale[1]) self.background = DirectFrame( frameColor=bg_color, frameSize=(-1 / self.scale[0], 1.0 / self.scale[0], 0.15 + self.scale[1] * self.text_size, 0.0), parent=base.a2dBottomLeft) self.prefix = OnscreenText( text=_("Target name:"), font=self.font, fg=self.color, align=TextNode.ALeft, parent=base.a2dBottomLeft, scale=tuple(self.scale * self.text_size), pos=(0, .15), ) bounds = self.prefix.getTightBounds() length = bounds[1][0] - bounds[0][ 0] + self.scale[0] * self.text_size / 2 self.query = DirectEntry(text="", text_fg=self.color, scale=tuple(scale3 * self.text_size), command=self.do_query, parent=base.a2dBottomLeft, frameColor=(0, 0, 0, 0), pos=(length, 0, .15), initialText="", numLines=1, width=200, entryFont=self.font, focus=1, suppressKeys=1) self.query.bind("press-escape-", self.escape) self.query.bind("press-tab-", self.select) self.query.accept(self.query.guiItem.getTypeEvent(), self.completion) self.query.accept(self.query.guiItem.getEraseEvent(), self.completion) pos = self.prefix.getPos() bounds = self.query.getBounds() llz = bounds[2] / self.text_size self.suggestions = OnscreenText( text="", font=self.font, fg=self.color, align=TextNode.ALeft, mayChange=True, parent=base.a2dBottomLeft, scale=tuple(self.scale * self.suggestions_text_size), pos=(pos[0], pos[1] + llz), )
def __init__(self, parent: DirectFrame, text: str, value: float, slider_edit_callback: Callable[['ColourChannel', float], None], entry_edit_callback: Callable[['ColourChannel', float], None], mouse1_press_callbacks: List[Callable[[], None]]): self.__frame = DirectFrame(parent=parent) self.__slider_edit_callback = slider_edit_callback self.__entry_edit_callback = entry_edit_callback self.__label = DirectLabel(parent=self.__frame, text=text, text_fg=WHITE, text_bg=WINDOW_BG_COLOUR, pos=(-0.5, 0.0, 0.0), scale=(0.1, 1.0, 0.1)) self.__slider = DirectSlider(parent=self.__frame, orientation=DGG.HORIZONTAL, borderWidth=(0.0, 0.0), frameColor=WIDGET_BG_COLOUR, frameSize=(-1.0, 1.0, -0.4, 0.4), thumb_frameSize=(-0.075, 0.075, -0.2, 0.2), value=value, pos=(0.05, 0.0, 0.0255), scale=(0.45, 1.0, 0.5)) self.__entry_hovered = False mouse1_press_callbacks.append(self.__entry_mouse_click_callback) self.__entry = DirectEntry(parent=self.__frame, frameColor=WIDGET_BG_COLOUR, text_fg=WHITE, initialText=str(value), scale=0.1, width=3, suppressKeys=True, pos=(0.55, 0.0, -0.01105)) self.__entry.bind(DGG.EXIT, self.__entry_exit_callback) self.__entry.bind(DGG.ENTER, self.__entry_enter_callback) self.__entry.bind(DGG.B1PRESS, self.__entry_mouse_click_callback) self.accept("mouse1", self.__entry_mouse_click_callback) self.__disable_frame_overlay = DirectButton(parent=self.__frame, frameColor=TRANSPARENT, borderWidth=(0.0, 0.0), frameSize=(-0.6, 0.9, -0.2, 0.2), suppressMouse=True) self.__disable_frame_overlay.hide() self.__enabled = True self.__set_callbacks()
def activate(self): # create main dialog frame # Note: frame position references the CENTER of the frame self.frm = DirectFrame(pos=(0, 0, 0), frameSize=(self.frmLeft, self.frmRight, self.frmBottom, self.frmTop), relief=DGG.RIDGE, borderWidth=(0.01, 0.01), frameColor=(0.6, 0.6, 0.6, 1.0)) self.frm.reparentTo(base.aspect2d) # Note: wonderfully enough, label position on the other hand # references the CENTER of the LEFT border of the label! titleLabel = DirectLabel(text=self.title, scale=0.04, frameColor=(0.5, 0.5, 0.5, 1), relief=DGG.RIDGE, borderWidth=(0.01, 0.01), text_align=TextNode.ALeft) titleLabel.setPos(-self.frmWidth / 2 + .02, 0, self.frmHeight / 2 - .045) titleLabel.reparentTo(self.frm) sc = .04 self.dir_edit_field = DirectEntry( text='', # prompt text scale=sc, frameColor=(0.65, 0.65, 0.65, 1), command=self.setText, width=32, numLines=1, focus=1, focusInCommand=self.efFocusIn, ) self.dir_edit_field.setPos(-self.frmWidth / 2 + .02, 0, self.frmHeight / 2 - .13) self.dir_edit_field.reparentTo(self.frm) self.statusLabel = DirectLabel( text=self.initial_status, scale=0.04, frameColor=(0.6, 0.6, 0.6, 1), # relief = DGG.RIDGE, # borderWidth = (0.01, 0.01), text_align=TextNode.ALeft) self.statusLabel.setPos(-self.frmWidth / 2 + .02, 0, self.frmHeight / 2 - .2) self.statusLabel.reparentTo(self.frm)
def __init__(self, parent=render2d, pos=(0.0, 0.0, 0.0), scale=1.0, value=0, callback=None, increment=0.01): DirectFrame.__init__(self, parent, pos=pos, scale=1.0) self.increment = increment self.value = Decimal(value) self.callback = callback self.display = DirectEntry(parent=self, relief=None, initialText="%.2f" % value, scale=1, text_scale=0.055, text_align=TextNode.ACenter, pos=(0.0, 0.0, 0.0), frameColor=(0.8, 0.8, 0.5, 1), borderWidth=(0.1, 0.1), numLines=1, width=6, frameSize=(-0.1, 0.1, -0.1, 0.1), cursorKeys=1) self.display.bind(DGG.TYPE, self.typeCallback) # This allows the text box to handle mouse events self.display.guiItem.setActive(True) gui = loader.loadModel('phase_3/models/gui/tt_m_gui_mat_mainGui.bam') image = (gui.find('**/tt_t_gui_mat_shuffleArrowUp'), gui.find('**/tt_t_gui_mat_shuffleArrowDown'), gui.find('**/tt_t_gui_mat_shuffleArrowUp'), gui.find('**/tt_t_gui_mat_shuffleArrowDisabled')) self.upArrow = DirectButton(self, relief=None, image=image, image_scale=(0.6, 0.6, 0.6), image1_scale=(0.7, 0.7, 0.7), image2_scale=(0.7, 0.7, 0.7), pos=(0.0, 0.0, 0.08), command=self.__handleUpClicked) self.upArrow.setR(90) self.downArrow = DirectButton(self, relief=None, image=image, image_scale=(0.6, 0.6, 0.6), image1_scale=(0.7, 0.7, 0.7), image2_scale=(0.7, 0.7, 0.7), pos=(0.0, 0.0, -0.05), command=self.__handleDownClicked) self.downArrow.setR(-90)
def createTextbox(parent=None, width=60, text='', pos=(0,1,0), scale=(0.1), focus=0): """docstring for createTextbox""" return DirectEntry(text = text, initialText=text, numLines=1, focus=focus, width=width, clickSound = None, rolloverSound = None, parent=parent, pos=pos, scale=scale, )
def _drawControls(self, dialogueFrame): """ Draw Helper that draws client settings controls """ iTopMrgn = JOPTS_CONTROL_TOP_MARGIN spacing = JOPTS_CONTROL_SPACING height = JOPTS_CONTROL_HEIGHT width = dialogueFrame.getWidth() # Create containers for UI: ipFrame = DirectFrame(parent=dialogueFrame, pos=(width / 2, 0, -iTopMrgn - spacing), frameSize=(-width / 2, width / 2, -height / 2, height / 2), frameTexture=UI_WINDOW) #nameFrame = DirectFrame(parent=dialogueFrame, # pos=(width/2, 0, -iTopMrgn - spacing * 2), # frameSize=(-width/2, width/2, -height/2, # height/2)) # Create the UI: ctrlWidth = ipFrame.getWidth() * (1 / 3) ctrlFontSize = (0.15, 0.15) self._ipAddressEntry = DirectEntry(parent=ipFrame, pos=(ctrlWidth / 2 - ctrlWidth * 1, 0, 0), frameSize=(0, ctrlWidth * 2, -height / 2, height / 2), frameColor=(0, 0, 0, 0), text_font=self._font, text_scale=ctrlFontSize, text_pos=PIERCEROMAN_OFFSET_MC, initialText=DEFAULT_IP_ADDRESS, width=8, cursorKeys=1, numLines=1) ipLabel = DirectLabel(parent=ipFrame, pos=(ctrlWidth - ctrlWidth * 2, 0, 0), frameSize=(-ctrlWidth / 2, ctrlWidth / 2, -height / 2, height / 2), text="Host IP:", text_font=self._font, text_scale=ctrlFontSize, text_pos=PIERCEROMAN_OFFSET_MC, frameTexture=(IMG_GRADIENT_1)) """self._userNameEntry = DirectEntry(parent=nameFrame, pos=(ctrlWidth/2-ctrlWidth*1, 0, 0), frameSize=(0, ctrlWidth*2, -height/2, height/2), text_font=self._font, text_scale=ctrlFontSize, text_pos=PIERCEROMAN_OFFSET_MC, width=8, cursorKeys=1, numLines=1)""" """
def _draw(self): winWidth = base.getAspectRatio() * 2 winHeight = 2 # Draw container: frameHeight = winHeight * NPKR_HEIGHT_PERCENTAGE frameWidth = winWidth * NPKR_WIDTH_PERCENTAGE cFCenterY = -winHeight / 2 + frameHeight / 2 self._rootFrame = DirectFrame( pos=(0, 0, cFCenterY), frameSize=(-frameWidth / 2, frameWidth / 2, -frameHeight / 2, frameHeight / 2), frameTexture=IMG_GRADIENT_1) self._rootFrame.setTransparency(TransparencyAttrib.MAlpha) # Draw Name Entry: entryWidth = self._rootFrame.getWidth() * NPKR_ENTRY_WIDTH_PERCENTAGE entryHeight = self._rootFrame.getHeight() entryCX = -(self._rootFrame.getWidth() - entryWidth) / 2 self._nameEntry = DirectEntry( parent=self._rootFrame, pos=(entryCX, 0, 0), frameSize=(-entryWidth / 2, entryWidth / 2, -entryHeight / 2, entryHeight / 2), frameColor=(0.25, 0.25, 0.25, 1), text_align=TextNode.ACenter, text_font=self._font, text_scale=NPKR_ENTRY_FONT_SIZE, text_pos=NPKR_ENTRY_FONT_OFFSET, initialText=NPKR_ENTRY_INITIAL_TEXT, numLines=1, focusOutCommand=self._syncName, focusInCommand=self._checkPlaceholderText, command=self._syncName, frameTexture=UI_WINDOW) # Draw Confirm Button: confirmWidth = self._rootFrame.getWidth()\ * (1-NPKR_ENTRY_WIDTH_PERCENTAGE) confirmHeight = self._rootFrame.getHeight() confirmCX = (self._rootFrame.getWidth() - confirmWidth) / 2 self._confirmButton = DirectButton( parent=self._rootFrame, pos=(confirmCX, 0, 0), frameSize=(-confirmWidth / 2, confirmWidth / 2, -confirmHeight / 2, confirmHeight / 2), command=self._onConfirmPressed, text_font=self._font, text_scale=NPKR_BUTTON_FONT_SIZE, text_pos=NPKR_BUTTON_FONT_OFFSET, text="Create Character", borderWidth=NPKR_BUTTON_BORDER_WIDTH)
def setMyEntry(self): self.myEntry = DirectEntry(text='', scale=self.scale, command=self.onCommand, numLines=self.lines, width=self.width, pos=(self.x, self.y, self.z), entryFont=self.myFont, focusInCommand=self.onFocus, focusOutCommand=self.onOutFocus, frameColor=(0, 0, 0, .7), text_fg=(1, 1, 1, 1), initialText=self.initial, clickSound=self.mode.game.app.beep01Sound, rolloverSound=None)
def bld_page(self): menu_gui = self.mdt.menu.gui menu_args = self.mdt.menu.gui.menu_args txt = OnscreenText(text=_('Client'), pos=(0, .4), **menu_gui.menu_args.text_args) widgets = [txt] self.ent = DirectEntry( scale=.12, pos=(-.68, 1, .2), entryFont=menu_args.font, width=12, frameColor=menu_args.btn_color, initialText=_('insert the server address')) self.ent.onscreenText['fg'] = menu_args.text_fg btn = DirectButton(text=_('Connect'), pos=(0, 1, -.2), command=self.connect, **menu_gui.menu_args.btn_args) widgets += [self.ent, btn] map(self.add_widget, widgets) ThanksPageGui.bld_page(self)
def __init__(self): self.instructions = OnscreenText(text='Type your name', scale=0.1, fg=(1, 1, 1, 1), pos=(0, 0.8, 0.8), shadow=(0, 0, 0, 1)) self.nameEntry = DirectEntry(focus=1, initialText='Toon', width=10, scale=0.1, pos=(-0.5, 0.3, 0.3), command=self.confirmNameAndContinue) self.confirmBtn = DirectButton(text='Confirm', scale=0.1, pos=(0, 0.1, 0.1), command=self.confirmNameAndContinue, extraArgs=[self.nameEntry.get()])
def __init__(self, manager, xml): sys.stdout = PseudoFile(self.writeOut) sys.stderr = PseudoFile(self.writeErr) tpErr = TextProperties() tpErr.setTextColor(1, 0.5, 0.5, 1) TextPropertiesManager.getGlobalPtr().setProperties("err", tpErr) self.manager = manager font = loader.loadFont("cmss12") self.frame = DirectFrame(parent=base.a2dTopCenter, text_align=TextNode.ALeft, text_pos=(-base.getAspectRatio() + TEXT_MARGIN[0], TEXT_MARGIN[1]), text_scale=0.05, text_fg=(1, 1, 1, 1), frameSize=(-2.0, 2.0, -0.5, 0.0), frameColor=(0, 0, 0, 0.5), text='', text_font=font) self.entry = DirectEntry(parent=base.a2dTopLeft, command=self.command, scale=0.05, width=1000.0, pos=(-0.02, 0, -0.48), relief=None, text_pos=(1.5, 0, 0), text_fg=(1, 1, 0.5, 1), rolloverSound=None, clickSound=None, text_font=font) self.otext = OnscreenText(parent=self.entry, scale=1, align=TextNode.ALeft, pos=(1, 0, 0), fg=(1, 1, 0.5, 1), text=':', font=font) self.lines = [''] * 9 self.commands = [] # All previously sent commands self.cscroll = None # Index of currently navigated command, None if current self.command = '' # Currently entered command self.block = '' # Temporarily stores a block of commands self.hide() self.initialized = False
def makeEntryField(caption, z, obscured): label = DirectLabel( parent=self.dialog, text=caption, text_scale=0.05, text_align=TextNode.ALeft, pos=(-0.82, 0, z + 0.1), ) entry = DirectEntry( parent=self.dialog, scale=0.05, width=32, pos=(-0.8, 0, z), pad=(0.2, 0.1), obscured=obscured, relief=DGG.GROOVE, ) return label, entry
def build_text_question(self, question_dict): # , xPos, yPos): xPos = 0 yPos = 0.2 numLines = 5 if question_dict[ 'type'] == 3 else 1 # type == 3 is essay Qs DirectLabel(parent=self._rButtonFrame, text=question_dict['question'], scale=0.05, pos=(xPos, 0, yPos), frameColor=(0, 0, 0, 0), text_wordwrap=20) DirectEntry(text="", scale=.07, command=None, initialText="", numLines=numLines, focus=1)
def __init__(self): super().__init__() self.entryLabel = self.label(text='', mayChange=True) self.entry = DirectEntry( initialText='Type card name...', scale=0.05, focus=1, command=self.useThiefAbility, focusInCommand=lambda: self.entry.enterText('')) self.entry.hide() self.thiefAbilityButton = self.button( text="Faction Ability", scale=1, pos=(0, 0, -1), parent=self.endPhaseButton, command=self.onThiefAbilityButton)
def makeTextBox(self, frame, text, invalid=False): colours = self.app.theme.colours if invalid: colour = colours.invalidServerEntry else: colour = colours.serverEntry result = DirectEntry( parent=frame, scale=0.04, width=12, pos=(-0.5, 0, 0), pad=(0.2, 0.1), text_fg=colour, frameColor=(1, 1, 1, 1), initialText=text, focusInCommand=self.textBoxEntered, focusInExtraArgs=[frame], focusOutCommand=self.textBoxExited, focusOutExtraArgs=[frame], ) result.entryInvalid = invalid return result
def __init__(self, parent=None, scale=.05, limitText=100, frameSize=(0, 1.3, 0.11, .2), pos=(0, 0, .1)): self.__show = True self.frmMsg = DirectFrame(parent=parent, frameColor=(0, 0, 0, .5), frameSize=frameSize, pos=pos, enableEdit=1) self.etyMsg = DirectEntry(frameColor=(1, 1, 1, .5), scale=scale, width=22, numLines=1, pos=(.02, 0, .14), cursorKeys=1, focus=1, command=self.__command_enviar_msg, focusInCommand=self.__command_clear_msg) self.btnMsgr = DirectButton(frameColor=(0, 0, 0, 1), text="Enviar", scale=scale, pos=(1.21, 0, .14), text_fg=(1, 1, 1, 1), rolloverSound=None, clickSound=None, command=self.__command_enviar_msg) self.etyMsg.reparentTo(self.frmMsg) self.btnMsgr.reparentTo(self.frmMsg) self.hide()
def __init__( self, parent ): self.parent = parent # line wrapper self.linewrap = textwrap.TextWrapper() self.linewrap.width = self.linelength # calculate window size left = (self.h_pos) / self.scale right = (self.h_pos + self.h_size) / self.scale bottom = (self.v_pos) / self.scale top = (self.v_pos + self.v_size) /self.scale # panda3d interface self.consoleFrame = DirectFrame ( relief = DGG.GROOVE , frameColor = (200, 200, 200, 0.5) , scale=self.scale , frameSize = (0, self.h_size / self.scale, 0, self.v_size / self.scale) ) self.windowEvent( base.win ) # try to load the defined font try: fixedWidthFont = loader.loadFont(self.font) except: print "pandaInteractiveConsole.py :: could not load the defined font %s" % str(self.font) fixedWidthFont = DGG.getDefaultFont() # if font is not valid use default font if not fixedWidthFont.isValid(): if self.font is None: print "pandaInteractiveConsole.py :: could not load the defined font %s" % str(self.font) fixedWidthFont = DGG.getDefaultFont() # text entry line self.consoleEntry = DirectEntry ( self.consoleFrame , text = "" , command = self.onEnterPress , width = self.h_size/self.scale - 2 , pos = (1, 0, 1.5) , initialText = "" , numLines = 1 , focus = 1 , entryFont = fixedWidthFont) # output lines self.consoleOutputList = list() for i in xrange( self.numlines ): label = OnscreenText( parent = self.consoleFrame , text = "" , pos = (1, -i+3+self.numlines) , align=TextNode.ALeft , mayChange=1 , scale=1.0 , fg = self.defaultTextColor ) label.setFont( fixedWidthFont ) self.consoleOutputList.append( label ) # list of the last commands of the user self.userCommandList = list() self.userCommandListLength = 100 for i in xrange(self.userCommandListLength): self.userCommandList.append('') self.userCommandPos = 0 # buffer for data self.textBuffer = list() self.textBufferLength = 1000 for i in xrange(self.textBufferLength): self.textBuffer.append(['', DEFAULT_COLOR]) self.textBufferPos = self.textBufferLength-self.numlines # toggle the window at least once to activate the events self.toggleConsole() self.toggleConsole() # call the help-command on start self.onEnterPress("help")
def __init__(self, services: Services, mouse1_press_callbacks: List[Callable[[], None]]): self.__services = services self.__services.ev_manager.register_listener(self) self.__base = self.__services.graphics.window self.__text = " t - find the path between the agent and goal\n\n" \ " mouse click - moves agent to mouse location \n\n mouse right click - moves goal to" \ " mouse location\n\n arrow keys, PgUp, PgDn - move agent / goal (Alt down)\n\n x - toggle trace" \ " animation (animations required)\n\n m - toggle map between Sparse and Dense\n\n o - take a " \ "default screenshot of the map\n\n p - take a custom screenshot of the scene\n\n w, a, s, d " \ "- orbit around the map\n\n q - top view of the map\n\n c, v - toggle Simulator Configuration /" \ " View Editor\n\n i - toggle Debug Overlay" self.__algorithms = self.__services.settings.algorithms self.__maps = self.__services.settings.maps self.__map_keys = list(self.__maps.keys()) self.__algorithm_keys = list(self.__algorithms.keys()) self.__animation_keys = list(self.__animations.keys()) self.__window = Window(self.__base, "simulator_config", mouse1_press_callbacks, borderWidth=(0.0, 0.0), frameColor=WINDOW_BG_COLOUR, pos=(-1, 0.5, 0.5), frameSize=(-1.7, 1.3, -5.68, 0.85)) # spacer # DirectFrame(parent=self.__window.frame, borderWidth=(.0, .0), frameColor=WIDGET_BG_COLOUR, frameSize=(-1.4, 1.4, -0.011, 0.011), pos=(-0.2, 0.0, 0.4)) DirectFrame(parent=self.__window.frame, borderWidth=(.0, .0), frameColor=WIDGET_BG_COLOUR, frameSize=(-1.4, 1.4, -0.01, 0.01), pos=(-0.2, 0.0, -2.96)) self.sim_config = DirectLabel(parent=self.__window.frame, text="Simulator Configuration", text_fg=WHITE, text_bg=WINDOW_BG_COLOUR, frameColor=WINDOW_BG_COLOUR, borderWidth=(.0, .0), pos=(-0.53, 0.0, 0.56), scale=(0.2, 3, 0.2)) # Zoom buttons self.btn_zoom_out = DirectButton(text="-", text_fg=WHITE, pressEffect=1, command=self.__window.zoom_out, pos=(0.71, 0., 0.55), parent=self.__window.frame, scale=(0.3, 4.15, 0.35), frameColor=TRANSPARENT) self.btn_zoom_in = DirectButton(text="+", text_fg=WHITE, pressEffect=1, command=self.__window.zoom_in, pos=(0.92, 0., 0.56), parent=self.__window.frame, scale=(0.3, 4.15, 0.35), frameColor=TRANSPARENT) # Quit button self.btn = DirectButton(text='x', text_fg=WHITE, command=self.__window.toggle_visible, pos=(1.12, 0., 0.576), parent=self.__window.frame, scale=(0.3, 2.9, 0.2), pressEffect=1, frameColor=TRANSPARENT) self.user_information = DirectLabel(parent=self.__window.frame, text=self.__text, text_fg=WHITE, text_bg=WINDOW_BG_COLOUR, frameColor=WINDOW_BG_COLOUR, text_align=TextNode.ALeft, borderWidth=(.0, .0), pos=(-1.55, 0.0, -3.2), scale=(0.11, 1.1, 0.11)) self.map_label = DirectLabel(parent=self.__window.frame, text="Map:", text_fg=WHITE, text_bg=WINDOW_BG_COLOUR, text_align=TextNode.ALeft, frameColor=WINDOW_BG_COLOUR, borderWidth=(.0, .0), pos=(-1.52, 0.4, 0.), scale=(0.17, 1.09, 0.13)) self.algo_label = DirectLabel(parent=self.__window.frame, text="Algorithm:", text_fg=WHITE, text_bg=WINDOW_BG_COLOUR, frameColor=WINDOW_BG_COLOUR, text_align=TextNode.ALeft, borderWidth=(.0, .0), pos=(-1.52, 0.4, -0.5), scale=(0.17, 1.09, 0.13)) self.animation_label = DirectLabel(parent=self.__window.frame, text="Animation:", text_fg=WHITE, text_bg=WINDOW_BG_COLOUR, frameColor=WINDOW_BG_COLOUR, text_align=TextNode.ALeft, borderWidth=(.0, .0), pos=(-1.52, 0.4, -1), scale=(0.17, 1.09, 0.13)) self.agent_label = DirectLabel(parent=self.__window.frame, text="Agent:", text_fg=WHITE, text_bg=WINDOW_BG_COLOUR, frameColor=WINDOW_BG_COLOUR, text_align=TextNode.ALeft, borderWidth=(.0, .0), pos=(-1.52, 0.4, -1.5), scale=(0.17, 1.09, 0.13)) self.goal_label = DirectLabel(parent=self.__window.frame, text="Goal:", text_fg=WHITE, text_bg=WINDOW_BG_COLOUR, frameColor=WINDOW_BG_COLOUR, text_align=TextNode.ALeft, borderWidth=(.0, .0), pos=(-1.52, 0.4, -2), scale=(0.17, 1.09, 0.13)) # Creating goal and agent's entry fields self.__entries = [] self.__entry_hovered = False mouse1_press_callbacks.append(self.__entry_mouse_click_callback) for i in range(0, 6): e = DirectEntry(parent=self.__window.frame, scale=0.12, pos=(-0.24 + (i % 3) * 0.57, 0.4, -1.5 - 0.5 * (i // 3)), numLines=1, width=3, suppressKeys=True, text_align=TextNode.ACenter, focusInCommand=self.clear_text, focusInExtraArgs=[i]) self.__entries.append(e) e.bind(DGG.EXIT, self.__entry_exit_callback) e.bind(DGG.ENTER, self.__entry_enter_callback) e.bind(DGG.B1PRESS, self.__entry_mouse_click_callback) self.accept("mouse1", self.__entry_mouse_click_callback) self.__agent_disable_overlay = DirectButton(parent=self.__window.frame, frameColor=TRANSPARENT, borderWidth=(0.0, 0.0), frameSize=(-0.6, 1.4, -0.2, 0.2), pos=(-0.24, 0.4, -1.5), suppressMouse=True) self.__agent_disable_overlay.hide() self.__maps_option = DirectOptionMenu( text="options", scale=0.14, parent=self.__window.frame, initialitem=self.__map_keys.index("Labyrinth") if "Labyrinth" in self.__map_keys else 0, items=self.__map_keys, pos=(-0.65, 0.4, 0.), highlightColor=(0.65, 0.65, 0.65, 1), textMayChange=1, command=self.__use_default_map_positions) self.__algorithms_option = DirectOptionMenu( text="options", scale=0.14, parent=self.__window.frame, initialitem=self.__algorithm_keys.index("A*") if "A*" in self.__algorithm_keys else 0, items=self.__algorithm_keys, pos=(-0.46, 0.4, -0.5), highlightColor=(0.65, 0.65, 0.65, 1), textMayChange=1) self.__animations_option = DirectOptionMenu( text="options", scale=0.14, parent=self.__window.frame, initialitem=self.__animation_keys.index("Fast"), items=self.__animation_keys, pos=(-0.45, 0.4, -1), highlightColor=(0.65, 0.65, 0.65, 1), textMayChange=1) self._update_frame = DirectFrame(parent=self.__window.frame, frameColor=WHITE, pos=(-1, 0.4, -2.6), borderWidth=(0.25, 0.15), frameSize=(-0.5, 0.95, -0.54, 0.54), scale=(0.50, 3.1, 0.25)) self._reset_frame = DirectFrame(parent=self.__window.frame, frameColor=WHITE, pos=(0.412, 0.4, -2.6), borderWidth=(0.25, 0.15), frameSize=(-0.5, 0.92, -0.54, 0.54), scale=(0.50, 3.1, 0.25)) self.btn_update = DirectButton( text="Update", text_fg=(0.3, 0.3, 0.3, 1.0), pressEffect=1, command=self.__update_simulator_callback, pos=(-0.9, 0.4, -2.65), parent=self.__window.frame, scale=(0.20, 2.1, 0.15), frameColor=TRANSPARENT) self.btn_reset = DirectButton(text="Reset", text_fg=(0.4, 0.3, 0.3, 1.0), pressEffect=1, command=self.__reset_simulator_callback, pos=(0.51, 0.4, -2.65), parent=self.__window.frame, scale=(0.20, 2.1, 0.15), frameColor=TRANSPARENT) # setup state & use saved state if possible self.__state = None for so in self.__services.state.objects: if isinstance(so, SimulatorConfigState): self.__state = so cmd = self.__maps_option['command'] try: self.__maps_option.set(self.__map_keys.index(so.mp)) self.__algorithms_option.set( self.__algorithm_keys.index(so.algo)) self.__animations_option.set( self.__animation_keys.index(so.ani)) self.__update_position_entries() except: msg = "Failed to load Simulator Config state:\n{}".format( traceback.format_exc()) self.__services.debug.write(msg, DebugLevel.NONE) break finally: self.__maps_option['command'] = cmd return new_state = self.__state is None if new_state: self.__state = SimulatorConfigState(self.__services.state) self.__state.mp = self.__maps_option.get() self.__state.algo = self.__algorithms_option.get() self.__state.ani = self.__animations_option.get() self.__use_default_map_positions() if new_state: self.__services.state.add(self.__state) else: self.__services.state.save()
def setDefaultText(): ''' Write the default message in the textbox ''' txt_msg.enterText('Your Message') def send(args=None): ''' Send the text written in the message textbox to the clients ''' client.sendMessage(txt_msg.get()) txt_msg.enterText('') # the Textbox where we write our Messages, which we # want to send over to the other users txt_msg = DirectEntry( initialText = 'Your Message', cursorKeys = True, pos = (-0.9,0,-0.9), scale = 0.1, width = 14, focusInCommand = clearText, focusOutCommand = setDefaultText, command = send, parent = frameMain) # a button to initiate the sending of the message btn_send = DirectButton( text = 'Send', pos = (0.75,0,-0.9), scale = 0.15, command = send, parent = frameMain) # This will show all sent messages txt_messages = DirectEntry(
def __init__(self, class_parent, parent, h_size, v_size, aspect, hugpos): self.h_size = h_size self.v_size = v_size self.scale = 0.04 self.parent = class_parent self.numlines = int(v_size / self.scale - 2) self.pos_min_x = 0 self.pos_min_y = 0 self.pos_max_x = self.h_size self.pos_max_y = 0.7 if aspect > 0: self.pos_max_x /= aspect else: self.pos_max_y *= aspect self.consoleFrame = DirectFrame(relief=DGG.RIDGE, frameColor=(0, 0, 0, 0), scale=self.scale, frameSize=(0, self.h_size / self.scale, 0, self.v_size / self.scale)) if parent == base.a2dBottomLeft: #@UndefinedVariable self.pos_min_x -= 1 self.pos_min_y -= 1 self.pos_max_x -= 1 self.pos_max_y -= 1 if hugpos == "bottom": self.consoleFrame.setPos(0, 0, GUI_BOTTOM_OFFSET - 0.085) self.pos_min_x = 0 self.pos_min_y = GUI_BOTTOM_OFFSET - 0.085 - 0.07 self.pos_max_x = self.h_size self.pos_max_y = GUI_BOTTOM_OFFSET - 0.085 fixedWidthFont = loader.loadFont(GUI_FONT) #@UndefinedVariable #fixedWidthFont.setPixelsPerUnit(60) #fixedWidthFont.setRenderMode(fixedWidthFont.RMSolid) if not fixedWidthFont.isValid(): print "pandaInteractiveConsole.py :: could not load the defined font %s" % str( self.font) fixedWidthFont = DGG.getDefaultFont() #fixedWidthFont.setPageSize(512,512) #fixedWidthFont.setPixelsPerUnit(60) self.consoleEntry = DirectEntry( self.consoleFrame, text="", command=self.onEnterPress #, width = self.h_size/self.scale -2 , pos=(0.01, 0, 0.02), initialText="Enter text...", numLines=1, focus=0, entryFont=fixedWidthFont, scale=1, frameColor=(0, 0, 0, 0.2), text_fg=(0, 1, 0, 1), text_shadow=(0, 0, 0, 1)) #self.consoleEntry = DirectEntry(self.consoleFrame) self.consoleEntry["frameSize"] = (0, self.h_size / self.scale, 0, 1) self.consoleEntry["width"] = self.h_size / self.scale self.consoleEntry["focusInCommand"] = self.focusInCallback self.consoleEntry["focusOutCommand"] = self.focusOutCallback self.consoleFrame.reparentTo(parent) self.textBuffer = list() self.textBufferLength = 100 for i in xrange(self.textBufferLength): self.textBuffer.append(['', (100, 100, 100, 1)]) self.textBufferPos = self.textBufferLength - self.numlines # output lines self.consoleOutputList = list() for i in xrange(self.numlines): label = OnscreenText(parent=self.consoleFrame, text="", pos=(0, i + 1.5), align=TextNode.ALeft, mayChange=1, scale=1.0, fg=(100, 100, 100, 1), shadow=(0, 0, 0, 1)) # , frame = (200,0,0,1) ) label.setFont(fixedWidthFont) self.consoleOutputList.append(label) self.linelength = 57 self.linewrap = textwrap.TextWrapper() self.linewrap.width = self.linelength self.toggleConsole()
def __init__( self, parent ): self.parent = parent # line wrapper self.linewrap = textwrap.TextWrapper() self.linewrap.width = self.linelength # calculate window size left = (self.h_pos) / self.scale right = (self.h_pos + self.h_size) / self.scale bottom = (self.v_pos) / self.scale top = (self.v_pos + self.v_size) /self.scale # panda3d interface self.consoleFrame = DirectFrame ( relief = DGG.GROOVE , frameColor = (200, 200, 200, 0.5) , scale=self.scale , frameSize = (0, self.h_size / self.scale, 0, self.v_size / self.scale) ) # vardis 27-02-2009: Added special cull bin in order to render on top of everything CullBinManager.getGlobalPtr().addBin(PanoConstants.CONSOLE_CULL_BIN_NAME, CullBinManager.BTUnsorted, PanoConstants.CONSOLE_CULL_BIN_VAL) self.consoleFrame.setBin("fixed", PanoConstants.RENDER_ORDER_CONSOLE) self.windowEvent( base.win ) # try to load the defined font fixedWidthFont = loader.loadFont(parent.game.getResources().getResourceFullPath(PanoConstants.RES_TYPE_FONTS, self.font)) # if font is not valid use default font if not fixedWidthFont.isValid(): if self.font is None: print "pandaInteractiveConsole.py :: could not load the defined font %s" % str(self.font) fixedWidthFont = DGG.getDefaultFont() # text entry line self.consoleEntry = DirectEntry ( self.consoleFrame , text = "" , command = self.onEnterPress , width = self.h_size/self.scale - 2 , pos = (1, 0, 1.5) , initialText = "" , numLines = 1 , focus = 1 , entryFont = fixedWidthFont) # output lines self.consoleOutputList = list() for i in xrange( self.numlines ): label = OnscreenText( parent = self.consoleFrame , text = "" , pos = (1, -i+3+self.numlines) , align=TextNode.ALeft , mayChange=1 , scale=1.0 , fg = self.defaultTextColor ) label.setFont( fixedWidthFont ) self.consoleOutputList.append( label ) # list of the last commands of the user self.userCommandList = list() self.userCommandListLength = 100 for i in xrange(self.userCommandListLength): self.userCommandList.append('') self.userCommandPos = 0 # buffer for data self.textBuffer = list() self.textBufferLength = 1000 for i in xrange(self.textBufferLength): self.textBuffer.append(['', DEFAULT_COLOR]) self.textBufferPos = self.textBufferLength-self.numlines # toggle the window at least once to activate the events self.toggleConsole() self.toggleConsole() self.help()
def __init__(self, showbase): self.showbase = showbase self.ready = False self.background = DirectFrame( frameSize=(-1, 1, -1, 1), frameTexture='media/gui/mainmenu/menu.png', parent=self.showbase.render2d, ) self.title = OnscreenText(text='Lobby!', fg=(1, 1, 1, 1), parent=self.background, pos=(-0.6, 0.1), scale=0.06) self.buttons = [] controlButtons = Vec3(-0.60, 0, -0.79) # Toggle ready p = controlButtons + Vec3(-0.25, 0, 0) self.toggleReadyButton = DirectButton( text='Ready/Unready', pos=p, scale=0.048, relief=DGG.GROOVE, command=self.toggleReady, ) self.buttons.append(self.toggleReadyButton) # Disconnect p = controlButtons + Vec3(0.0, 0.0, 0.0) self.disconnectButton = DirectButton( text='Disconnect', pos=p, scale=0.048, relief=DGG.GROOVE, command=self.disconnect, ) self.buttons.append(self.disconnectButton) # Send message p = controlButtons + Vec3(0.25, 0.0, 0.0) self.sendMessageButton = DirectButton( text='Send Message', pos=p, scale=0.048, relief=DGG.GROOVE, command=self.sendMessage, extraArgs=[''], ) self.buttons.append(self.sendMessageButton) # Message input self.message = DirectEntry( command=self.sendMessage, focusInCommand=self.clearText, frameSize=(-3, 3, -.5, 1), initialText='', parent=self.buttons[2], pos=(0, -0.6, -1.5), text_align=TextNode.ACenter, ) self.showbase.gameData = GameData() self.showbase.users = [] self.hide()