当前位置: 首页>>代码示例>>Python>>正文


Python ListBox.setSelectedIndex方法代码示例

本文整理汇总了Python中pyjamas.ui.ListBox.ListBox.setSelectedIndex方法的典型用法代码示例。如果您正苦于以下问题:Python ListBox.setSelectedIndex方法的具体用法?Python ListBox.setSelectedIndex怎么用?Python ListBox.setSelectedIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyjamas.ui.ListBox.ListBox的用法示例。


在下文中一共展示了ListBox.setSelectedIndex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: editMovieButton_Click

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import setSelectedIndex [as 别名]
		def editMovieButton_Click(sender):   		
    	    # Add textboxes and listbox
			editMovieButton.setVisible(False)
			cancelButton.setVisible(True)
			saveButton.setVisible(True)
			editCategory = TextBox()
			editName = TextBox()
			editRating = ListBox(False)
			for i in range(self.MAX_RATING + 1):
				editRating.addItem(str(i))
    		
    		# Variable width textboxes
			catlen = len(movie.category)
			namelen = len(movie.name)    		
			if (catlen > 8):
				editCategory.setWidth(str(catlen*10) + "px")
			else:
				editCategory.setWidth("80px")
			if (namelen > 8):
				editName.setWidth(str(namelen*10) + "px")
			else:
				editName.setWidth("80px")
    		
			self.moviesFlexTable.setWidget(row, 1, editCategory)
			self.moviesFlexTable.setWidget(row, 2, editName)
			self.moviesFlexTable.setWidget(row, 3, editRating)
			editCategory.setText(movie.category)
			editName.setText(movie.name)
			editRating.setSelectedIndex(movie.rating)			
开发者ID:FloorLamp,项目名称:CS3300-HW4,代码行数:31,代码来源:MovieRatings.py

示例2: make_panel

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import setSelectedIndex [as 别名]
    def make_panel(self):
        duration = ListBox()
        duration.setVisibleItemCount(1)
        choices = [ 1, 2, 3, 4, 5, 7, 10, 15, 20, 25, 30, 40, 50, 60 ]
        for seconds in choices:
            duration.addItem(
                    '%ds' % seconds if seconds < 60 else '%dm' % (seconds / 60),
                    seconds)
        duration.setSelectedIndex(2)

        button = Button('test')
        handler = TestHandler(duration)
        button.addClickListener(handler.func)

        panel = HorizontalPanel()
        panel.add(duration)
        panel.add(button)
        return panel
开发者ID:christophgysin,项目名称:schoolbell,代码行数:20,代码来源:testwidget.py

示例3: Lists

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import setSelectedIndex [as 别名]
class Lists(Sink):
    def __init__(self):
        Sink.__init__(self)

        self.sStrings=[["foo0", "bar0", "baz0", "toto0", "tintin0"],
            ["foo1", "bar1", "baz1", "toto1", "tintin1"],
            ["foo2", "bar2", "baz2", "toto2", "tintin2"],
            ["foo3", "bar3", "baz3", "toto3", "tintin3"],
            ["foo4", "bar4", "baz4", "toto4", "tintin4"]]

        self.combo=ListBox(VisibleItemCount=1)
        self.list=ListBox(MultipleSelect=True, VisibleItemCount=10)
        self.echo=Label()

        self.combo.addChangeListener(self)

        for i in range(len(self.sStrings)):
            txt = "List %d" % i
            self.combo.addItem(txt)
            # test setItemText
            self.combo.setItemText(i, txt + " using set text")
        self.combo.setSelectedIndex(0)
        self.fillList(0)
        self.list.setItemSelected(0, False)
        self.list.setItemSelected(1, True)

        self.list.addChangeListener(self)

        horz = HorizontalPanel(VerticalAlignment=HasAlignment.ALIGN_TOP,
                               Spacing=8)
        horz.add(self.combo)
        horz.add(self.list)

        panel = VerticalPanel(HorizontalAlignment=HasAlignment.ALIGN_LEFT)
        panel.add(horz)
        panel.add(self.echo)
        self.initWidget(panel)

        self.echoSelection()

    def onChange(self, sender):
        if sender == self.combo:
            self.fillList(self.combo.getSelectedIndex())
        elif sender == self.list:
            self.echoSelection()

    def onShow(self):
        pass

    def fillList(self, idx):
        self.list.clear()
        strings = self.sStrings[idx]
        for i in range(len(strings)):
            self.list.addItem(strings[i])

        self.echoSelection()

    def echoSelection(self):
        msg = "Selected items: "
        for i in range(self.list.getItemCount()):
            if self.list.isItemSelected(i):
                msg += self.list.getItemText(i) + " "
        self.echo.setText(msg)
