Exemple #1
0
    def on_fldLabel_loseFocus(self, event):
        def normalize(label):
            name = label.replace("&", "").replace(".", "").replace(" ", "")
            return name

        sel = self.components.listMenus.selection
        try:
            label = event.target.text
            if self.menuList[sel]['type'] == 'Menu' and self.menuList[sel][
                    'label'] == 'New Menu':
                oldname = self.menuList[sel]['name']
                if oldname == 'menuNewMenu':
                    name = 'menu' + normalize(label)
                    self.menuList[sel]['name'] = name
                    self.components.fldName.text = name
            elif self.menuList[sel]['type'] == 'MenuItem' and self.menuList[
                    sel]['label'] == 'New Item':
                oldname = self.menuList[sel]['name']
                menuname = 'menuMenu'
                for i in range(sel + 1):
                    if self.menuList[sel - i]['type'] == 'Menu':
                        menuname = self.menuList[sel - i]['name']
                        break
                if oldname == menuname + 'NewItem':
                    name = menuname + normalize(label)
                    self.menuList[sel]['name'] = name
                    self.components.fldName.text = name
            self.menuList[sel]['label'] = label
            if self.menuList[sel]['type'] == 'MenuItem':
                label = MENULIST_PADDING + label
            self.components.listMenus.setString(sel, label)
            log.info(self.menuList[sel])
        except:
            pass
Exemple #2
0
    def on_findRecord_command(self, event):
        self.saveFocus()

        searchableFields = self.document.searchableFields[:]
        searchableFields.sort()
        result = findDialog.findDialog(self, self.lastFind['searchText'],
                                       self.lastFind['wholeWordsOnly'],
                                       self.lastFind['caseSensitive'],
                                       self.lastFind['searchField'],
                                       searchableFields)
        if result.accepted:
            startTime = time.time()

            self.lastFind['searchText'] = result.searchText
            self.lastFind['wholeWordsOnly'] = result.wholeWordsOnly
            self.lastFind['caseSensitive'] = result.caseSensitive
            self.lastFind['searchField'] = result.searchField
            self.document.findRecord(self.lastFind['searchText'],
                                     self.lastFind['caseSensitive'],
                                     self.lastFind['wholeWordsOnly'],
                                     self.lastFind['field'],
                                     self.lastFind['offset'],
                                     self.lastFind['searchField'])
            log.info("findRecord_command took %f seconds" %
                     (time.time() - startTime))
Exemple #3
0
 def on_fldName_loseFocus(self, event):
     sel = self.components.listMenus.selection
     try:
         self.menuList[sel]['name'] = event.target.text
         log.info(self.menuList[sel])
     except:
         pass
Exemple #4
0
    def sortByFieldName(self, name, ascending=1):
        comp = self.view.components[name]
        fieldType = self.getFieldType(name)
        if fieldType == 'string':
            if self.view.statusBar is not None:
                self.view.statusBar.text = 'Sorting...'

            current = self.current
            currentRecord = {}
            for field in self.fieldNames:
                value = getattr(self.records[current], field)
                if value:
                    currentRecord[field] = value
            #print currentRecord
            #print current, currentRecord[name]
            startTime = time.time()
            if fieldType == 'string':
                ##self.records = util.caseinsensitive_listKeySort(self.records, name)
                ##self.records.sort(self.records.Company)
                self.records = self.records.sort(getattr(self.records, name))
                if fieldType in ['string', 'integer']:
                    pass
                    # don't reverse if we didn't sort above
                    ##if not ascending:
                    ##    self.records.reverse()
                    ## this needs to use the metakit reverse sort operation
            log.info("sort took %f seconds" % (time.time() - startTime))
            index = self.records.find(currentRecord)
            ##index = self.records.index(currentRecord)
            #print "index", index
            self.current = index
            #print self.current, self.records[self.current][name]
            self.updateStatusBar()
