def writeSelected(self): """ writeSelected() -> write the current selections to the app config """ config = util.appConfig(util.groups.summary) config.writeEntry('Selected', self.summaries.keys()) config.sync()
def __init__(self, parent, ticker): fmtflt, zeroflt = '%.2f', 0.0 args = ( '%s' % ticker.current_data.get('position', 0), fmtflt % ticker.current_data.get('market_value', zeroflt), fmtflt % ticker.current_data.get(base.PriceTypes.Ask, zeroflt), fmtflt % ticker.current_data.get(base.PriceTypes.Bid, zeroflt), fmtflt % ticker.current_data.get(base.PriceTypes.Last, zeroflt), ) args = ( self, parent, ticker.symbol, ) + args qt.QListViewItem.__init__(*args) pxm = util.loadIcon(ticker.symbol.lower()) self.setPixmap(0, pxm) self.ticker = ticker self.current = ticker.current_data self.previous = ticker.previous_data ## need to handle an updated config as this is static config = util.appConfig(util.groups.misc) self.useColor = config.readNumEntry(util.keys.colorTickers, util.defaults.colorTickers)
def font(self, style): """font(style) -> the qt font to display for the indicated style """ font = util.appConfig('Fonts').readFontEntry('code', qt.QFont('fixed')) if style in (5, 8, 9): # (Keyword, ClassName, FunctionMethodName,) font.setBold(True) return font
def showConfigureKeys(self): """ showConfigureKeys() -> show the shortcut keys dialog """ ret = kdeui.KKeyDialog.configure(self.actionCollection(), self) if ret == qt.QDialog.Accepted: actions = self.actionCollection() actions.writeShortcutSettings(util.groups.shortcuts, util.appConfig())
def setupInitial(self): """ setupInitial() -> setup the initial display """ config = util.appConfig(util.groups.summary) initkeys = [str(k) for k in config.readListEntry('Selected', ',')] initkeys = initkeys or defaultKeys for key in initkeys: self.addSummary(key)
def defaultSummaries(self): """ defaultSummaries() -> clear and then create the default summary lcds """ self.clearSummaries() config = util.appConfig() config.deleteGroup(util.groups.summary, True) for key in defaultKeys: self.addSummary(key) self.showSummaries() self.writeSelected()
def queryClose(self): """ queryClose() -> prompts user for close confirmation when connected """ okay = True try: connected = self.session.account.connection.reader.active except (AttributeError, KeyError): pass else: if connected: msg = i18n("Broker connection is active, quit anyway?") title = i18n("Confirm Quit") dlg = kdeui.KMessageBox okay = dlg.warningYesNo(self, msg, title) == dlg.Yes if okay: config = util.appConfig() self.saveMainWindowSettings(config) config = util.appConfig(util.groups.main) self.saveWindowSize(config) return okay
def queryClose(self): """ queryClose() -> prompts user for close confirmation when connected """ okay = True try: connected = self.session.account.connection.reader.active except (AttributeError, KeyError): pass else: if connected: msg = i18n('Broker connection is active, quit anyway?') title = i18n('Confirm Quit') dlg = kdeui.KMessageBox okay = (dlg.warningYesNo(self, msg, title) == dlg.Yes) if okay: config = util.appConfig() self.saveMainWindowSettings(config) config = util.appConfig(util.groups.main) self.saveWindowSize(config) return okay
def writeLcd(self, key, widget): """ writeLcd(key, widget) -> write lcd settings to the config """ style = widget.segmentStyle() forecolor = widget.paletteForegroundColor() backcolor = widget.paletteBackgroundColor() config = util.appConfig(util.groups.summary) config.writeEntry('%s__style' % (key, ), style) config.writeEntry('%s__fore' % (key, ), forecolor) config.writeEntry('%s__back' % (key, ), backcolor) config.sync()
def slotApply(self): """ slotApply() -> write the configuration """ for page in self.pages: config = util.appConfig(page.groupLabel) for items in self.getConfigWidgets(page): key = items[0] getter = items[3] config.writeEntry(key, getter()) config.sync() self.emit(util.sigConfigChanged, (config, )) self.enableButtonApply(False)
def setupFinal(self): """ setupFinal() -> various final setup operations """ config = util.appConfig(util.groups.main) self.restoreWindowSize(config) xmlfile = os.path.join(self.appDir, "profitdevice.rc") self.createGUI(xmlfile, 0) kargs = kdecore.KCmdLineArgs.parsedArgs() if kargs.isSet("session"): self.newAction.activate() if kargs.isSet("start-tws"): self.startTwsAction.activate() ## apply the previous dock config and then delete it to keep it small config = util.appConfig() self.readDockConfig(config, util.groups.docks) config.deleteGroup(util.groups.docks, True) config.sync() ## looks nice with the sparkling icons pxm = util.loadIcon("tab_breakoff", size=kdecore.KIcon.SizeLarge) mpx = util.loadIcon("tab_breakoff", size=kdecore.KIcon.SizeSmall) kdecore.KWin.setIcons(self.winId(), pxm, mpx) config = util.appConfig() self.applyMainWindowSettings(config) self.toolBar().applySettings(config, None) self.pythonShell.onGuiComplete() ## optional parameter used because the main widget isn't built yet link.connect(self.statusBar(), self) link.connect(self.summaryFrame, self)
def setupFinal(self): """ setupFinal() -> various final setup operations """ config = util.appConfig(util.groups.main) self.restoreWindowSize(config) xmlfile = os.path.join(self.appDir, 'profitdevice.rc') self.createGUI(xmlfile, 0) kargs = kdecore.KCmdLineArgs.parsedArgs() if kargs.isSet('session'): self.newAction.activate() if kargs.isSet('start-tws'): self.startTwsAction.activate() ## apply the previous dock config and then delete it to keep it small config = util.appConfig() self.readDockConfig(config, util.groups.docks) config.deleteGroup(util.groups.docks, True) config.sync() ## looks nice with the sparkling icons pxm = util.loadIcon('tab_breakoff', size=kdecore.KIcon.SizeLarge) mpx = util.loadIcon('tab_breakoff', size=kdecore.KIcon.SizeSmall) kdecore.KWin.setIcons(self.winId(), pxm, mpx) config = util.appConfig() self.applyMainWindowSettings(config) self.toolBar().applySettings(config, None) self.pythonShell.onGuiComplete() ## optional parameter used because the main widget isn't built yet link.connect(self.statusBar(), self) link.connect(self.summaryFrame, self)
def setupActions(self): """ setupActions() -> create the action attributes for the widget """ config = util.appConfig() actions = self.actionCollection() stdaction = kdeui.KStdAction actions.readShortcutSettings(util.groups.shortcuts, config) self.newAction = stdaction.openNew(self.newSession, actions) self.newAction.setIconSet(util.loadIconSet('blockdevice')) self.newAction.setIcon('blockdevice') self.newAction.setText(i18n('New Session')) self.quitAction = stdaction.quit(self.close, actions) self.closeWindowAction = stdaction.close(self.closeDockWindow, actions) self.toggleMenubarAction = \ stdaction.showMenubar(self.showMenubar, actions) self.toggleToolbarAction = \ stdaction.showToolbar(self.showToolbar, actions) self.toggleStatusbarAction = \ stdaction.showStatusbar(self.showStatusbar, actions) self.configureKeysAction = \ stdaction.keyBindings(self.showConfigureKeys, actions) self.configureToolbarAction = \ stdaction.configureToolbars(self.showConfigureToolbars, actions) self.configureAppAction = \ stdaction.preferences(self.showConfiguration, actions) self.webBrowserAction = util.buildAction('web_browser', 'Web Browser', 'konqueror', 'Ctrl+B', 'Show a web browser window', actions) self.startTwsAction = util.buildAction('start_tws', 'Start TWS', 'exec', 'Ctrl+T', 'Start the TWS application', actions) self.connectTwsAction = util.buildAction('connect_tws', 'Connect to TWS', 'network', 'Ctrl+G', 'Connect to the TWS application', actions) sigAct = util.sigActivated self.connect(self.startTwsAction, sigAct, self.startTws) self.connect(self.connectTwsAction, sigAct, self.connectTws) self.connect(self.webBrowserAction, sigAct, util.invokeBrowser)
def readLcd(self, key, widget): """ readLcd(key, widget) -> configure an lcd """ config = util.appConfig(util.groups.summary) style = qt.QLCDNumber.Flat forecolor = qt.QColor(0, 255, 128) backcolor = qt.QColor(0, 0, 0) style = config.readNumEntry('%s__style' % (key, ), style) forecolor = config.readColorEntry('%s__fore' % (key, ), forecolor) backcolor = config.readColorEntry('%s__back' % (key, ), backcolor) widget.setFrameStyle(qt.QFrame.StyledPanel | qt.QFrame.Sunken) widget.setSegmentStyle(style) widget.setPaletteForegroundColor(forecolor) widget.setPaletteBackgroundColor(backcolor)
def __init__(self, parent=None): KDialogBase.__init__(self, KDialogBase.IconList, i18n(self.title), self.buttonsMask, KDialogBase.Ok, parent, self.title, False, True) self.pages = pages = [] self.configWidgets = {} medium = kdecore.KIcon.SizeMedium for label, title, icon in self.pageDefs: builder = getattr(self, 'build%sPage' % (label, )) config = util.appConfig(label) icon = util.loadIcon(icon, size=medium) frame = self.addPage(i18n(label), i18n(title), icon) frame.groupLabel = label builder(config, frame) pages.append(frame) self.enableButton(KDialogBase.Help, False) self.enableButton(KDialogBase.Apply, False)
def startGuiHelper(self): """ startGuiHelper() -> start the gui keystroke helper script """ config = util.appConfig(util.groups.broker) script = config.readPathEntry(util.keys.keyScript, "") if not str(script): return helper = qt.QProcess() for arg in str(script).split(): helper.addArgument(arg) code = helper.start() if code: label = "Keystroke Helper" dock, outputframe = self.buildDock(label, "openterm", util.OutputFrame) dock.manualDock(self.outputDock, dockCenter, 20) outputframe.connectProcess(helper) dock.dockManager().makeWidgetDockVisible(outputframe)
def startGuiHelper(self): """ startGuiHelper() -> start the gui keystroke helper script """ config = util.appConfig(util.groups.broker) script = config.readPathEntry(util.keys.keyScript, '') if not str(script): return helper = qt.QProcess() for arg in str(script).split(): helper.addArgument(arg) code = helper.start() if code: label = 'Keystroke Helper' dock, outputframe = \ self.buildDock(label, 'openterm', util.OutputFrame) dock.manualDock(self.outputDock, dockCenter, 20) outputframe.connectProcess(helper) dock.dockManager().makeWidgetDockVisible(outputframe)
def setupActions(self): """ setupActions() -> create the action attributes for the widget """ config = util.appConfig() actions = self.actionCollection() stdaction = kdeui.KStdAction actions.readShortcutSettings(util.groups.shortcuts, config) self.newAction = stdaction.openNew(self.newSession, actions) self.newAction.setIconSet(util.loadIconSet("blockdevice")) self.newAction.setIcon("blockdevice") self.newAction.setText(i18n("New Session")) self.quitAction = stdaction.quit(self.close, actions) self.closeWindowAction = stdaction.close(self.closeDockWindow, actions) self.toggleMenubarAction = stdaction.showMenubar(self.showMenubar, actions) self.toggleToolbarAction = stdaction.showToolbar(self.showToolbar, actions) self.toggleStatusbarAction = stdaction.showStatusbar(self.showStatusbar, actions) self.configureKeysAction = stdaction.keyBindings(self.showConfigureKeys, actions) self.configureToolbarAction = stdaction.configureToolbars(self.showConfigureToolbars, actions) self.configureAppAction = stdaction.preferences(self.showConfiguration, actions) self.webBrowserAction = util.buildAction( "web_browser", "Web Browser", "konqueror", "Ctrl+B", "Show a web browser window", actions ) self.startTwsAction = util.buildAction( "start_tws", "Start TWS", "exec", "Ctrl+T", "Start the TWS application", actions ) self.connectTwsAction = util.buildAction( "connect_tws", "Connect to TWS", "network", "Ctrl+G", "Connect to the TWS application", actions ) sigAct = util.sigActivated self.connect(self.startTwsAction, sigAct, self.startTws) self.connect(self.connectTwsAction, sigAct, self.connectTws) self.connect(self.webBrowserAction, sigAct, util.invokeBrowser)
def connectTws(self): """ connectTws() -> handles request to connect to tws If the broker is connected, this method requests the external data feed. """ config = util.appConfig(util.groups.broker) dsn = config.readEntry(util.keys.brokerDsn, util.defaults.brokerDsn) if not str(dsn): msg = 'Connection string not set.' title = 'Did Not Connect' kdeui.KMessageBox.sorry(self, msg, title) return host, port = str(dsn).split(':') broker = self.session.broker try: connected = broker.connection.reader.active except (AttributeError, ): pass else: if connected: msg = 'Broker connection is active, connect anyway?' title = 'Confirm Connect' dlg = kdeui.KMessageBox cancel = (dlg.warningYesNo(self, msg, title) == dlg.No) if cancel: return try: ## connect the lib object and request data feeds broker.connect((host, int(port))) broker.request_external() self.emit(util.sigConnectedTws, ()) except (Exception, ), ex: self.emit(util.sigConnectedTwsError, (ex, ))
def __init__(self, parent, ticker): fmtflt, zeroflt = "%.2f", 0.0 args = ( "%s" % ticker.current_data.get("position", 0), fmtflt % ticker.current_data.get("market_value", zeroflt), fmtflt % ticker.current_data.get(base.PriceTypes.Ask, zeroflt), fmtflt % ticker.current_data.get(base.PriceTypes.Bid, zeroflt), fmtflt % ticker.current_data.get(base.PriceTypes.Last, zeroflt), ) args = (self, parent, ticker.symbol) + args qt.QListViewItem.__init__(*args) pxm = util.loadIcon(ticker.symbol.lower()) self.setPixmap(0, pxm) self.ticker = ticker self.current = ticker.current_data self.previous = ticker.previous_data ## need to handle an updated config as this is static config = util.appConfig(util.groups.misc) self.useColor = config.readNumEntry(util.keys.colorTickers, util.defaults.colorTickers)
def connectTws(self): """ connectTws() -> handles request to connect to tws If the broker is connected, this method requests the external data feed. """ config = util.appConfig(util.groups.broker) dsn = config.readEntry(util.keys.brokerDsn, util.defaults.brokerDsn) if not str(dsn): msg = "Connection string not set." title = "Did Not Connect" kdeui.KMessageBox.sorry(self, msg, title) return host, port = str(dsn).split(":") broker = self.session.broker try: connected = broker.connection.reader.active except (AttributeError,): pass else: if connected: msg = "Broker connection is active, connect anyway?" title = "Confirm Connect" dlg = kdeui.KMessageBox cancel = dlg.warningYesNo(self, msg, title) == dlg.No if cancel: return try: ## connect the lib object and request data feeds broker.connect((host, int(port))) broker.request_external() self.emit(util.sigConnectedTws, ()) except (Exception,), ex: self.emit(util.sigConnectedTwsError, (ex,))
def newSession(self): """ newSession() -> slot for new session construction This is where the new session is actually created. A separate signal is then emitted from this slot. """ params = {} params['connection_builder'] = link.QIbSocketReader.build config = util.appConfig(util.groups.session) for (bkey, ckey) in configdialog.sessionBuilderKeys: value = '%s' % config.readEntry(ckey, '') if value: params[bkey] = value try: sess = session.Session(**params) except (Exception, ), ex: import traceback traceback.print_exc() print >> sys.__stdout__, ex util.displayException(self, 'Problem building session object', ex) sess = {}
def newSession(self): """ newSession() -> slot for new session construction This is where the new session is actually created. A separate signal is then emitted from this slot. """ params = {} params["connection_builder"] = link.QIbSocketReader.build config = util.appConfig(util.groups.session) for (bkey, ckey) in configdialog.sessionBuilderKeys: value = "%s" % config.readEntry(ckey, "") if value: params[bkey] = value try: sess = session.Session(**params) except (Exception,), ex: import traceback traceback.print_exc() print >>sys.__stdout__, ex util.displayException(self, "Problem building session object", ex) sess = {}
def startTws(self): """ startTws() -> handles TWS start request """ config = util.appConfig(util.groups.broker) script = config.readPathEntry(util.keys.brokerScript, '') if not str(script): msg = 'Broker application start command not set.' title = 'Application Not Started' kdeui.KMessageBox.sorry(self, msg, title) return tws = qt.QProcess() for arg in str(script).split(): tws.addArgument(arg) code = tws.start() if code: self.startGuiHelper() dock, outputframe = \ self.buildDock('TWS Output', 'openterm', util.OutputFrame) #, parent=None, transient=True) dock.manualDock(self.outputDock, dockCenter, 20) dock.dockManager().makeWidgetDockVisible(outputframe) outputframe.connectProcess(tws) #print self.shellDock, #self.anyOtherDock = dock #print self.getMainDockWidget(), dock #dock.manualDock(self.getMainDockWidget(), dockBottom, 50) # , 100, qt.QPoint(0, 0), False, -1) #dock.dockManager().makeWidgetDockVisible(outputframe) #self.connect(dock, util.sigDockClosed, self.closeClicked) #self.shellDock.manualDock(dock, dockCenter) #print dock.manualDock #outputframe.connectProcess(tws) #dock.dockManager().makeWidgetDockVisible(outputframe) if 0: # this is how node viewers pull it off, but !!! it doesn't work here parent = self.parent() framector = base.PartialCall(NodeFrame, node=node, label=label) dock, obj = parent.buildDock(label, iconname, framector, transient=True) dock.manualDock(parent.getMainDockWidget(), center, 20) dock.dockManager().makeWidgetDockVisible(obj) self.connect(dock, util.sigDockClosed, self.closeClicked) defaults = util.defaults keys = util.keys readnum = util.appConfig(util.groups.broker).readNumEntry connectdelay = readnum(keys.connectDelay, defaults.connectDelay) embeddelay = readnum(keys.embedDelay, defaults.embedDelay) if connectdelay: qt.QTimer.singleShot(connectdelay*1000, self.connectTws) if embeddelay: qt.QTimer.singleShot(embeddelay*1000, self.embedTws) self.connect(tws, qt.SIGNAL('processExited()'), self.finishedTws) sig, args = (util.sigStartTws, (tws, )) else: sig, args = (util.sigStartTwsFail, (code, )) self.emit(sig, args)
def startTws(self): """ startTws() -> handles TWS start request """ config = util.appConfig(util.groups.broker) script = config.readPathEntry(util.keys.brokerScript, "") if not str(script): msg = "Broker application start command not set." title = "Application Not Started" kdeui.KMessageBox.sorry(self, msg, title) return tws = qt.QProcess() for arg in str(script).split(): tws.addArgument(arg) code = tws.start() if code: self.startGuiHelper() dock, outputframe = self.buildDock( "TWS Output", "openterm", util.OutputFrame ) # , parent=None, transient=True) dock.manualDock(self.outputDock, dockCenter, 20) dock.dockManager().makeWidgetDockVisible(outputframe) outputframe.connectProcess(tws) # print self.shellDock, # self.anyOtherDock = dock # print self.getMainDockWidget(), dock # dock.manualDock(self.getMainDockWidget(), dockBottom, 50) # , 100, qt.QPoint(0, 0), False, -1) # dock.dockManager().makeWidgetDockVisible(outputframe) # self.connect(dock, util.sigDockClosed, self.closeClicked) # self.shellDock.manualDock(dock, dockCenter) # print dock.manualDock # outputframe.connectProcess(tws) # dock.dockManager().makeWidgetDockVisible(outputframe) if 0: # this is how node viewers pull it off, but !!! it doesn't work here parent = self.parent() framector = base.PartialCall(NodeFrame, node=node, label=label) dock, obj = parent.buildDock(label, iconname, framector, transient=True) dock.manualDock(parent.getMainDockWidget(), center, 20) dock.dockManager().makeWidgetDockVisible(obj) self.connect(dock, util.sigDockClosed, self.closeClicked) defaults = util.defaults keys = util.keys readnum = util.appConfig(util.groups.broker).readNumEntry connectdelay = readnum(keys.connectDelay, defaults.connectDelay) embeddelay = readnum(keys.embedDelay, defaults.embedDelay) if connectdelay: qt.QTimer.singleShot(connectdelay * 1000, self.connectTws) if embeddelay: qt.QTimer.singleShot(embeddelay * 1000, self.embedTws) self.connect(tws, qt.SIGNAL("processExited()"), self.finishedTws) sig, args = (util.sigStartTws, (tws,)) else: sig, args = (util.sigStartTwsFail, (code,)) self.emit(sig, args)