开发者ID:Afey,项目名称:pyjs,代码行数:65,代码来源:Lists.py

示例4: onModuleLoad

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import setSelectedIndex [as 别名]
class JSONRPCExample:
    def onModuleLoad(self):
        self.TEXT_WAITING = "Waiting for response..."
        self.TEXT_ERROR = "Server Error"
        self.METHOD_ECHO = "Echo"
        self.METHOD_REVERSE = "Reverse"
        self.METHOD_UPPERCASE = "UPPERCASE"
        self.METHOD_LOWERCASE = "lowercase"
        self.METHOD_NONEXISTANT = "Non existant"
        self.methods = [self.METHOD_ECHO, self.METHOD_REVERSE,
                        self.METHOD_UPPERCASE, self.METHOD_LOWERCASE,
                        self.METHOD_NONEXISTANT]

        self.remote_php = EchoServicePHP()
        self.remote_py = EchoServicePython()

        self.status=Label()
        self.text_area = TextArea()
        self.text_area.setText("""{'Test'} [\"String\"]
\tTest Tab
Test Newline\n
after newline
""" + r"""Literal String:
{'Test'} [\"String\"]
""")
        self.text_area.setCharacterWidth(80)
        self.text_area.setVisibleLines(8)

        self.method_list = ListBox()
        self.method_list.setName("hello")
        self.method_list.setVisibleItemCount(1)
        for method in self.methods:
            self.method_list.addItem(method)
        self.method_list.setSelectedIndex(0)

        method_panel = HorizontalPanel()
        method_panel.add(HTML("Remote string method to call: "))
        method_panel.add(self.method_list)
        method_panel.setSpacing(8)

        self.button_php = Button("Send to PHP Service", self)
        self.button_py = Button("Send to Python Service", self)

        buttons = HorizontalPanel()
        buttons.add(self.button_php)
        buttons.add(self.button_py)
        buttons.setSpacing(8)

        info = """<h2>JSON-RPC Example</h2>
        <p>This example demonstrates the calling of server services with
           <a href="http://json-rpc.org/">JSON-RPC</a>.
        </p>
        <p>Enter some text below, and press a button to send the text
           to an Echo service on your server. An echo service simply sends the exact same text back that it receives.
           </p>"""

        panel = VerticalPanel()
        panel.add(HTML(info))
        panel.add(self.text_area)
        panel.add(method_panel)
        panel.add(buttons)
        panel.add(self.status)

        RootPanel().add(panel)

    def onClick(self, sender):
        self.status.setText(self.TEXT_WAITING)
        method = self.methods[self.method_list.getSelectedIndex()]
        text = self.text_area.getText()

        # demonstrate proxy & callMethod()
        if sender == self.button_php:
            if method == self.METHOD_ECHO:
                id = self.remote_php.echo(text, self)
            elif method == self.METHOD_REVERSE:
                id = self.remote_php.callMethod("reverse", [text], self)
            elif method == self.METHOD_UPPERCASE:
                id = self.remote_php.uppercase(text, self)
            elif method == self.METHOD_LOWERCASE:
                id = self.remote_php.lowercase(self, msg=text)
            elif method == self.METHOD_NONEXISTANT:
                id = self.remote_php.nonexistant(text, self)
        else:
            if method == self.METHOD_ECHO:
                id = self.remote_py.echo(text, self)
            elif method == self.METHOD_REVERSE:
                id = self.remote_py.reverse(text, self)
            elif method == self.METHOD_UPPERCASE:
                id = self.remote_py.uppercase(text, self)
            elif method == self.METHOD_LOWERCASE:
                id = self.remote_py.lowercase(text, self)
            elif method == self.METHOD_NONEXISTANT:
                id = self.remote_py.nonexistant(text, self)

    def onRemoteResponse(self, response, request_info):
        self.status.setText(response)

    def onRemoteError(self, code, errobj, request_info):
        # onRemoteError gets the HTTP error code or 0 and
        # errobj is an jsonrpc 2.0 error dict:
