コード例 #1
0
def test_set_scrollbar_width():
    w = 1

    frm = DirectScrolledFrame(scrollBarWidth=w)

    assert frm['scrollBarWidth'] == 1

    assert frm.verticalScroll['frameSize'] == (-w / 2.0, w / 2.0, -1, 1)
    assert frm.horizontalScroll['frameSize'] == (-1, 1, -w / 2.0, w / 2.0)

    # manual changes to the framesize
    frm.verticalScroll['frameSize'] = (-2, 2, -4, 4)
    frm.horizontalScroll['frameSize'] = (-4, 4, -2, 2)
    assert frm.verticalScroll['frameSize'] == (-2, 2, -4, 4)
    assert frm.horizontalScroll['frameSize'] == (-4, 4, -2, 2)

    # change scrollbar width to a new value
    w = 2
    frm['scrollBarWidth'] = w

    # check, new value is set correct
    assert frm['scrollBarWidth'] == 2

    # check if new size is set correct
    assert frm.verticalScroll['frameSize'] == (-w / 2.0, w / 2.0, -4, 4)
    assert frm.horizontalScroll['frameSize'] == (-4, 4, -w / 2.0, w / 2.0)
コード例 #2
0
ファイル: widgets.py プロジェクト: ondrocks/cosmonium
 def __init__(self,
              text='',
              align=TextNode.ALeft,
              scale=(1, 1),
              font=None,
              font_size=12,
              parent=None,
              frameColor=(0.33, 0.33, 0.33, .66)):
     if parent is None:
         parent = aspect2d
     self.parent = parent
     self.frame = DirectScrolledFrame(
         parent=parent,
         frameColor=frameColor,
         state=DGG.DISABLED,
         relief=DGG.FLAT,
         scrollBarWidth=scale[0] * font_size,
         horizontalScroll_relief=DGG.FLAT,
         verticalScroll_relief=DGG.FLAT,
     )
     self.text = OnscreenText(parent=self.frame.getCanvas(),
                              text=text,
                              align=align,
                              scale=tuple(scale * font_size),
                              font=font)
     bounds = self.text.getTightBounds()
     self.frame['canvasSize'] = [
         0, bounds[1][0] - bounds[0][0], -bounds[1][2] + bounds[0][2], 0
     ]
     self.frame['frameSize'] = [0, 0.5, -0.5, 0]
     self.text.setPos(-bounds[0][0], -bounds[1][2])
     self.frame.setPos(0, 0, 0)
コード例 #3
0
    def __init__(self):
        '''
        Constructor
        '''
        SogalForm.__init__(self, fading = True, fading_duration = 0.3, enableMask = True,backgroundColor = (0,0,0,0.6))
        self.reparentTo(aspect2d,sort = 101)
        

        self.frame = DirectScrolledFrame(parent = self, canvasSize = CANVASSIZE, 
                                         frameSize = FRAMESIZE, 
                                         autoHideScrollBars = AUTO_HIDE_SCROLLBARS,
                                         )
        
        self.reloadTheme()
        
        self.height = TOP
        self.shiftedHeight = 0
        self.shifter = NodePath('text_history_shifter')
        self.shifter.reparentTo(self.frame.getCanvas())
        
        if not prop_set_up:
            nameprops = TextProperties()  # @UndefinedVariable
            nameprops.setTextScale(0.75)
            TextPropertiesManager.getGlobalPtr().setProperties("th_name", nameprops)  # @UndefinedVariable
 
        self.labels = []
コード例 #4
0
    def __init__(self, parent, getEditorRootCanvas, elementDict,
                 selectedElement):
        height = DGH.getRealHeight(parent)
        self.collapsedElements = []

        self.parent = parent

        self.box = DirectBoxSizer(frameColor=(0.25, 0.25, 0.25, 1),
                                  autoUpdateFrameSize=False,
                                  orientation=DGG.VERTICAL)
        self.sizer = DirectAutoSizer(parent=parent,
                                     child=self.box,
                                     childUpdateSizeFunc=self.box.refresh)

        self.lblHeader = DirectLabel(
            text="Structure",
            text_scale=16,
            text_align=TextNode.ALeft,
            text_fg=(1, 1, 1, 1),
            frameColor=VBase4(0, 0, 0, 0),
        )
        self.box.addItem(self.lblHeader)

        color = (
            (0.8, 0.8, 0.8, 1),  # Normal
            (0.9, 0.9, 1, 1),  # Click
            (0.8, 0.8, 1, 1),  # Hover
            (0.5, 0.5, 0.5, 1))  # Disabled
        self.structureFrame = DirectScrolledFrame(
            # make the frame fit into our background frame
            frameSize=VBase4(
                self.parent["frameSize"][0], self.parent["frameSize"][1],
                self.parent["frameSize"][2] +
                DGH.getRealHeight(self.lblHeader),
                self.parent["frameSize"][3]),
            #canvasSize=VBase4(parent["frameSize"][0], parent["frameSize"][1]-20, height+30, 0),
            # set the frames color to transparent
            frameColor=VBase4(1, 1, 1, 1),
            scrollBarWidth=20,
            verticalScroll_scrollSize=20,
            verticalScroll_thumb_relief=DGG.FLAT,
            verticalScroll_incButton_relief=DGG.FLAT,
            verticalScroll_decButton_relief=DGG.FLAT,
            verticalScroll_thumb_frameColor=color,
            verticalScroll_incButton_frameColor=color,
            verticalScroll_decButton_frameColor=color,
            horizontalScroll_thumb_relief=DGG.FLAT,
            horizontalScroll_incButton_relief=DGG.FLAT,
            horizontalScroll_decButton_relief=DGG.FLAT,
            horizontalScroll_thumb_frameColor=color,
            horizontalScroll_incButton_frameColor=color,
            horizontalScroll_decButton_frameColor=color,
            state=DGG.NORMAL)
        self.box.addItem(self.structureFrame)
        self.structureFrame.bind(DGG.MWDOWN, self.scroll, [0.01])
        self.structureFrame.bind(DGG.MWUP, self.scroll, [-0.01])
        self.maxWidth = parent["frameSize"][1] - 20
        self.getEditorRootCanvas = getEditorRootCanvas
        self.refreshStructureTree(elementDict, selectedElement)
コード例 #5
0
ファイル: messagefrm.py プロジェクト: xinxinxinxinxin/yorg
 def __init__(self, menu_args):
     GameObject.__init__(self)
     self.eng.log('created match message form')
     self.chat = None
     self.msg_frm = DirectFrame(
         frameSize=(-.02, 2.5, 0, 1.22),
         frameColor=(.2, .2, .2, .5),
         pos=(.04, 1, -1.69), parent=base.a2dTopLeft)
     t_a = menu_args.text_args
     t_a['scale'] = .05
     t_a['fg'] = menu_args.text_normal
     self.dst_txt = OnscreenText(
         text='', pos=(0, 1.16), parent=self.msg_frm, align=TextNode.A_left,
         **t_a)
     self.ent = Entry(
         scale=.04, pos=(0, 1, .03), entryFont=menu_args.font, width=62,
         frameColor=menu_args.btn_color, parent=self.msg_frm,
         initialText=_('write here your message'),
         command=self.on_typed_msg, focusInCommand=self.on_focus,
         focusInExtraArgs=['in'], focusOutCommand=self.on_focus,
         focusOutExtraArgs=['out'], text_fg=menu_args.text_active)
     self.ent['state'] = DISABLED
     self.txt_frm = DirectScrolledFrame(
         frameSize=(-.02, 2.46, -.02, 1.02),
         canvasSize=(-.02, 2.42, -.02, 1.02),
         scrollBarWidth=.036,
         verticalScroll_relief=FLAT,
         verticalScroll_frameColor=(.2, .2, .2, .4),
         verticalScroll_thumb_relief=FLAT,
         verticalScroll_thumb_frameColor=(.8, .8, .8, .6),
         verticalScroll_incButton_relief=FLAT,
         verticalScroll_incButton_frameColor=(.8, .8, .8, .6),
         verticalScroll_decButton_relief=FLAT,
         verticalScroll_decButton_frameColor=(.8, .8, .8, .6),
         horizontalScroll_relief=FLAT,
         frameColor=(1, 1, 1, .0),
         pos=(.02, 1, .11), parent=self.msg_frm)
     t_a['scale'] = .046
     self.msg_txt = OnscreenText(
         text='', pos=(0, .24), parent=self.txt_frm.getCanvas(),
         align=TextNode.A_left, wordwrap=52, **t_a)
     lab_args = menu_args.label_args
     lab_args['scale'] = .046
     lab_args['text_fg'] = menu_args.text_normal
     self.lab_frm = Btn(
         frameSize=(-.02, 2.5, -.01, .05),
         frameColor=(1, 1, 1, 0),
         pos=(0, 1, 1.15), parent=self.msg_frm)
     self.lab_frm.bind(ENTER, self.on_enter)
     self.lab_frm.bind(EXIT, self.on_exit)
     self.tooltip = DirectLabel(
         text='', pos=(2.4, 1, -.06),
         parent=self.lab_frm, text_wordwrap=50, text_bg=(.2, .2, .2, .8),
         text_align=TextNode.A_right, **lab_args)
     self.tooltip.set_bin('gui-popup', 10)
     self.tooltip.hide()
