Re #752 (CEGUIDemo) Profiles menu (a list-box with multi-selection) done + improved (future) Python 3 compatibility

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5101 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: cc91c5de7e471138827d0d80457ecb7bbbf0d372
Former-commit-id: 5263931c30e6ac6929b424d9a8da5ecaa46f3eec
This commit is contained in:
pouillot 2013-01-15 15:29:45 +00:00
parent abedf1a271
commit 07e1a3e7e3
15 changed files with 370 additions and 60 deletions

View file

@ -1,25 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project CEGUIDefaultResolution="800x600" CEGUIVersion="0.7" baseDirectory="." fontsPath="datafiles/fonts" imagesetsPath="datafiles/imagesets" layoutsPath="datafiles/layouts" looknfeelsPath="datafiles/looknfeels" schemesPath="datafiles/schemes" version="CEED Project 1" xmlSchemasPath="datafiles/xml_schemas">
<Items>
<Item name="ImageSets" type="folder">
<Item path="datafiles/imagesets/ceguidemolook.imageset" type="file" />
<Item path="datafiles/imagesets/sd-logo.imageset" type="file" />
<Item path="datafiles/imagesets/splash-carselect.imageset" type="file" />
<Item path="datafiles/imagesets/splash-credits.imageset" type="file" />
<Item path="datafiles/imagesets/splash-main.imageset" type="file" />
<Item path="datafiles/imagesets/splash-options.imageset" type="file" />
<Item path="datafiles/imagesets/splash-trackselect.imageset" type="file" />
</Item>
<Item name="Layouts" type="folder">
<Item path="datafiles/layouts/dialogokcancel.layout" type="file" />
<Item path="datafiles/layouts/menucarselect.layout" type="file" />
<Item path="datafiles/layouts/menucredits.layout" type="file" />
<Item path="datafiles/layouts/menumain.layout" type="file" />
<Item path="datafiles/layouts/menuoptions.layout" type="file" />
<Item path="datafiles/layouts/menutrackselect.layout" type="file" />
</Item>
<Item name="Schemes" type="folder">
<Item path="datafiles/schemes/ceguidemo.scheme" type="file" />
</Item>
</Items>
<?xml version="1.0" encoding="utf-8"?>
<Project CEGUIDefaultResolution="800x600" CEGUIVersion="0.7" baseDirectory="." fontsPath="datafiles/fonts" imagesetsPath="datafiles/imagesets" layoutsPath="datafiles/layouts" looknfeelsPath="datafiles/looknfeels" schemesPath="datafiles/schemes" version="CEED Project 1" xmlSchemasPath="datafiles/xml_schemas">
<Items>
<Item name="ImageSets" type="folder">
<Item path="datafiles/imagesets/ceguidemolook.imageset" type="file" />
<Item path="datafiles/imagesets/sd-logo.imageset" type="file" />
<Item path="datafiles/imagesets/splash-carselect.imageset" type="file" />
<Item path="datafiles/imagesets/splash-credits.imageset" type="file" />
<Item path="datafiles/imagesets/splash-main.imageset" type="file" />
<Item path="datafiles/imagesets/splash-options.imageset" type="file" />
<Item path="datafiles/imagesets/splash-trackselect.imageset" type="file" />
</Item>
<Item name="Layouts" type="folder">
<Item path="datafiles/layouts/dialogokcancel.layout" type="file" />
<Item path="datafiles/layouts/menucarselect.layout" type="file" />
<Item path="datafiles/layouts/menucredits.layout" type="file" />
<Item path="datafiles/layouts/menumain.layout" type="file" />
<Item path="datafiles/layouts/menuoptions.layout" type="file" />
<Item path="datafiles/layouts/menutrackselect.layout" type="file" />
<Item path="datafiles/layouts/menuprofiles.layout" type="file" />
</Item>
<Item name="Schemes" type="folder">
<Item path="datafiles/schemes/ceguidemo.scheme" type="file" />
</Item>
</Items>
</Project>

View file

