1
#!/usr/bin/env python2.5
2
# -*- coding: utf-8 -*-
7
from PyQt4.QtCore import (
10
from PyQt4.QtGui import (
11
QApplication, qApp, QSplashScreen,
12
QMainWindow, QDockWidget, QMenu, QToolBar, QAction,
19
from codeaide.interface import implements
29
def call_on_idle(func):
30
QTimer.singleShot(0, func)
36
class ToolbarManager(object):
39
def __init__(self, mainwin):
40
self.mainwin = mainwin
44
def get_toolbar(self, title):
45
tb = self.toolbars.get(title)
49
def add_toolbar(self, title):
50
tb = QToolBar(title, self.mainwin)
51
group = self.mainwin.addToolBar(tb)
52
self.toolbars[title] = tb
56
def get_or_create_toolbar(self, title):
57
tb = self.get_toolbar(title)
59
tb = self.add_toolbar(title)
63
def add_toolbar_action(self, tb_title, action):
64
tb = self.get_or_create_toolbar(tb_title)
69
class MenuManager(object):
72
def __init__(self, menubar):
73
self.menubar = menubar
77
def get_menu(self, title):
78
menu = self.menus.get(title)
82
def add_menu(self, title):
83
menu = QMenu(title, self.menubar)
84
self.menubar.addMenu(menu)
85
self.menus[title] = menu
89
def get_or_create_menu(self, title):
90
menu = self.get_menu(title)
92
menu = self.add_menu(title)
96
def add_menu_action(self, menu_title, item_action):
97
menu = self.get_or_create_menu(menu_title)
98
menu.addAction(item_action)
104
class CommandBase(object):
113
def __init__(self, parent):
114
self.action = QAction(parent)
116
self.action.setText(self.title)
118
self.action.setIcon(QIcon(self.icon))
120
self.action.setShortcut(QKeySequence(self.shortcut))
122
parent.menu_manager.add_menu_action(self.menu, self.action)
123
self.action.connect(self.action, SIGNAL("triggered()"), self.execute)
125
parent.toolbar_manager.add_toolbar_action(self.toolbar, self.action)
130
raise NotImplementedError, self.execute
134
class CheckCommandBase(CommandBase):
138
def __init__(self, parent):
139
CommandBase.__init__(self, parent)
140
self.action.setCheckable(True)
141
self.action.setChecked(self.checked)
146
class DockBase(object):
149
area = Qt.BottomDockWidgetArea
151
toggle_shortcut = None
155
def __init__(self, parent):
157
call_on_idle(self._setup_ui)
161
self.dock = QDockWidget(self.parent)
162
self.dock.setWindowTitle(self.title)
163
self.widget = self.create_widget(self.dock)
164
self.dock.setWidget(self.widget)
165
self.parent.addDockWidget(self.area, self.dock)
168
action = self.dock.toggleViewAction()
170
action.setIcon(QIcon(self.icon))
171
if self.toggle_shortcut:
172
action.setShortcut(QKeySequence(self.toggle_shortcut))
173
self.parent.menu_manager.add_menu_action(self.toggle_menu, action)
176
def create_widget(self, parent):
177
raise NotImplementedError, self.create_widget