#.........这里部分代码省略.........
开发者ID:chopin,项目名称:pyjs,代码行数:103,代码来源:JSONRPCExample.py

示例5: CompaniesAppGUI

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import setSelectedIndex [as 别名]

#.........这里部分代码省略.........
                
                for item in self.app.employees:
                        if item.id != index and name == item.name and item.address == address:
                                self.errors.add(Label("- There is already an employee with the same name and address combination. Enter a valid name and address, please."))
                                valid = False
                return valid
			
	def initCompanyGUI(self):
		self.current = self.app.company
	
		self.grid.clear()
		self.grid.resize(4, 3)
		
		# row 1
		self.grid.setWidget(0, 0, Label("Name:"))
		self.grid.setWidget(1, 0, Label("Department:"))
		self.grid.setWidget(2, 0, Label("Total:"))
		
		# row 2
		self.grid.setWidget(0, 1, self.name)
		self.grid.setWidget(1, 1, self.departments)
		self.grid.setWidget(2, 1, self.total)

		# row 3
		self.grid.setWidget(0, 2, self.save)
		self.grid.setWidget(1, 2, self.selectDepartment)
		self.grid.setWidget(2, 2, self.cut)
		
		self.name.setText(self.current.name)
		self.departments.clear()
		for item in self.current.departments:
			self.departments.addItem(item.name, item.id)
		if self.departments.getItemCount() > 0:
			self.departments.setSelectedIndex(0)
		self.total.setText(self.current.total())
		
	def initDepartmentGUI(self):	
		self.grid.clear()
		self.grid.resize(6, 3)
		
		# row 1
		self.grid.setWidget(0, 0, Label("Name:"))
		self.grid.setWidget(1, 0, Label("Manager:"))
		self.grid.setWidget(2, 0, Label("Department:"))
		self.grid.setWidget(3, 0, Label("Employee:"))
		self.grid.setWidget(4, 0, Label("Total:"))
		
		# row 2
		self.grid.setWidget(0, 1, self.name)
		self.grid.setWidget(1, 1, self.manager)
		self.grid.setWidget(2, 1, self.departments)
		self.grid.setWidget(3, 1, self.employees)
		self.grid.setWidget(4, 1, self.total)

		# row 3
		self.grid.setWidget(0, 2, self.save)
		self.grid.setWidget(1, 2, self.edit)
		self.grid.setWidget(2, 2, self.selectDepartment)
		self.grid.setWidget(3, 2, self.selectEmployee)
		self.grid.setWidget(4, 2, self.cut)
		
		# back
		self.grid.setWidget(5, 2, self.back)
		
		self.name.setText(self.current.name)
		self.departments.clear()
开发者ID:101companies,项目名称:101repo,代码行数:70,代码来源:101Companies.py

