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


Python ListBox.clear方法代码示例

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


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

示例1: Lists

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import clear [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

示例2: CompaniesAppGUI

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import clear [as 别名]
class CompaniesAppGUI(AbsolutePanel):
	def __init__(self):
		AbsolutePanel.__init__(self)
		
		self.app = CompaniesApp()
		
		self.history = []
		
		self.save = Button("save", self)
		self.selectDepartment = Button("select", self)
		self.selectEmployee = Button("select", self)
		self.edit = Button("edit", self)
		self.cut = Button("cut", self)
		self.back = Button("back", self)
		
		self.name = TextBox()
		self.address = TextBox()
		self.manager = TextBox()
		self.departments = ListBox(Size=("100%"), VisibleItemCount="5")
		self.employees = ListBox(Size=("100%"), VisibleItemCount="5")
		self.total = TextBox()

		self.errors = VerticalPanel()
		
		self.grid = Grid()
		self.allPanels = VerticalPanel()
		self.allPanels.add(self.grid)
		self.allPanels.add(self.errors)
		self.add(self.allPanels)
		
		self.initCompanyGUI()
		
	def onClick(self, sender):
                self.errors.clear()
		if sender == self.cut:
			self.current.cut()
			self.total.setText(self.current.total())
		if sender == self.save:
			if self.current.__class__.__name__ == "Employee":
                                if self.validateEmployee(self.current.id, self.name.getText(), self.address.getText(), self.total.getText()) == True:
                                        self.current.save(self.name.getText(), self.address.getText(), float(self.total.getText()))
			else:
                                if self.validateDepartment(self.current.id, self.name.getText()) == True:
                                        self.current.save(self.name.getText())
		if sender == self.selectDepartment:
			if (self.departments.getSelectedIndex() > -1):
				self.history.append(self.current)
				self.current = self.app.getDepartment(self.departments.getValue(self.departments.getSelectedIndex()))
				self.initDepartmentGUI()
		if sender == self.selectEmployee:
			if (self.employees.getSelectedIndex() > -1):
				self.history.append(self.current)
				self.current = self.app.getEmployee(self.employees.getValue(self.employees.getSelectedIndex()))
				self.initEmployeeGUI()
		if sender == self.edit:
			self.history.append(self.current)
			self.current = self.current.getManager()
			self.initEmployeeGUI()
		if sender == self.back:
			if len(self.history) > 0:
				self.current = self.history.pop()
				if self.current.__class__.__name__ == "Company":
					self.initCompanyGUI()
				else:
					self.initDepartmentGUI()

	def validateDepartment(self, index, name):
                valid = True

                if name == "":
                        self.errors.add(Label("- Enter a valid name, please."))
                        valid = False
                
                for item in self.app.departments:
                        if item.id != index and name == item.name:
                                self.errors.add(Label("- There is already a department with the same name. Enter a valid name, please."))
                                valid = False
                return valid

        def validateEmployee(self, index, name, address, salary):
                valid = True

                if name == "":
                        self.errors.add(Label("- Enter a valid name, please."))
                        valid = False

                if address == "":
                        self.errors.add(Label("- Enter a valid address, please."))
                        valid = False

                if salary == "":
                        self.errors.add(Label("- Enter a valid salary, please."))
                        valid = False

                try:
                        float(salary)
                except ValueError:
                        self.errors.add(Label("- The salary must be a number. Enter a valid salary, please."))
                        valid = False
                        
#.........这里部分代码省略.........
开发者ID:101companies,项目名称:101repo,代码行数:103,代码来源:101Companies.py

示例3: onModuleLoad

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

#.........这里部分代码省略.........
        self.deleteSongButton.addClickListener(self)
        songlist_layout.add(self.deleteSongButton)
         
        h_layout.add(songlist_layout)
        
        #self.textArea = TextArea()
        #self.textArea.setCharacterWidth(30)
        #self.textArea.setVisibleLines(50)
        #h_layout.add(self.textArea)
        
        #self.scrollPanel = ScrollPanel(Size=("400px", "500px"))
        self.songHtml = HTML("<b>Please select a song in the left table</b>")
        #self.scrollPanel.add(self.songHtml)
        #h_layout.add(self.scrollPanel)
        h_layout.add(self.songHtml)
        
        main_layout.add(h_layout)
        
        self.status = Label()
        main_layout.add(self.status)
        
        RootPanel().add(main_layout)
        
        # Populate the song table:
        self.remote.getAllSongs(self)
    

    def onKeyUp(self, sender, keyCode, modifiers):
        pass

    def onKeyDown(self, sender, keyCode, modifiers):
        pass

    def onKeyPress(self, sender, keyCode, modifiers):
        """
        This functon handles the onKeyPress event
        """
        if keyCode == KeyboardListener.KEY_ENTER and sender == self.newSongTextBox:
            id = self.remote.addSong(self.newSongTextBox.getText(), self)
            self.newSongTextBox.setText("")

            if id<0:
                self.status.setText("Server Error or Invalid Response")

    def onClick(self, sender):
        """
        Gets called when a user clicked in the <sender> widget.
        Currently deletes the song on which the user clicked.
        """
        if sender == self.songListBox:
            song_id = self.songListBox.getValue(self.songListBox.getSelectedIndex())
            self.status.setText("selected song_id: %s" % song_id)
            id = self.remote.getSong(song_id, self)
            if id<0:
                self.status.setText("Server Error or Invalid Response")
        
	elif sender == self.addSongButton:
            id = self.remote.addSong(self.newSongTextBox.getText(), self)
            self.newSongTextBox.setText("")
            if id<0:
                self.status.setText("Server Error or Invalid Response")
 
        elif sender == self.deleteSongButton:
            # Figure out what song is selected in the table:
            song_id = self.songListBox.getValue(self.songListBox.getSelectedIndex())
            self.status.setText("delete song_id: %s" % song_id)
            id = self.remote.deleteSong(song_id, self)
            if id<0:
                self.status.setText("Server Error or Invalid Response")
    
    def onRemoteResponse(self, response, request_info):
        """
        Gets called when the backend (django) sends a packet to us.
        Populates the song table with all songs in the database.
        """
        self.status.setText("response received")
        if request_info.method == 'getAllSongs' or request_info.method == 'addSong' or request_info.method == 'deleteSong':
            self.status.setText(self.status.getText() + " - song list received")
            self.songListBox.clear()
            for item in response:
                song_id, song_num, song_title = item
                if song_num:
                    song_title = "%i %s" % (song_num, song_title)
                self.songListBox.addItem(song_title)
                self.songListBox.setValue(self.songListBox.getItemCount()-1, song_id)
        
        elif request_info.method == 'getSong':
            self.status.setText(self.status.getText() + " - song received")
            song_obj = songs.Song(response)
            self.status.setText(self.status.getText() + "; id: %i; num-chords: %i" % (song_obj.id, len(song_obj.chords) ) )
            self.songHtml.setHTML(song_obj.getHtml())
            #self.textArea.setText(song_obj.text)
        
        else:
            # Unknown response received form the server
            self.status.setText(self.status.getText() + "none!")
    
    def onRemoteError(self, code, errobj, request_info):
        message = errobj['message']
        self.status.setText("Server Error or Invalid Response: ERROR %s - %s" % (code, message))
开发者ID:academicsam,项目名称:softChord,代码行数:104,代码来源:softchordapp.py

示例4: UserForm

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import clear [as 别名]
class UserForm(AbsolutePanel):

    MODE_ADD    = "modeAdd";
    MODE_EDIT   = "modeEdit";

    user = None
    mode = None

    usernameInput = None
    firstInput = None
    lastInput = None
    emailInput = None
    passwordInput = None
    confirmInput = None
    departmentCombo = None
    addBtn = None
    cancelBtn = None

    def __init__(self,parent):
        AbsolutePanel.__init__(self)
        ftable = FlexTable()

        ftable.setWidget(0, 0, Label("First Name", wordWrap=False))
        ftableFormatter = ftable.getFlexCellFormatter()
        self.firstInput = TextBox()
        self.firstInput.addChangeListener(self.checkValid)
        self.firstInput.addKeyboardListener(self)
        ftable.setWidget(0, 1, self.firstInput)

        ftable.setWidget(1, 0, Label("Last Name", wordWrap=False))
        self.lastInput = TextBox()
        self.lastInput.addChangeListener(self.checkValid)
        self.lastInput.addKeyboardListener(self)
        ftable.setWidget(1, 1, self.lastInput)

        ftable.setWidget(2, 0, Label("Email", wordWrap=False))
        self.emailInput = TextBox()
        self.emailInput.addChangeListener(self.checkValid)
        self.emailInput.addKeyboardListener(self)
        ftable.setWidget(2, 1, self.emailInput)

        w = Label("* Username", wordWrap=False)
        w.addMouseListener(TooltipListener("Required, not changable"))
        ftable.setWidget(3, 0, w)
        self.usernameInput = TextBox()
        self.usernameInput.addChangeListener(self.checkValid)
        self.usernameInput.addKeyboardListener(self)
        ftable.setWidget(3, 1, self.usernameInput)

        w = Label("* Password", wordWrap=False)
        w.addMouseListener(TooltipListener("Required"))
        ftable.setWidget(4, 0, w)
        self.passwordInput = PasswordTextBox()
        self.passwordInput.addChangeListener(self.checkValid)
        self.passwordInput.addKeyboardListener(self)
        ftable.setWidget(4, 1, self.passwordInput)

        w = Label("* Confirm", wordWrap=False)
        w.addMouseListener(TooltipListener("Required"))
        ftable.setWidget(5, 0, w)
        self.confirmInput = PasswordTextBox()
        self.confirmInput.addChangeListener(self.checkValid)
        self.confirmInput.addKeyboardListener(self)
        ftable.setWidget(5, 1, self.confirmInput)

        w = Label("* Department", wordWrap=False)
        w.addMouseListener(TooltipListener("Required"))
        ftable.setWidget(6, 0, w)
        self.departmentCombo = ListBox()
        self.departmentCombo.addChangeListener(self.checkValid)
        self.departmentCombo.addKeyboardListener(self)
        ftable.setWidget(6, 1, self.departmentCombo)

        hpanel = HorizontalPanel()
        self.addBtn = Button("Add User")
        self.addBtn.setEnabled(False)
        hpanel.add(self.addBtn)
        self.cancelBtn = Button("Cancel")
        hpanel.add(self.cancelBtn)
        ftable.setWidget(7, 0, hpanel)
        ftableFormatter.setColSpan(7, 0, 2)

        self.add(ftable)
        self.clearForm()
        return

    def clearForm(self):
        self.user = None
        self.usernameInput.setText('')
        self.firstInput.setText('')
        self.lastInput.setText('')
        self.emailInput.setText('')
        self.passwordInput.setText('')
        self.confirmInput.setText('')
        self.departmentCombo.setItemTextSelection(None)
        self.updateMode(self.MODE_ADD)
        self.checkValid()

    def updateUser(self, user):
        def setText(elem, value):
#.........这里部分代码省略.........
开发者ID:Afey,项目名称:pyjs,代码行数:103,代码来源:components.py

示例5: RolePanel

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import clear [as 别名]
class RolePanel(AbsolutePanel):

    user = None
    selectedRole = None

    roleList = None
    roleCombo = None
    addBtn = None
    removeBtn = None

    def __init__(self,parent):
        AbsolutePanel.__init__(self)

        self.roleList = ListBox()
        self.roleList.setWidth('300px')
        self.roleList.setVisibleItemCount(6)
        self.roleList.addChangeListener(self.onListChange)
        #self.roleList.addKeyboardListener(self)
        self.roleCombo = ListBox()
        self.roleCombo.addKeyboardListener(self)
        self.roleCombo.addChangeListener(self.onComboChange)
        self.addBtn = Button("Add")
        self.addBtn.setEnabled(False)
        self.removeBtn = Button("Remove")
        self.removeBtn.setEnabled(False)

        vpanel = VerticalPanel()
        vpanel.add(self.roleList)
        hpanel = HorizontalPanel()
        hpanel.add(self.roleCombo)
        hpanel.add(self.addBtn)
        hpanel.add(self.removeBtn)
        vpanel.add(hpanel)

        self.add(vpanel)
        self.clearForm()
        return

    def clearForm(self):
        self.user = None
        self.updateRoleList([])
        self.roleCombo.setItemTextSelection(None)

    def updateRoleList(self,items):
        self.roleList.clear()
        for item in items:
            self.roleList.addItem(item)
        #self.roleList.addItem('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;')
        #self.roleList.addItem('- - - - - - - -')

    def updateRoleCombo(self,choices, default_):
        self.roleCombo.clear()
        for choice in choices:
            self.roleCombo.addItem(choice)
        self.roleCombo.selectValue(default_)

    def onComboChange(self, sender, keyCode=None, modifiers=None):
        selected = self.roleCombo.getSelectedItemText()
        if  not selected \
            or selected[0] == ApplicationConstants.ROLE_NONE_SELECTED \
            or not self.user:
            self.addBtn.setEnabled(False)
            self.selectedRole=None
        else:
            self.addBtn.setEnabled(True)
            self.selectedRole=selected[0]
        self.removeBtn.setEnabled(False)
        self.roleList.setItemTextSelection(None)

    def onListChange(self, sender):
        selected = self.roleList.getSelectedItemText()
        if selected:
            self.removeBtn.setEnabled(True)
            self.selectedRole=selected[0]
        else:
            self.removeBtn.setEnabled(False)
            self.selectedRole=None
        self.addBtn.setEnabled(False)
        self.roleCombo.setItemTextSelection(None)

    def onClick(self, sender):
        pass

    def onKeyUp(self, sender, keyCode, modifiers):
        if sender == self.roleCombo:
            self.onComboChange(sender)
        elif sender == self.roleList:
            self.onListChange(sender)

    def onKeyDown(self, sender, keyCode, modifiers):
        pass

    def onKeyPress(self, sender, keyCode, modifiers):
        pass
开发者ID:Afey,项目名称:pyjs,代码行数:96,代码来源:components.py

示例6: RolePanel

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import clear [as 别名]
class RolePanel(AbsolutePanel):
    
    user = None
    selectedRole = None
    
    roleList = None
    roleCombo = None
    addBtn = None
    removeBtn = None
    
    def __init__(self,parent):
        AbsolutePanel.__init__(self)

        self.roleList = ListBox()
        self.roleList.setWidth('300px')
        self.roleList.setVisibleItemCount(6)
        self.roleList.addClickListener(self.onListClick)
        self.roleList.addKeyboardListener(self)
        self.roleCombo = ListBox()
        self.roleCombo.addClickListener(self.onComboClick)
        self.roleCombo.addKeyboardListener(self)
        self.addBtn = Button("Add", self)
        self.addBtn.addClickListener(self.onAdd)
        self.addBtn.setEnabled(False)
        self.removeBtn = Button("Remove", self)
        self.removeBtn.addClickListener(self.onRemove)
        self.removeBtn.setEnabled(False)

        vpanel = VerticalPanel()
        vpanel.add(self.roleList)
        hpanel = HorizontalPanel()
        hpanel.add(self.roleCombo)
        hpanel.add(self.addBtn)
        hpanel.add(self.removeBtn)
        vpanel.add(hpanel)

        self.add(vpanel)

        return
    
    def updateRoleList(self,items):
        self.roleList.clear()
        for item in items:
            self.roleList.addItem(item)
        #self.roleList.addItem('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;')
        #self.roleList.addItem('- - - - - - - -')
    
    def updateRoleCombo(self,choices, default_):
        self.roleCombo.clear()
        for choice in choices:
            self.roleCombo.addItem(choice)
        self.roleCombo.selectValue(default_)
    
    def onComboClick(self, sender, keyCode=None, modifiers=None):
        selected = self.roleCombo.getSelectedItemText()
        if not selected or not self.user:
            self.addBtn.setEnabled(False)
            self.selectedRole=None
        else:
            self.addBtn.setEnabled(True)
            self.selectedRole=selected[0]
        self.removeBtn.setEnabled(False)
        self.roleList.setItemTextSelection(None)
    
    def onListClick(self, sender):
        selected = self.roleList.getSelectedItemText()
        if selected:
            self.removeBtn.setEnabled(True)
            self.selectedRole=selected[0]
        else:
            self.removeBtn.setEnabled(False)
            self.selectedRole=None
        self.addBtn.setEnabled(False)
        self.roleCombo.setItemTextSelection(None)
    
    def onAdd(self, evt):
        self.mediator.sendNotification(EmployeeAdmin.AppFacade.ADD_ROLE,self.selectedRole)
    
    def onRemove(self,evt):
        self.mediator.sendNotification(EmployeeAdmin.AppFacade.REMOVE_ROLE,self.selectedRole)

    def onClick(self, sender):
        pass

    def onKeyUp(self, sender, keyCode, modifiers):
        if sender == self.roleCombo:
            self.onComboClick(sender)
        elif sender == self.roleList:
            self.onListClick(sender)

    def onKeyDown(self, sender, keyCode, modifiers):
        pass

    def onKeyPress(self, sender, keyCode, modifiers):
        pass
开发者ID:FreakTheMighty,项目名称:pyjamas,代码行数:97,代码来源:components.py

示例7: AutoCompleteTextBox

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import clear [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

示例8: onModuleLoad

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import clear [as 别名]
class TodoApp:
    def onModuleLoad(self):
        self.remote = DataService()
        panel = VerticalPanel()

        self.todoTextBox = TextBox()
        self.todoTextBox.addKeyboardListener(self)

        self.todoList = ListBox()
        self.todoList.setVisibleItemCount(7)
        self.todoList.setWidth("200px")
        self.todoList.addClickListener(self)

        panel.add(Label("Add New Todo:"))
        panel.add(self.todoTextBox)
        panel.add(Label("Click to Remove:"))
        panel.add(self.todoList)

        self.status = Label()
        panel.add(self.status)

        RootPanel().add(panel)



    def onKeyUp(self, sender, keyCode, modifiers):
        pass

    def onKeyDown(self, sender, keyCode, modifiers):
        pass

    def onKeyPress(self, sender, keyCode, modifiers):
        """
        This functon handles the onKeyPress event, and will add the item in the text box to the list when the user presses the enter key.  In the future, this method will also handle the auto complete feature.
        """
        if keyCode == KeyboardListener.KEY_ENTER and sender == self.todoTextBox:
            id = self.remote.addTask(sender.getText(),self)
            sender.setText("")

            if id<0:
                self.status.setText("Server Error or Invalid Response")


    def onClick(self, sender):
        id = self.remote.deleteTask(sender.getValue(sender.getSelectedIndex()),self)
        if id<0:
            self.status.setText("Server Error or Invalid Response")

    def onRemoteResponse(self, response, request_info):
        self.status.setText("response received")
        if request_info.method == 'getTasks' or request_info.method == 'addTask' or request_info.method == 'deleteTask':
            self.status.setText(self.status.getText() + "HERE!")
            self.todoList.clear()
            for task in response:
                self.todoList.addItem(task[0])
                self.todoList.setValue(self.todoList.getItemCount()-1,task[1])
        else:
            self.status.setText(self.status.getText() + "none!")

    def onRemoteError(self, code, errobj, request_info):
        message = errobj['message']
        self.status.setText("Server Error or Invalid Response: ERROR %s - %s" % (code, message))
开发者ID:Afey,项目名称:pyjs,代码行数:64,代码来源:TodoApp.py

示例9: WebPageEdit

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

#.........这里部分代码省略.........

        panel.add(HTML("Status:"))
        panel.add(self.status)
        panel.add(self.fDialogButton)
        panel.add(Label("Create New Page (doesn't save current one!):"))
        panel.add(self.newpage)
        panel.add(Label("Add/Edit New Page:"))
        panel.add(self.todoTextName)
        panel.add(Label("Click to Load and Edit (doesn't save current one!):"))
        panel.add(self.todoList)
        panel.add(self.view)
        panel.add(Label("New Page HTML.  Click 'save' icon to save.  (pagename is editable as well)"))
        panel.add(self.todoTextArea)

        self.setWidget(panel)

        self.remote.getPages(self)

    def onKeyUp(self, sender, keyCode, modifiers):
        pass

    def onKeyDown(self, sender, keyCode, modifiers):
        pass

    def onKeyPress(self, sender, keyCode, modifiers):
        """
        This functon handles the onKeyPress event, and will add the item in the text box to the list when the user presses the enter key.  In the future, this method will also handle the auto complete feature.
        """
        pass

    def onSave(self, editor):
        self.status.setText("")
        name = self.todoTextName.getText()
        if not name:
            self.status.setText("Please enter a name for the page")
            return
        item = {"name": name, "text": self.todoTextArea.getHTML()}
        if self.todoId is None:
            rid = self.remote.addPage(item, self)
        else:
            item["id"] = self.todoId
            rid = self.remote.updatePage(item, self)

        if rid < 0:
            self.status.setHTML("Server Error or Invalid Response")
            return

    def onClick(self, sender):
        if sender == self.newpage:
            self.todoId = None
            self.todoTextName.setText("")
            self.todoTextArea.setHTML("")
            return
        elif sender == self.view:
            name = self.todoTextName.getText()
            html = self.todoTextArea.getHTML()
            if not html:
                return
            p = HTMLDialog(name, html)
            p.setPopupPosition(10, 10)
            p.setWidth(Window.getClientWidth() - 40)
            p.setHeight(Window.getClientHeight() - 40)
            p.show()
            return
        elif sender == self.fDialogButton:
            Window.open(fileedit_url, "fileupload", "width=800,height=600")
            return
            dlg = FileDialog(fileedit_url)
            left = self.fDialogButton.getAbsoluteLeft() + 10
            top = self.fDialogButton.getAbsoluteTop() + 10
            dlg.setPopupPosition(left, top)
            dlg.show()

        id = self.remote.getPage(sender.getValue(sender.getSelectedIndex()), self)
        if id < 0:
            self.status.setHTML("Server Error or Invalid Response")

    def onRemoteResponse(self, response, request_info):
        self.status.setHTML("response received")
        if request_info.method == "getPage":
            self.status.setHTML(self.status.getText() + "HERE!")
            item = response[0]
            self.todoId = item["pk"]
            self.todoTextName.setText(item["fields"]["name"])
            self.todoTextArea.setHTML(item["fields"]["text"])

        elif (
            request_info.method == "getPages" or request_info.method == "addPage" or request_info.method == "deletePage"
        ):
            self.status.setHTML(self.status.getText() + "HERE!")
            self.todoList.clear()
            for task in response:
                self.todoList.addItem(task["fields"]["name"])
                self.todoList.setValue(self.todoList.getItemCount() - 1, str(task["pk"]))

        else:
            self.status.setHTML(self.status.getText() + "none!")

    def onRemoteError(self, code, message, request_info):
        self.status.setHTML("Server Error or Invalid Response: ERROR " + str(code) + " - " + str(message))
开发者ID:janjaapbos,项目名称:pyjs,代码行数:104,代码来源:WebPageEdit.py

示例10: ReducePanelIFACE

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import clear [as 别名]
class ReducePanelIFACE(PanelIFACE):
    def __init__(self, parent = None):
        
        PanelIFACE.__init__(self, parent)
        self.panel = VerticalPanel()
        self.panel.setBorderWidth(1)
        self.panel.setWidth("100%")
        # prepare panel
        self.prepareReduce = HTML("<tt> .. none yet .. </tt>", True, )

        self.recipeList = ListBox()
        self.recipeList.addChangeListener(getattr(self, "onRecipeSelected"))
        self.recipeList.addItem("None")
        HTTPRequest().asyncGet("recipes.xml",
                                RecipeListLoader(self))

        #EO prepare panel
        self.reduceCLPanel = DockPanel(Spacing = 5)
        self.reduceCLPanel.add(HTML("<i>Reduce Command Line</i>:"), DockPanel.NORTH)                        
        self.reduceCLPanel.add(self.prepareReduce, DockPanel.NORTH)

        self.reduceFilesPanel = DockPanel(Spacing = 5)
        self.reduceFilesPanel.add(HTML("<b>Datasets</b>:"), DockPanel.WEST)

        self.reduceFiles = ListBox()
        self.reduceFiles.setVisibleItemCount(5)
        self.reduceFilesPanel.add(self.reduceFiles, DockPanel.WEST)
        self.clearReduceFilesButton = Button("<b>Clear List</b>", listener = getattr(self, "onClearReduceFiles"))
        self.reduceFilesPanel.add(self.clearReduceFilesButton, DockPanel.SOUTH)

        self.recipeListPanel = DockPanel(Spacing = 5)
        self.recipeListPanel.add(HTML("<b>Recipes List</b>:"),DockPanel.WEST)
        self.recipeListPanel.add(self.recipeList, DockPanel.WEST)

        self.runReduceButton = Button("<b>RUN REDUCE</b>", listener = getattr(self, "onRunReduce"))

        self.adInfo = HTML("file info...")
        # major sub panels
        self.panel.add(self.reduceCLPanel)
        self.panel.add(self.reduceFilesPanel)
        self.panel.add(self.recipeListPanel)
        self.panel.add(self.runReduceButton)
        self.panel.add(self.adInfo)
    def onRecipeSelected(self, event):
        self.updateReduceCL()
    
    def onClearReduceFiles(self, event):
        self.reduceFiles.clear() 
        self.adInfo.setHTML("file info...") 
        self.updateReduceCL()
        
    def updateReduceCL(self):
        recipe = self.recipeList.getItemText(self.recipeList.getSelectedIndex())
        
        if recipe=="None":
            rstr = ""
        else:
            rstr = "-r "+recipe

        rfiles = []            
        for i in range(0, self.reduceFiles.getItemCount()):
            fname = self.reduceFiles.getItemText(i)
            rfiles.append(fname)
        filesstr = " ".join(rfiles)
        
                
        self.prepareReduce.setHTML('<b>reduce</b> %(recipe)s %(files)s' % 
                                        { "recipe":rstr, 
                                          "files":filesstr})
    def onRunReduce(self):
        recipe = self.recipeList.getItemText(self.recipeList.getSelectedIndex())
        
        if recipe=="None":
            rstr = ""
        else:
            rstr = "p=-r"+recipe

        rfiles = []            
        for i in range(0, self.reduceFiles.getItemCount()):
            fname = self.reduceFiles.getItemText(i)
            rfiles.append(quote(self.pathdict[fname]["path"]))
        filesstr = "&p=".join(rfiles)
                
        cl = "/runreduce?%s&p=%s" % (rstr, filesstr)
        # @@TEST
        # cl = "/recipes.xml"
        if False:
            msg = repr(self.parent)+repr(dir(self.parent))
            JS("alert(msg)")
        if hasattr(self.parent, "roFrame"):
            self.parent.roFrame.setUrl(cl)
            self.parent.tabPanel.selectTab(self.parent.tabIFACEdict["rogui"])
        else:
            JS("window.open(cl)")

    def onTreeItemSelected(self, item):
        pathdict = self.pathdict
        
        tfile = item.getText()
        #check if already in
#.........这里部分代码省略.........
开发者ID:pyrrho314,项目名称:recipesystem,代码行数:103,代码来源:RecipeSystemIFACE.py

示例11: Trees

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import clear [as 别名]
class Trees(Sink):
    pathdict = {}
    reduceFiles = None
    def __init__(self, parent = None):
        Sink.__init__(self, parent)
        self.reduceFiles = []
        if True:
            HTTPRequest().asyncGet("datadir.xml", 
                                    DirDictLoader(self),
                                )
        dock = DockPanel(HorizontalAlignment=HasAlignment.ALIGN_LEFT, 
                            Spacing=10,
                             Size=("100%","100%"))
        self.dock = dock
        self.fProto = []

        self.fTree = Tree()
        self.prPanel = VerticalPanel(Size=("50%", ""))
        self.treePanel = HorizontalPanel(Size=("50%", "100%"))
        self.treePanel.add(self.fTree)
        dock.add(self.treePanel, DockPanel.WEST)
        
        self.treePanel.setBorderWidth(1)
        self.treePanel.setWidth("100%")
        self.prPanel.setBorderWidth(1)
        self.prPanel.setWidth("100%")
        # prepare panel
        self.prepareReduce = HTML("<tt> .. none yet .. </tt>", True, )
        
        self.recipeList = ListBox()
        self.recipeList.addChangeListener(getattr(self, "onRecipeSelected"))
        self.recipeList.addItem("None")
        HTTPRequest().asyncGet("recipes.xml",
                                RecipeListLoader(self))

        #EO prepare panel
        self.reduceCLPanel = DockPanel(Spacing = 5)
        self.reduceCLPanel.add(HTML("<i>Reduce Command Line</i>:"), DockPanel.NORTH)                        
        self.reduceCLPanel.add(self.prepareReduce, DockPanel.NORTH)

        self.reduceFilesPanel = DockPanel(Spacing = 5)
        self.reduceFilesPanel.add(HTML("<b>Datasets</b>:"), DockPanel.WEST)
        
        self.reduceFiles = ListBox()
        self.reduceFiles.setVisibleItemCount(5)
        self.reduceFilesPanel.add(self.reduceFiles, DockPanel.WEST)
        self.clearReduceFilesButton = Button("<b>Clear List</b>", listener = getattr(self, "onClearReduceFiles"))
        self.reduceFilesPanel.add(self.clearReduceFilesButton, DockPanel.SOUTH)

        self.recipeListPanel = DockPanel(Spacing = 5)
        self.recipeListPanel.add(HTML("<b>Recipes List</b>:"),DockPanel.WEST)
        self.recipeListPanel.add(self.recipeList, DockPanel.WEST)
        
        self.runReduceButton = Button("<b>RUN REDUCE</b>", listener = getattr(self, "onRunReduce"))
        
        self.adInfo = HTML("file info...")
        # major sub panels
        self.prPanel.add(self.reduceCLPanel)
        self.prPanel.add(self.reduceFilesPanel)
        self.prPanel.add(self.recipeListPanel)
        self.prPanel.add(self.runReduceButton)
        self.prPanel.add(self.adInfo)
       
        
        dock.add(self.prPanel,DockPanel.EAST)
        
        dock.setCellWidth(self.treePanel, "50%")
        dock.setCellWidth(self.prPanel, "50%")
        for i in range(len(self.fProto)):
            self.createItem(self.fProto[i])
            self.fTree.addItem(self.fProto[i].item)

        self.fTree.addTreeListener(self)
        self.initWidget(self.dock)
        
        if False: #self.parent.filexml != None:
            DirDictLoader(self).onCompletion(self.parent.filexml)

    def onTreeItemSelected(self, item):
        pathdict = self.pathdict
        
        tfile = item.getText()
        #check if already in

        for i in range(0, self.reduceFiles.getItemCount()):
            fname = self.reduceFiles.getItemText(i)
            if fname == tfile:
                return
        self.reduceFiles.addItem(tfile)
        self.updateReduceCL()
        
        filename = tfile
        if filename in pathdict:
            if pathdict[filename]["filetype"] == "fileEntry":
                HTTPRequest().asyncGet("adinfo?filename=%s" % self.pathdict[item.getText()]["path"], 
                               ADInfoLoader(self),
                              )
            else:
                self.adInfo.setHTML("""
                    <b style="font-size:200%%">%s</b>""" % pathdict[filename]["filetype"])
#.........这里部分代码省略.........
开发者ID:pyrrho314,项目名称:recipesystem,代码行数:103,代码来源:RecipeSystemIFACE.py

示例12: DisplayHistogramsView

# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import clear [as 别名]
class DisplayHistogramsView(object) :
	"""
	@brief View in the MVP pattern for displaying histograms.

	@author Mark Grimes ([email protected])
	@date 09/Feb/2014
	"""
	def __init__( self ) :
		self.cbcList=ListBox(MultipleSelect=True, VisibleItemCount=4)
		self.channelList=ListBox(MultipleSelect=True, VisibleItemCount=20)
		self.updateButton=Button("Update")

		controls=VerticalPanel()
		controls.add(self.updateButton)
		controls.add(self.cbcList)
		controls.add(self.channelList)

		controls.setCellHorizontalAlignment( self.updateButton, HasHorizontalAlignment.ALIGN_CENTER )
		self.cbcList.setWidth("95%")
		self.channelList.setWidth("95%")

		self.cbcList.addItem( "waiting..." )
		for index in range(0,254) :
			self.channelList.addItem( "Channel %3d"%index )

		self.histogram = Image()
		self.mainPanel = HorizontalPanel()
		self.mainPanel.add( controls )
		self.mainPanel.add( self.histogram )
		self.histogram.setUrl( "defaultScurveHistogram.png" )

	def getPanel( self ) :
		return self.mainPanel

	def setAvailableCBCs( self, cbcNames ) :
		self.cbcList.clear()
		for name in cbcNames :
			self.cbcList.addItem( name )

	def enable( self ) :
		self.updateButton.setEnabled(True)
		self.cbcList.setEnabled(True)
		self.channelList.setEnabled(True)

	def disable( self ) :
		self.updateButton.setEnabled(False)
		self.cbcList.setEnabled(False)
		self.channelList.setEnabled(False)
	
	def getUpdateButton( self ) :
		return self.updateButton
	
	def getSelectedCBCChannels( self ) :
		"""
		Returns a dictionary of which channels are selected, with CBC name as a key and
		an array of the channels for that CBC as the value.
		"""
		# The way this view is currently set up, the selected channels have to be the same
		# for each selected CBC.
		selectedChannels=[]
		for index in range(self.channelList.getItemCount()) :
			if self.channelList.isItemSelected(index) :
				selectedChannels.append(index)
		returnValue={}
		for index in range(self.cbcList.getItemCount()) :
			if self.cbcList.isItemSelected(index) : returnValue[self.cbcList.getItemText(index)]=selectedChannels

		return returnValue

	def setImage( self, url ) :
		self.histogram.setUrl( url )
开发者ID:BristolHEP-CBC-Testing,项目名称:cbcanalysis,代码行数:73,代码来源:DisplayHistogramsPanel.py


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