Exemple #5
0
 def commonOpenFileInit(self, filename):
     #self.records = SortableList()
     self.records = []
     self.clearViewFields()
     self.documentChanged = 0
     self.filename = filename
     log.info("filename: %s" % (filename))
Exemple #6
0
 def on_fldShortcut_loseFocus(self, event):
     sel = self.components.listMenus.selection
     try:
         if self.menuList[sel]['type'] == 'MenuItem':
             self.menuList[sel]['shortcut'] = event.target.text
         log.info(self.menuList[sel])
     except:
         pass
Exemple #7
0
 def on_chkChecked_mouseClick(self, event):
     sel = self.components.listMenus.selection
     try:
         if self.menuList[sel]['type'] == 'MenuItem':
             self.menuList[sel]['checked'] = event.target.checked
         log.info(self.menuList[sel])
     except:
         pass
Exemple #8
0
 def on_fldCommand_loseFocus(self, event):
     sel = self.components.listMenus.selection
     try:
         if self.menuList[sel]['type'] == 'MenuItem':
             if event.target.text == '':
                 self.menuList[sel]['command'] = None
             else:
                 self.menuList[sel]['command'] = event.target.text
         log.info(self.menuList[sel])
     except:
         pass
Exemple #9
0
    def on_findNextRecord_command(self, event):
        startTime = time.time()

        self.saveFocus()
        self.document.findRecord(self.lastFind['searchText'],
                                 self.lastFind['caseSensitive'],
                                 self.lastFind['wholeWordsOnly'],
                                 self.lastFind['field'],
                                 self.lastFind['offset'],
                                 self.lastFind['searchField'])
        log.info("findNextRecord took %f seconds" % (time.time() - startTime))
Exemple #10
0
 def SearchFile(self, filename):
     if self.verbose:
         log.info('# ..'+filename)
     try:
         lines = open(filename, 'r').readlines()
     except:
         lines = []
     found = 0
     for i in range(len(lines)):
         line = lines[i]
         if self.pat.search(line) is not None:
             if not found:
                 self.components.listResults.append(filename)
                 found = 1
             self.components.listResults.append('  '+`i+1` + ': '+line[:-1])
     return found
Exemple #11
0
    def sortByFieldName(self, name, ascending=1):
        comp = self.view.components[name]
        fieldType = self.getFieldType(name)
        if fieldType == 'string':
            if self.view.statusBar is not None:
                self.view.statusBar.text = 'Sorting...'

            current = self.current
            currentRecord = self.records[self.current]
            #print current, currentRecord[name]
            startTime = time.time()
            try:
                # the 'integer' checks below will never happen since the
                # outer if above prevents sorting on anything but
                # strings, but eventually this will need to be expanded to cover
                # dates and other field types
                if fieldType == 'string':
                    # to see how we got to this function
                    # check out the source and extensive comments in an older version
                    # of the sortByFieldName method, join the url below
                    # http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/pythoncard/PythonCard
                    # /flatfileDatabase.py?rev=1.5&content-type=text/vnd.viewcvs-markup
                    self.records = util.caseinsensitive_listKeySort(
                        self.records, name)
                elif fieldType == 'integer':
                    # need to figure out how to generalize the code above to work
                    # with different field types, or just put the test for fieldType
                    # in the initial offsets building loop
                    # one of th problems here is that trying to convert a non-existant
                    # field to a float will throw an exception, so instead of '' or None
                    # what value should be used? 0?
                    self.records.sort(
                        lambda a, b: cmp(float(a[name]), float(b[name])))
                if fieldType in ['string', 'integer']:
                    # don't reverse if we didn't sort above
                    if not ascending:
                        self.records.reverse()
            except:
                print "sort failed"
            log.info("sort took %f seconds" % (time.time() - startTime))
            index = self.records.index(currentRecord)
            #print "index", index
            self.current = index
            #print self.current, self.records[self.current][name]
            self.updateStatusBar()