@ -57,7 +57,6 @@
<Image Height="16" Name="SpinnerUpHover" Width="14" XPos="81" YPos="227" />
<Image Height="16" Name="SpinnerUpPushed" Width="14" XPos="97" YPos="227" />
<Image Height="16" Name="TextSelectionBrush" Width="16" XPos="234" YPos="238" />
<Image Height="40" Name="VertScrollBarSegment" Width="2" XPos="158" YPos="313" />
<Image Height="10" Name="VertScrollThumbTopNormal" Width="16" XPos="140" YPos="313" />
<Image Height="20" Name="VertScrollThumbMiddleNormal" Width="16" XPos="140" YPos="323" />
@ -74,7 +73,6 @@
<Image Height="16" Name="VertScrollUpNormal" Width="14" XPos="65" YPos="227" />
<Image Height="16" Name="VertScrollUpHover" Width="14" XPos="81" YPos="227" />
<Image Height="16" Name="VertScrollUpPushed" Width="14" XPos="97" YPos="227" />
<Image Height="2" Name="HorzScrollBarSegment" Width="40" XPos="162" YPos="367" />
<Image Height="16" Name="HorzScrollThumbLeftNormal" Width="10" XPos="162" YPos="349" />
<Image Height="16" Name="HorzScrollThumbMiddleNormal" Width="20" XPos="172" YPos="349" />
@ -98,15 +96,15 @@
<Image Height="9" Name="HorizSliderBody" Width="48" XPos="57" YPos="301" />
<Image Height="15" Name="HorizSliderThumbNormal" Width="6" XPos="50" YPos="295" />
<Image Height="15" Name="HorizSliderThumbHover" Width="6" XPos="42" YPos="295" />
<Image Height="6" Name="ListboxLeft" Width="7" XPos="41" YPos="89" />
<Image Height="6" Name="ListboxRight" Width="7" XPos="62" YPos="89" />
<Image Height="7" Name="ListboxTop" Width="6" XPos="52" YPos="78" />
<Image Height="7" Name="ListboxBottom" Width="6" XPos="52" YPos="99" />
<Image Height="7" Name="ListboxTopLeft" Width="7" XPos="41" YPos="78" />
<Image Height="7" Name="ListboxTopRight" Width="7" XPos="62" YPos="78" />
<Image Height="7" Name="ListboxBottomLeft" Width="7" XPos="41" YPos="99" />
<Image Height="7" Name="ListboxBottomRight" Width="7" XPos="62" YPos="99" />
<Image Height="6" Name="ListboxBackdrop" Width="6" XPos="52" YPos="89" />
<Image Height="6" Name="ListboxLeft" Width="7" XPos="45" YPos="362" />
<Image Height="6" Name="ListboxRight" Width="7" XPos="66" YPos="362" />
<Image Height="7" Name="ListboxTop" Width="6" XPos="56" YPos="351" />
<Image Height="7" Name="ListboxBottom" Width="6" XPos="56" YPos="372" />
<Image Height="7" Name="ListboxTopLeft" Width="7" XPos="45" YPos="351" />
<Image Height="7" Name="ListboxTopRight" Width="7" XPos="66" YPos="351" />
<Image Height="7" Name="ListboxBottomLeft" Width="7" XPos="45" YPos="372" />
<Image Height="7" Name="ListboxBottomRight" Width="7" XPos="66" YPos="372" />
<Image Height="6" Name="ListboxBackdrop" Width="6" XPos="56" YPos="362" />
<Image Height="16" Name="ListboxSelectionBrush" Width="16" XPos="234" YPos="238" />
<Image Height="16" Name="ComboboxEditLeft" Width="9" XPos="185" YPos="219" />
<Image Height="16" Name="ComboboxEditMiddle" Width="8" XPos="195" YPos="219" />
@ -259,4 +257,12 @@
<Image Height="16" Name="HorizontalVUMeterMiddle" Width="20" XPos="113" YPos="295" />
<Image Height="16" Name="HorizontalVUMeterRight" Width="8" XPos="135" YPos="295" />
<Image Height="16" Name="HorizontalVUMeterLitSegment" Width="64" XPos="145" YPos="295" />
<Image Height="24" Name="IconAddNormal" Width="24" XPos="1" YPos="382" />
<Image Height="24" Name="IconAddHighlight" Width="24" XPos="26" YPos="382" />
<Image Height="24" Name="IconAddPushed" Width="24" XPos="51" YPos="382" />
<Image Height="24" Name="IconAddDisabled" Width="24" XPos="76" YPos="382" />
<Image Height="24" Name="IconRemoveNormal" Width="24" XPos="101" YPos="382" />
<Image Height="24" Name="IconRemoveHighlight" Width="24" XPos="126" YPos="382" />
<Image Height="24" Name="IconRemovePushed" Width="24" XPos="151" YPos="382" />
<Image Height="24" Name="IconRemoveDisabled" Width="24" XPos="176" YPos="382" />
</Imageset>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 45 KiB