コード例 #6
0
ファイル: save_load_form.py プロジェクト: PlumpMath/Sogal
    def __init__(self):
        '''
        Constructor
        '''
        SogalForm.__init__(self,
                           fading=True,
                           fading_duration=0.5,
                           enableMask=True,
                           backgroundColor=color_themes.sirius_bgColor)
        self.reparentTo(aspect2d, sort=102)

        self.frame = DirectScrolledFrame(
            parent=self,
            canvasSize=LOAD_CANVAS_SIZE,
            frameSize=FRAMESIZE,
            autoHideScrollBars=AUTO_HIDE_SCROLLBARS,
            **color_themes.sirius_frame)

        self.labels = []
        self.labelDict = {}
        self.vbox = VLayout(parent=self.frame.getCanvas(), margin=vspacing)

        hbox = None
        self.__dumped = None

        pos2 = MAX_SAVE + runtime_data.MAX_QUICKSAVE
        pos3 = MAX_SAVE + runtime_data.MAX_QUICKSAVE + runtime_data.MAX_AUTOSAVE
        for i in range(1, pos3 + 1):
            if i <= MAX_SAVE:
                fname = 'save' + str(i)
                head = str(i)
            elif MAX_SAVE < i <= pos2:
                index = i - MAX_SAVE
                fname = 'quick_save' + str(index)
                head = 'Quick Save ' + str(index)
            elif pos2 < i <= pos3:
                index = i - pos2
                fname = 'auto_save' + str(index)
                head = 'Auto Save ' + str(index)

            label = SaveLoadLabel(command=self.load,
                                  always_enable=False,
                                  fileName=fname,
                                  head=head,
                                  extraArgs=[fname],
                                  style=color_themes.sirius_button)
            self.labels.append(label)
            self.labelDict[label.getFileName()] = label
            if not hbox:
                hbox = HLayout(margin=hspacing)
                self.vbox.append(hbox)
                hbox.append(label)
            else:
                hbox.append(label)
                hbox = None
コード例 #7
0
 def createDirectScrolledFrame(self, parent=None):
     parent = self.getEditorRootCanvas() if parent is None else parent
     pos = self.editorCenter if parent == self.getEditorRootCanvas() else (0,0,0)
     if self.visEditorInAspect2D:
         element = DirectScrolledFrame(
             frameColor=(1,1,1,1),
             frameSize=(-1,1,-1,1),
             canvasSize=(-2,2,-2,2),
             parent=parent,
             state = DGG.NORMAL)
     else:
         element = DirectScrolledFrame(
             frameColor=(1,1,1,1),
             text_scale=24,
             frameSize=(-150, 150, -150, 150),
             pos=pos,
             borderWidth=(2, 2),
             canvasSize=(-300,300,-300,300),
             scrollBarWidth=20,
             parent=parent,
             state = DGG.NORMAL)
     elementInfo = ElementInfo(element, "DirectScrolledFrame")
     self.setupBind(elementInfo)
     return elementInfo
コード例 #8
0
    def _create_components(self):
        """ Internal method to create the window components """
        DraggableWindow._create_components(self)

        self._content_frame = DirectScrolledFrame(
            frameSize=(0, self._width - 40, 0, self._height - 80),
            canvasSize=(0, self._scroll_width, 0, self._scroll_height),
            autoHideScrollBars=False,
            scrollBarWidth=20.0,
            frameColor=(0, 0, 0, 0),
            verticalScroll_relief=False,
            horizontalScroll_relief=False,
            parent=self._node,
            pos=(20, 1, -self._height + 20))
        self._content_node = self._content_frame.getCanvas().attach_new_node("PipeComponents")
        self._content_node.set_scale(1, 1, -1)
        self._content_node.set_z(self._scroll_height)
コード例 #9
0
 def __init__(self, menu_args, yorg_srv):
     GameObject.__init__(self)
     self.eng.log('create users form')
     self.ver_check = VersionChecker()
     self.yorg_srv = yorg_srv
     self.room_name = None
     self.labels = []
     self.invited_users = []
     self.menu_args = menu_args
     lab_args = menu_args.label_args
     lab_args['scale'] = .046
     self.users_lab = DirectLabel(text=_('Current online users'),
                                  pos=(-.85, 1, -.02),
                                  hpr=(0, 0, -90),
                                  parent=base.a2dTopRight,
                                  text_align=TextNode.A_right,
                                  **lab_args)
     self.frm = DirectScrolledFrame(
         frameSize=(-.02, .8, .45, 2.43),
         canvasSize=(-.02, .76, -.08, 3.8),
         scrollBarWidth=.036,
         verticalScroll_relief=FLAT,
         verticalScroll_frameColor=(.2, .2, .2, .4),
         verticalScroll_thumb_relief=FLAT,
         verticalScroll_thumb_frameColor=(.8, .8, .8, .6),
         verticalScroll_incButton_relief=FLAT,
         verticalScroll_incButton_frameColor=(.8, .8, .8, .6),
         verticalScroll_decButton_relief=FLAT,
         verticalScroll_decButton_frameColor=(.8, .8, .8, .6),
         horizontalScroll_relief=FLAT,
         frameColor=(.2, .2, .2, .5),
         pos=(-.82, 1, -2.44),
         parent=base.a2dTopRight)
     self.conn_lab = DirectLabel(text='',
                                 pos=(.38, 1, 1.5),
                                 parent=self.frm,
                                 text_wordwrap=10,
                                 **lab_args)
     self.set_connection_label()
     self.in_match_room = None
     self.invited = False
コード例 #10
0
ファイル: save_load_form.py プロジェクト: PlumpMath/Sogal
    def __init__(self):
        '''
        Constructor
        '''
        SogalForm.__init__(self,
                           fading=True,
                           fading_duration=0.5,
                           enableMask=True,
                           backgroundColor=color_themes.ilia_bgColor)
        self.reparentTo(aspect2d, sort=102)
        self.frame = DirectScrolledFrame(
            parent=self,
            canvasSize=SAVE_CANVAS_SIZE,
            frameSize=FRAMESIZE,
            autoHideScrollBars=AUTO_HIDE_SCROLLBARS,
            **color_themes.ilia_frame)

        self.labels = []
        self.labelDict = {}
        self.vbox = VLayout(parent=self.frame.getCanvas(), margin=vspacing)
        hbox = None
        self.__dumped = None
        for i in range(1, MAX_SAVE + 1):
            fname = 'save' + str(i)
            head = str(i)
            label = SaveLoadLabel(command=self.save,
                                  always_enable=True,
                                  fileName=fname,
                                  head=head,
                                  extraArgs=[fname],
                                  style=color_themes.ilia_button)
            self.labels.append(label)
            self.labelDict[label.getFileName()] = label
            if not hbox:
                hbox = HLayout(margin=hspacing)
                self.vbox.append(hbox)
                hbox.append(label)
            else:
                hbox.append(label)
                hbox = None