Exemple #12
0
    def on_initialize(self, event):
        startTime = time.time()

        # allow a subclass to change provide
        # its own dataFile item so it doesn't need
        # to have a config file
        # see companies sample
        if not hasattr(self, 'dataFile'):
            # KEA 2002-07-04
            # allow a subclass to change the config file
            if not hasattr(self, 'configFilename'):
                self.configFilename = CONFIG_FILE
            self.dataFile = self.getDataFile(self.configFilename)

        if self.dataFile.endswith('.pickle'):
            self.document = PickleDocument(self, self.dataFile)
        elif self.dataFile.endswith('.xml'):
            self.document = XmlDocument(self, self.dataFile)
        elif self.dataFile.endswith('.mk'):
            self.document = MetakitDocument(self, self.dataFile)
        else:
            self.document = Document(self, self.dataFile)

        self.document.filename = self.dataFile

        self.lastFind = {
            'searchText': '',
            'replaceText': '',
            'wholeWordsOnly': 0,
            'caseSensitive': 0,
            'field': '',
            'offset': 0,
            'searchField': None
        }

        # KEA 2002-06-24
        # workaround for loseFocus event occuring before openBackground
        # probably need to rework how openBackground gets posted to make
        # sure it comes before a window can be deactivated...
        self._initComplete = 1

        log.info("startup took %f seconds" % (time.time() - startTime))
Exemple #13
0
    def on_initialize(self, event):
        # only respond to size events the user generates
        # I'm not sure of a better way to do this than an IDLE
        # hack
        self.ignoreSizeEvent = 1

        self.x = 0
        self.y = 0
        self.filename = None
        self.bmp = None

        # figure out the maximum usable window size
        # size we can use without overlapping
        # the taskbar
        bgSize = self.size
        bufSize = self.GetClientSize()
        widthDiff = bgSize[0] - bufSize[0]
        heightDiff = bgSize[1] - bufSize[1]
        displayRect = wx.GetClientDisplayRect()
        self.maximizePosition = (displayRect[0], displayRect[1])
        self.maximumSize = (displayRect[2] - widthDiff,
                            displayRect[3] - heightDiff)

        #self.initSizers()
        if len(sys.argv) > 1:
            # accept a file argument on the command-line
            filename = os.path.abspath(sys.argv[1])
            log.info('pictureViewer filename: ' + filename)
            if not os.path.exists(filename):
                filename = os.path.abspath(
                    os.path.join(self.application.startingDirectory,
                                 sys.argv[1]))
            #print filename
            if os.path.isfile(filename):
                self.openFile(filename)

        if self.filename is None:
            self.fitWindow()

        self.visible = True
Exemple #14
0
    def on_initialize(self, event):
        startTime = time.time()

        # allow a subclass to provide its own configuration so it doesn't need
        # to have a config file. See companies sample
        if not hasattr(self, 'configFilename'):
           self.configFilename = CONFIG_FILE

        db, tableName = self.getDatabase(self.configFilename)
        self.document = Document(self, db, tableName)

        self.lastFind = {'searchText':'', 
                         'replaceText':'', 
                         'wholeWordsOnly':0, 
                         'caseSensitive':0,
                         'field':'',
                         'offset':0,
                         'searchField':None
                        }

        self._initComplete = 1
        log.info("startup took %f seconds" % (time.time() - startTime))
