Last active
November 29, 2016 19:16
-
-
Save virantha/5ace1fa44a2e1156e8542523596124f1 to your computer and use it in GitHub Desktop.
Simple moneydance gui extension in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from com.infinitekind.moneydance.model import * | |
import os | |
from javax.swing import JButton, JFrame, JScrollPane, JTextArea, BoxLayout, BorderFactory | |
class SimplePopupExtension(object): | |
def initialize(self, extension_context, extension_object): | |
self.moneydanceContext = extension_context | |
self.moneydanceExtensionObject = extension_object | |
# here we register ourselves with a menu item to invoke a feature | |
# (ignore the button and icon mentions in the docs) | |
self.moneydanceContext.registerFeature(extension_object, "popup", None, "Test popup") | |
# invoke(eventstring) is called when we receive a callback for the feature that | |
# we registered in the initialize method | |
def invoke(self, eventString=""): | |
self.moneydanceContext.setStatus("Python extension received command: %s" % (eventString)) | |
if eventString=='popup': | |
self._show_popup() | |
def __str__(self): | |
return "SimplePopup" | |
# Our actual user code | |
def _show_popup(self): | |
self._initUI() | |
book = moneydance.getCurrentAccountBook() | |
account_names = [] | |
for acct in AccountUtil.getAccountIterator(book): | |
account_names.append(acct.getFullAccountName()) | |
self.text_area.text = '\n'.join(account_names) | |
def _initUI(self): | |
frame = JFrame('Simple popup', defaultCloseOperation = JFrame.DISPOSE_ON_CLOSE, size=(300,300)) | |
frame.setLayout(BoxLayout(frame.contentPane, BoxLayout.PAGE_AXIS)) | |
# Call-back to close popup | |
def closeDialog(event): | |
frame.visible = False | |
frame.dispose() | |
# Instantiate components | |
self.text_area = JTextArea() | |
msgScroller = JScrollPane() | |
msgScroller.setBorder(BorderFactory.createTitledBorder("Accounts")) | |
msgScroller.setViewportView(self.text_area) | |
self.close_button = JButton('Close', actionPerformed = closeDialog) | |
# Add components to frame | |
frame.add(msgScroller) | |
frame.add(self.close_button) | |
frame.visible = True | |
# Tell moneydance this is an extension | |
moneydance_extension = SimplePopupExtension() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment