Skip to content

Commit

Permalink
Added popup menu; shortcut to Snowberry prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jul 6, 2005
1 parent 0f9b856 commit 79e836f
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 12 deletions.
2 changes: 1 addition & 1 deletion snowberry/conf/osx-doomsday.conf
Expand Up @@ -13,7 +13,7 @@ configure doomsday (
)

configure common (
options: -appdir "../Doomsday.app/Contents/Bundles"
options: -appdir ".."
)


Expand Down
14 changes: 10 additions & 4 deletions snowberry/lang/english.lang
Expand Up @@ -90,7 +90,7 @@ unhiding-profiles: Select one or more hidden profiles to show.
unhide-select-all: Select all
unhide-clear-all: Clear all
view-command-line-dialog: Command Line
view-command-line-title: Viewing Command Line Options
view-command-line-title: Previewing Command Line Options
install-addon-dialog: Addon Installer
install-addon-title: Choose Addons to Install
addon-dialog-folder: Folder:
Expand Down Expand Up @@ -176,6 +176,7 @@ uninstall-addon: -
load-order: Load Order
addon-settings: Settings
about: About
popup-menu: Menu
preferences: Preferences

#
Expand All @@ -190,15 +191,20 @@ menu-hide-profile: Hide
menu-unhide-profiles: Show...
menu-uninstall-addon: Uninstall
menu-addon-info: Info
menu-load-order: Load Order...
menu-install-addon: Install New...
menu-load-order: Load order...
menu-install-addon: Install new...
menu-addon-settings: Settings
menu-check-category: Check category
menu-uncheck-category: Uncheck category
menu-expand-all-categories: Expand all
menu-collapse-all-categories: Collapse all
menu-reset-slider: Reset to default
menu-view-command-line: View command line
menu-play: Launch selected game
menu-view-command-line: Preview command line
menu-run-setup-wizard: Show setup wizard
menu-show-snowberry-settings: Preferences
menu-about: About
menu-quit: Quit

#
# Tab Labels
Expand Down
7 changes: 5 additions & 2 deletions snowberry/plugins/about.py
Expand Up @@ -28,11 +28,14 @@

def init():
# Create the About button in the Preferences Command area.
area = ui.getArea(Area.PREFCOMMAND)
area.createButton('about')
#area = ui.getArea(Area.PREFCOMMAND)
#area.createButton('about')

# Listen for the About button.
events.addCommandListener(handleCommand)

# Commands for the popup menu.
ui.addPopupMenuCommand(2, 'about')


def handleCommand(event):
Expand Down
9 changes: 9 additions & 0 deletions snowberry/plugins/launcher.py
Expand Up @@ -87,6 +87,11 @@ def init():

# Register for listening to commands.
events.addCommandListener(handleCommand)

# Commands for the popup menu.
ui.addPopupMenuCommand(0, 'play')
ui.addPopupMenuCommand(1, 'view-command-line')
ui.addPopupMenuCommand(2, 'quit')


def handleNotify(event):
Expand All @@ -98,6 +103,10 @@ def handleNotify(event):


def handleCommand(event):
if pr.getActive() is pr.getDefaults():
# We're not even listening when the Defaults profile is selected.
return;

if event.hasId('play'):
# Launch the game with the active profile.
startGame(pr.getActive())
Expand Down
3 changes: 3 additions & 0 deletions snowberry/plugins/preferences.py
Expand Up @@ -32,6 +32,9 @@ def init():

# Listen for the About button.
#events.addCommandListener(handleCommand)

# Commands for the popup menu.
ui.addPopupMenuCommand(1, 'show-snowberry-settings')


def handleNotify(event):
Expand Down
10 changes: 10 additions & 0 deletions snowberry/plugins/tab3_settings.py
Expand Up @@ -125,6 +125,16 @@ def handleCommand(event):

# Switch to the correct tab.
addonArea.selectTab(event.addon)

elif event.hasId('show-snowberry-settings'):
# Change to the Defaults profile.
pr.setActive(pr.getDefaults())

# Switch to the Settings tab.
ui.selectTab(SETTINGS)

# Switch to the Snowberry category.
categoryArea.selectTab('general-options')


def handleNotify(event):
Expand Down
7 changes: 5 additions & 2 deletions snowberry/plugins/wizard.py
Expand Up @@ -32,15 +32,18 @@