Exemple #15
0
    def on_listResults_mouseDoubleClick(self, event):
        target = self.components.listResults
        #clickLine = target.positionToXY(target.getInsertionPoint())[1] + 1
        clickLine = target.selection
        log.info("clickLine: " + str(clickLine))
        # getLineText is 0 based
        #current = target.getLineText(clickLine - 1)
        current = target.stringSelection
        if not current.startswith("  "):
            self.editFile(current.rstrip())
        else:
            """
            if current[:1] == '#':  # we have a comment line
                return current
            if current[:2] != '  ': # just fake a result line
                return current[:-1] + "(1) # LLAMA LINE\n"
            """

            delim = current.find(': ')
            greplineno = current[2:delim]
            greptext = current[delim+2:]
            # search backwards in the results until we find
            # a line that doesn't begin with two spaces, which should
            # be the full path for the grep result
            line = ''
            lineno = clickLine
            while lineno != 0:
                lineno = lineno - 1
                line = target.getString(lineno)
                if not line.startswith("  "):
                    break
            # chop any trailing newline
            filename = line.rstrip() 
            #print 'delim:', delim
            #print 'greplineno:', greplineno
            #print 'greptext:', greptext
            #print 'filename:', filename
            #print filename + '(' + greplineno + ') ' + greptext
            self.editFile(filename, greplineno)
Exemple #16
0
    def on_initialize(self, event):
        self.x = 0
        self.y = 0
        self.filename = None
        self.directory = None
        self.zip = None
        self.bmp = None
        self.fileList = None
        self.fileIndex = 0
        self.clockTimer = timer.Timer(self.components.bufOff, -1)
        self.interval = 1000 * 2  # 5 seconds
        self.loop = 0

        self.components.bufOff.backgroundColor = 'black'
        self.components.bufOff.clear()

        if sys.platform.startswith('win'):
            del self.components['htmlView']
            self.components['htmlView'] = {
                'type': 'IEHtmlWindow',
                'name': 'htmlView',
                'position': (0, 0),
                'size': (150, 150),
                'visible': 0
            }
            # can't disable the component if we want it
            # to scroll, so need another way to capture
            # key presses so the IE control doesn't get them
            # however since slideshow is for displaying HTML
            # where you shouldn't need to scroll this is probably fine
            # there is still some kind of focus bug with the IE control
            # on certain HTML pages
            self.components.htmlView.enabled = 0

        # this is the code from pictureViewer
        # instead of a file argument, slideshow
        # should take either a file or directory
        # argument
        # if given a directory, the slide show would
        # be setup to start in that directory
        # if given a file argument, the contents
        # of the file would contain a list of files to
        # display, one file per line
        if len(sys.argv) > 1:
            # accept a file argument on the command-line
            filename = os.path.abspath(sys.argv[1])
            log.info('slideshow filename: ' + filename)
            if not os.path.exists(filename):
                filename = os.path.abspath(
                    os.path.join(self.application.startingDirectory,
                                 sys.argv[1]))
            #print filename
            if os.path.isfile(filename):
                #self.openFile(filename)
                self.buildFileListFromFile(filename)
                self.on_menuSlideshowFirstSlide_select(None)
            elif os.path.isdir(filename):
                includeSubDirs = self.menuBar.getChecked(
                    'menuOptionsIncludeSubDirectories')
                self.buildFileListFromDirectory(filename, includeSubDirs)
                self.on_menuSlideshowFirstSlide_select(None)

        # PythonCard doesn't currently support
        # binding key presses to just the background, so this
        # is a hack
        wx.EVT_KEY_UP(self.components.bufOff, self.on_keyPress)
        wx.EVT_KEY_UP(self.components.htmlView, self.on_keyPress)

        self.visible = True
        self.on_size(None)
Exemple #17
0
 def doSearch(self):
     self.toggleSearchCancel(False)
     
     log.info("Grep for %s in %s" % (self.greppattern, self.filpattern))
     log.info('#Search '+self.dirpattern)
     if self.verbose:
         log.info('#   ='+self.dirpattern)
     log.info('# Files '+self.filpattern)
     log.info('#   For '+self.greppattern)
     # KEA 2002-06-11
     # "There's no equivalent of regex_syntax; 
     # re supports only one syntax, and you can't change it."
     # http://py-howto.sourceforge.net/regex-to-re/node3.html
     #regex.set_syntax(regex_syntax.RE_SYNTAX_GREP)
     if self.casesensitive:
         self.pat = re.compile(self.greppattern)
     else:
         self.pat = re.compile(self.greppattern, re.IGNORECASE)
     log.info("Searching.  Please wait...")
     
     patterns = self.filpattern.split(";")
     self.components.listResults.clear()
     self.statusBar.text = "Searching..."
     found = 0
     self.stopSearching = False
     for dir in self.dirpattern.split(';'):
         for filename in util.dirwalk(dir, patterns, self.recurse):
             if self.SearchFile(filename):
                 found += 1
             if self.stopSearching:
                 break
             else:
                 self.statusBar.text = "Files found: %d     Searching: %s" % (found, filename)
                 wx.SafeYield(self, True)
     self.statusBar.text = "Files found: %d" % found
     self.toggleSearchCancel(True)