示例6: ParamGroup

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import setSelectedIndex [as 别名]
class ParamGroup(object):
    def __init__(self, container, kind, parent=None, level=0, draw=True, title=None):
        self.container = container
        self.kind = kind
        self.parent = parent
        self.level = level
        self.title = title
        self.panel = SimplePanel(StyleName='aur-search-advanced-group')
        if level % 2 == 0: self.panel.addStyleName('aur-search-advanced-group-nested')
        self.childPanel = VerticalPanel(StyleName='aur-search-advanced-group-list', Width='100%')
        self.paramPanel = VerticalPanel(StyleName='aur-search-advanced-param-list', Width='100%')
        self.listPanel = VerticalPanel(StyleName='aur-search-advanced-list-boundary', Width='100%', Visible=False)
        self.paramChooser = ListBox()
        self.children = []
        self.parameters = []
        self.isInverted = False
        self.operator = 'and'
        # assigned by parent, visual use only
        self.op = None if parent else Label('and')
        if draw: self.draw()

    def draw(self):
        cont = VerticalPanel(Width='100%')
        header = HorizontalPanel(Width='100%', VerticalAlignment='middle', StyleName='aur-search-advanced-group-header')
        params = self.paramChooser
        addParam = Image(url='/ico/tick.png', Title='Add parameter to this group')
        addGroup = Image(url='/ico/table_add.png', Title='Nest group within this group')
        addGroupFull = Image(url='/ico/table_lightning.png', Title='Nest group within this group; all parameters')
        invertSelf = Image(url='/ico/exclamation.png', Title='Invert this parameter group')
        self.container.add(self.panel)
        self.panel.setWidget(cont)
        cont.add(header)
        if self.parent:
            d = Image(url='/ico/cross.png', Title='Delete this parameter group')
            d.addStyleName('aur-search-advanced-delete')
            header.add(d)
            header.setCellWidth(d, '1px')
            d.addClickListener(getattr(self, 'delSelf'))
        if self.title:
            t = Label(self.title, StyleName='aur-search-advanced-group-header-title')
            header.add(t)
            header.setCellWidth(t, '1px')
        header.add(params)
        header.add(addParam)
        header.add(addGroup)
        header.add(addGroupFull)
        header.add(invertSelf)
        header.setCellWidth(params, '1px')
        header.setCellWidth(addGroup, '1px')
        header.setCellWidth(addGroupFull, '1px')
        header.setCellWidth(invertSelf, '1px')
        for x in self.kind:
            params.addItem(x['item'], x['index'])
        cont.add(self.listPanel)
        self.listPanel.add(self.paramPanel)
        self.listPanel.add(self.childPanel)
        addParam.addClickListener(getattr(self, 'addParam'))
        addGroup.addClickListener(getattr(self, 'addGroup'))
        addGroupFull.addClickListener(getattr(self, 'addGroupFull'))
        invertSelf.addClickListener(getattr(self, 'invertSelf'))

    def addGroup(self, sender):
        self.listPanel.setVisible(True)
        op = Label(self.operator, Title='Invert group operator', StyleName='aur-search-advanced-group-op', Visible=False)
        op.addClickListener(getattr(self, 'invertOperator'))
        if len(self.children) > 0 or len(self.parameters) > 0: op.setVisible(True)
        self.childPanel.add(op)
        self.childPanel.setCellHorizontalAlignment(op, 'right')
        g = ParamGroup(self.childPanel, self.kind, self, self.level+1)
        g.op = op
        self.children.append(g)

    def addGroupFull(self, sender):
        # this is a little hacky, but it's so fast you don't see it
        self.addGroup(None)
        group = self.children[len(self.children)-1]
        for x in range(group.paramChooser.getItemCount()):
            group.paramChooser.setSelectedIndex(x)
            group.addParam(None)
        group.paramChooser.setSelectedIndex(0)

    def addParam(self, sender):
        self.listPanel.setVisible(True)
        op = Label(self.operator, Title='Invert group operator', StyleName='aur-search-advanced-param-op', Visible=False)
        op.addClickListener(getattr(self, 'invertOperator'))
        if len(self.parameters) > 0: op.setVisible(True)
        self.paramPanel.add(op)
        self.paramPanel.setCellHorizontalAlignment(op, 'right')
        k = self.kind[self.paramChooser.getSelectedValues()[0]]
        p = Param(self.paramPanel, k, self)
        p.op = op
        self.parameters.append(p)
        if len(self.children) > 0:
            self.children[0].op.setVisible(True)

    def addParamFull(self, sender):
        # this is a little hacky, but it's so fast you don't see it
        old = self.paramChooser.getSelectedIndex()
        for x in range(self.paramChooser.getItemCount()):
            self.paramChooser.setSelectedIndex(x)
