Example #1
0
    def __init__(self, action, myorca):
        self.action = action
        self.myorca = myorca
        self.config = self.myorca.config

        def cleanUp(*args):
            if hasattr(__main__, "_KSpreadOrca"):
                getattr(__main__, "_KSpreadOrca").finalized()

        self.action.connect("started(Kross::Action*)", cleanUp)
        self.action.connect("finalized(Kross::Action*)", cleanUp)

        self._view = KSpread.view()
        self._setSheet(KSpread.currentSheet())

        def selectionChanged():
            print "Selection changed"
            s = KSpread.currentSheet()
            if s:
                if s.sheetName() != self.sheetName:
                    self._setSheet(s)
                    if self.config.sheetNameOnSheetChanged:
                        self.speakSheetName()
                else:
                    if self.config.cellNameOnSelectionChanged:
                        self.speakCellName()
                    if self.config.cellValueOnSelectionChanged:
                        self.speakCellValue()

        self._view.connect("selectionChanged()", selectionChanged)
Example #2
0
    def __init__(self, scriptaction):
        self.scriptaction = scriptaction
        #self.currentpath = self.scriptaction.currentPath()

        #self.undostack = KSpread.undoStack()
        #self.undostack.connect("indexChanged(int)",self.indexChanged)

        #file = os.path(self.getLogDir(),"KSpread.log")

        self.forms = Kross.module("forms")
        self.dialog = self.forms.createDialog("Logger")
        self.dialog.setButtons("Ok|Cancel")
        self.dialog.setFaceType("Plain") #Auto Plain List Tree Tabbed

        savepage = self.dialog.addPage("Save","Save to Log File","document-save")
        self.savewidget = self.forms.createFileWidget(savepage, "kfiledialog:///kspreadlogger")
        self.savewidget.setMode("Saving")
        self.savewidget.setFilter("*.txt *.log|Log File\n*|All Files")

        if self.dialog.exec_loop():
            filename = self.savewidget.selectedFile()
            if os.path.isfile(filename):
                if self.forms.showMessageBox("WarningContinueCancel", "Overwrite file?", "The file \"%s\" does already exist. Overwrite the file?" % filename) != "Continue":
                    raise "Aborted."
            sheetname = KSpread.currentSheet().sheetName()
            cellrange = "A1:F50" #FIXME
            try:
                self.file = open(filename, "w")
                self.startLogging(sheetname, cellrange)
            except IOError, (errno, strerror):
                raise "Failed to write Log File \"%s\":\n%s" % (filename,strerror)
Example #3
0
    def __init__(self, action, myorca):
        self.action = action
        self.myorca = myorca
        self.config = self.myorca.config

        def cleanUp(*args):
            if hasattr(__main__, "_KSpreadOrca"):
                getattr(__main__, "_KSpreadOrca").finalized()

        self.action.connect("started(Kross::Action*)", cleanUp)
        self.action.connect("finalized(Kross::Action*)", cleanUp)

        self._view = KSpread.view()
        self._setSheet(KSpread.currentSheet())

        def selectionChanged():
            print "Selection changed"
            s = KSpread.currentSheet()
            if s:
                if s.sheetName() != self.sheetName:
                    self._setSheet(s)
                    if self.config.sheetNameOnSheetChanged:
                        self.speakSheetName()
                else:
                    if self.config.cellNameOnSelectionChanged:
                        self.speakCellName()
                    if self.config.cellValueOnSelectionChanged:
                        self.speakCellValue()

        self._view.connect("selectionChanged()", selectionChanged)
Example #4
0
 def selectionChanged():
     print "Selection changed"
     s = KSpread.currentSheet()
     if s:
         if s.sheetName() != self.sheetName:
             self._setSheet(s)
             if self.config.sheetNameOnSheetChanged:
                 self.speakSheetName()
         else:
             if self.config.cellNameOnSelectionChanged:
                 self.speakCellName()
             if self.config.cellValueOnSelectionChanged:
                 self.speakCellValue()
Example #5
0
 def selectionChanged():
     print "Selection changed"
     s = KSpread.currentSheet()
     if s:
         if s.sheetName() != self.sheetName:
             self._setSheet(s)
             if self.config.sheetNameOnSheetChanged:
                 self.speakSheetName()
         else:
             if self.config.cellNameOnSelectionChanged:
                 self.speakCellName()
             if self.config.cellValueOnSelectionChanged:
                 self.speakCellValue()
