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


Python JComboBox.removeAllItems方法代码示例

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


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

示例1: GameSelector

# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import removeAllItems [as 别名]
class GameSelector(ActionListener):
    """ generated source for class GameSelector """

    theGameList = JComboBox()
    theRepositoryList = JComboBox()
    theSelectedRepository = GameRepository()
    theCachedRepositories = Map()

    class NamedItem(object):
        """ generated source for class NamedItem """

        theKey = str()
        theName = str()

        def __init__(self, theKey, theName):
            """ generated source for method __init__ """
            self.theKey = theKey
            self.theName = theName

        def __str__(self):
            """ generated source for method toString """
            return self.theName

    def __init__(self):
        """ generated source for method __init__ """
        super(GameSelector, self).__init__()
        self.theGameList = JComboBox()
        self.theGameList.addActionListener(self)
        self.theRepositoryList = JComboBox()
        self.theRepositoryList.addActionListener(self)
        self.theCachedRepositories = HashMap()
        self.theRepositoryList.addItem("games.ggp.org/base")
        self.theRepositoryList.addItem("games.ggp.org/dresden")
        self.theRepositoryList.addItem("games.ggp.org/stanford")
        self.theRepositoryList.addItem("Local Game Repository")

    def actionPerformed(self, e):
        """ generated source for method actionPerformed """
        if e.getSource() == self.theRepositoryList:
            if self.theCachedRepositories.containsKey(theRepositoryName):
                self.theSelectedRepository = self.theCachedRepositories.get(theRepositoryName)
            else:
                if theRepositoryName == "Local Game Repository":
                    self.theSelectedRepository = LocalGameRepository()
                else:
                    self.theSelectedRepository = CloudGameRepository(theRepositoryName)
                self.theCachedRepositories.put(theRepositoryName, self.theSelectedRepository)
            repopulateGameList()

    def getSelectedGameRepository(self):
        """ generated source for method getSelectedGameRepository """
        return self.theSelectedRepository

    def repopulateGameList(self):
        """ generated source for method repopulateGameList """
        theRepository = self.getSelectedGameRepository()
        theKeyList = ArrayList(theRepository.getGameKeys())
        Collections.sort(theKeyList)
        self.theGameList.removeAllItems()
        for theKey in theKeyList:
            if theGame == None:
                continue
            if theName == None:
                theName = theKey
            if 24 > len(theName):
                theName = theName.substring(0, 24) + "..."
            self.theGameList.addItem(self.NamedItem(theKey, theName))

    def getRepositoryList(self):
        """ generated source for method getRepositoryList """
        return self.theRepositoryList

    def getGameList(self):
        """ generated source for method getGameList """
        return self.theGameList

    def getSelectedGame(self):
        """ generated source for method getSelectedGame """
        try:
            return self.getSelectedGameRepository().getGame((self.theGameList.getSelectedItem()).theKey)
        except Exception as e:
            return None
开发者ID:hobson,项目名称:ggpy,代码行数:84,代码来源:GameSelector.py

示例2: EventsPane

# 需要导入模块: from javax.swing import JComboBox [as 别名]
# 或者: from javax.swing.JComboBox import removeAllItems [as 别名]
class EventsPane(WindowPane, ActionListener, DocumentListener):
    
    def __init__(self, window, api):
        self.api = api
        self.component = JPanel(BorderLayout())

        # Create editor pane
        scrollpane = JScrollPane()
        self.script_area = InputPane(window)
        self.script_area.undo = UndoManager()
        line_numbers = LineNumbering(self.script_area.component)
        scrollpane.viewport.view = self.script_area.component
        scrollpane.rowHeaderView = line_numbers.component
        self.component.add(scrollpane, BorderLayout.CENTER)

        # Create Selection pane
        select_pane = JPanel()
        self.objects_box = JComboBox([], actionCommand="object")
        select_pane.add(self.objects_box)
        self.events_box = JComboBox(
            ["update", "click"],
            actionCommand="event"
        )
        self.event_types = [EventType.UPDATE, EventType.CLICK]
        select_pane.add(self.events_box)
        self.languages = list(ScriptType.values())
        self.language_box = JComboBox(
            [l.getName() for l in self.languages],
            actionCommand="language"
        )        
        select_pane.add(self.language_box)
        self.save_btn = JButton("Save")
        select_pane.add(self.save_btn)
        self.component.add(select_pane, BorderLayout.PAGE_START)

        self.events_box.addActionListener(self)
        self.objects_box.addActionListener(self)
        self.language_box.addActionListener(self)
        self.save_btn.addActionListener(self)
        
        self.current = None
        self.update_geos()
        interface.addEventListener("add", self.event_listener)
        interface.addEventListener("remove", self.event_listener)
        interface.addEventListener("rename", self.event_listener)
        
        # Listen to script_area changes in order to know when the save
        # button can be activated
        self.script_area.doc.addDocumentListener(self)
        
        # Hack to be able to change the objects_box
        self.building_objects_box = False

        self.active = False

    def activate(self):
        self.active = True
        if self.must_update_geos:
            self.update_geos()
    def deactivate(self):
        self.active = False
    
    def indent_selection(self):
        return self.script_area.indent_selection()
    def dedent_selection(self):
        return self.script_area.dedent_selection()

    def update_geos(self):
        self.must_update_geos = False
        try:
            self.building_objects_box = True
            self.objects_box.removeAllItems()
            self.geos = self.api.getAllGeos()
            for geo in self.geos:
                tp = API.Geo.getTypeString(geo)
                label = API.Geo.getLabel(geo)
                self.objects_box.addItem(tp + " " + label)
        finally:
            self.building_objects_box = False
        
        if not self.geos:
            self.current = None
            self.objects_box.enabled = False
            self.events_box.enabled = False
            self.language_box.enabled = False
            self.script_area.input = ""
            self.script_area.component.enabled = False
        else:
            changed = False
            if self.current is None:
                index, event = 0, 1
                changed = True
            else:
                geo, event = self.current
                try:
                    index = self.geos.index(geo)
                except ValueError:
                    index, event = 0, 1
                    changed = True
            self.events_box.selectedIndex = event
#.........这里部分代码省略.........
开发者ID:aeriksson,项目名称:geogebra,代码行数:103,代码来源:gui.py


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