コード例 #11
0
    def _create_components(self):
        """ Creates the window components """
        DraggableWindow._create_components(self)

        self._content_frame = DirectScrolledFrame(
            frameSize=(0, self._width - 15, 0, self._height - 70),
            canvasSize=(0, self._width - 80, 0, self._scroll_height),
            autoHideScrollBars=False,
            scrollBarWidth=12.0,
            frameColor=(0, 0, 0, 0),
            verticalScroll_relief=DGG.FLAT,
            verticalScroll_incButton_relief=DGG.FLAT,
            verticalScroll_decButton_relief=DGG.FLAT,
            verticalScroll_thumb_relief=DGG.FLAT,
            verticalScroll_frameColor=(0.05, 0.05, 0.05, 1),
            verticalScroll_thumb_frameColor=(0.8, 0.8, 0.8, 1),
            verticalScroll_incButton_frameColor=(0.6, 0.6, 0.6, 1),
            verticalScroll_decButton_frameColor=(0.6, 0.6, 0.6, 1),
            horizontalScroll_frameColor=(0, 0, 0, 0),
            horizontalScroll_relief=False,
            horizontalScroll_thumb_relief=False,
            horizontalScroll_incButton_relief=False,
            horizontalScroll_decButton_relief=False,
            parent=self._node,
            pos=(0, 1, -self._height))
        self._content_node = self._content_frame.getCanvas().attach_new_node(
            "BufferComponents")
        self._content_node.set_scale(1, 1, -1)
        self._content_node.set_z(self._scroll_height)
        self._chb_show_images = LabeledCheckbox(
            parent=self._node,
            x=10,
            y=43,
            chb_callback=self._set_show_images,
            chb_checked=False,
            text="Display image resources",
            text_color=Vec3(0.4),
            expand_width=330)
コード例 #12
0
    def __init__(self, parent):
        height = DGH.getRealHeight(parent)
        self.parent = parent

        self.box = DirectBoxSizer(frameColor=(0.25, 0.25, 0.25, 1),
                                  autoUpdateFrameSize=False,
                                  orientation=DGG.VERTICAL)
        self.sizer = DirectAutoSizer(parent=parent,
                                     child=self.box,
                                     childUpdateSizeFunc=self.box.refresh)

        self.lblHeader = DirectLabel(
            text="Toolbox",
            text_scale=16,
            text_align=TextNode.ALeft,
            text_fg=(1, 1, 1, 1),
            frameColor=VBase4(0, 0, 0, 0),
        )
        self.box.addItem(self.lblHeader)

        color = (
            (0.8, 0.8, 0.8, 1),  # Normal
            (0.9, 0.9, 1, 1),  # Click
            (0.8, 0.8, 1, 1),  # Hover
            (0.5, 0.5, 0.5, 1))  # Disabled
        self.toolboxFrame = DirectScrolledFrame(
            # make the frame fit into our background frame
            frameSize=VBase4(
                self.parent["frameSize"][0], self.parent["frameSize"][1],
                self.parent["frameSize"][2] +
                DGH.getRealHeight(self.lblHeader),
                self.parent["frameSize"][3]),
            scrollBarWidth=20,
            verticalScroll_scrollSize=20,
            verticalScroll_thumb_relief=DGG.FLAT,
            verticalScroll_incButton_relief=DGG.FLAT,
            verticalScroll_decButton_relief=DGG.FLAT,
            verticalScroll_thumb_frameColor=color,
            verticalScroll_incButton_frameColor=color,
            verticalScroll_decButton_frameColor=color,
            horizontalScroll_thumb_relief=DGG.FLAT,
            horizontalScroll_incButton_relief=DGG.FLAT,
            horizontalScroll_decButton_relief=DGG.FLAT,
            horizontalScroll_thumb_frameColor=color,
            horizontalScroll_incButton_frameColor=color,
            horizontalScroll_decButton_frameColor=color,
            state=DGG.NORMAL)
        self.box.addItem(self.toolboxFrame)
        self.toolboxFrame.bind(DGG.MWDOWN, self.scroll, [0.01])
        self.toolboxFrame.bind(DGG.MWUP, self.scroll, [-0.01])
        self.toolboxEntries = [
            ["~Interactive Elements~"],
            ["Button", "DirectButton"],
            ["Entry", "DirectEntry"],
            ["Scrolled Entry", "DirectEntryScroll"],
            ["Check Box", "DirectCheckBox"],
            ["Check Button", "DirectCheckButton"],
            ["Option Menu", "DirectOptionMenu"],
            ["Radio Button", "DirectRadioButton"],
            ["Slider", "DirectSlider"],
            ["Scroll Bar", "DirectScrollBar"],
            ["Scrolled List Item", "DirectScrolledListItem"],
            ["~Display Elements~"],
            ["Label", "DirectLabel"],
            ["Wait Bar", "DirectWaitBar"],
            ["~Container~"],
            ["Frame", "DirectFrame"],
            ["Scrolled Frame", "DirectScrolledFrame"],
            ["Scrolled List", "DirectScrolledList"],
            ["~Dialogs~"],
            ["OK Dialog", "OkDialog"],
            ["OK Cancel Dialog", "OkCancelDialog"],
            ["Yes No Dialog", "YesNoDialog"],
            ["Yes No Cancel Dialog", "YesNoCancelDialog"],
            ["Retry Cancel Dialog", "RetryCancelDialog"],
        ]
        self.createEntries()
コード例 #13
0
    def __init__(self, rootParent=None):

        self.frmMain = DirectFrame(
            frameColor=(1, 1, 1, 1),
            frameSize=(-1.777778, 1.77777778, -1.1638, 1.1638),
            hpr=LVecBase3f(0, 0, 0),
            image='assets/menu/Background.png',
            pos=LPoint3f(0, 0, 0),
            image_scale=LVecBase3f(1.77778, 1, 1.1638),
            image_pos=LPoint3f(0, 0, 0),
            parent=rootParent,
        )
        self.frmMain.setTransparency(0)

        self.frmRoomList = DirectScrolledFrame(
            canvasSize=(-1.0, 1.0, -2.0, 0.0),
            frameColor=(1, 1, 1, 1),
            frameSize=(-1.0, 1.08, -1.4, 0.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0, 0, 0.7),
            scrollBarWidth=0.08,
            state='normal',
            horizontalScroll_borderWidth=(0.01, 0.01),
            horizontalScroll_frameSize=(-0.05, 0.05, -0.04, 0.04),
            horizontalScroll_hpr=LVecBase3f(0, 0, 0),
            horizontalScroll_pos=LPoint3f(0, 0, 0),
            horizontalScroll_decButton_borderWidth=(0.01, 0.01),
            horizontalScroll_decButton_frameSize=(-0.05, 0.05, -0.04, 0.04),
            horizontalScroll_decButton_hpr=LVecBase3f(0, 0, 0),
            horizontalScroll_decButton_pos=LPoint3f(-0.96, 0, -1.36),
            horizontalScroll_incButton_borderWidth=(0.01, 0.01),
            horizontalScroll_incButton_frameSize=(-0.05, 0.05, -0.04, 0.04),
            horizontalScroll_incButton_hpr=LVecBase3f(0, 0, 0),
            horizontalScroll_incButton_pos=LPoint3f(0.96, 0, -1.36),
            horizontalScroll_thumb_borderWidth=(0.01, 0.01),
            horizontalScroll_thumb_hpr=LVecBase3f(0, 0, 0),
            horizontalScroll_thumb_pos=LPoint3f(0, 0, -1.36),
            verticalScroll_borderWidth=(0.01, 0.01),
            verticalScroll_frameSize=(-0.04, 0.04, -0.05, 0.05),
            verticalScroll_hpr=LVecBase3f(0, 0, 0),
            verticalScroll_pos=LPoint3f(0, 0, 0),
            verticalScroll_decButton_borderWidth=(0.01, 0.01),
            verticalScroll_decButton_frameSize=(-0.04, 0.04, -0.05, 0.05),
            verticalScroll_decButton_hpr=LVecBase3f(0, 0, 0),
            verticalScroll_decButton_pos=LPoint3f(1.04, 0, -0.04),
            verticalScroll_incButton_borderWidth=(0.01, 0.01),
            verticalScroll_incButton_frameSize=(-0.04, 0.04, -0.05, 0.05),
            verticalScroll_incButton_hpr=LVecBase3f(0, 0, 0),
            verticalScroll_incButton_pos=LPoint3f(1.04, 0, -1.28),
            verticalScroll_thumb_borderWidth=(0.01, 0.01),
            verticalScroll_thumb_hpr=LVecBase3f(0, 0, 0),
            verticalScroll_thumb_pos=LPoint3f(1.04, 0, -0.4628),
            parent=self.frmMain,
        )
        self.frmRoomList.setTransparency(0)

        self.btnBack = DirectButton(
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0.96, 0, -0.825),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Back',
            text_align=TextNode.A_center,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
            command=base.messenger.send,
            extraArgs=["roomList_back"],
        )
        self.btnBack.setTransparency(0)

        self.lblRoomName = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(-1, 0, 0.725),
            scale=LVecBase3f(0.07, 0.1, 0.07),
            text='Room Name',
            text_align=TextNode.A_left,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
        )
        self.lblRoomName.setTransparency(0)

        self.lblPlayerCount = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(-0.15, 0, 0.725),
            scale=LVecBase3f(0.07, 0.1, 0.07),
            text='Players',
            text_align=TextNode.A_center,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
        )
        self.lblPlayerCount.setTransparency(0)

        self.btnCreateRoom = DirectButton(
            hpr=LVecBase3f(0, 0, 0),
            pad=(0.2, 0.2),
            pos=LPoint3f(-0.955, 0, -0.815),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='+',
            text_align=TextNode.A_center,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
        )
        self.btnCreateRoom.setTransparency(0)

        self.btnReloadRoomList = DirectButton(
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0.025, 0, -0.825),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Reload Rooms',
            text_align=TextNode.A_center,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
            command=base.messenger.send,
            extraArgs=["roomList_reload"],
        )
        self.btnReloadRoomList.setTransparency(0)

        self.lblGameType = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0.125, 0, 0.725),
            scale=LVecBase3f(0.07, 0.1, 0.07),
            text='Type',
            text_align=TextNode.A_center,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
        )
        self.lblGameType.setTransparency(0)

        self.lblDifficulty = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0.54, 0, 0.72),
            scale=LVecBase3f(0.07, 0.1, 0.07),
            text='Difficulty',
            text_align=TextNode.A_center,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
        )
        self.lblDifficulty.setTransparency(0)