View file

@ -0,0 +1,4 @@
<?xml version="1.0" ?>
<Imageset Name="SplashProfiles" AutoScaled="true" Imagefile="splash-profiles.jpg" NativeHorzRes="800" NativeVertRes="600">
<Image Name="everything" Height="800" Width="1280" XPos="0" YPos="0" />
</Imageset>

View file

@ -0,0 +1,103 @@
<GUILayout>
<Window Name="MenuProfiles" Type="CEGUIDemo/StaticImage">
<Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
<Property Name="Image" Value="set:SplashProfiles image:everything" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="FrameEnabled" Value="False" />
<Property Name="BackgroundEnabled" Value="False" />
<Window Name="MenuProfiles/ImgLogo" Type="CEGUIDemo/StaticImage">
<Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{0.3,0},{0.25,0}}" />
<Property Name="Image" Value="set:Logo image:everything" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="Tooltip" Value="What a nice logo !" />
<Property Name="FrameEnabled" Value="False" />
<Property Name="BackgroundEnabled" Value="False" />
</Window>
<Window Name="MenuProfiles/TxtTitle" Type="CEGUIDemo/PageTitle">
<Property Name="UnifiedAreaRect" Value="{{0.22,0},{0.1,0},{0.92,0},{0.2,0}}" />
<Property Name="Font" Value="MenuTitle" />
<Property Name="Text" Value="Profiles" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="Tooltip" Value="Yeah, this is the title of the menu !" />
<Property Name="FrameEnabled" Value="False" />
</Window>
<Window Name="MenuProfiles/TxtFrameRate" Type="CEGUIDemo/StaticText">
<Property Name="UnifiedAreaRect" Value="{{0.95,0},{0.01,0},{0.99,0},{0.04,0}}" />
<Property Name="Font" Value="TextSmall" />
<Property Name="Text" Value="99.9" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="TextColours" Value="tl:FFFFFFFF tr:FFC0C0C0 bl:FF808080 br:FF606060" />
<Property Name="Tooltip" Value="Frame rate (F/s)" />
<Property Name="FrameEnabled" Value="False" />
<Property Name="HorzFormatting" Value="RightAligned" />
<Property Name="VertFormatting" Value="TopAligned" />
<Property Name="BackgroundEnabled" Value="False" />
</Window>
<Window Name="MenuProfiles/BtnAccept" Type="CEGUIDemo/Button">
<Property Name="UnifiedAreaRect" Value="{{0.23,0},{0.9,0},{0.38,0},{0.95,0}}" />
<Property Name="Font" Value="MenuMedium" />
<Property Name="Text" Value="Accept" />
<Property Name="Tooltip" Value="Accept changes and go back to main menu" />
</Window>
<Window Name="MenuProfiles/BtnCancel" Type="CEGUIDemo/Button">
<Property Name="UnifiedAreaRect" Value="{{0.63,0},{0.9,0},{0.78,0},{0.95,0}}" />
<Property Name="Font" Value="MenuMedium" />
<Property Name="Text" Value="Cancel" />
<Property Name="Tooltip" Value="Revert changes and go back to main menu" />
</Window>
<Window Name="MenuProfiles/LblName" Type="CEGUIDemo/StaticText">
<Property Name="UnifiedAreaRect" Value="{{0.10,0},{0.24,0},{0.25,0},{0.31,0}}" />
<Property Name="Font" Value="MenuNormal" />
<Property Name="Text" Value="Name" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="FrameEnabled" Value="False" />
<Property Name="BackgroundEnabled" Value="False" />
</Window>
<Window Name="MenuProfiles/LblSkill" Type="CEGUIDemo/StaticText">
<Property Name="UnifiedAreaRect" Value="{{0.10,0},{0.34,0},{0.25,0},{0.41,0}}" />
<Property Name="Font" Value="MenuNormal" />
<Property Name="Text" Value="Skill level" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="FrameEnabled" Value="False" />
<Property Name="BackgroundEnabled" Value="False" />
</Window>
<Window Name="MenuProfiles/EdxName" Type="CEGUIDemo/Editbox">
<Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.25,0},{0.50,0},{0.30,0}}" />
<Property Name="Font" Value="MenuMedium" />
<Property Name="Text" Value="" />
<Property Name="BlinkCaret" Value="True" />
<Property Name="MaxTextLength" Value="20" />
<Property Name="TextFormatting" Value="LeftAligned" />
<Property Name="Tooltip" Value="Enter / edit the profile name" />
</Window>
<Window Name="MenuProfiles/CbxSkill" Type="CEGUIDemo/Combobox">
<Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.35,0},{0.50,0},{0.55,0}}" />
<Property Name="Font" Value="MenuMedium" />
<Property Name="Tooltip" Value="Select the skill level" />
<Property Name="EditTextFormatting" Value="LeftAligned" />
<Property Name="ReadOnly" Value="True" />
</Window>
<Window Name="MenuProfiles/LbxProfiles" Type="CEGUIDemo/ItemListbox">
<Property Name="UnifiedAreaRect" Value="{{0.60,0},{0.25,0},{0.90,0},{0.60,0}}" />
<Property Name="MultiSelect" Value="True" />
<Property Name="Tooltip" Value="Profile list" />
</Window>
<Window Name="MenuProfiles/BtnAdd" Type="CEGUIDemo/ImageButton">
<Property Name="UnifiedAreaRect" Value="{{0.60,0},{0.65,0},{0.68,0},{0.75,0}}" />
<Property Name="Tooltip" Value="Add a new profile" />
<Property Name="NormalImage" Value="set:CEGUIDemo image:IconAddNormal" />
<Property Name="HoverImage" Value="set:CEGUIDemo image:IconAddHighlight" />
<Property Name="PushedImage" Value="set:CEGUIDemo image:IconAddPushed" />
<Property Name="DisabledImage" Value="set:CEGUIDemo image:IconAddDisabled" />
</Window>
<Window Name="MenuProfiles/BtnRemove" Type="CEGUIDemo/ImageButton">
<Property Name="UnifiedAreaRect" Value="{{0.70,0},{0.65,0},{0.78,0},{0.75,0}}" />
<Property Name="Tooltip" Value="Remove selected profile" />
<Property Name="NormalImage" Value="set:CEGUIDemo image:IconRemoveNormal" />
<Property Name="HoverImage" Value="set:CEGUIDemo image:IconRemoveHighlight" />
<Property Name="PushedImage" Value="set:CEGUIDemo image:IconRemovePushed" />
<Property Name="DisabledImage" Value="set:CEGUIDemo image:IconRemoveDisabled" />
<Property Name="Disabled" Value="True" />
</Window>
</Window>
</GUILayout>