Example #6
0
        def update(argument):
            print "Yweather.update !"
            location = argument[0]  #e.g. "GMXX0151"
            if location.startswith('='):
                sheet = KSpread.currentSheet()
                location = sheet.text(location[1:])

            if location == None or not re.compile('^[a-zA-Z0-9]+$').match(
                    location):
                func.error = T.i18n("Invalid location")
                return

            url = "http://weather.yahooapis.com/forecastrss?p=%s" % location
            if len(argument) >= 2:
                url += "&u=%s" % urllib.quote_plus(argument[1])

            print "url=%s" % url
            namespace = 'http://xml.weather.yahoo.com/ns/rss/1.0'
            dom = None
            try:
                dom = minidom.parse(urllib.urlopen(url))
            except:
                func.error = T.i18n("Web services request failed")
                return

            forecasts = []
            for node in dom.getElementsByTagNameNS(namespace, 'forecast'):
                forecasts.append({
                    'date': node.getAttribute('date'),
                    'low': node.getAttribute('low'),
                    'high': node.getAttribute('high'),
                    'condition': node.getAttribute('text')
                })

            try:
                ycondition = dom.getElementsByTagNameNS(
                    namespace, 'condition')[0]
            except IndexError:
                func.error = T.i18n("Invalid condition")
                return
            #my_current_condition = ycondition.getAttribute('text')
            #my_current_temp = ycondition.getAttribute('temp')
            #my_forecasts = forecasts
            #my_title = dom.getElementsByTagName('title')[0].firstChild.data

            temp = ycondition.getAttribute('temp')
            print "Y! Weather Temperature: %s" % temp
            func.result = temp
Example #7
0
        def update(argument):
            print "Yweather.update !"
            location = argument[0] #e.g. "GMXX0151"
            if location.startswith('='):
                sheet = KSpread.currentSheet()
                location = sheet.text(location[1:])

            if location == None or not re.compile('^[a-zA-Z0-9]+$').match(location):
                func.error = "Invalid location"
                return

            url = "http://weather.yahooapis.com/forecastrss?p=%s" % location
            if len(argument) >= 2:
                url += "&u=%s" % urllib.quote_plus(argument[1])

            print "url=%s" % url
            namespace = 'http://xml.weather.yahoo.com/ns/rss/1.0'
            dom = None
            try:
                dom = minidom.parse(urllib.urlopen(url))
            except:
                func.error = "Web services request failed"
                return

            forecasts = []
            for node in dom.getElementsByTagNameNS(namespace, 'forecast'):
                forecasts.append({
                    'date': node.getAttribute('date'),
                    'low': node.getAttribute('low'),
                    'high': node.getAttribute('high'),
                    'condition': node.getAttribute('text')
                })

            try:
                ycondition = dom.getElementsByTagNameNS(namespace, 'condition')[0]
            except IndexError:
                func.error = "Invalid condition"
                return
            #my_current_condition = ycondition.getAttribute('text')
            #my_current_temp = ycondition.getAttribute('temp')
            #my_forecasts = forecasts
            #my_title = dom.getElementsByTagName('title')[0].firstChild.data

            temp = ycondition.getAttribute('temp')
            print "Y! Weather Temperatur: %s" % temp
            func.result = temp
Example #8
0
    def __init__(self, scriptaction):
        self.scriptaction = scriptaction
        #self.currentpath = self.scriptaction.currentPath()

        #self.undostack = KSpread.undoStack()
        #self.undostack.connect("indexChanged(int)",self.indexChanged)

        #file = os.path(self.getLogDir(),"KSpread.log")

        self.forms = Kross.module("forms")
        self.dialog = self.forms.createDialog(T.i18n("Logger"))
        self.dialog.setButtons("Ok|Cancel")
        self.dialog.setFaceType("Plain")  #Auto Plain List Tree Tabbed

        savepage = self.dialog.addPage(T.i18nc("Options page name", "Save"),
                                       T.i18n("Save to Log File"),
                                       "document-save")
        self.savewidget = self.forms.createFileWidget(
            savepage, "kfiledialog:///kspreadlogger")
        self.savewidget.setMode("Saving")
        self.savewidget.setFilter("*.txt *.log|%(1)s\n*|%(2)s" % {
            '1': T.i18n("Log File"),
            '2': T.i18n("All Files")
        })

        if self.dialog.exec_loop():
            filename = self.savewidget.selectedFile()
            if os.path.isfile(filename):
                if self.forms.showMessageBox(
                        "WarningContinueCancel", T.i18n("Overwrite file?"),
                        T.i18n(
                            "The file \"%1\" does already exist. Overwrite the file?",
                            [filename])) != "Continue":
                    raise Exception, T.i18n("Aborted.")
            sheetname = KSpread.currentSheet().sheetName()
            cellrange = "A1:F50"  #FIXME
            try:
                self.file = open(filename, "w")
                self.startLogging(sheetname, cellrange)
            except IOError, (errno, strerror):
                raise Exception, T.i18n("Failed to write Log File \"%1\":\n%2",
                                        [filename], [strerror])
Example #9
0
 def speakCellValue(self):
     sheet = KSpread.currentSheet()
     (x1, y1, x2, y2) = KSpread.view().selection()
     t = sheet.text(x1, y1)
     self.myorca.speak(t)
Example #10
0
 def speakCellName(self):
     sheet = KSpread.currentSheet()
     (x1, y1, x2, y2) = KSpread.view().selection()
     p1 = sheet.cellName(x1, y1)
     self.myorca.speak(p1)