コード例 #14
0
def test_set_scrollbar_width_on_init():
    frm = DirectScrolledFrame(verticalScroll_frameSize=(-2, 2, -4, 4), horizontalScroll_frameSize=(-4, 4, -2, 2))
    assert frm.verticalScroll['frameSize'] == (-2, 2, -4, 4)
    assert frm.horizontalScroll['frameSize'] == (-4, 4, -2, 2)
コード例 #15
0
    def __init__(self, command, fileBrowser=False, defaultPath="~", defaultFilename="unnamed.txt", fileExtensions=[], tooltip=None):
        """
        A simple file and folder browser

        command: The command that will be called on closing the browser
        fileBrowser: If set to True the browser will show files, otherwise it will only show folders
        defaultPath: The initial path the browser will be set to show
        defaultFilename: The filename that will be set by default, only usefull if fileBrowser is True
        fileExtensions: A list of extensions. Only files with those extensions will be shown. Only usefull if fileBrowser is True
        tooltip: An instance of the Tooltip class to display tooltips for certain parts of the editor
        """
        self.tt = tooltip
        self.command = command
        self.showFiles = fileBrowser
        self.fileExtensions = fileExtensions
        self.showHidden = False

        self.currentPath = os.path.expanduser(defaultPath)
        if not os.path.exists(self.currentPath):
            self.currentPath = os.path.expanduser("~")
        self.previousPath = self.currentPath

        self.screenWidthPx = base.getSize()[0]
        self.screenWidthPxHalf = self.screenWidthPx * 0.5
        self.screenHeightPx = base.getSize()[1]
        self.screenHeightPxHalf = self.screenHeightPx * 0.5

        self.mainFrame = DirectFrame(
            relief=1,
            frameSize=(-self.screenWidthPxHalf,self.screenWidthPxHalf,-self.screenHeightPxHalf,self.screenHeightPxHalf),
            frameColor=(1, 1, 1, 1),
            pos=LPoint3f(base.getSize()[0]/2, 0, -base.getSize()[1]/2),
            parent=base.pixel2d,
            state=DGG.NORMAL,
        )

        self.pathRightMargin = 153
        self.pathEntryWidth = self.screenWidthPx - self.pathRightMargin

        self.pathEntry = DirectEntry(
            parent=self.mainFrame,
            relief=DGG.SUNKEN,
            frameColor=(1, 1, 1, 1),
            pad=(0.2, 0.2),
            pos=LPoint3f(-self.screenWidthPxHalf + 15, 0, self.screenHeightPxHalf - 25),
            scale=12,
            width=self.pathEntryWidth/12,
            overflow=True,
            command=self.entryAccept,
            initialText=self.currentPath,
            focusInCommand=base.messenger.send,
            focusInExtraArgs=["unregisterKeyboardEvents"],
            focusOutCommand=base.messenger.send,
            focusOutExtraArgs=["reregisterKeyboardEvents"],
        )
        x = self.pathEntryWidth/2-28
        self.btnReload = DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor = (
                (0.8, 0.8, 0.8, 1), # Normal
                (0.9, 0.9, 1, 1), # Click
                (0.8, 0.8, 1, 1), # Hover
                (0.5, 0.5, 0.5, 1)), # Disabled
            frameSize=(-14, 14, -10, 18),
            pos=LPoint3f(x, 0, self.screenHeightPxHalf - 25),
            command=self.folderReload,
            image="icons/Reload.png",
            image_scale=14,
            image_pos=(0,0,4),
        )
        self.btnReload.setTransparency(TransparencyAttrib.M_multisample)
        if self.tt is not None:
            self.btnReload.bind(DGG.ENTER, self.tt.show, ["Reload Folder"])
            self.btnReload.bind(DGG.EXIT, self.tt.hide)
        x += 28
        self.btnFolderUp = DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor = (
                (0.8, 0.8, 0.8, 1), # Normal
                (0.9, 0.9, 1, 1), # Click
                (0.8, 0.8, 1, 1), # Hover
                (0.5, 0.5, 0.5, 1)), # Disabled
            frameSize=(-14, 14, -10, 18),
            pos=LPoint3f(x, 0, self.screenHeightPxHalf - 25),
            command=self.folderUp,
            image="icons/FolderUp.png",
            image_scale=14,
            image_pos=(0,0,4),
        )
        self.btnFolderUp.setTransparency(TransparencyAttrib.M_multisample)
        if self.tt is not None:
            self.btnFolderUp.bind(DGG.ENTER, self.tt.show, ["Move up one level"])
            self.btnFolderUp.bind(DGG.EXIT, self.tt.hide)
        x += 28
        self.btnFolderNew = DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor = (
                (0.8, 0.8, 0.8, 1), # Normal
                (0.9, 0.9, 1, 1), # Click
                (0.8, 0.8, 1, 1), # Hover
                (0.5, 0.5, 0.5, 1)), # Disabled
            frameSize=(-14, 14, -10, 18),
            pos=LPoint3f(x, 0, self.screenHeightPxHalf - 25),
            command=self.folderNew,
            image="icons/FolderNew.png",
            image_scale=14,
            image_pos=(0,0,4),
        )
        self.btnFolderNew.setTransparency(TransparencyAttrib.M_multisample)
        if self.tt is not None:
            self.btnFolderNew.bind(DGG.ENTER, self.tt.show, ["Create new folder"])
            self.btnFolderNew.bind(DGG.EXIT, self.tt.hide)
        x += 28
        self.btnFolderShowHidden = DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor = (
                (0.8, 0.8, 0.8, 1), # Normal
                (0.9, 0.9, 1, 1), # Click
                (0.8, 0.8, 1, 1), # Hover
                (0.5, 0.5, 0.5, 1)), # Disabled
            frameSize=(-14, 14, -10, 18),
            pos=LPoint3f(x, 0, self.screenHeightPxHalf - 25),
            command=self.folderShowHidden,
            image="icons/FolderShowHidden.png",
            image_scale=14,
            image_pos=(0,0,4),
        )
        self.btnFolderShowHidden.setTransparency(TransparencyAttrib.M_multisample)
        if self.tt is not None:
            self.btnFolderShowHidden.bind(DGG.ENTER, self.tt.show, ["Show/Hide hidden files and folders"])
            self.btnFolderShowHidden.bind(DGG.EXIT, self.tt.hide)

        color = (
            (0.8, 0.8, 0.8, 1), # Normal
            (0.9, 0.9, 1, 1), # Click
            (0.8, 0.8, 1, 1), # Hover
            (0.5, 0.5, 0.5, 1)) # Disabled
        self.container = DirectScrolledFrame(
            relief=DGG.RIDGE,
            borderWidth=(2, 2),
            frameColor=(1, 1, 1, 1),
            frameSize=(-self.screenWidthPxHalf+10, self.screenWidthPxHalf-10, -self.screenHeightPxHalf+50, self.screenHeightPxHalf-50),
            canvasSize=(-self.screenWidthPxHalf+31, self.screenWidthPxHalf-10, -self.screenHeightPxHalf+50, self.screenHeightPxHalf-50),
            pos=LPoint3f(0, 0, 0),
            parent=self.mainFrame,
            scrollBarWidth=20,
            verticalScroll_scrollSize=20,
            verticalScroll_thumb_relief=DGG.FLAT,
            verticalScroll_incButton_relief=DGG.FLAT,
            verticalScroll_decButton_relief=DGG.FLAT,
            verticalScroll_thumb_frameColor=color,
            verticalScroll_incButton_frameColor=color,
            verticalScroll_decButton_frameColor=color,
            horizontalScroll_thumb_relief=DGG.FLAT,
            horizontalScroll_incButton_relief=DGG.FLAT,
            horizontalScroll_decButton_relief=DGG.FLAT,
            horizontalScroll_thumb_frameColor=color,
            horizontalScroll_incButton_frameColor=color,
            horizontalScroll_decButton_frameColor=color,
            state=DGG.NORMAL,
        )
        self.container.bind(DGG.MWDOWN, self.scroll, [0.01])
        self.container.bind(DGG.MWUP, self.scroll, [-0.01])

        self.btnOk = DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor = (
                (0.8, 0.8, 0.8, 1), # Normal
                (0.9, 0.9, 1, 1), # Click
                (0.8, 0.8, 1, 1), # Hover
                (0.5, 0.5, 0.5, 1)), # Disabled
            frameSize=(-45, 45, -6, 14),
            pos=LPoint3f(self.screenWidthPxHalf-160, 0, -self.screenHeightPxHalf+25),
            text = "ok",
            text_scale=12,
            command=command,
            extraArgs=[1],
        )
        self.btnCancel = DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor = (
                (0.8, 0.8, 0.8, 1), # Normal
                (0.9, 0.9, 1, 1), # Click
                (0.8, 0.8, 1, 1), # Hover
                (0.5, 0.5, 0.5, 1)), # Disabled
            frameSize=(-45, 45, -6, 14),
            pos=LPoint3f(self.screenWidthPxHalf-55, 0, -self.screenHeightPxHalf+25),
            text = "Cancel",
            text_scale=12,
            command=command,
            extraArgs=[0]
        )

        if self.showFiles:
            self.txtFileName = DirectEntry(
                parent=self.mainFrame,
                relief=DGG.SUNKEN,
                frameColor=(1, 1, 1, 1),
                pad=(0.2, 0.2),
                pos=LPoint3f(-self.screenWidthPxHalf+25, 0, -self.screenHeightPxHalf+25),
                scale=12,
                width=200/12,
                overflow=True,
                command=self.filenameAccept,
                initialText=defaultFilename,
                focusInCommand=base.messenger.send,
                focusInExtraArgs=["unregisterKeyboardEvents"],
                focusOutCommand=base.messenger.send,
                focusOutExtraArgs=["reregisterKeyboardEvents"],
            )

        self.newFolderFrame = DirectFrame(
            parent=self.mainFrame,
            relief=1,
            frameSize=(-self.screenWidthPxHalf+10,self.screenWidthPxHalf-10,-20,20),
            pos=LPoint3f(0, 0, self.screenHeightPxHalf-55),
            frameColor=(0.5,0.5,0.5,1),
        )
        self.txtNewFolderName = DirectLabel(
            parent=self.newFolderFrame,
            text="New Folder Name",
            text_scale=12,
            frameColor=(0,0,0,0),
            text_align=TextNode.ALeft,
            pos=(-self.screenWidthPxHalf+15, 0, -3),
        )
        self.folderName = DirectEntry(
            parent=self.newFolderFrame,
            relief=DGG.SUNKEN,
            frameColor=(1, 1, 1, 1),
            pad=(0.2, 0.2),
            pos=LPoint3f(-self.screenWidthPxHalf+25 + self.txtNewFolderName.getWidth(), 0, -4),
            scale=12,
            width=((self.screenWidthPxHalf-25)*2-self.txtNewFolderName.getWidth() - 100)/12,
            overflow=True,
            command=self.entryAccept,
            initialText="New Folder",
            focusInCommand=base.messenger.send,
            focusInExtraArgs=["unregisterKeyboardEvents"],
            focusOutCommand=base.messenger.send,
            focusOutExtraArgs=["reregisterKeyboardEvents"],
        )
        self.btnCreate = DirectButton(
            parent=self.newFolderFrame,
            relief=1,
            frameColor = (
                (0.8, 0.8, 0.8, 1), # Normal
                (0.9, 0.9, 1, 1), # Click
                (0.8, 0.8, 1, 1), # Hover
                (0.5, 0.5, 0.5, 1)), # Disabled
            frameSize=(-45, 45, -6, 14),
            pos=LPoint3f(self.screenWidthPxHalf-65, 0, -4),
            text = "Create",
            text_scale=12,
            command=self.folderCreate,
            extraArgs=[0]
        )
        self.newFolderFrame.hide()

        self.folderReload()

        # handle window resizing
        self.prevScreenSize = base.getSize()
        self.accept("window-event", self.windowEventHandler)