View file

@ -1900,7 +1900,7 @@
</StateImagery>
</WidgetLook>
<!--
<!-- WARNING: Deprecated, rather use the more powerful ItemListbox !
***************************************************
CEGUIDemo/Listbox
***************************************************
@ -4545,7 +4545,7 @@
</WidgetLook>
<!--
<!-- An item of the ItemListbox
***************************************************
CEGUIDemo/ListboxItem
***************************************************
@ -4555,6 +4555,7 @@
<PropertyDefinition name="SelectedTextColour" initialValue="FFFFFFFF" redrawOnWrite="true" />
<PropertyDefinition name="SelectionBrush" initialValue="set:CEGUIDemo image:ListboxSelectionBrush" redrawOnWrite="true" />
<PropertyDefinition name="SelectionColour" initialValue="FF3FFFEE" redrawOnWrite="true" />
<PropertyDefinition name="HorzLabelFormatting" initialValue="LeftAligned" redrawOnWrite="true" />
<Property name="Selectable" value="True" />
<Property name="MouseInputPropagationEnabled" value="True" />
<NamedArea name="ContentSize">
@ -4589,6 +4590,7 @@
<UnifiedDim scale="1" type="BottomEdge" />
</Dim>
</Area>
<HorzFormatProperty name="HorzLabelFormatting" />
</TextComponent>
</ImagerySection>
<ImagerySection name="selection">
@ -4747,8 +4749,8 @@
<PropertyDefinition name="NormalTextColour" initialValue="FFFFFFFF" redrawOnWrite="true" />
<PropertyDefinition name="PushedTextColour" initialValue="FF69FFF6" redrawOnWrite="true" />
<PropertyDefinition name="DisabledTextColour" initialValue="FF7F7F7F" redrawOnWrite="true" />
<PropertyDefinition name="VertLabelFormatting" initialValue="CentreAligned" />
<PropertyDefinition name="HorzLabelFormatting" initialValue="LeftAligned" />
<PropertyDefinition name="VertLabelFormatting" initialValue="CentreAligned" redrawOnWrite="true" />
<PropertyDefinition name="HorzLabelFormatting" initialValue="LeftAligned" redrawOnWrite="true" />
<PropertyDefinition name="NormalImage" initialValue="" redrawOnWrite="true" />
<PropertyDefinition name="HoverImage" initialValue="" redrawOnWrite="true" />
<PropertyDefinition name="PushedImage" initialValue="" redrawOnWrite="true" />

