Exemplo n.º 1
0
    def __init__(self, scriptaction):
        self.scriptaction = scriptaction
        #self.currentpath = self.scriptaction.currentPath()

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

        #file = os.path(self.getLogDir(),"KCells.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:///kcellslogger")
        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 = KCells.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)
Exemplo n.º 2
0
    def __init__(self, action, myorca):
        self.action = action
        self.myorca = myorca
        self.config = self.myorca.config

        def cleanUp(*args):
            if hasattr(__main__,"_KCellsOrca"):
                getattr(__main__,"_KCellsOrca").finalized()
        self.action.connect("started(Kross::Action*)", cleanUp)
        self.action.connect("finalized(Kross::Action*)", cleanUp)

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

        def selectionChanged():
            print "Selection changed"
            s = KCells.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)
Exemplo n.º 3
0
 def selectionChanged():
     print "Selection changed"
     s = KCells.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()
Exemplo n.º 4
0
        def update(argument):
            print "Yweather.update !"
            location = argument[0]  #e.g. "GMXX0151"
            if location.startswith('='):
                sheet = KCells.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
Exemplo n.º 5
0
        def update(argument):
            print "Yweather.update !"
            location = argument[0] #e.g. "GMXX0151"
            if location.startswith('='):
                sheet = KCells.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
Exemplo n.º 6
0
    def __init__(self, scriptaction):
        self.scriptaction = scriptaction
        #self.currentpath = self.scriptaction.currentPath()

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

        #file = os.path(self.getLogDir(),"KCells.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:///kcellslogger")
        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 = KCells.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)
Exemplo n.º 7
0
        def update(argument):
            print "Yfinance.update !"
            ticker = argument[0]  #e.g. "yhoo" or "goog"
            if ticker.startswith('='):
                ticker = KCells.currentSheet().text(ticker[1:])

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

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

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

            if len(todate) != 8 or not re.compile('^[0-9]+$').match(todate):
                func.error = "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 = "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 = "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 = "No stock"
                return
            if len(resultlist) < 7:
                func.error = "Invalid stock"
                return

            v = resultlist[typenr]
            print "Y! Finance: %s %s" % (v, resultlist)
            func.result = v
Exemplo n.º 8
0
        def update(argument):
            print "Yfinance.update !"
            ticker = argument[0] #e.g. "yhoo" or "goog"
            if ticker.startswith('='):
                ticker = KCells.currentSheet().text(ticker[1:])

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

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

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

            if len(todate) != 8 or not re.compile('^[0-9]+$').match(todate):
                func.error = "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 = "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 = "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 = "No stock"
                return
            if len(resultlist) < 7:
                func.error = "Invalid stock"
                return

            v = resultlist[typenr]
            print "Y! Finance: %s %s" % (v,resultlist)
            func.result = v
Exemplo n.º 9
0
 def speakCellValue(self):
     sheet = KCells.currentSheet()
     (x1,y1,x2,y2) = KCells.view().selection()
     t = sheet.text(x1,y1)
     self.myorca.speak(t)
Exemplo n.º 10
0
 def speakCellName(self):
     sheet = KCells.currentSheet()
     (x1,y1,x2,y2) = KCells.view().selection()
     p1 = sheet.cellName(x1,y1)
     self.myorca.speak(p1)