コード例 #16
0
ファイル: Chat.py プロジェクト: fireclawthefox/AnkandoraLight
    def __init__(self, rootParent=None):
        
        self.frmChat = DirectFrame(
            frameColor=(0.25, 0.25, 0.25, 1.0),
            frameSize=(-0.4, 0.4, -1.25, 0.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0, 0, 0),
            parent=rootParent,
        )
        self.frmChat.setTransparency(0)

        self.frmMessages = DirectScrolledFrame(
            borderWidth=(0.005, 0.005),
            canvasSize=(-0.38, 0.34, -1.2, 0.0),
            frameColor=(1, 1, 1, 1),
            frameSize=(-0.38, 0.38, -1.0, 0.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0, 0, -0.1),
            relief=3,
            scrollBarWidth=0.03,
            state='normal',
            horizontalScroll_borderWidth=(0.01, 0.01),
            horizontalScroll_frameSize=(-0.05, 0.05, -0.015, 0.015),
            horizontalScroll_hpr=LVecBase3f(0, 0, 0),
            horizontalScroll_pos=LPoint3f(0, 0, 0),
            horizontalScroll_decButton_borderWidth=(0.01, 0.01),
            horizontalScroll_decButton_frameSize=(-0.05, 0.05, -0.04, 0.04),
            horizontalScroll_decButton_hpr=LVecBase3f(0, 0, 0),
            horizontalScroll_decButton_pos=LPoint3f(0, 0, 0),
            horizontalScroll_incButton_borderWidth=(0.01, 0.01),
            horizontalScroll_incButton_frameSize=(-0.05, 0.05, -0.04, 0.04),
            horizontalScroll_incButton_hpr=LVecBase3f(0, 0, 0),
            horizontalScroll_incButton_pos=LPoint3f(0, 0, 0),
            horizontalScroll_thumb_borderWidth=(0.01, 0.01),
            horizontalScroll_thumb_hpr=LVecBase3f(0, 0, 0),
            horizontalScroll_thumb_pos=LPoint3f(0, 0, 0),
            verticalScroll_borderWidth=(0.01, 0.01),
            verticalScroll_frameSize=(-0.015, 0.015, -0.05, 0.05),
            verticalScroll_hpr=LVecBase3f(0, 0, 0),
            verticalScroll_pos=LPoint3f(0, 0, 0),
            verticalScroll_decButton_borderWidth=(0.01, 0.01),
            verticalScroll_decButton_frameSize=(-0.04, 0.04, -0.05, 0.05),
            verticalScroll_decButton_hpr=LVecBase3f(0, 0, 0),
            verticalScroll_decButton_pos=LPoint3f(0.36, 0, -0.02),
            verticalScroll_incButton_borderWidth=(0.01, 0.01),
            verticalScroll_incButton_frameSize=(-0.04, 0.04, -0.05, 0.05),
            verticalScroll_incButton_hpr=LVecBase3f(0, 0, 0),
            verticalScroll_incButton_pos=LPoint3f(0.36, 0, -0.98),
            verticalScroll_thumb_borderWidth=(0.01, 0.01),
            verticalScroll_thumb_hpr=LVecBase3f(0, 0, 0),
            verticalScroll_thumb_pos=LPoint3f(0.36, 0, -0.418625),
            parent=self.frmChat,
        )
        self.frmMessages.setTransparency(0)

        self.txtMessage = DirectEntry(
            borderWidth=(0.005, 0.005),
            frameColor=(1.0, 1.0, 1.0, 1.0),
            hpr=LVecBase3f(0, 0, 0),
            overflow=1,
            pos=LPoint3f(-0.375, 0, -1.195),
            relief=3,
            scale=LVecBase3f(0.045, 0.045, 0.045),
            width=14.0,
            text_align=TextNode.A_left,
            text_scale=(1.0, 1.0),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmChat,
        )
        self.txtMessage.setTransparency(0)

        self.btnSend = DirectButton(
            frameColor=(0.0, 0.0, 0.0, 0.0),
            frameSize=(-0.4, 0.4, -0.4, 0.4),
            hpr=LVecBase3f(0, 0, 0),
            image='assets/chat/ChatSend.png',
            pos=LPoint3f(0.33, 0, -1.18),
            relief=1,
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='',
            image_scale=LVecBase3f(0.4, 1, 0.4),
            image_pos=LPoint3f(0, 0, 0),
            text_align=TextNode.A_center,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmChat,
            command=base.messenger.send,
            extraArgs=["sendMessage"],
        )
        self.btnSend.setTransparency(1)

        self.btnToggleChat = DirectButton(
            frameColor=(0.15, 0.15, 0.15, 1.0),
            frameSize=(-0.4, 0.4, -0.02, 0.05),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0, 0, -0.05),
            relief=1,
            scale=LVecBase3f(1, 1, 1),
            text='Toggle Chat',
            text_align=TextNode.A_center,
            text_scale=(0.05, 0.05),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0.8, 0.8, 0.8, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=rootParent,
            command=base.messenger.send,
            extraArgs=["toggleChat"],
        )
        self.btnToggleChat.setTransparency(0)
