余録:worldCup/jython/ex09/wcFrame.py
#! /usr/bin/env python # coding: utf-8 ## ---------------------------------------- ## ## (C) Copyright 2000-2010, 小粒ちゃん《監修》小泉ひよ子とタマゴ倶楽部 ## ## ---------------------------------------- ## History: Swing Example "2010 FIFA World Cup South Africa™" ## 2003/07, Java/Jython ## 2006/07, Jython ## 2008/02, Jython 2.2.1 ## 2010/06, Jython 2.5.0 #...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 """ >>> tips() >>> ## ---------------------------------------- >>> None version: #1.0.14a """ from __init__ import * ## ---------------------------------------- demo: jython """ $ cd /Users/sketch/home_sketch/worldCup/jython/ $ jython -i ex09/wcFrame.py """ ## ---------------------------------------- from javax.swing import ImageIcon from javax.swing import JFrame from javax.swing import JLabel from javax.swing import JList from javax.swing import JPanel from javax.swing import JScrollPane from javax.swing import JSplitPane class WcModel: groups = { "A": [ # Group A {"rsa": "South Africa"}, {"mex": "Mexico"}, {"uru": "Uruguay"}, {"fra": "France"}, ], "B": [ # Group B {"arg": "Argentina"}, {"nga": "Nigeria"}, {"kor": "Korea Republic"}, {"gre": "Greece"}, ], "C": [ # Group C {"eng": "England"}, {"usa": "USA"}, {"alg": "Algeria"}, {"svn": "Slovenia"}, ], "D": [ # Group D {"ger": "Germany"}, {"aus": "Australia"}, {"srb": "Serbia"}, {"gha": "Ghana"}, ], "E": [ # Group E {"ned": "Netherlands"}, {"den": "Denmark"}, {"jpn": "Japan"}, {"cmr": "Cameroon"}, ], "F": [ # Group F {"ita": "Italy"}, {"par": "Paraguay"}, {"nzl": "New Zealand"}, {"svk": "Slovakia"}, ], "G": [ # Group G {"bra": "Brazil"}, {"prk": "Korea DPR"}, {"civ": "Cote d Ivoire"}, {"por": "Portugal"}, ], "H": [ # Group H {"esp": "Spain"}, {"sui": "Switzerland"}, {"hon": "Honduras"}, {"chi": "Chile"}, ], } teams = sorted([team for group in "ABCDEFGH" for teams in groups[group] for team in teams]) teamNames = dict*1 ## ---------------------------------------- class TopPanel(JPanel): def __init__(self, master, *args, **keys): master.contentPane = self def leftComponent(): listData = WcModel.teams view = JList( listData, # java.util.Vector valueChanged = self, ) comp = JScrollPane( viewportView = view, preferredSize = (120,150), ) return comp def rightComponent(): view = JLabel( icon = ImageIcon("matches/fifa.png"), ) comp = JScrollPane( viewportView = view, preferredSize = (180,0), ) return comp def splitPane(): comp = JSplitPane( orientation = JSplitPane.HORIZONTAL_SPLIT, oneTouchExpandable = True, dividerLocation = 100, leftComponent = leftComponent(), rightComponent = rightComponent(), ) return comp comp = splitPane() self.add(comp) master.pack() def __call__(self, e): # javax.swing.event.ListSelectionEvent value = e.source.selectedValue print(":: %s"%WcModel.teamNames[value]) ## ---------------------------------------- def tips(): global Qt; Qt = \ frame = JFrame( title = "FIFA World Cup #09", size = (320,180), locationRelativeTo = None, defaultCloseOperation = JFrame.EXIT_ON_CLOSE, ) TopPanel(frame) frame.visible = True ## ---------------------------------------- if __name__=='__main__': inform() testmod() ## ========================================
*1:k,v) for group in groups.values() for team in group for k,v in team.items(