Example #11
0
        def update(argument):
            print "Yfinance.update !"
            ticker = argument[0] #e.g. "yhoo" or "goog"
            if ticker.startswith('='):
                ticker = KSpread.currentSheet().text(ticker[1:])

            todate = argument[1] #e.g. "20060119"
            if todate.startswith('='):
                todate = KSpread.currentSheet().text(todate[1:])
            fromdate=todate

            typename = argument[2] #e.g. "Open"
            if typename.startswith('='):
                typename = KSpread.currentSheet().text(typename[1:])
            typename = typename.lower()

            if not re.compile('^[a-zA-Z0-9]+$').match(ticker):
                func.error = T.i18n("Invalid symbol")
                return

            if len(todate) != 8 or not re.compile('^[0-9]+$').match(todate):
                func.error = T.i18n("Invalid date")
                return

            typenr = None
            if typename == "date": typenr = 0
            elif typename == "open": typenr = 1
            elif typename == "high": typenr = 2
            elif typename == "low": typenr = 3
            elif typename == "close": typenr = 4
            elif typename == "volume": typenr = 5
            elif typename == "adjclose": typenr = 6
            else:
                func.error = T.i18n("Invalid type")
                return

            quote = dict()
            quote['s'] = ticker
            quote['d'] = str(int(todate[4:6]) - 1)
            quote['e'] = str(int(todate[6:8]))
            quote['f'] = str(int(todate[0:4]))
            quote['g'] = "d"
            quote['a'] = str(int(fromdate[4:6]) - 1)
            quote['b'] = str(int(fromdate[6:8]))
            quote['c'] = str(int(fromdate[0:4]))
            params = urllib.urlencode(quote)
            params += "&ignore=.csv"
            url = "http://ichart.yahoo.com/table.csv?%s" % params
            try:
                f = urllib.urlopen(url)
            except:
                func.error = T.i18n("Web services request failed")
                return
            result = f.read().split("\n")
            resultlist = []
            rx = re.compile('^[0-9]+')
            for i in range(0,len(result)):
                if rx.match(result[i]):
                    resultlist = result[i].split(',')
                    break

            if len(resultlist) < 1:
                func.error = T.i18n("No stock")
                return
            if len(resultlist) < 7:
                func.error = T.i18n("Invalid stock")
                return

            v = resultlist[typenr]
            print "Y! Finance: %s %s" % (v,resultlist)
            func.result = v
Example #12
0
 def speakCellValue(self):
     sheet = KSpread.currentSheet()
     (x1, y1, x2, y2) = KSpread.view().selection()
     t = sheet.text(x1, y1)
     self.myorca.speak(t)
Example #13
0
 def speakCellName(self):
     sheet = KSpread.currentSheet()
     (x1, y1, x2, y2) = KSpread.view().selection()
     p1 = sheet.cellName(x1, y1)
     self.myorca.speak(p1)
Example #14
0
        def update(argument):
            print "Yfinance.update !"
            ticker = argument[0]  #e.g. "yhoo" or "goog"
            if ticker.startswith('='):
                ticker = KSpread.currentSheet().text(ticker[1:])

            todate = argument[1]  #e.g. "20060119"
            if todate.startswith('='):
                todate = KSpread.currentSheet().text(todate[1:])
            fromdate = todate

            typename = argument[2]  #e.g. "Open"
            if typename.startswith('='):
                typename = KSpread.currentSheet().text(typename[1:])
            typename = typename.lower()

            if not re.compile('^[a-zA-Z0-9]+$').match(ticker):
                func.error = T.i18n("Invalid symbol")
                return

            if len(todate) != 8 or not re.compile('^[0-9]+$').match(todate):
                func.error = T.i18n("Invalid date")
                return

            typenr = None
            if typename == "date": typenr = 0
            elif typename == "open": typenr = 1
            elif typename == "high": typenr = 2
            elif typename == "low": typenr = 3
            elif typename == "close": typenr = 4
            elif typename == "volume": typenr = 5
            elif typename == "adjclose": typenr = 6
            else:
                func.error = T.i18n("Invalid type")
                return

            quote = dict()
            quote['s'] = ticker
            quote['d'] = str(int(todate[4:6]) - 1)
            quote['e'] = str(int(todate[6:8]))
            quote['f'] = str(int(todate[0:4]))
            quote['g'] = "d"
            quote['a'] = str(int(fromdate[4:6]) - 1)
            quote['b'] = str(int(fromdate[6:8]))
            quote['c'] = str(int(fromdate[0:4]))
            params = urllib.urlencode(quote)
            params += "&ignore=.csv"
            url = "http://ichart.yahoo.com/table.csv?%s" % params
            try:
                f = urllib.urlopen(url)
            except:
                func.error = T.i18n("Web services request failed")
                return
            result = f.read().split("\n")
            resultlist = []
            rx = re.compile('^[0-9]+')
            for i in range(0, len(result)):
                if rx.match(result[i]):
                    resultlist = result[i].split(',')
                    break

            if len(resultlist) < 1:
                func.error = T.i18n("No stock")
                return
            if len(resultlist) < 7:
                func.error = T.i18n("Invalid stock")
                return

            v = resultlist[typenr]
            print "Y! Finance: %s %s" % (v, resultlist)
            func.result = v