コード例 #17
0
ファイル: gameScreen.py プロジェクト: fireclawthefox/pyweek31
    def __init__(self, rootParent=None):
        
        self.frmInventory = DirectFrame(
            frameColor=(0.2, 0.2, 0.2, 1.0),
            frameSize=(-0.3, 0.3, -0.5, 0.5),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0.725, 0, 0.2),
            parent=rootParent,
        )
        self.frmInventory.setTransparency(0)

        self.frmContent = DirectScrolledFrame(
            canvasSize=(-0.8, 0.8, -0.8, 0.8),
            frameColor=(0.2, 0.2, 0.2, 1.0),
            frameSize=(-0.8, 0.8, -0.8, 0.8),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(-0.475, 0, 0.1),
            scrollBarWidth=0.08,
            state='normal',
            horizontalScroll_borderWidth=(0.01, 0.01),
            horizontalScroll_frameSize=(-0.05, 0.05, -0.04, 0.04),
            horizontalScroll_hpr=LVecBase3f(0, 0, 0),
            horizontalScroll_pos=LPoint3f(0, 0, 0),
            horizontalScroll_decButton_borderWidth=(0.01, 0.01),
            horizontalScroll_decButton_frameSize=(-0.05, 0.05, -0.04, 0.04),
            horizontalScroll_decButton_hpr=LVecBase3f(0, 0, 0),
            horizontalScroll_decButton_pos=LPoint3f(0, 0, 0),
            horizontalScroll_incButton_borderWidth=(0.01, 0.01),
            horizontalScroll_incButton_frameSize=(-0.05, 0.05, -0.04, 0.04),
            horizontalScroll_incButton_hpr=LVecBase3f(0, 0, 0),
            horizontalScroll_incButton_pos=LPoint3f(0, 0, 0),
            horizontalScroll_thumb_borderWidth=(0.01, 0.01),
            horizontalScroll_thumb_hpr=LVecBase3f(0, 0, 0),
            horizontalScroll_thumb_pos=LPoint3f(0, 0, 0),
            verticalScroll_borderWidth=(0.01, 0.01),
            verticalScroll_frameSize=(-0.04, 0.04, -0.05, 0.05),
            verticalScroll_hpr=LVecBase3f(0, 0, 0),
            verticalScroll_pos=LPoint3f(0, 0, 0),
            verticalScroll_decButton_borderWidth=(0.01, 0.01),
            verticalScroll_decButton_frameSize=(-0.04, 0.04, -0.05, 0.05),
            verticalScroll_decButton_hpr=LVecBase3f(0, 0, 0),
            verticalScroll_decButton_pos=LPoint3f(0, 0, 0),
            verticalScroll_incButton_borderWidth=(0.01, 0.01),
            verticalScroll_incButton_frameSize=(-0.04, 0.04, -0.05, 0.05),
            verticalScroll_incButton_hpr=LVecBase3f(0, 0, 0),
            verticalScroll_incButton_pos=LPoint3f(0, 0, 0),
            verticalScroll_thumb_borderWidth=(0.01, 0.01),
            verticalScroll_thumb_hpr=LVecBase3f(0, 0, 0),
            verticalScroll_thumb_pos=LPoint3f(0, 0, 0),
            parent=rootParent,
        )
        self.frmContent.setTransparency(1)

        self.btnQuit = DirectButton(
            frameSize=(-3.0, 3.0, -0.3, 0.9),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0.725, 0, -0.85),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Quit',
            text_align=TextNode.A_center,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
            command=base.messenger.send,
            extraArgs=["quitGame"],
            pressEffect=1,
        )
        self.btnQuit.setTransparency(0)

        self.btnAudioToggle = DirectButton(
            frameSize=(-3.0, 3.0, -0.3, 0.9),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0.725, 0, -0.7),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Audio On',
            text_align=TextNode.A_center,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
            command=base.messenger.send,
            extraArgs=["toggleAudio"],
            pressEffect=1,
        )
        self.btnAudioToggle.setTransparency(0)

        self.frmBorderOverlay = DirectFrame(
            frameColor=(1.0, 1.0, 1.0, 0.0),
            frameSize=(-0.8, 0.8, -0.8, 0.8),
            hpr=LVecBase3f(0, 0, 0),
            image='gameScreen/border.png',
            pos=LPoint3f(-0.475, 0, 0.1),
            image_scale=LVecBase3f(0.8, 1, 0.8),
            image_pos=LPoint3f(0, 0, 0),
            parent=rootParent,
        )
        self.frmBorderOverlay.setTransparency(1)

        self.lblInventory = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0.725, 0, 0.775),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Inventory',
            text_align=TextNode.A_center,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0.9, 0.9, 0.9, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
        )
        self.lblInventory.setTransparency(0)

        self.lblStory = DirectLabel(
            frameSize=(-0.125, 12.0, -0.313, 0.925),
            hpr=LVecBase3f(0, 0, 0),
            pad=(0.2, 0.2),
            pos=LPoint3f(-1.26, 0, -0.845),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='',
            text_align=TextNode.A_left,
            text_scale=(0.4, 0.4),
            text_pos=(0.0, 0.4),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=29.8,
            parent=rootParent,
        )
        self.lblStory.setTransparency(0)

        self.btnContinue = DirectButton(
            frameSize=(-1.8, 1.8, -0.3, 0.9),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0.145, 0, -0.845),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Cont.',
            text_align=TextNode.A_center,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            text_wordwrap=None,
            parent=rootParent,
            command=base.messenger.send,
            extraArgs=["story_continue"],
            pressEffect=1,
        )
        self.btnContinue.setTransparency(0)

        self.frmFadeOverlay = DirectFrame(
            frameColor=(0.0, 0.0, 0.0, 1.0),
            frameSize=(-0.8, 0.8, -0.8, 0.8),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(-0.475, 0, 0.1),
            parent=rootParent,
        )
        self.frmFadeOverlay.setTransparency(1)