View file

@ -7,6 +7,7 @@
<Imageset Filename="splash-carselect.imageset" />
<Imageset Filename="splash-credits.imageset" />
<Imageset Filename="splash-options.imageset" />
<Imageset Filename="splash-profiles.imageset" />
<Imageset Filename="splash-okcancel.imageset" />
<Font Name="MenuSmall" Filename="menu-small.font" />
<Font Name="MenuMedium" Filename="menu-medium.font" />

View file

@ -146,15 +146,18 @@ class Input(object):
if not key['is_held']:
key['is_held'] = True
PyCEGUI.System.getSingleton().injectKeyDown(key['scancode'])
print("handleModifierKeys: Down %s" % name)
elif key['is_held']:
key['is_held'] = False
PyCEGUI.System.getSingleton().injectKeyUp(key['scancode'])
print("handleModifierKeys: Up %s " % name)
# Handler: Normal Key Down
def handlerNormalKeyDown(self, key, x, y):
key = key.encode('ascii', 'ignore')
self.handleModifierKeys()
key = key.encode('ascii', 'ignore')
scancode = self.ascii2Scancode(key)
if scancode:
PyCEGUI.System.getSingleton().injectKeyDown(int(scancode))
@ -165,8 +168,9 @@ class Input(object):
# Handler: Normal Key Up
def handlerNormalKeyUp(self, key, x, y):
key = key.encode('ascii', 'ignore')
self.handleModifierKeys()
key = key.encode('ascii', 'ignore')
scancode = self.ascii2Scancode(key)
if scancode:
PyCEGUI.System.getSingleton().injectKeyDown(int(scancode))
@ -178,6 +182,7 @@ class Input(object):
def handlerSpecialKeyDown(self, key, x, y):
self.handleModifierKeys()
scancode = self.special2Scancode(key)
if scancode:
PyCEGUI.System.getSingleton().injectKeyDown(int(scancode))
@ -188,6 +193,7 @@ class Input(object):
def handlerSpecialKeyUp(self, key, x, y):
self.handleModifierKeys()
scancode = self.special2Scancode(key)
if scancode:
PyCEGUI.System.getSingleton().injectKeyUp(int(scancode))
@ -197,6 +203,8 @@ class Input(object):
# Handler: Mouse Button
def handlerMouseButton(self, button, state, x, y):
self.handleModifierKeys()
if button == GLUT_LEFT_BUTTON:
if state == GLUT_UP:
PyCEGUI.System.getSingleton().injectMouseButtonUp(PyCEGUI.LeftButton)

View file

@ -35,7 +35,7 @@ def main():
inp.initialize()
gui.initialize()
except InitializationError as error:
print error
print(error)
return 1
# Setup the interface

View file