Exemple #18
0
 def on_sort_command(self, event):
     startTime = time.time()
     self.document.sortRecords()
     log.info("sort_command took %f seconds" % (time.time() - startTime))
Exemple #19
0
    def on_initialize(self, event):
        self.initSizers()

        self.setDefaultStyles()

        # KEA 2002-05-08
        # wxFileHistory isn't wrapped, so use raw wxPython
        # the file history is not actually saved when you quit
        # or shared between windows right now
        # also the file list gets appended to the File menu
        # rather than going in front of the Exit menu
        # I suspect I have to add the Exit menu after the file history
        # which means changing how the menus in resources are loaded
        # so I'll do that later
        self.fileHistory = wx.FileHistory()
        fileMenu = self.GetMenuBar().GetMenu(0)
        self.fileHistory.UseMenu(fileMenu)
        wx.EVT_MENU_RANGE(self, wx.ID_FILE1, wx.ID_FILE9, self.OnFileHistory)

        self.lastStatus = None
        self.lastPos = None
        #self.configPath = os.path.abspath(os.curdir)
        self.configPath = os.path.join(configuration.homedir, 'codeeditor')
        self.loadConfig()
        self.cmdLineArgs = {
            'debugmenu': False,
            'logging': False,
            'messagewatcher': False,
            'namespaceviewer': False,
            'propertyeditor': False,
            'shell': False,
            'otherargs': ''
        }
        self.lastFind = {
            'searchText': '',
            'replaceText': '',
            'wholeWordsOnly': False,
            'caseSensitive': False
        }
        self.startTitle = self.title
        if len(sys.argv) > 1:
            # accept a file argument on the command-line
            filename = os.path.abspath(sys.argv[1])
            log.info('codeEditor filename: ' + filename)
            if not os.path.exists(filename):
                filename = os.path.abspath(
                    os.path.join(self.application.startingDirectory,
                                 sys.argv[1]))
            #print filename
            if os.path.isfile(filename):
                self.openFile(filename)
                # the second argument can be a line number to jump to
                # this is experimental, but a nice feature
                # KEA 2002-05-01
                # gotoLine causes the Mac to segfault
                if (len(sys.argv) > 2):
                    try:
                        line = int(sys.argv[2])
                        self.gotoLine(line)
                    except:
                        pass
            else:
                self.newFile()
        else:
            self.newFile()

        self.printer = HtmlEasyPrinting()

        # KEA 2002-05-08
        # wxSTC defaults will eventually be settable via a dialog
        # and saved in a user config, perhaps compatible with IDLE
        # or Pythonwin
        self.components.document.SetEdgeColumn(75)

        # KEA 2002-05-08
        # the wxFindReplaceDialog is not wrapped
        # so this is an experiment to see how it works
        wx.EVT_COMMAND_FIND(self, -1, self.OnFind)
        wx.EVT_COMMAND_FIND_NEXT(self, -1, self.OnFind)
        wx.EVT_COMMAND_FIND_REPLACE(self, -1, self.OnFind)
        wx.EVT_COMMAND_FIND_REPLACE_ALL(self, -1, self.OnFind)
        wx.EVT_COMMAND_FIND_CLOSE(self, -1, self.OnFindClose)

        self.visible = True
        self.loadShell()