コード例 #18
0
 def __init__(self, menu_args):
     GameObject.__init__(self)
     self.eng.log('created message form')
     self.chats = []
     self.curr_chat = None
     self.curr_match_room = None
     self.msg_frm = DirectFrame(frameSize=(-.02, .8, 0, .45),
                                frameColor=(.2, .2, .2, .5),
                                pos=(-.82, 1, .02),
                                parent=base.a2dBottomRight)
     self.presences_sent = []
     self.menu_args = menu_args
     t_a = menu_args.text_args
     t_a['scale'] = .05
     t_a['fg'] = menu_args.text_normal
     self.dst_txt = OnscreenText(text='',
                                 pos=(0, .4),
                                 parent=self.msg_frm,
                                 align=TextNode.A_left,
                                 **t_a)
     self.arrow_btn = ImgBtn(parent=self.msg_frm,
                             scale=.024,
                             pos=(.7, 1, .42),
                             frameColor=(1, 1, 1, 1),
                             frameTexture='assets/images/gui/arrow.txo',
                             command=self.on_arrow,
                             **menu_args.imgbtn_args)
     self.arrow_btn.disable()
     self.close_btn = ImgBtn(parent=self.msg_frm,
                             scale=.024,
                             pos=(.76, 1, .42),
                             frameColor=(1, 1, 1, 1),
                             frameTexture='assets/images/gui/close.txo',
                             command=self.on_close,
                             **menu_args.imgbtn_args)
     self.close_btn.disable()
     self.ent = Entry(scale=.04,
                      pos=(0, 1, .03),
                      entryFont=menu_args.font,
                      width=19.5,
                      frameColor=menu_args.btn_color,
                      parent=self.msg_frm,
                      initialText=_('write here your message'),
                      command=self.on_typed_msg,
                      focusInCommand=self.on_focus,
                      focusInExtraArgs=['in'],
                      focusOutCommand=self.on_focus,
                      focusOutExtraArgs=['out'],
                      text_fg=menu_args.text_active)
     self.ent['state'] = DISABLED
     self.txt_frm = DirectScrolledFrame(
         frameSize=(-.02, .76, -.02, .28),
         canvasSize=(-.02, .72, -.02, .28),
         scrollBarWidth=.036,
         verticalScroll_relief=FLAT,
         verticalScroll_frameColor=(.2, .2, .2, .4),
         verticalScroll_thumb_relief=FLAT,
         verticalScroll_thumb_frameColor=(.8, .8, .8, .6),
         verticalScroll_incButton_relief=FLAT,
         verticalScroll_incButton_frameColor=(.8, .8, .8, .6),
         verticalScroll_decButton_relief=FLAT,
         verticalScroll_decButton_frameColor=(.8, .8, .8, .6),
         horizontalScroll_relief=FLAT,
         frameColor=(1, 1, 1, 0),
         pos=(.02, 1, .11),
         parent=self.msg_frm)
     t_a['scale'] = .046
     self.msg_txt = OnscreenText(text='',
                                 pos=(0, .24),
                                 parent=self.txt_frm.getCanvas(),
                                 align=TextNode.A_left,
                                 wordwrap=14,
                                 **t_a)
     lab_args = menu_args.label_args
     lab_args['scale'] = .046
     lab_args['text_fg'] = menu_args.text_normal
     self.lab_frm = Btn(frameSize=(-.02, .64, -.01, .05),
                        frameColor=(1, 1, 1, 0),
                        pos=(0, 1, .4),
                        parent=self.msg_frm)
     self.lab_frm.bind(ENTER, self.on_enter)
     self.lab_frm.bind(EXIT, self.on_exit)
     self.tooltip = DirectLabel(text='',
                                pos=(.78, 1, -.06),
                                parent=self.lab_frm,
                                text_wordwrap=16,
                                text_bg=(.2, .2, .2, .8),
                                text_align=TextNode.A_right,
                                **lab_args)
     self.tooltip.set_bin('gui-popup', 10)
     self.tooltip.hide()