@ -104,9 +104,9 @@ class Menu(object):
self.txtFrameRate = window.getChild(name + "/TxtFrameRate")
# Trace info. about children.
#print "Menu: Children (n=%d) :" % self.window.getChildCount()
#print("Menu: Children (n=%d) :" % self.window.getChildCount())
#for chldInd in range(self.window.getChildCount()):
# print " #%d : name=%r" % (chldInd, self.window.getChildAtIdx(chldInd).getName())
# print(" #%d : name=%r" % (chldInd, self.window.getChildAtIdx(chldInd).getName()))
# Setup animations.
self.animFadeIn = PyCEGUI.AnimationManager.getSingleton().instantiateAnimation("MenuFadeIn")
@ -147,7 +147,7 @@ class Menu(object):
# Activate
def deactivate(self):
print "%s.deactivate" % self.__class__.__name__
print("%s.deactivate" % self.__class__.__name__)
# Detach.
#self.disconnectHandlers()
@ -158,7 +158,7 @@ class Menu(object):
# Activate
def activate(self, previous=None):
print "%s.activate" % self.__class__.__name__
print("%s.activate" % self.__class__.__name__)
# Attach new.
PyCEGUI.System.getSingleton().setGUISheet(self.window)
@ -188,7 +188,7 @@ class Menu(object):
self.deactivate()
self.prevMenu.activate()
else:
print "Warning: No previous menu to return to ; ignoring."
print("Warning: No previous menu to return to ; ignoring.")
# Update frame rate indicator.
def onUpdate(self, winArgs): # Bug: Not an UpdateEventArgs, but a WindowEventArgs !
@ -204,18 +204,18 @@ class Menu(object):
def onKeyDown(self, keyArgs):
# Just in case not specialised in actual class.
print "Menu.onKeyDown: sc=", keyArgs.scancode
print("Menu.onKeyDown: sc=", keyArgs.scancode)
return False
# Debug : Seems that EventActivated is only fired once ever !
def onActivated(self, args):
print "%s.onActivated" % self.__class__.__name__
print("%s.onActivated" % self.__class__.__name__)
#self.connectHandlers()
return False
def onDeactivated(self, args):
print "%s.onDeactivated" % self.__class__.__name__
print("%s.onDeactivated" % self.__class__.__name__)
#self.disconnectHandlers()
return False

View file

@ -21,6 +21,7 @@ from configuration import TheConfig
from menustandard import MenuStandard
from menucredits import MenuCredits
from menuoptions import MenuOptions
from menuprofiles import MenuProfiles
# Car selection menu
class MenuCarSelect(MenuStandard):
@ -60,7 +61,7 @@ class MenuCarSelect(MenuStandard):
def __init__(self):
MenuStandard.__init__(self, MenuCredits, MenuOptions) #, MenuProfiles, )
MenuStandard.__init__(self, MenuCredits, MenuOptions, MenuProfiles)
# Initialize
def initialize(self):
@ -146,7 +147,6 @@ class MenuCarSelect(MenuStandard):
def onTreeSelectionChanged(self, args):
print("onTreeSelectionChanged")
treeItem = args.treeItem
if treeItem and treeItem.getID() in self.dictTreeItemID2Car:
car = self.dictTreeItemID2Car[treeItem.getID()]

View file

@ -20,6 +20,7 @@ from configuration import TheConfig
from menustandard import MenuStandard
from menucredits import MenuCredits
from menuoptions import MenuOptions
from menuprofiles import MenuProfiles
from menutrackselect import MenuTrackSelect
# Main menu
@ -27,7 +28,7 @@ class MenuMain(MenuStandard):
def __init__(self):
MenuStandard.__init__(self, MenuCredits, MenuOptions) #, MenuProfiles, )
MenuStandard.__init__(self, MenuCredits, MenuOptions, MenuProfiles)
self.menuTrackSelect = None

View file