#.........这里部分代码省略.........
开发者ID:anthonyrisinger,项目名称:aur-pyjs,代码行数:103,代码来源:Search.py

示例7: MechOptionPanel

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import setSelectedIndex [as 别名]
class MechOptionPanel(HorizontalPanel):
    def __init__(self, handle, idx, checkOptions = [False, True]):
        HorizontalPanel.__init__(self)
        self.log = logging.getConsoleLogger(type(self).__name__, lev)
        self.log.disabled = False
        self.log.debug('__init__: Instantiation')
        self.idx = idx
        self._handle = handle
        self._checkOptions = checkOptions
        self.setStyleName('os-mech-checkbox-options')
        #checkbox = CheckBox('symbol')
        #checkbox.setChecked(checkOptions[0])
        #checkbox.addClickListener(self.onClickOption)
        #checkbox.setID('CBSY%d'%idx)
        #self.append(checkbox)
        #checkbox = CheckBox('value')
        #checkbox.setChecked(checkOptions[1])
        #checkbox.addClickListener(self.onClickOption)
        #checkbox.setID('CBVA%d'%idx)
        #self.append(checkbox)
        
        self._textBoxRatio = TextBox('1:1')
        self._ratioCache = self._textBoxRatio.getText()
        self._textBoxRatio.setTitle('Ratio')
        self._ratioCache = self._textBoxRatio.getText()
        
        self._textBoxRatio.addChangeListener(self.onRatioChange) 
        self._textBoxRatio.setID('TXRT%d'%idx)
        self._textBoxRatio.setStyleName('os-mech-textbox-ratio')
        
        self._listBoxSize = ListBox()
        self._listBoxSize.addChangeListener(self.onSizeSet)
        self._listBoxSize.setVisibleItemCount(1)
        self._listBoxSize.setStyleName('os-mech-listbox-size')

        self._listBoxUnit = ListBox()
        self._listBoxUnit.addChangeListener(self.onUnitSet)
        self._listBoxUnit.setVisibleItemCount(1)
        self._listBoxUnit.setStyleName('os-mech-listbox-unit')

        self.append(Label('Ratio'))
        self.append(self._textBoxRatio)
        self.append(Label('Size'))
        self.append(self._listBoxSize)
        self.append(Label('Unit'))
        self.append(self._listBoxUnit)
    def onSizeSet(self, sender, event):
        value = sender.getSelectedItemText()[0]
        self.log.debug('Change size to %s'%value)
        self._handle.remoteService.mech_options_set(self._handle._handle, self.idx, 'size', value)
    def onUnitSet(self, sender, event):
        value = sender.getSelectedValues()[0]
        self._handle.remoteService.mech_options_set(self._handle._handle, self.idx, 'unit',int(value))
    def onRatioChange(self, sender, event):
        #validate ratio change
        matches = re.findall(r'^\d{1,4}:\d{1,4}$', self._textBoxRatio.getText())
        if len(matches) == 1: # correct
            self._ratioCache = self._textBoxRatio.getText()
            self._handle.remoteService.mech_options_set(self._handle._handle, self.idx, 'ratio', self._ratioCache)
        else: # invalid
            self._textBoxRatio.setText(self._ratioCache)
    def actSizeFill(self, options, value = 0):
        for idx, option in enumerate(options, idx):
            self._listBoxSize.addItem(option, idx)
        self._listBoxSize.setSelectedIndex(value)
    def actUnitFill(self, options, value = 0):
        for number, name in options.items():
            self._listBoxUnit.addItem(name, number)
        if value < 100000:
            self._listBoxUnit.setSelectedIndex(value)
        else:
            self._listBoxUnit.selectValue(value)
    def actSizeSet(self, value):
        self.log.debug('actSizeSet, setting value %s'%value)
        self._listBoxSize.selectValue(value)
    def actRatioChange(self, ratio):
        self._textBoxRatio.setText(ratio)
        self._ratioCache = ratio
    def onClickOption(self, sender, event):
        sendId = int(sender.getID()[4:])
        if sendId == 0:
            self._checkOptions[0] = sender.isChecked()
            self._checkOptions[1] = not(sender.isChecked())
        else:
            self._checkOptions[0] = not(sender.isChecked())
            self._checkOptions[1] = sender.isChecked()
        checkbox = self.getWidget(0)
        checkbox.setChecked(self._checkOptions[0])
        checkbox = self.getWidget(1)
        checkbox.setChecked(self._checkOptions[1])
        self._handle.remoteService.mech_options_set(self._handle._handle, self.idx,  'checkOptions', self._checkOptions)