コード例 #19
0
    def __init__(self,
                 command,
                 fileBrowser=False,
                 defaultPath="~",
                 defaultFilename="unnamed.txt",
                 fileExtensions=[],
                 tooltip=None,
                 iconDir=None,
                 parent=None,
                 theme=None):
        """
        A simple file and folder browser

        command: The command that will be called on closing the browser
        fileBrowser: If set to True the browser will show files, otherwise it will only show folders
        defaultPath: The initial path the browser will be set to show
        defaultFilename: The filename that will be set by default, only usefull if fileBrowser is True
        fileExtensions: A list of extensions. Only files with those extensions will be shown. Only usefull if fileBrowser is True
        tooltip: An instance of the Tooltip class to display tooltips for certain parts of the editor
        iconDir: A directory path that contains replacement images. It must contain all required images which are:
            File.png
            Folder.png
            FolderNew.png
            FolderShowHidden.png
            FolderUp.png
            Reload.png
        parent: Another DirectGUI element which has pixel2d as root parent.
            The browser frame is placed centered so a frame for example should have equal sizes in horizontal and vertical directions
            e.g. frameSize=(-250,250,-200,200)
        """
        self.theme = theme if theme is not None else LightTheme()
        self.tt = tooltip
        self.command = command
        self.showFiles = fileBrowser
        self.fileExtensions = fileExtensions
        self.showHidden = False
        self.parent = parent

        self.imageOpts = LoaderOptions()
        self.imageOpts.set_auto_texture_scale(ATS_none)

        if self.theme.icon_dir is not None:
            self.iconDir = self.theme.icon_dir
        elif iconDir is None:
            fn = Filename.fromOsSpecific(os.path.dirname(__file__))
            fn.makeTrueCase()
            self.iconDir = str(fn) + "/icons"
        else:
            self.iconDir = iconDir
        self.selectedViewType = "Symbol"

        self.currentPath = os.path.expanduser(defaultPath)
        if not os.path.exists(self.currentPath):
            self.currentPath = os.path.expanduser("~")
        self.previousPath = self.currentPath

        if self.parent is None:
            self.parent = base.pixel2d
            self.screenWidthPx = base.getSize()[0]
            self.screenHeightPx = base.getSize()[1]
            self.position = LPoint3f(base.getSize()[0] / 2, 0,
                                     -base.getSize()[1] / 2)
        else:
            self.screenWidthPx = self.parent.getWidth()
            self.screenHeightPx = self.parent.getHeight()
            self.position = LPoint3f(0)
        self.screenWidthPxHalf = self.screenWidthPx * 0.5
        self.screenHeightPxHalf = self.screenHeightPx * 0.5

        self.mainFrame = DirectFrame(
            relief=1,
            frameSize=(-self.screenWidthPxHalf, self.screenWidthPxHalf,
                       -self.screenHeightPxHalf, self.screenHeightPxHalf),
            frameColor=self.theme.main_background,
            pos=self.position,
            parent=self.parent,
            state=DGG.NORMAL,
        )

        self.pathRightMargin = 155  # NOTE: Add 28 for each button to the right + 15px margin
        self.pathEntryWidth = self.screenWidthPx - self.pathRightMargin - 28

        # The path entry on top of the window
        self.pathEntry = DirectEntry(
            text_fg=self.theme.default_text_color,
            parent=self.mainFrame,
            relief=DGG.SUNKEN,
            frameColor=self.theme.entry_background,
            pad=(0.2, 0.2),
            pos=LPoint3f(-self.screenWidthPxHalf + 15, 0,
                         self.screenHeightPxHalf - 25),
            scale=12,
            width=self.pathEntryWidth / 12,
            overflow=True,
            command=self.entryAccept,
            initialText=self.currentPath,
            focusInCommand=base.messenger.send,
            focusInExtraArgs=["unregisterKeyboardEvents"],
            focusOutCommand=base.messenger.send,
            focusOutExtraArgs=["reregisterKeyboardEvents"],
        )

        # ----------------
        # CONTROL BUTTONS
        # ----------------
        x = self.screenWidthPxHalf - self.pathRightMargin + 18

        # RELOAD
        self.btnReload = DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor=self.theme.icon_button_background,
            frameSize=(-14, 14, -10, 18),
            pos=LPoint3f(x, 0, self.screenHeightPxHalf - 25),
            command=self.folderReload,
            image=loader.load_texture(f"{self.iconDir}/Reload.png",
                                      loaderOptions=self.imageOpts),
            image_scale=14,
            image_pos=(0, 0, 4),
        )
        self.btnReload.setTransparency(TransparencyAttrib.M_multisample)
        if self.tt is not None:
            self.btnReload.bind(DGG.ENTER, self.tt.show, ["Reload Folder"])
            self.btnReload.bind(DGG.EXIT, self.tt.hide)

        # MOVE UP ONE FOLDER
        x += 28
        self.btnFolderUp = DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor=self.theme.icon_button_background,
            frameSize=(-14, 14, -10, 18),
            pos=LPoint3f(x, 0, self.screenHeightPxHalf - 25),
            command=self.folderUp,
            image=loader.load_texture(f"{self.iconDir}/FolderUp.png",
                                      loaderOptions=self.imageOpts),
            image_scale=14,
            image_pos=(0, 0, 4),
        )
        self.btnFolderUp.setTransparency(TransparencyAttrib.M_multisample)
        if self.tt is not None:
            self.btnFolderUp.bind(DGG.ENTER, self.tt.show,
                                  ["Move up one level"])
            self.btnFolderUp.bind(DGG.EXIT, self.tt.hide)

        # CREATE NEW FOLDER
        x += 28
        self.btnFolderNew = DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor=self.theme.icon_button_background,
            frameSize=(-14, 14, -10, 18),
            pos=LPoint3f(x, 0, self.screenHeightPxHalf - 25),
            command=self.folderNew,
            image=loader.load_texture(f"{self.iconDir}/FolderNew.png",
                                      loaderOptions=self.imageOpts),
            image_scale=14,
            image_pos=(0, 0, 4),
        )
        self.btnFolderNew.setTransparency(TransparencyAttrib.M_multisample)
        if self.tt is not None:
            self.btnFolderNew.bind(DGG.ENTER, self.tt.show,
                                   ["Create new folder"])
            self.btnFolderNew.bind(DGG.EXIT, self.tt.hide)

        # SHOW HIDDEN FOLDERS
        x += 28
        self.btnFolderShowHidden = DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor=self.theme.icon_button_background,
            frameSize=(-14, 14, -10, 18),
            pos=LPoint3f(x, 0, self.screenHeightPxHalf - 25),
            command=self.folderShowHidden,
            image=loader.load_texture(f"{self.iconDir}/FolderShowHidden.png",
                                      loaderOptions=self.imageOpts),
            image_scale=14,
            image_pos=(0, 0, 4),
        )
        self.btnFolderShowHidden.setTransparency(
            TransparencyAttrib.M_multisample)
        if self.tt is not None:
            self.btnFolderShowHidden.bind(
                DGG.ENTER, self.tt.show,
                ["Show/Hide hidden files and folders"])
            self.btnFolderShowHidden.bind(DGG.EXIT, self.tt.hide)

        # TOGGLE VIEW TYPE
        x += 28
        self.btnViewType = DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor=self.theme.icon_button_background,
            frameSize=(-14, 14, -10, 18),
            pos=LPoint3f(x, 0, self.screenHeightPxHalf - 25),
            command=self.toggleViewType,
            image=loader.load_texture(f"{self.iconDir}/ViewTypeSymbol.png",
                                      loaderOptions=self.imageOpts),
            image_scale=14,
            image_pos=(0, 0, 4),
        )
        self.btnViewType.setTransparency(TransparencyAttrib.M_multisample)
        if self.tt is not None:
            self.btnViewType.bind(
                DGG.ENTER, self.tt.show,
                ["Toggle view between Symbols and Detail list"])
            self.btnViewType.bind(DGG.EXIT, self.tt.hide)

        # --------------
        # CONTENT FRAME
        # --------------
        color = self.theme.scrollbar_controlls_color
        self.container = DirectScrolledFrame(
            relief=DGG.RIDGE,
            borderWidth=(2, 2),
            frameColor=self.theme.main_background,
            frameSize=(-self.screenWidthPxHalf + 10,
                       self.screenWidthPxHalf - 10,
                       -self.screenHeightPxHalf + 50,
                       self.screenHeightPxHalf - 50),
            canvasSize=(-self.screenWidthPxHalf + 31,
                        self.screenWidthPxHalf - 10,
                        -self.screenHeightPxHalf + 50,
                        self.screenHeightPxHalf - 50),
            pos=LPoint3f(0, 0, 0),
            parent=self.mainFrame,
            scrollBarWidth=20,
            verticalScroll_scrollSize=20,
            verticalScroll_thumb_relief=DGG.FLAT,
            verticalScroll_incButton_relief=DGG.FLAT,
            verticalScroll_decButton_relief=DGG.FLAT,
            verticalScroll_thumb_frameColor=color,
            verticalScroll_incButton_frameColor=color,
            verticalScroll_decButton_frameColor=color,
            verticalScroll_frameColor=self.theme.scroll_background,
            horizontalScroll_thumb_relief=DGG.FLAT,
            horizontalScroll_incButton_relief=DGG.FLAT,
            horizontalScroll_decButton_relief=DGG.FLAT,
            horizontalScroll_thumb_frameColor=color,
            horizontalScroll_incButton_frameColor=color,
            horizontalScroll_decButton_frameColor=color,
            horizontalScroll_frameColor=self.theme.scroll_background,
            state=DGG.NORMAL,
        )
        self.container.bind(DGG.MWDOWN, self.scroll, [0.01])
        self.container.bind(DGG.MWUP, self.scroll, [-0.01])

        # ACCEPT BUTTON
        self.btnOk = DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor=self.theme.text_button_background,
            frameSize=(-45, 45, -6, 14),
            pos=LPoint3f(self.screenWidthPxHalf - 160, 0,
                         -self.screenHeightPxHalf + 25),
            text="ok",
            text_scale=12,
            text_fg=self.theme.default_text_color,
            command=command,
            extraArgs=[1],
        )

        # CANCEL BUTTON
        self.btnCancel = DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor=self.theme.text_button_background,
            frameSize=(-45, 45, -6, 14),
            pos=LPoint3f(self.screenWidthPxHalf - 55, 0,
                         -self.screenHeightPxHalf + 25),
            text="Cancel",
            text_scale=12,
            text_fg=self.theme.default_text_color,
            command=command,
            extraArgs=[0])

        # SELECTED FILE ENTRY FIELD
        if self.showFiles:
            self.txtFileName = DirectEntry(
                text_fg=self.theme.default_text_color,
                parent=self.mainFrame,
                relief=DGG.SUNKEN,
                frameColor=self.theme.entry_background,
                pad=(0.2, 0.2),
                pos=LPoint3f(-self.screenWidthPxHalf + 25, 0,
                             -self.screenHeightPxHalf + 25),
                scale=12,
                width=200 / 12,
                overflow=True,
                command=self.filenameAccept,
                initialText=defaultFilename,
                focusInCommand=base.messenger.send,
                focusInExtraArgs=["unregisterKeyboardEvents"],
                focusOutCommand=base.messenger.send,
                focusOutExtraArgs=["reregisterKeyboardEvents"],
            )

        # ------------------
        # CREATE NEW FOLDER
        # ------------------
        # FRAME FOR CREATING NEW FOLDER
        self.newFolderFrame = DirectFrame(
            parent=self.mainFrame,
            relief=1,
            frameSize=(-self.screenWidthPxHalf + 10,
                       self.screenWidthPxHalf - 10, -20, 20),
            pos=LPoint3f(0, 0, self.screenHeightPxHalf - 55),
            frameColor=self.theme.popup_frame_background,
        )

        # LABEL FOR NEW FOLDER NAME ENTRY
        self.txtNewFolderName = DirectLabel(
            parent=self.newFolderFrame,
            text="New Folder Name",
            text_scale=12,
            text_fg=self.theme.default_text_color,
            frameColor=(0, 0, 0, 0),
            text_align=TextNode.ALeft,
            pos=(-self.screenWidthPxHalf + 15, 0, -3),
        )

        # ENTRY FOR THE NEW FOLDER NAME
        self.folderName = DirectEntry(
            text_fg=self.theme.default_text_color,
            parent=self.newFolderFrame,
            relief=DGG.SUNKEN,
            frameColor=self.theme.entry_background,
            pad=(0.2, 0.2),
            pos=LPoint3f(
                -self.screenWidthPxHalf + 25 +
                self.txtNewFolderName.getWidth(), 0, -4),
            scale=12,
            width=((self.screenWidthPxHalf - 25) * 2 -
                   self.txtNewFolderName.getWidth() - 100) / 12,
            overflow=True,
            command=self.entryAccept,
            initialText="New Folder",
            focusInCommand=base.messenger.send,
            focusInExtraArgs=["unregisterKeyboardEvents"],
            focusOutCommand=base.messenger.send,
            focusOutExtraArgs=["reregisterKeyboardEvents"],
        )

        # ACCEPT BUTTON FOR THE CREATE NEW FOLDER
        self.btnCreate = DirectButton(
            parent=self.newFolderFrame,
            relief=1,
            frameColor=self.theme.text_button_background,
            frameSize=(-45, 45, -6, 14),
            pos=LPoint3f(self.screenWidthPxHalf - 65, 0, -4),
            text="Create",
            text_scale=12,
            text_fg=self.theme.default_text_color,
            command=self.folderCreate,
            extraArgs=[0])
        # Hide the create new folder frame by default
        self.newFolderFrame.hide()

        # ---------------
        # UPDATE CONTENT
        # ---------------
        # Initial loading of the files and folders of the current path
        self.folderReload()

        # handle window resizing
        self.prevScreenSize = base.getSize()
        if self.parent is base.pixel2d:
            self.accept("window-event", self.windowEventHandler)