IS_MAEMO = True
-PLUGIN_SEARCH_PATHS = [
- os.path.join(os.path.dirname(__file__), "plugins/"),
-]
-
-
class Calculator(object):
def __init__(self, app):
def __init__(self):
self._messages = []
- icon = QtGui.QIcon.fromTheme("gtk-dialog-error")
- self._severityIcon = icon.pixmap(32, 32)
+ errorIcon = QtGui.QIcon.fromTheme("app_install_error")
+ if errorIcon.isNull():
+ errorIcon = QtGui.QIcon.fromTheme("gtk-dialog-error")
+ self._severityIcon = errorIcon.pixmap(32, 32)
self._severityLabel = QtGui.QLabel()
self._severityLabel.setPixmap(self._severityIcon)
self._message = QtGui.QLabel()
self._message.setText("Boo")
- icon = QtGui.QIcon.fromTheme("gtk-close")
- self._closeLabel = QtGui.QPushButton(icon, "")
+ closeIcon = QtGui.QIcon.fromTheme("general_close")
+ if closeIcon.isNull():
+ closeIcon = QtGui.QIcon.fromTheme("gtk-close")
+ self._closeLabel = QtGui.QPushButton(closeIcon, "")
self._closeLabel.clicked.connect(self._on_close)
self._controlLayout = QtGui.QHBoxLayout()
self._topLevelLayout = QtGui.QHBoxLayout()
self._topLevelLayout.addLayout(self._controlLayout)
+ self._widget = QtGui.QWidget()
+ self._widget.setLayout(self._topLevelLayout)
self._hide_message()
@property
def toplevel(self):
- return self._topLevelLayout
+ return self._widget
def push_message(self, message):
self._messages.append(message)
def _show_message(self, message):
self._message.setText(message)
- self._severityLabel.show()
- self._message.show()
- self._closeLabel.show()
+ self._widget.show()
def _hide_message(self):
self._message.setText("")
- self._severityLabel.hide()
- self._message.hide()
- self._closeLabel.hide()
+ self._widget.hide()
class QValueEntry(object):
class MainWindow(object):
_plugin_search_paths = [
- "/opt/epi/lib/plugins/",
- "/usr/lib/ejpi/plugins/",
os.path.join(os.path.dirname(__file__), "plugins/"),
]
self._userEntryLayout.addWidget(self._userEntry.toplevel)
self._controlLayout = QtGui.QVBoxLayout()
- self._controlLayout.addLayout(self._errorDisplay.toplevel)
+ self._controlLayout.addWidget(self._errorDisplay.toplevel)
self._controlLayout.addWidget(self._historyView.toplevel)
self._controlLayout.addLayout(self._userEntryLayout)
- self._inputLayout = QtGui.QVBoxLayout()
+ self._keyboardTabs = QtGui.QTabWidget()
- self._layout = QtGui.QHBoxLayout()
+ if maeqt.screen_orientation() == QtCore.Qt.Vertical:
+ defaultLayoutOrientation = QtGui.QBoxLayout.TopToBottom
+ self._keyboardTabs.setTabPosition(QtGui.QTabWidget.East)
+ else:
+ defaultLayoutOrientation = QtGui.QBoxLayout.LeftToRight
+ self._keyboardTabs.setTabPosition(QtGui.QTabWidget.North)
+ self._layout = QtGui.QBoxLayout(defaultLayoutOrientation)
self._layout.addLayout(self._controlLayout)
- self._layout.addLayout(self._inputLayout)
+ self._layout.addWidget(self._keyboardTabs)
centralWidget = QtGui.QWidget()
centralWidget.setLayout(self._layout)
self._window = QtGui.QMainWindow(parent)
self._window.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
- maeqt.set_autorient(self._window, True)
+ #maeqt.set_autorient(self._window, True)
maeqt.set_stackable(self._window, True)
self._window.setWindowTitle("%s" % constants.__pretty_app_name__)
self._window.setCentralWidget(centralWidget)
- self._window.destroyed.connect(self._on_close_window)
+ self._window.destroyed.connect(self._on_window_closed)
+
+ self._copyItemAction = QtGui.QAction(None)
+ self._copyItemAction.setText("Copy")
+ self._copyItemAction.setShortcut(QtGui.QKeySequence("CTRL+c"))
+ self._copyItemAction.triggered.connect(self._on_copy)
+
+ self._pasteItemAction = QtGui.QAction(None)
+ self._pasteItemAction.setText("Paste")
+ self._pasteItemAction.setShortcut(QtGui.QKeySequence("CTRL+v"))
+ self._pasteItemAction.triggered.connect(self._on_paste)
self._closeWindowAction = QtGui.QAction(None)
self._closeWindowAction.setText("Close")
self._closeWindowAction.setShortcut(QtGui.QKeySequence("CTRL+w"))
self._closeWindowAction.triggered.connect(self._on_close_window)
- if IS_MAEMO:
- #fileMenu = self._window.menuBar().addMenu("&File")
-
- #viewMenu = self._window.menuBar().addMenu("&View")
-
- self._window.addAction(self._closeWindowAction)
- self._window.addAction(self._app.quitAction)
- self._window.addAction(self._app.fullscreenAction)
- else:
- fileMenu = self._window.menuBar().addMenu("&Units")
- fileMenu.addAction(self._closeWindowAction)
- fileMenu.addAction(self._app.quitAction)
-
- viewMenu = self._window.menuBar().addMenu("&View")
- viewMenu.addAction(self._app.fullscreenAction)
+ self._window.addAction(self._copyItemAction)
+ self._window.addAction(self._pasteItemAction)
+ self._window.addAction(self._closeWindowAction)
+ self._window.addAction(self._app.quitAction)
+ self._window.addAction(self._app.fullscreenAction)
self._window.addAction(self._app.logAction)
self._constantPlugins = plugin_utils.ConstantPluginManager()
self._constantPlugins.add_path(*self._plugin_search_paths)
- for pluginName in ["Builtin", "Trigonometry", "Computer", "Alphabet"]:
+ for pluginName in ["Builtins", "Trigonometry", "Computer", "Alphabet"]:
try:
pluginId = self._constantPlugins.lookup_plugin(pluginName)
self._constantPlugins.enable_plugin(pluginId)
self._operatorPlugins = plugin_utils.OperatorPluginManager()
self._operatorPlugins.add_path(*self._plugin_search_paths)
- for pluginName in ["Builtin", "Trigonometry", "Computer", "Alphabet"]:
+ for pluginName in ["Builtins", "Trigonometry", "Computer", "Alphabet"]:
try:
pluginId = self._operatorPlugins.lookup_plugin(pluginName)
self._operatorPlugins.enable_plugin(pluginId)
self._handler.register_command_handler("clear", self._on_entry_clear)
# Main keyboard
- builtinKeyboardId = self._keyboardPlugins.lookup_plugin("Builtin")
- self._keyboardPlugins.enable_plugin(builtinKeyboardId)
- self._builtinPlugin = self._keyboardPlugins.keyboards["Builtin"].construct_keyboard()
- self._builtinKeyboard = self._builtinPlugin.setup(self._history, self._handler)
-
entryKeyboardId = self._keyboardPlugins.lookup_plugin("Entry")
self._keyboardPlugins.enable_plugin(entryKeyboardId)
entryPlugin = self._keyboardPlugins.keyboards["Entry"].construct_keyboard()
entryKeyboard = entryPlugin.setup(self._history, self._handler)
- self._userEntryLayout.addLayout(entryKeyboard.toplevel)
+ self._userEntryLayout.addWidget(entryKeyboard.toplevel)
# Plugins
+ self.enable_plugin(self._keyboardPlugins.lookup_plugin("Builtins"))
self.enable_plugin(self._keyboardPlugins.lookup_plugin("Trigonometry"))
self.enable_plugin(self._keyboardPlugins.lookup_plugin("Computer"))
self.enable_plugin(self._keyboardPlugins.lookup_plugin("Alphabet"))
- self._inputLayout.addLayout(self._builtinKeyboard.toplevel)
- for keyboardData in self._activeKeyboards:
- keyboardData["pluginKeyboard"].hide()
- self._set_plugin_kb(0)
self.set_fullscreen(self._app.fullscreenAction.isChecked())
+
self._window.show()
@property
pluginData = self._keyboardPlugins.plugin_info(pluginId)
pluginName = pluginData[0]
plugin = self._keyboardPlugins.keyboards[pluginName].construct_keyboard()
+ relIcon = self._keyboardPlugins.keyboards[pluginName].icon
+ for iconPath in self._keyboardPlugins.keyboards[pluginName].iconPaths:
+ absIconPath = os.path.join(iconPath, relIcon)
+ if os.path.exists(absIconPath):
+ icon = QtGui.QIcon(absIconPath)
+ break
+ else:
+ icon = None
pluginKeyboard = plugin.setup(self._history, self._handler)
self._activeKeyboards.append({
"plugin": plugin,
"pluginKeyboard": pluginKeyboard,
})
- self._inputLayout.addLayout(pluginKeyboard.toplevel)
-
- def _set_plugin_kb(self, pluginIndex):
- plugin = self._activeKeyboards[pluginIndex]
-
- for keyboardData in self._activeKeyboards:
- if plugin["pluginName"] != keyboardData["pluginName"]:
- keyboardData["pluginKeyboard"].hide()
-
- # @todo self._pluginButton.set_label(plugin["pluginName"])
- pluginKeyboard = plugin["pluginKeyboard"]
- pluginKeyboard.show()
+ if icon is None:
+ self._keyboardTabs.addTab(pluginKeyboard.toplevel, pluginName)
+ else:
+ self._keyboardTabs.addTab(pluginKeyboard.toplevel, icon, "")
def _load_history(self):
serialized = []
f.write("%s\n" % line)
@misc_utils.log_exception(_moduleLogger)
+ def _on_copy(self, *args):
+ eqNode = self._historyView.peek()
+ resultNode = eqNode.simplify()
+ self._app._clipboard.setText(str(resultNode))
+
+ @misc_utils.log_exception(_moduleLogger)
+ def _on_paste(self, *args):
+ result = str(self._app._clipboard.text())
+ self._userEntry.append(result)
+
+ @misc_utils.log_exception(_moduleLogger)
def _on_entry_direct(self, keys, modifiers):
if "shift" in modifiers:
keys = keys.upper()
@misc_utils.log_exception(_moduleLogger)
def _on_unpush(self, *args):
- self._historyStore.unpush()
+ self._historyView.unpush()
@misc_utils.log_exception(_moduleLogger)
def _on_entry_backspace(self, *args):
self._history.clear()
@misc_utils.log_exception(_moduleLogger)
- def _on_close_window(self, checked = True):
+ def _on_window_closed(self, checked = True):
self._save_history()
+ @misc_utils.log_exception(_moduleLogger)
+ def _on_close_window(self, checked = True):
+ self.close()
+
def run():
app = QtGui.QApplication([])