开发者ID:OneSolver,项目名称:onesolver,代码行数:93,代码来源:Drawing.py

示例8: AutoCompleteTextBox

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import setSelectedIndex [as 别名]
class AutoCompleteTextBox(TextBox):
    def __init__(self, **kwargs):
        self.choicesPopup = PopupPanel(True, False)
        self.choices = ListBox()
        self.items = SimpleAutoCompletionItems()
        self.popupAdded = False
        self.visible = False

        self.choices.addClickListener(self)
        self.choices.addChangeListener(self)

        self.choicesPopup.add(self.choices)
        self.choicesPopup.addStyleName("AutoCompleteChoices")
            
        self.choices.setStyleName("list")

        if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-AutoCompleteTextBox"

        TextBox.__init__(self, **kwargs)
        self.addKeyboardListener(self)

    def setCompletionItems(self, items):
        if not hasattr(items, 'getCompletionItems'):
            items = SimpleAutoCompletionItems(items)
        
        self.items = items

    def getCompletionItems(self):
        return self.items

    def onKeyDown(self, arg0, arg1, arg2):
        pass

    def onKeyPress(self, arg0, arg1, arg2):
        pass

    def onKeyUp(self, arg0, arg1, arg2):
        if arg1 == KeyboardListener.KEY_DOWN:
            selectedIndex = self.choices.getSelectedIndex()
            selectedIndex += 1
            if selectedIndex >= self.choices.getItemCount():
                selectedIndex = 0
            self.choices.setSelectedIndex(selectedIndex)           
            return

        if arg1 == KeyboardListener.KEY_UP:
            selectedIndex = self.choices.getSelectedIndex()
            selectedIndex -= 1
            if selectedIndex < 0:
                selectedIndex = self.choices.getItemCount() - 1
            self.choices.setSelectedIndex(selectedIndex)
            return

        if arg1 == KeyboardListener.KEY_ENTER:
            if self.visible:
                self.complete()      
            return

        if arg1 == KeyboardListener.KEY_ESCAPE:
            self.choices.clear()
            self.choicesPopup.hide()
            self.visible = False
            return

        text = self.getText()
        matches = []
        if len(text) > 0:
            matches = self.items.getCompletionItems(text)

        if len(matches) > 0:
            self.choices.clear()

            for i in range(len(matches)):
                self.choices.addItem(matches[i])
                
            if len(matches) == 1 and matches[0] == text:
                self.choicesPopup.hide()
            else:
                self.choices.setSelectedIndex(0)
                self.choices.setVisibleItemCount(len(matches) + 1)
                    
                if not self.popupAdded:
                    RootPanel().add(self.choicesPopup)
                    self.popupAdded = True

                self.choicesPopup.show()
                self.visible = True
                self.choicesPopup.setPopupPosition(self.getAbsoluteLeft(), self.getAbsoluteTop() + self.getOffsetHeight())
                self.choices.setWidth("%dpx" % self.getOffsetWidth())
        else:
            self.visible = False
            self.choicesPopup.hide()

    def onChange(self, arg0):
        self.complete()

    def onClick(self, arg0):
        self.complete()

    def complete(self):
#.........这里部分代码省略.........
开发者ID:anandology,项目名称:pyjamas,代码行数:103,代码来源:AutoComplete.py

