余録:worldCup/jython/ex12/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.23a """ from __init__ import * ## ---------------------------------------- demo: jython """ $ cd /Users/sketch/home_sketch/worldCup/jython/ $ jython -i ex12/wcFrame.py """ ## ---------------------------------------- from wcModel import WcModel 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 from javax.swing import JTabbedPane class TopPanel(JPanel): def __init__(self, master, *args, **keys): master.contentPane = self self.group = None self.label = {} def leftComponent(group): listData = WcModel.teamsBelongTo(group) view = JList( listData, # java.util.Vector valueChanged = self, ) comp = JScrollPane( viewportView = view, preferredSize = (120,150), ) return comp def rightComponent(group): self.label[group] = \ view = JLabel( icon = ImageIcon("matches/wc2010logo.png"), text = u"2010 FIFA World Cup South Africa™", horizontalAlignment = JLabel.CENTER, verticalTextPosition = JLabel.BOTTOM, horizontalTextPosition = JLabel.CENTER, ) comp = JScrollPane( viewportView = view, preferredSize = (180,0), ) return comp def splitPane(group): comp = JSplitPane( orientation = JSplitPane.HORIZONTAL_SPLIT, oneTouchExpandable = True, dividerLocation = 70, leftComponent = leftComponent(group), rightComponent = rightComponent(group), ) return comp def tabbedPane(): def stateChanged(e): index = e.source.selectedIndex self.group = WcModel.groupTabAt(index) comp = JTabbedPane( stateChanged = stateChanged, ) for e in WcModel.groupTabs: comp.addTab(e, splitPane(e)) return comp ## ---------------------------------------- comp = tabbedPane() self.add(comp) master.pack() def __call__(self, e): # javax.swing.event.ListSelectionEvent value = e.source.selectedValue self.update_(value) def update_(self, team): comp = self.label[self.group] comp.icon = ImageIcon("squad/%s.gif"%team) comp.text = WcModel.teamName(team) ## ---------------------------------------- def tips(): global Qt; Qt = \ frame = JFrame( title = "FIFA World Cup #12", size = (320,180), locationRelativeTo = None, defaultCloseOperation = JFrame.EXIT_ON_CLOSE, ) TopPanel(frame) frame.visible = True ## ---------------------------------------- if __name__=='__main__': inform() testmod() ## ========================================
余録:worldCup/jython/ex12/wcModel.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.14 """ print(__name__,"1.0.09") ## ---------------------------------------- class WcModel: groupTabs = "ABCDEFGH" _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 groupTabs for teams in _groups[group] for team in teams]) _teamNames = dict*1 @classmethod def teamName(self, team): return self._teamNames[team] @classmethod def teamsBelongTo(self, group): return [k for e in self._groups[group] for k,v in e.items()] @classmethod def groupTabAt(self, index): return self.groupTabs[index] ## ========================================
*1:k,v) for group in _groups.values() for team in group for k,v in team.items(
Java の素描 #012: タブ付の枠を利用する
《前の記事|記事一覧|次の記事》
Java.use(better, Jython=Swing)
Jython 弾丸ツアー -- FIFA World Cup への道
■ Step12: タブ付の枠を利用する
タブ付き枠を利用して、グループ別にチームを管理します。
from javax.swing import JTabbedPane
...
class TopPanel(JPanel):
def __init__(self, master, *args, **keys):
...
self.group = None
self.label = {}
def leftComponent(group):
...
def rightComponent(group):
...
def splitPane(group):
comp = JSplitPane(
...
leftComponent = leftComponent(group),
rightComponent = rightComponent(group),
)
return comp
def tabbedPane():
def stateChanged(e):
index = e.source.selectedIndex
self.group = WcModel.groupTabAt(index)
comp = JTabbedPane(
stateChanged = stateChanged,
)
for e in WcModel.groupTabs:
comp.addTab(e, splitPane(e))
return comp
## ----------------------------------------
comp = tabbedPane()
def update_(self, team):
comp = self.label[self.group]
comp.icon = ImageIcon("squad/%s.gif"%team)
comp.text = WcModel.teamName(team)
## ---------------------------------------- wcModel.py
class WcModel:
groupTabs = "ABCDEFGH"
@classmethod
def teamName(self, team):
return self._teamNames[team]
@classmethod
def teamsBelongTo(self, group):
return [k
for e in self._groups[group] for k,v in e.items()]
@classmethod
def groupTabAt(self, index):
return self.groupTabs[index]
》作業中です《
↑ TOP
Last updated♪2010/07/13