@ -0,0 +1,183 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Profiles menu.
"""
# Import: std
import sys
# Import: PyCEGUI
import PyCEGUI
# Import: Configuration
from configuration import TheConfig
# Import: Menu
from menu import Menu
# Main menu
class MenuProfiles(Menu):
singleton = None
def getSingleton():
if not MenuProfiles.singleton:
MenuProfiles.singleton = MenuProfiles()
MenuProfiles.singleton.initialize()
MenuProfiles.singleton.setup()
return MenuProfiles.singleton
getSingleton = staticmethod(getSingleton)
def __init__(self):
Menu.__init__(self)
# Initialize
def initialize(self):
name = "MenuProfiles"
# No code written for this menu : use mandatory layout.
window = Menu.initialize(self, name=name, title="Profiles", layout="menuprofiles")
# Retrieve window descendants created here.
self.btnAccept = window.getChild(name + "/BtnAccept")
self.btnCancel = window.getChild(name + "/BtnCancel")
self.edxName = window.getChild(name + "/EdxName")
self.cbxSkill = window.getChild(name + "/CbxSkill")
self.lbxProfiles = window.getChild(name + "/LbxProfiles")
self.btnAdd = window.getChild(name + "/BtnAdd")
self.btnRemove = window.getChild(name + "/BtnRemove")
# Complete widget initialization.
self.cbxSkillItems = []
for skill in ("Rookie", "Amateur", "Semi-pro", "Pro"):
cbxItem = PyCEGUI.ListboxTextItem(skill)
cbxItem.setSelectionBrushImage("CEGUIDemo", "ComboboxSelectionBrush")
cbxItem.setSelectionColours(0xFF3FFFEE)
self.cbxSkill.addItem(cbxItem)
self.cbxSkillItems.append(cbxItem) # Avoid its being GC'd at return !
if skill.startswith("Rookie"):
self.cbxSkill.setText(cbxItem.getText())
#self.lbProfItems = []
self.lbItemId = 0
for name in ("Mike", "Horst", "Paolo", "Albert", "Yuuki", "Bjorn",
"Jane", "Henri", "Francesca", "Joao", "Klaus"):
# Obsolete Listbox use case.
#lbItem = PyCEGUI.ListboxTextItem(name, auto_delete=False)
#lbItem.setSelectionBrushImage("CEGUIDemo", "ListboxSelectionBrush")
#lbItem.setSelectionColours(0xFF3FFFEE)
#lbItem.setSelectionBrushImage("CEGUIDemo", "ListboxSelectionBrush")
#lbItem.setSelectionColours(0xFF3FFFEE)
#self.lbProfItems.append(lbItem) # Avoid its being GC'd at return !
lbItem = PyCEGUI.WindowManager.getSingleton().createWindow("CEGUIDemo/ListboxItem", "profile_%d" % self.lbItemId)
self.lbItemId += 1
lbItem.setText(name)
self.lbxProfiles.addItem(lbItem)
return window
# connectHandlers
# - Wrapper method to define the subscription/listener relationships.
# - If there are a lot, it may behoove the coder to encapsulate them in methods, then call those methods here.
def connectHandlers(self):
# Inherited connections.
Menu.connectHandlers(self)
# Specific connections.
self.btnCancel.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, "onCancelButtonClicked")
self.btnAccept.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, "onAcceptButtonClicked")
self.btnAdd.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, "onAddButtonClicked")
self.btnRemove.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, "onRemoveButtonClicked")
self.edxName.subscribeEvent(PyCEGUI.Editbox.EventTextAccepted, self, "onNameAccepted")
self.lbxProfiles.subscribeEvent(PyCEGUI.ItemListbox.EventSelectionChanged, self, "onListSelectionChanged")
def onCancelButtonClicked(self, args):
print("Profiles : Cancelled.")
self.back()
def onAcceptButtonClicked(self, args):
print("Profiles : Accepted.")
self.back()
def onListSelectionChanged(self, notUsed):
lbItem = self.lbxProfiles.getFirstSelectedItem()
if lbItem:
self.edxName.setText(lbItem.getText())
self.btnRemove.enable()
else:
self.edxName.setText("")
self.btnRemove.disable()
def onNameAccepted(self, notUsed):
lbItem = self.lbxProfiles.getFirstSelectedItem()
if lbItem:
lbItem.setText(self.edxName.getText())
# Obsolete Listbox use case.
#self.lbxProfiles.handleUpdatedItemData()
#self.lbxProfiles.ensureItemIsVisible(lbItem)
self.lbxProfiles.ensureItemIsVisibleVert(lbItem)
def onAddButtonClicked(self, args):
self.lbxProfiles.clearAllSelections()
# Obsolete Listbox use case.
#lbItem = PyCEGUI.ListboxTextItem("-- no one --", auto_delete=False)
#lbItem.setSelectionBrushImage("CEGUIDemo", "ListboxSelectionBrush")
#lbItem.setSelectionColours(0xFF3FFFEE)
#self.lbProfItems.append(lbItem) # Avoid its being GC'd at return !
lbItem = PyCEGUI.WindowManager.getSingleton().createWindow("CEGUIDemo/ListboxItem", "profile_%d" % self.lbItemId)
self.lbItemId += 1
lbItem.setText("-- no one --")
self.lbxProfiles.addItem(lbItem)
# Obsolete Listbox use case.
#self.lbxProfiles.setItemSelectState(lbItem, True)
#self.lbxProfiles.ensureItemIsVisible(lbItem)
lbItem.setSelected(True)
self.lbxProfiles.ensureItemIsVisibleVert(lbItem)
def onRemoveButtonClicked(self, args):
lbItem = self.lbxProfiles.getFirstSelectedItem()
while lbItem:
#print("removing %s (%s)" % (lbItem, lbItem.getText()))
# Obsolete Listbox use case.
#lbItem2Rremove = lbItem
#lbItem = self.lbxProfiles.getNextSelected(lbItem)
#self.lbxProfiles.setItemSelectState(lbItem2Rremove, False)
#self.lbProfItems.remove(lbItem2Rremove)
lbItem.setSelected(False)
self.lbxProfiles.removeItem(lbItem)
lbItem = self.lbxProfiles.getNextSelectedItem()
def onKeyDown(self, keyArgs):
if keyArgs.scancode == PyCEGUI.Key.Escape:
keyArgs.handled += 1
self.onCancelButtonClicked(keyArgs)
return True
elif keyArgs.scancode == PyCEGUI.Key.Return:
keyArgs.handled += 1
self.onAcceptButtonClicked(keyArgs)
return True
return False

View file

@ -23,13 +23,13 @@ from dialogs import DialogOKCancel
# Main menu
class MenuStandard(Menu):
def __init__(self, clsMenuCredits, clsMenuOptions): #, clsMenuProfiles):
def __init__(self, clsMenuCredits, clsMenuOptions, clsMenuProfiles):
Menu.__init__(self)
self.clsMenuCredits = clsMenuCredits
self.clsMenuOptions = clsMenuOptions
#self.clsMenuProfiles = clsMenuProfiles
self.clsMenuProfiles = clsMenuProfiles
self.menuCredits = None
self.menuProfiles = None
@ -121,7 +121,7 @@ class MenuStandard(Menu):
def onProfilesButtonClicked(self, args):
print("onProfilesButtonClicked")
self.switchTo(self.clsMenuProfiles.getSingleton())
def onOptionsButtonClicked(self, args):
@ -139,7 +139,7 @@ class MenuStandard(Menu):
def onKeyDown(self, keyArgs):
print "MenuStandard.onKeyDown: sc=%d, " % (keyArgs.scancode, )
print("MenuStandard.onKeyDown: sc=%d, " % keyArgs.scancode)
if keyArgs.scancode == PyCEGUI.Key.Escape:
keyArgs.handled = True

View file

@ -21,6 +21,7 @@ from configuration import TheConfig
from menustandard import MenuStandard
from menucredits import MenuCredits
from menuoptions import MenuOptions
from menuprofiles import MenuProfiles
from menucarselect import MenuCarSelect
# Track selection menu
@ -75,7 +76,7 @@ class MenuTrackSelect(MenuStandard):
def __init__(self):
MenuStandard.__init__(self, MenuCredits, MenuOptions) #, MenuProfiles, )
MenuStandard.__init__(self, MenuCredits, MenuOptions, MenuProfiles)
self.menuCarSelect = None
@ -151,7 +152,7 @@ class MenuTrackSelect(MenuStandard):
selCatName = self.cbxCat.getSelectedItem().getText()
print "onCatChanged(%s)" % selCatName
#print("onCatChanged(%s)" % selCatName)
# Re-initialise track combo-box.
self.cbxTrack.clearAllSelections()
@ -176,7 +177,7 @@ class MenuTrackSelect(MenuStandard):
selCatName = self.cbxCat.getSelectedItem().getText()
selTrackName = self.cbxTrack.getSelectedItem().getText()
print "onTrackChanged(cat=%s, track=%s)" % (selCatName, selTrackName)
#print("onTrackChanged(cat=%s, track=%s)" % (selCatName, selTrackName))
track = self.Tracks[selCatName][selTrackName]