示例9: AlarmWidget

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import setSelectedIndex [as 别名]
class AlarmWidget(object):
    weekday_name = { 0: 'Mo', 1: 'Di', 2: 'Mi', 3: 'Do', 4: 'Fr', 5: 'Sa', 6: 'So' }

    def __init__(self):
        self.alarms = Alarms(self)
        self.make_table()
        self.fill_table()
        self.status = Label()
        self.panel = self.make_panel()

    def make_panel(self):
        message = Label(
            'The configuration has been changed.\n'
            'You must apply the changes in order for them to take effect.')
        DOM.setStyleAttribute(message.getElement(), "whiteSpace", 'pre')

        msgbox = Grid(1, 2, StyleName='changes')
        msgbox.setWidget(0, 0, Image('icons/exclam.png'))
        msgbox.setWidget(0, 1, message)
        msgbox.getCellFormatter().setStyleName(0, 0, 'changes-image')
        msgbox.getCellFormatter().setStyleName(0, 1, 'changes-text')

        button = Button('apply changes')
        button.addClickListener(self.apply_clicked)

        self.changes = VerticalPanel()
        self.changes.setHorizontalAlignment('right')
        self.changes.setVisible(False)
        self.changes.add(msgbox)
        self.changes.add(button)

        panel = VerticalPanel()
        panel.setSpacing(10)
        panel.add(self.table)
        panel.add(self.status)
        panel.add(self.changes)

        return panel

    def make_table(self):
        self.table = FlexTable(StyleName='alarms')
        self.table.setBorderWidth(1)
        self.make_header()
        self.make_footer()

    def make_header(self):
        headers = [ 'Time', 'Days', 'Duration' ]
        for col, text in enumerate(headers):
            self.table.setText(0, col, text)
            self.table.getCellFormatter().setStyleName(0, col, 'tablecell header')

    def make_footer(self):
        self.time = {}

        self.time['hour'] = ListBox()
        self.time['hour'].setVisibleItemCount(1)
        for hour in range(24):
            self.time['hour'].addItem('%02d' % hour)
        self.time['hour'].setSelectedIndex(12)

        self.time['minute'] = ListBox()
        self.time['minute'].setVisibleItemCount(1)
        for minute in range(0, 60, 5):
            self.time['minute'].addItem('%02d' % minute)
        self.time['minute'].setSelectedIndex(0)

        time_panel = HorizontalPanel()
        time_panel.setVerticalAlignment('center')
        time_panel.add(self.time['hour'])
        time_panel.add(Label(':'))
        time_panel.add(self.time['minute'])
        self.table.setWidget(1, 0, time_panel)

        weekdays_panel = HorizontalPanel()
        weekdays_panel.setSpacing(5)
        self.weekdays = {}
        for i in range(7):
            self.weekdays[i] = CheckBox(AlarmWidget.weekday_name[i])
            self.weekdays[i].setChecked(i < 6)
            weekdays_panel.add(self.weekdays[i])
        self.table.setWidget(1, 1, weekdays_panel)

        self.duration = ListBox()
        self.duration.setVisibleItemCount(1)
        choices = [ 1, 2, 3, 4, 5, 7, 10, 15, 20, 25, 30, 40, 50, 60 ]
        for seconds in choices:
            self.duration.addItem(
                    '%ds' % seconds if seconds < 60 else '%dm' % (seconds / 60),
                    seconds)
        self.duration.setSelectedIndex(2)
        self.table.setWidget(1, 2, self.duration)

        image = Image('icons/plus.png')
        image.setTitle('add');
        image.addClickListener(self.plus_clicked)
        self.table.setWidget(1, 3, image)

        for col in range(4):
            self.table.getCellFormatter().setStyleName(1, col, 'tablecell noborder')

#.........这里部分代码省略.........
开发者ID:christophgysin,项目名称:schoolbell,代码行数:103,代码来源:alarmwidget.py

