Mercurial > fife-parpg
changeset 359:ad5818097cd6
* Some cleanups for Editor class to match new coding standards
* Minor cleanups in imports
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 26 Sep 2009 10:38:24 +0000 |
parents | 8f64a9d1e7ab |
children | 11896fe26c1d |
files | clients/editor/__init__.py clients/editor/plugins/HistoryManager.py clients/editor/plugins/LayerTool.py clients/editor/plugins/LightEdit.py clients/editor/plugins/ObjectEdit.py clients/editor/plugins/ObjectSelector.py clients/editor/scripts/editor.py clients/editor/scripts/events/events.py clients/editor/scripts/gui/filemanager.py clients/editor/scripts/gui/mapeditor.py clients/editor/scripts/plugin.py clients/editor/scripts/undomanager.py |
diffstat | 12 files changed, 140 insertions(+), 135 deletions(-) [+] |
line wrap: on
line diff
--- a/clients/editor/__init__.py Sat Sep 26 09:51:11 2009 +0000 +++ b/clients/editor/__init__.py Sat Sep 26 10:38:24 2009 +0000 @@ -21,4 +21,3 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # #################################################################### -__all__ = [ 'plugins', 'scripts' ]
--- a/clients/editor/plugins/HistoryManager.py Sat Sep 26 09:51:11 2009 +0000 +++ b/clients/editor/plugins/HistoryManager.py Sat Sep 26 10:38:24 2009 +0000 @@ -49,33 +49,33 @@ self.editor = scripts.editor.getEditor() self.engine = self.editor.getEngine() - self._showAction = Action(u"History manager", checkable=True) - self._undoAction = Action(u"Undo", "gui/icons/undo.png") - self._redoAction = Action(u"Redo", "gui/icons/redo.png") - self._nextAction = Action(u"Next branch", "gui/icons/next_branch.png") - self._prevAction = Action(u"Previous branch", "gui/icons/previous_branch.png") + self._show_action = Action(u"History manager", checkable=True) + self._undo_action = Action(u"Undo", "gui/icons/undo.png") + self._redo_action = Action(u"Redo", "gui/icons/redo.png") + self._next_action = Action(u"Next branch", "gui/icons/next_branch.png") + self._prev_action = Action(u"Previous branch", "gui/icons/previous_branch.png") - self._showAction.helptext = u"Toggle HistoryManager" - self._undoAction.helptext = u"Undo action (CTRL+Z)" - self._redoAction.helptext = u"Redo action (CTRL+SHIFT+Z)" - self._nextAction.helptext = u"Next branch (CTRL+ALT+Z" - self._prevAction.helptext = u"Previous branch (CTRL+ALT+SHIFT+Z)" + self._show_action.helptext = u"Toggle HistoryManager" + self._undo_action.helptext = u"Undo action (CTRL+Z)" + self._redo_action.helptext = u"Redo action (CTRL+SHIFT+Z)" + self._next_action.helptext = u"Next branch (CTRL+ALT+Z" + self._prev_action.helptext = u"Previous branch (CTRL+ALT+SHIFT+Z)" - scripts.gui.action.activated.connect(self.toggle, sender=self._showAction) - scripts.gui.action.activated.connect(self._undo, sender=self._undoAction) - scripts.gui.action.activated.connect(self._redo, sender=self._redoAction) - scripts.gui.action.activated.connect(self._next, sender=self._nextAction) - scripts.gui.action.activated.connect(self._prev, sender=self._prevAction) + scripts.gui.action.activated.connect(self.toggle, sender=self._show_action) + scripts.gui.action.activated.connect(self._undo, sender=self._undo_action) + scripts.gui.action.activated.connect(self._redo, sender=self._redo_action) + scripts.gui.action.activated.connect(self._next, sender=self._next_action) + scripts.gui.action.activated.connect(self._prev, sender=self._prev_action) - self._undoGroup = ActionGroup(name=u"UndoGroup") - self._undoGroup.addAction(self._undoAction) - self._undoGroup.addAction(self._redoAction) - self._undoGroup.addAction(self._nextAction) - self._undoGroup.addAction(self._prevAction) + self._undo_group = ActionGroup(name=u"UndoGroup") + self._undo_group.addAction(self._undo_action) + self._undo_group.addAction(self._redo_action) + self._undo_group.addAction(self._next_action) + self._undo_group.addAction(self._prev_action) - self.editor._toolsMenu.addAction(self._showAction) - self.editor._editMenu.insertAction(self._undoGroup, 0) - self.editor._editMenu.insertSeparator(position=1) + self.editor._tools_menu.addAction(self._show_action) + self.editor._edit_menu.insertAction(self._undo_group, 0) + self.editor._edit_menu.insertSeparator(position=1) events.postMapShown.connect(self.update) undomanager.changed.connect(self.update) @@ -92,14 +92,14 @@ events.postMapShown.disconnect(self.update) undomanager.changed.disconnect(self.update) - scripts.gui.action.activated.connect(self.toggle, sender=self._showAction) - scripts.gui.action.activated.disconnect(self._undo, sender=self._undoAction) - scripts.gui.action.activated.disconnect(self._redo, sender=self._redoAction) - scripts.gui.action.activated.disconnect(self._next, sender=self._nextAction) - scripts.gui.action.activated.disconnect(self._prev, sender=self._prevAction) + scripts.gui.action.activated.connect(self.toggle, sender=self._show_action) + scripts.gui.action.activated.disconnect(self._undo, sender=self._undo_action) + scripts.gui.action.activated.disconnect(self._redo, sender=self._redo_action) + scripts.gui.action.activated.disconnect(self._next, sender=self._next_action) + scripts.gui.action.activated.disconnect(self._prev, sender=self._prev_action) - self.editor._toolsMenu.removeAction(self._showAction) - self.editor._toolsMenu.removeAction(self._undoGroup) + self.editor._tools_menu.removeAction(self._show_action) + self.editor._tools_menu.removeAction(self._undo_group) def isEnabled(self): @@ -297,12 +297,12 @@ def show(self): self.update() self.gui.show() - self._showAction.setChecked(True) + self._show_action.setChecked(True) def hide(self): self.gui.setDocked(False) self.gui.hide() - self._showAction.setChecked(False) + self._show_action.setChecked(False) def _undo(self): if self.undomanager:
--- a/clients/editor/plugins/LayerTool.py Sat Sep 26 09:51:11 2009 +0000 +++ b/clients/editor/plugins/LayerTool.py Sat Sep 26 10:38:24 2009 +0000 @@ -77,7 +77,7 @@ self._editor = scripts.editor.getEditor() self._action_show = Action(u"LayerTool", checkable=True) scripts.gui.action.activated.connect(self.toggle, sender=self._action_show) - self._editor._toolsMenu.addAction(self._action_show) + self._editor._tools_menu.addAction(self._action_show) self._createGui() @@ -94,7 +94,7 @@ events.postMapShown.disconnect(self.update) - self._editor._toolsMenu.removeAction(self._action_show) + self._editor._tools_menu.removeAction(self._action_show) def isEnabled(self): """ Returns True if plugin is enabled """
--- a/clients/editor/plugins/LightEdit.py Sat Sep 26 09:51:11 2009 +0000 +++ b/clients/editor/plugins/LightEdit.py Sat Sep 26 10:38:24 2009 +0000 @@ -93,7 +93,7 @@ self._showAction = Action(unicode(self.getName(),"utf-8"), checkable=True) scripts.gui.action.activated.connect(self.toggle_gui, sender=self._showAction) - self._editor._toolsMenu.addAction(self._showAction) + self._editor._tools_menu.addAction(self._showAction) events.postMapShown.connect(self.update_renderer) events.onMapChanged.connect(self.update_renderer) @@ -110,7 +110,7 @@ self.container.hide() self.removeAllChildren() - self._editor._toolsMenu.removeAction(self._showAction) + self._editor._tools_menu.removeAction(self._showAction) events.postMapShown.disconnect(self.update_renderer) events.onMapChanged.disconnect(self.update_renderer)
--- a/clients/editor/plugins/ObjectEdit.py Sat Sep 26 09:51:11 2009 +0000 +++ b/clients/editor/plugins/ObjectEdit.py Sat Sep 26 10:38:24 2009 +0000 @@ -127,7 +127,7 @@ self._showAction = Action(unicode(self.getName(),"utf-8"), checkable=True) scripts.gui.action.activated.connect(self.toggle_gui, sender=self._showAction) - self._editor._toolsMenu.addAction(self._showAction) + self._editor._tools_menu.addAction(self._showAction) events.onInstancesSelected.connect(self.input) @@ -145,7 +145,7 @@ events.onInstancesSelected.disconnect(self.input) - self._editor._toolsMenu.removeAction(self._showAction) + self._editor._tools_menu.removeAction(self._showAction) def isEnabled(self): """ plugin method """
--- a/clients/editor/plugins/ObjectSelector.py Sat Sep 26 09:51:11 2009 +0000 +++ b/clients/editor/plugins/ObjectSelector.py Sat Sep 26 10:38:24 2009 +0000 @@ -147,7 +147,7 @@ self._showAction = Action(u"Object selector", checkable=True) scripts.gui.action.activated.connect(self.toggle, sender=self._showAction) - self.editor._toolsMenu.addAction(self._showAction) + self.editor._tools_menu.addAction(self._showAction) events.postMapShown.connect(self.update_namespace) events.onObjectSelected.connect(self.setPreview) @@ -166,7 +166,7 @@ events.onObjectSelected.disconnect(self.setPreview) events.onObjectsImported.disconnect(self.update_namespace) - self.editor._toolsMenu.removeAction(self._showAction) + self.editor._tools_menu.removeAction(self._showAction) def isEnabled(self): return self._enabled;
--- a/clients/editor/scripts/editor.py Sat Sep 26 09:51:11 2009 +0000 +++ b/clients/editor/scripts/editor.py Sat Sep 26 10:38:24 2009 +0000 @@ -21,14 +21,26 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # #################################################################### -from basicapplication import ApplicationBase -import pychan +""" +Editor +====== + +This class serves as +""" + +import sys +import traceback + import fife import loaders import events import plugin -from mapview import MapView -from events import EventListener + +from basicapplication import ApplicationBase + +import pychan +from pychan.tools import callbackWithArguments as cbwa + from events import * from gui import ToolBar, action from gui.action import Action, ActionGroup @@ -37,9 +49,8 @@ from gui.mapeditor import MapEditor from gui.menubar import Menu, MenuBar from gui.error import ErrorDialog +from mapview import MapView from settings import Settings -from pychan.tools import callbackWithArguments as cbwa -import sys, traceback def getEditor(): """ Returns the Global editor instance """ @@ -56,28 +67,28 @@ self._filemanager = None - self.params = params + self._params = params self._eventlistener = None self._pluginmanager = None self._inited = False self._mapview = None - self._mapviewList = [] + self._mapviewlist = [] self._mapgroup = None self._mapbar = None self._maparea = None self._mapeditor = None - self._fileMenu = None - self._editMenu = None - self._viewMenu = None - self._toolsMenu = None - self._helpMenu = None + self._file_menu = None + self._edit_menu = None + self._view_menu = None + self._tools_menu = None + self._help_menu = None self._settings = None - self._helpDialog = None + self._help_dialog = None ApplicationBase.__init__(self, *args, **kwargs) MainWindow.__init__(self, *args, **kwargs) @@ -115,14 +126,14 @@ """ import fifelog - LogModules = self._settings.get("FIFE", "LogModules") + logModules = self._settings.get("FIFE", "LogModules") self.log = fifelog.LogManager(self.engine, self._settings.get("FIFE", "LogToPrompt"), self._settings.get("FIFE", "LogToFile")) - if LogModules: - self.log.setVisibleModules(*LogModules) + if logModules: + self.log.setVisibleModules(*logModules) def _initTools(self): """ Initializes tools """ - self._pluginmanager = plugin.PluginManager() + self._pluginmanager = plugin.PluginManager(self.getSettings()) self._filemanager = FileManager() self._toolbar.adaptLayout() @@ -172,72 +183,72 @@ exitAction.helptext = u"Exit program" action.activated.connect(self.quit, sender=exitAction) - self._fileMenu = Menu(name=u"File") - self._fileMenu.addAction(exitAction) + self._file_menu = Menu(name=u"File") + self._file_menu.addAction(exitAction) - self._editMenu = Menu(name=u"Edit") - self._viewMenu = Menu(name=u"View") - self._toolsMenu = Menu(name=u"Tools") - self._windowMenu = Menu(name=u"Window") - self._helpMenu = Menu(name=u"Help") + self._edit_menu = Menu(name=u"Edit") + self._view_menu = Menu(name=u"View") + self._tools_menu = Menu(name=u"Tools") + self._window_menu = Menu(name=u"Window") + self._help_menu = Menu(name=u"Help") - self._actionShowStatusbar = Action(u"Statusbar") - self._actionShowStatusbar.helptext = u"Toggle statusbar" - action.activated.connect(self.toggleStatusbar, sender=self._actionShowStatusbar) + self._action_show_statusbar = Action(u"Statusbar") + self._action_show_statusbar.helptext = u"Toggle statusbar" + action.activated.connect(self.toggleStatusbar, sender=self._action_show_statusbar) - self._actionShowToolbar = Action(u"Toolbar") - self._actionShowToolbar.helptext = u"Toggle toolbar" - action.activated.connect(self.toggleToolbar, sender=self._actionShowToolbar) + self._action_show_toolbar = Action(u"Toolbar") + self._action_show_toolbar.helptext = u"Toggle toolbar" + action.activated.connect(self.toggleToolbar, sender=self._action_show_toolbar) - self._actionShowToolbox = Action(u"Tool box") - self._actionShowToolbox.helptext = u"Toggle tool box" - action.activated.connect(self.toggleToolbox, sender=self._actionShowToolbox) + self._action_show_toolbox = Action(u"Tool box") + self._action_show_toolbox.helptext = u"Toggle tool box" + action.activated.connect(self.toggleToolbox, sender=self._action_show_toolbox) - self._viewMenu.addAction(self._actionShowStatusbar) - self._viewMenu.addAction(self._actionShowToolbar) - self._viewMenu.addAction(self._actionShowToolbox) - self._viewMenu.addSeparator() + self._view_menu.addAction(self._action_show_statusbar) + self._view_menu.addAction(self._action_show_toolbar) + self._view_menu.addAction(self._action_show_toolbox) + self._view_menu.addSeparator() - testAction1 = Action(u"Cycle buttonstyles", "gui/icons/cycle_styles.png") - testAction1.helptext = u"Cycles button styles. There are currently four button styles." - action.activated.connect(self._actionActivated, sender=testAction1) - self._viewMenu.addAction(testAction1) + test_action1 = Action(u"Cycle buttonstyles", "gui/icons/cycle_styles.png") + test_action1.helptext = u"Cycles button styles. There are currently four button styles." + action.activated.connect(self._actionActivated, sender=test_action1) + self._view_menu.addAction(test_action1) self._mapgroup = ActionGroup(exclusive=True, name="Mapgroup") self._mapbar.addAction(self._mapgroup) self._mapbar.addAction(ActionGroup(exclusive=True, name="Mapgroup2")) - self._windowMenu.addAction(self._mapgroup) + self._window_menu.addAction(self._mapgroup) - helpAction = Action(u"Help", "gui/icons/help.png") - helpAction.helptext = u"Displays a window with some simple instructions" - action.activated.connect(self._showHelpDialog, sender=helpAction) - self._helpMenu.addAction(helpAction) + help_action = Action(u"Help", "gui/icons/help.png") + help_action.helptext = u"Displays a window with some simple instructions" + action.activated.connect(self._showHelpDialog, sender=help_action) + self._help_menu.addAction(help_action) - self._menubar.addMenu(self._fileMenu) - self._menubar.addMenu(self._editMenu) - self._menubar.addMenu(self._viewMenu) - self._menubar.addMenu(self._toolsMenu) - self._menubar.addMenu(self._windowMenu) - self._menubar.addMenu(self._helpMenu) + self._menubar.addMenu(self._file_menu) + self._menubar.addMenu(self._edit_menu) + self._menubar.addMenu(self._view_menu) + self._menubar.addMenu(self._tools_menu) + self._menubar.addMenu(self._window_menu) + self._menubar.addMenu(self._help_menu) def _actionActivated(self, sender): self._toolbar.button_style += 1 def _showHelpDialog(self, sender): """ Shows the help dialog """ - if self._helpDialog is not None: - self._helpDialog.show() + if self._help_dialog is not None: + self._help_dialog.show() return - self._helpDialog = pychan.loadXML("gui/help.xml") - self._helpDialog.findChild(name="closeButton").capture(self._helpDialog.hide) + self._help_dialog = pychan.loadXML("gui/help.xml") + self._help_dialog.findChild(name="closeButton").capture(self._help_dialog.hide) f = open('lang/infotext.txt', 'r') - self._helpDialog.findChild(name="helpText").text = unicode(f.read()) + self._help_dialog.findChild(name="helpText").text = unicode(f.read()) f.close() - self._helpDialog.show() + self._help_dialog.show() def toggleStatusbar(self): """ Toggles status bar """ @@ -245,11 +256,11 @@ if statusbar.max_size[1] > 0: statusbar.min_size=(statusbar.min_size[0], 0) statusbar.max_size=(statusbar.max_size[0], 0) - self._actionShowStatusbar.setChecked(False) + self._action_show_statusbar.setChecked(False) else: statusbar.min_size=(statusbar.min_size[0], statusbar.min_size[0]) statusbar.max_size=(statusbar.max_size[0], statusbar.max_size[0]) - self._actionShowStatusbar.setChecked(True) + self._action_show_statusbar.setChecked(True) statusbar.adaptLayout() def toggleToolbar(self): @@ -258,14 +269,14 @@ if toolbar.isVisible(): toolbar.setDocked(False) toolbar.hide() - self._actionShowToolbar.setChecked(False) + self._action_show_toolbar.setChecked(False) else: tx = toolbar.x ty = toolbar.y toolbar.show() toolbar.x = tx toolbar.y = ty - self._actionShowToolbar.setChecked(True) + self._action_show_toolbar.setChecked(True) def toggleToolbox(self): """ Toggles tool box """ @@ -273,14 +284,14 @@ if toolbox.isVisible(): toolbox.setDocked(False) toolbox.hide() - self._actionShowToolbox.setChecked(False) + self._action_show_toolbox.setChecked(False) else: tx = toolbox.x ty = toolbox.y toolbox.show() toolbox.x = tx toolbox.y = ty - self._actionShowToolbox.setChecked(True) + self._action_show_toolbox.setChecked(True) toolbox.adaptLayout() def getToolbox(self): @@ -293,7 +304,7 @@ return self.engine def getMapViews(self): - return self._mapviewList + return self._mapviewlist def getActiveMapView(self): return self._mapview @@ -326,11 +337,11 @@ """ Creates a new map view """ mapview = MapView(map) - self._mapviewList.append(mapview) + self._mapviewlist.append(mapview) - mapAction = Action(unicode(map.getId())) - action.activated.connect(cbwa(self.showMapView, mapview), sender=mapAction, weak=False) - self._mapgroup.addAction(mapAction) + map_action = Action(unicode(map.getId())) + action.activated.connect(cbwa(self.showMapView, mapview), sender=map_action, weak=False) + self._mapgroup.addAction(map_action) self.showMapView(mapview) @@ -354,11 +365,11 @@ def saveAll(self): """ Saves all open maps """ - tmpView = self._mapview - for mapView in self._mapviewList: - self._mapview = mapView + tmpview = self._mapview + for mapview in self._mapviewlist: + self._mapview = mapview self._filemanager.save() - self._mapview = tmpView + self._mapview = tmpview def quit(self): """ Quits the editor. An onQuit signal is sent before the application closes """ @@ -379,34 +390,34 @@ def __sendMouseEvent(self, event, **kwargs): """ Function used to capture mouse events for EventListener """ - msEvent = fife.MouseEvent + ms_event = fife.MouseEvent type = event.getType() - if type == msEvent.MOVED: + if type == ms_event.MOVED: mouseMoved.send(sender=self._maparea, event=event) - elif type == msEvent.PRESSED: + elif type == ms_event.PRESSED: mousePressed.send(sender=self._maparea, event=event) - elif type == msEvent.RELEASED: + elif type == ms_event.RELEASED: mouseReleased.send(sender=self._maparea, event=event) - elif type == msEvent.WHEEL_MOVED_DOWN: + elif type == ms_event.WHEEL_MOVED_DOWN: mouseWheelMovedDown.send(sender=self._maparea, event=event) - elif type == msEvent.WHEEL_MOVED_UP: + elif type == ms_event.WHEEL_MOVED_UP: mouseWheelMovedUp.send(sender=self._maparea, event=event) - elif type == msEvent.CLICKED: + elif type == ms_event.CLICKED: mouseClicked.send(sender=self._maparea, event=event) - elif type == msEvent.ENTERED: + elif type == ms_event.ENTERED: mouseEntered.send(sender=self._maparea, event=event) - elif type == msEvent.EXITED: + elif type == ms_event.EXITED: mouseExited.send(sender=self._maparea, event=event) - elif type == msEvent.DRAGGED: + elif type == ms_event.DRAGGED: mouseDragged.send(sender=self._maparea, event=event) def __sendKeyEvent(self, event, **kwargs):
--- a/clients/editor/scripts/events/events.py Sat Sep 26 09:51:11 2009 +0000 +++ b/clients/editor/scripts/events/events.py Sat Sep 26 10:38:24 2009 +0000 @@ -20,8 +20,6 @@ # Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # #################################################################### -#from editor import getEditor # Needed to quit application - import fife, scripts from fife import IKeyListener, ICommandListener, IMouseListener, LayerChangeListener, MapChangeListener, ConsoleExecuter from signal import Signal
--- a/clients/editor/scripts/gui/filemanager.py Sat Sep 26 09:51:11 2009 +0000 +++ b/clients/editor/scripts/gui/filemanager.py Sat Sep 26 10:38:24 2009 +0000 @@ -94,8 +94,8 @@ self.editor.getToolBar().insertAction(fileGroup, 0) self.editor.getToolBar().insertSeparator(None, 1) - self.editor._fileMenu.insertAction(fileGroup, 0) - self.editor._fileMenu.insertSeparator(None, 1) + self.editor._file_menu.insertAction(fileGroup, 0) + self.editor._file_menu.insertSeparator(None, 1) def showLoadDialog(self): if self._filebrowser is None:
--- a/clients/editor/scripts/gui/mapeditor.py Sat Sep 26 09:51:11 2009 +0000 +++ b/clients/editor/scripts/gui/mapeditor.py Sat Sep 26 10:38:24 2009 +0000 @@ -194,7 +194,7 @@ self._toolbox.addAction(self._toolgroup) self._toolbox.adaptLayout() - self._editor._editMenu.addAction(self._toolgroup) + self._editor._edit_menu.addAction(self._toolgroup) def _initToolbarbuttons(self): rotateLeftAction = Action(text=u"Rotate counterclockwise", icon="gui/icons/rotate_countercw.png")
--- a/clients/editor/scripts/plugin.py Sat Sep 26 09:51:11 2009 +0000 +++ b/clients/editor/scripts/plugin.py Sat Sep 26 10:38:24 2009 +0000 @@ -22,7 +22,6 @@ # #################################################################### import os -import editor class PluginManager: """ Currently, pluginmanager iterates through the plugin directory @@ -33,8 +32,8 @@ If a plugin fails to load due to exceptions, they are caught and a line of the error is printed to console. """ - def __init__(self, *args, **kwargs): - self._settings = editor.getEditor().getSettings() + def __init__(self, settings, *args, **kwargs): + self._settings = settings self._pluginDir = "plugins" self._plugins = []
--- a/clients/editor/scripts/undomanager.py Sat Sep 26 09:51:11 2009 +0000 +++ b/clients/editor/scripts/undomanager.py Sat Sep 26 10:38:24 2009 +0000 @@ -22,8 +22,6 @@ # #################################################################### from events.signal import Signal -import collections -import pdb actionAdded = Signal(providing_args=["action"]) preUndo = Signal()