def init():
# Create the Rerun button in the Preferences Command area.
area = ui.getArea(ui.Area.PREFCOMMAND)
area.createButton('run-setup-wizard')
#area = ui.getArea(ui.Area.PREFCOMMAND)
#area.createButton('run-setup-wizard')

# Register a listener for detecting the completion of Snowberry
# startup.
events.addNotifyListener(handleNotify)

# Listen for wizard commands.
events.addCommandListener(handleCommand)

# Commands for the popup menu.
ui.addPopupMenuCommand(1, 'run-setup-wizard')


def handleNotify(event):
Expand Down
74 changes: 74 additions & 0 deletions snowberry/ui.py
Expand Up @@ -62,6 +62,25 @@
uiAreas = {}
mainPanel = None

# Items for the popup menu. Three separate levels of priority.
popupMenuItems = [[], [], []]


def addPopupMenuCommand(level, identifier, label=None):
"""Insert a new popup menu item for the Menu button.
@param level Priority level (0, 1, 2).
@param identifier Identifier of the command.
@param label Label for the command. If not specified, the same
as the identifier.
"""
global popupMenuItems

if(label == None):
popupMenuItems[level].append(identifier)
else:
popupMenuItems[level].append((identifier, label))


def getArea(id):
"""Returns the UI area with the specified ID.
Expand Down Expand Up @@ -1342,6 +1361,9 @@ def __init__(self, parent):
area.setExpanding(False)
area.setWeight(0)
_newArea(area)

# Create the Menu button in the Preferences Command area.
self.menuButton = area.createButton('popup-menu')

eSizer.Add(prefCommandPanel, 0, wx.EXPAND)
eSizer.Add(commandPanel, 1, wx.EXPAND)
Expand Down Expand Up @@ -1395,7 +1417,10 @@ def __init__(self, title):
@param title Title for the main window.
"""
# Commands for the popup menu.
self.menuCommandMap = {}

# FIXME: Layout is botched. Way too wide.
if host.isMac():
initialSize = (900, 550)
else:
Expand Down Expand Up @@ -1619,6 +1644,55 @@ def handleCommand(self, event):
"""
if event.hasId('quit'):
self.Close()

elif event.hasId('popup-menu'):
# TODO: This would be more logical as a part of MainPanel.
# Show the popup commands menu.
menu = wx.Menu()
self.menuCommandMap = {}

global popupMenuItems

menuItems = []

# Three levels of priority.
for prio in range(3):
if len(popupMenuItems[prio]) > 0 and len(menuItems) > 0:
# Separate the priority levels.
menuItems.append('-')
menuItems += popupMenuItems[prio]

#menuItems = ['play', '-', 'about', 'run-setup-wizard', '-', 'quit']

# Create the menu items.
for item in menuItems:
if type(item) == tuple:
itemId = item[0]
itemCommand = item[1]
else:
itemId = item
itemCommand = item

if itemId == '-':
# This is just a separator.
menu.AppendSeparator()
continue

# Generate a new ID for the item.
wxId = wx.NewId()
self.menuCommandMap[wxId] = itemCommand
menu.Append(wxId,
uniConv(language.translate('menu-' + itemId)))
wx.EVT_MENU(self, wxId, self.onPopupCommand)

# Display the menu. The callback gets called during this.
button = self.mainPanel.menuButton.getWxWidget()
button.PopupMenu(menu, (0, button.GetSizeTuple()[1]))
menu.Destroy()

def onPopupCommand(self, ev):
"""Called when a selection is made in the popup menu."""
events.send(events.Command(self.menuCommandMap[ev.GetId()]))


class SnowberryApp (wx.App):
Expand Down
6 changes: 3 additions & 3 deletions snowberry/widgets.py
Expand Up @@ -274,9 +274,6 @@ def setPopupMenu(self, menuItems):
self.menuItems = menuItems

def onRightClick(self, ev):
# Let wxWidgets handle the event, too.
ev.Skip()

# Display the popup menu.
if self.menuItems and self.getWxWidget().IsEnabled():
menu = wx.Menu()
Expand Down Expand Up @@ -309,6 +306,9 @@ def onRightClick(self, ev):
# Display the menu. The callback gets called during this.
self.getWxWidget().PopupMenu(menu, ev.GetPosition())
menu.Destroy()

# Let wxWidgets handle the event, too.
ev.Skip()

def onPopupCommand(self, ev):
events.send(events.Command(self.commandMap[ev.GetId()]))
Expand Down

0 comments on commit 79e836f

Please sign in to comment.