示例10: cTestPanel

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import setSelectedIndex [as 别名]
class cTestPanel(VerticalPanel):
    def __init__(self, **kwargs):
        VerticalPanel.__init__(self, **kwargs)

        info = """<h2>JSON-RPC Example</h2>
        #<p>This example demonstrates the calling of server services with
        #   <a href="http://json-rpc.org/">JSON-RPC</a>.
        #</p>
        #<p>Choose a service below, and press a the "call service" button to initiate it. An echo service simply sends the exact same text back that it receives.
        #   </p>"""

        self.status=Label()
        self.dockey = TextBox(Text="12")
        self.TEXT_WAITING = "Waiting for response..."

        self.METHOD_ECHO = "Echo"
        self.METHOD_DOCTYPES = "get doc types"
        self.METHOD_UPPERCASE = "get schema"
        self.METHOD_GETINBOX = "get inbox"
        self.METHOD_GETDOCS = "get documents"
        self.methods = [self.METHOD_ECHO, self.METHOD_DOCTYPES, 
                     self.METHOD_UPPERCASE, self.METHOD_GETINBOX, 
                        self.METHOD_GETDOCS]

        self.method_list = ListBox()
        self.method_list.setName("hello")
        self.method_list.setVisibleItemCount(1)

        for method in self.methods:
            self.method_list.addItem(method)
        self.method_list.setSelectedIndex(0)

        method_panel = HorizontalPanel()
        method_panel.add(HTML("Remote string method to call: "))
        method_panel.add(self.method_list)
        method_panel.setSpacing(8)

        self.button_action = Button("Call Service", self)

        buttons = HorizontalPanel()
        buttons.add(self.button_action)
        buttons.setSpacing(8)

        panel = VerticalPanel()
        panel.add(HTML(info))
        panel.add(HTML("Primary key of the patient in the database:"))
        panel.add(self.dockey)
        panel.add(method_panel)
        panel.add(buttons)
        panel.add(self.status)
        self.add(panel)

    #--------------------------------------------------
    def onClick(self, sender):
        self.status.setText(self.TEXT_WAITING)
        method = self.methods[self.method_list.getSelectedIndex()]

        # demonstrate proxy & callMethod()
        if sender == self.button_action:
            if method == self.METHOD_ECHO:
                id = Remote.svc.echo("Hello", self)
            elif method == self.METHOD_DOCTYPES:
                id = Remote.svc.get_doc_types(self)
            elif method == self.METHOD_UPPERCASE:
                id = Remote.svc.get_schema_version(self)
            elif method == self.METHOD_GETINBOX:
                id = Remote.svc.get_provider_inbox_data(self)
            elif method == self.METHOD_GETDOCS:
                key = int(self.dockey.getText()) # TODO: check it!
                id = Remote.svc.get_documents(key, self)

    #--------------------------------------------------
    def onRemoteResponse(self, response, request_info):
        method = request_info.method
        if method == 'get_documents':
            grid = Grid()
            grid.resize(len(response)+1, 8)
            grid.setHTML(0, 0, "Comment")
            grid.setHTML(0, 1, "Episode")
            grid.setHTML(0, 2, "When")
            for (row, item) in enumerate(response):
                grid.setHTML(row+1, 0, item.comment)
                grid.setHTML(row+1, 1, item.episode)
                grid.setHTML(row+1, 2, str(item.clin_when))
            #RootPanel().add(grid)
            self.add(grid)
        else:
            self.status.setText(str(response))

    #--------------------------------------------------
    def onRemoteError(self, code, errobj, request_info):
        # onRemoteError gets the HTTP error code or 0 and
        # errobj is an jsonrpc 2.0 error dict:
        #     {
        #       'code': jsonrpc-error-code (integer) ,
        #       'message': jsonrpc-error-message (string) ,
        #       'data' : extra-error-data
        #     }
        message = errobj['message']
        if code != 0:
#.........这里部分代码省略.........
开发者ID:ncqgm,项目名称:gnumed,代码行数:103,代码来源:TestPanel.py


注:本文中的pyjamas.ui.ListBox.ListBox.setSelectedIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。