Exemplo n.º 1
0
 def OnSave(self, event):
     dlg = drFileDialog.FileDialog(self.filedialogparent,
                                   "Save Regular Expression As",
                                   wildcard,
                                   IsASaveDialog=True)
     if self.regdatdirectory:
         try:
             dlg.SetDirectory(self.regdatdirectory)
         except:
             drScrolledMessageDialog.ShowMessage(
                 self, ("Error Setting Default Directory To: " +
                        self.regdatdirectory), "EasyPython Error")
     if dlg.ShowModal() == wx.ID_OK:
         refile = dlg.GetPath().replace("\\", "/")
         try:
             f = file(refile, 'w')
             f.write(self.txtRE.GetValue())
             f.close()
         except:
             drScrolledMessageDialog.ShowMessage(
                 self, ("Error Writing To: " + refile), "EasyPython Error")
             return
         if self.enablefeedback:
             drScrolledMessageDialog.ShowMessage(
                 self, ("Successfully Saved: " + refile), "Save Success")
         dlg.Destroy()
     self.Raise()
Exemplo n.º 2
0
    def OnLoad(self, event):
        dlg = drFileDialog.FileDialog(self.filedialogparent,
                                      "Load Regular Expression From", wildcard)
        if self.regdatdirectory:
            try:
                dlg.SetDirectory(self.regdatdirectory)
            except:
                drScrolledMessageDialog.ShowMessage(
                    self, ("Error Setting Default Directory To: " +
                           self.regdatdirectory), "EasyPython Error")
        if dlg.ShowModal() == wx.ID_OK:
            refile = dlg.GetPath().replace("\\", "/")
            try:
                f = file(refile, 'r')
                text = f.read()
                f.close()
            except:
                drScrolledMessageDialog.ShowMessage(
                    self, ("Error Reading From: " + refile),
                    "EasyPython Error")
                text = ""
            if (text.find('\n') > -1) or (text.find('\r') > -1):
                drScrolledMessageDialog.ShowMessage(
                    self, ("Error Reading From: " + refile),
                    "EasyPython Error")
                text = ""
            self.txtRE.SetValue(text)

        dlg.Destroy()
        self.Raise()
Exemplo n.º 3
0
    def OnbtnSave(self, event):
        y = 0
        c = self.popupmenu.GetCount()

        popupmenustring = ""
        popupmenulist = []

        while y < c:
            pop = self.popupmenu.GetString(y)
            if not pop == "<ROOT>":
                popupmenustring = popupmenustring + pop + "\n"
                popupmenulist.append(pop)
            y = y + 1

        self.parent.popupmenulist = popupmenulist

        popupfile = self.AppDataDir + "/popupmenu.dat"
        try:
            f = file(popupfile, 'w')
            f.write(popupmenustring)
            f.close()
        except IOError:
            drScrolledMessageDialog.ShowMessage(self, ("There were some problems writing to:\n"  + popupfile + "\nEither the file is having metaphysical issues, or you do not have permission to write.\nFor metaphysical issues, consult the documentation.\nFor permission issues, change the permissions on the directory to allow yourself write access.\nEasyPython will now politely ignore your request to save.\nTry again when you have fixed the problem."), "Write Error")
            return
        if config.prefs.enablefeedback:
            drScrolledMessageDialog.ShowMessage(self, ("Succesfully wrote to:\n"  + popupfile + "\nand updated the current instance of EasyPython."), "Saved Pop Up Menu")
Exemplo n.º 4
0
    def OnbtnRemove(self, event):
        sel = self.popupmenu.GetSelection()
        if not sel:
            drScrolledMessageDialog.ShowMessage(self, "You cannot remove the root item.", "Mistake")
            return
        if sel == -1:
            drScrolledMessageDialog.ShowMessage(self, "Nothing Selected to Remove", "Mistake")
            return

        self.popupmenu.Delete(sel)
        self.popupmenu.SetSelection(sel-1)
Exemplo n.º 5
0
 def OnbtnSave(self, event):
     try:
         root = self.datatree.GetRootItem()
         f = open(self.targetfile, 'w')
         self.WriteBranch(self.datatree, root, f, 0)
         f.close()
     except IOError:
         drScrolledMessageDialog.ShowMessage(self, ("There were some problems writing to:\n"  + self.targetfile + "\nEither the file is having metaphysical issues, or you do not have permission to write.\nFor metaphysical issues, consult the documentation.\nFor permission issues, change the permissions on the directory to allow yourself write access.\nDrPython will now politely ignore your request to save.\nTry again when you have fixed the problem."), "Write Error")
         return
     self.datatree.SetModified(False)
     if self.config.prefs.enablefeedback:
         drScrolledMessageDialog.ShowMessage(self, ("Succesfully wrote to:\n"  + self.targetfile), "Success")
Exemplo n.º 6
0
    def OnbtnSave(self, event):
        #STC
        shortcutsfile = self.AppDataDir + "/stcshortcuts.dat"
        try:
            drShortcutsFile.WriteShortcuts(shortcutsfile, self.ShortcutsArray[1], self.parent.STCShortcutNames, "", False)
        except:
            drScrolledMessageDialog.ShowMessage(self, ("There were some problems writing to:\n"  + shortcutsfile + "\nEither the file is having metaphysical issues, or you do not have permission to write.\nFor metaphysical issues, consult the documentation.\nFor permission issues, change the permissions on the directory to allow yourself write access.\nDrPython will now politely ignore your request to save.\nTry again when you have fixed the problem."), "Write Error")
            return

        #STCDefault
        if self.parent.STCUseDefault:
            self.parent.STCUseDefault = 0

        #Main
        shortcutsfile = self.AppDataDir + "/shortcuts.dat"
        try:
            drShortcutsFile.WriteShortcuts(shortcutsfile, self.ShortcutsArray[0], self.parent.ShortcutNames, self.txtIgnore.GetValue())
        except:
            drScrolledMessageDialog.ShowMessage(self, ("There were some problems writing to:\n"  + shortcutsfile + "\nEither the file is having metaphysical issues, or you do not have permission to write.\nFor metaphysical issues, consult the documentation.\nFor permission issues, change the permissions on the directory to allow yourself write access.\nDrPython will now politely ignore your request to save.\nTry again when you have fixed the problem."), "Write Error")
            return

        #DrScripts
        shortcutsfile = self.AppDataDir + "/drscript.shortcuts.dat"
        try:
            drShortcutsFile.WriteShortcuts(shortcutsfile, self.ShortcutsArray[2], self.parent.DrScriptShortcutNames, "", False)
        except:
            drScrolledMessageDialog.ShowMessage(self, ("There were some problems writing to:\n"  + shortcutsfile + "\nEither the file is having metaphysical issues, or you do not have permission to write.\nFor metaphysical issues, consult the documentation.\nFor permission issues, change the permissions on the directory to allow yourself write access.\nDrPython will now politely ignore your request to save.\nTry again when you have fixed the problem."), "Write Error")
            return

        #Plugins
        x = 3
        l = len(self.ShortcutsArray)
        while x < l:
            plugin = self.ShortcutList[x]
            if plugin.find("<Plugin>") > -1:
                shortcutsfile = os.path.join(self.parent.pluginsshortcutsdirectory, plugin[plugin.find(':')+1:] + ".shortcuts.dat")
                try:
                    drShortcutsFile.WriteShortcuts(shortcutsfile, self.ShortcutsArray[x], self.PluginShortcutNameList[x-3], "", False)
                except:
                    drScrolledMessageDialog.ShowMessage(self, ("There were some problems writing to:\n"  + shortcutsfile + "\nEither the file is having metaphysical issues, or you do not have permission to write.\nFor metaphysical issues, consult the documentation.\nFor permission issues, change the permissions on the directory to allow yourself write access.\nDrPython will now politely ignore your request to save.\nTry again when you have fixed the problem."), "Write Error")
                    return

            x = x + 1

        self.update()

        if config.prefs.enablefeedback:
            drScrolledMessageDialog.ShowMessage(self, ("Succesfully saved shortcuts\nand updated the current instance of DrPython."), "Saved Shortcuts")
Exemplo n.º 7
0
 def OnTextChange(self, event):
     v = self.txtColor.GetValue()
     if self.txtColor.IsEditable():
         if not v:
             self.red.Enable(False)
             self.green.Enable(False)
             self.blue.Enable(False)
             return
         if (v[0] == "#") and (len(v) == 7):
             #Update Sliders
             self.red.Enable(True)
             self.green.Enable(True)
             self.blue.Enable(True)
             try:
                 self.red.SetValue(int(v[1:3], 16))
                 self.green.SetValue(int(v[3:5], 16))
                 self.blue.SetValue(int(v[5:7], 16))
             except:
                 drScrolledMessageDialog.ShowMessage(
                     self,
                     ("Bad Color Data.  Should be in the form #00A3F4\nUse only digits 0-9, characters A-F"
                      ), "Error")
         else:
             self.red.Enable(False)
             self.green.Enable(False)
             self.blue.Enable(False)
     if len(v) == 7:
         if v[0] == "#":
             #Update Parent
             if self.isForeground:
                 self.GetParent().foreground = v
             else:
                 self.GetParent().background = v
             self.GetParent().SetColor()
     event.Skip()
Exemplo n.º 8
0
def GetShortcuts(filename, frame):
    try:
        f = file(filename, 'r')
        text = f.read()
        f.close()
    except:
        drScrolledMessageDialog.ShowMessage(frame, 'File error with: "' + filename + '".', "ERROR")
        return ""

    reShortcuts = re.compile(r'^\s*?DrFrame\.AddPluginShortcutFunction\(.*\)', re.MULTILINE)

    allShortcuts = reShortcuts.findall(text)

    ShortcutsArray = []

    for s in allShortcuts:
        #From the Left most '('
        start = s.find('(')
        #To the Right most ')'
        end = s.rfind(')')

        if (start > -1) and (end > -1):
            s = s[start+1:end]
            i = s.find(',')
            e = i + 1 + s[i+1:].find(',')
            argfunctionname = s[i+1:e].strip().strip('"')

            ShortcutsArray.append(argfunctionname)

    return ShortcutsArray
Exemplo n.º 9
0
    def OnItemActivated(self, event):
        sel = self.GetSelection()
        if not sel.IsOk():
            return
        t = self.GetItemText(sel)
        try:
            i = self.parent.ItemsIndex.index(sel)
            pos = self.parent.ItemsPos[i]
            
            line = EpyGlob.docMgr.currDoc.LineFromPosition(pos)
            
            if config.prefs.docfolding:
                EpyGlob.docMgr.currDoc.EnsureVisible(line)

            EpyGlob.docMgr.currDoc.ScrollToLine(line)
            EpyGlob.docMgr.currDoc.GotoLine(line)
            EpyGlob.docMgr.currDoc.GotoPos(pos)
            
            #self.grandparent.Raise()
            #self.grandparent.SetFocus()
            
            if config.prefs.sourcebrowsercloseonactivate:
                self.parent.OnBtnClose(event)
            else:
                EpyGlob.docMgr.currDoc.SetFocus()
        except:
            drScrolledMessageDialog.ShowMessage(self.parent, 'Error Activating Item', 'Source Browser Error')
Exemplo n.º 10
0
    def SetShortcut(self, shortcut, shortcutIndex, listIndex):
        try:
            self.shortcutIndex = shortcutIndex
            self.listIndex = listIndex

            keycode = drShortcuts.GetKeycodeFromShortcut(shortcut)

            if keycode:
                found, text = drShortcuts.GetKeycodeText(keycode)
                if found:
                    self.txtKeyChar.SetValue(text)
                elif (keycode < 0) or (keycode > 256):
                    self.txtKeyChar.SetValue("UnKnown")
                else:
                    self.txtKeyChar.SetValue(chr(keycode))
            else:
                self.txtKeyChar.SetValue("None")

            self.txtKeyCode.SetValue(str(keycode))

            self.chkAlt.SetValue(drShortcuts.MatchAlt(shortcut))
            self.chkControl.SetValue(drShortcuts.MatchControl(shortcut))
            self.chkMeta.SetValue(drShortcuts.MatchMeta(shortcut))
            self.chkShift.SetValue(drShortcuts.MatchShift(shortcut))
        except:
            drScrolledMessageDialog.ShowMessage(self.parent, "Error Selecting Shortcut", "DrPython Error")
            return
Exemplo n.º 11
0
def GetPopUpMenuLabels(filename, frame):
    try:
        f = file(filename, 'r')
        text = f.read()
        f.close()
    except:
        drScrolledMessageDialog.ShowMessage(frame, 'File error with: "' + filename + '".', "ERROR")
        return []

    rePopUpMenu = re.compile(r'^\s*?DrFrame\.AddPluginPopUpMenuFunction\(.*\)', re.MULTILINE)

    allPopUps = rePopUpMenu.findall(text)

    PopUpArray = []

    for s in allPopUps:
        #From the Left most '('
        start = s.find('(')
        #To the Right most ')'
        end = s.rfind(')')

        if (start > -1) and (end > -1):
            s = s[start+1:end]
            i = s.find(',')
            e = i + 1 + s[i+1:].find(',')
            arglabel = s[i+1:e].strip().strip('"')

            PopUpArray.append("<Plugin>:"+arglabel)

    return PopUpArray
Exemplo n.º 12
0
 def initialize(self):
     if os.path.exists(self.targetfile):
         try:
             f = open(self.targetfile, 'r')
             self.BuildTreeFromString(self, self.datatree.GetRootItem(), f.read())
             f.close()
         except:
             drScrolledMessageDialog.ShowMessage(self.parent, ('File Error.\n"'+self.targetfile+'"\n'), "Error")
Exemplo n.º 13
0
 def OnScroll(self, event):
     self.txtColor.SetEditable(False)
     i = event.GetId()
     if i == self.ID_RED:
         r = self.red.GetValue()
         sr = ''
         if r < 16:
             sr = '0'
         sr = sr + hex(r)[2:]
         sr = sr.upper()
         text = self.txtColor.GetValue()
         if len(text) != 7:
             drScrolledMessageDialog.ShowMessage(self, (
                 "The text box above should be formatted as follows:\n#0033AA,\nStart with the # character, followed by 6 characters which can be 0-9 or a-f.\nDrPython will ignore any changes to the color until this is fixed."
             ), "Error")
             return
         self.txtColor.SetValue(text[0:1] + sr + text[3:])
     elif i == self.ID_GREEN:
         g = self.green.GetValue()
         sr = ''
         if g < 16:
             sr = '0'
         sr = sr + hex(g)[2:]
         sr = sr.upper()
         text = self.txtColor.GetValue()
         if len(text) != 7:
             drScrolledMessageDialog.ShowMessage(self, (
                 "The text box above should be formatted as follows:\n#0033AA,\nStart with the # character, followed by 6 characters which can be 0-9 or a-f.\nDrPython will ignore any changes to the color until this is fixed."
             ), "Error")
             return
         self.txtColor.SetValue(text[0:3] + sr + text[5:])
     elif i == self.ID_BLUE:
         b = self.blue.GetValue()
         sr = ''
         if b < 16:
             sr = '0'
         sr = sr + hex(b)[2:]
         sr = sr.upper()
         text = self.txtColor.GetValue()
         if len(text) != 7:
             drScrolledMessageDialog.ShowMessage(self, (
                 "The text box above should be formatted as follows:\n#0033AA,\nStart with the # character, followed by 6 characters which can be 0-9 or a-f.\nDrPython will ignore any changes to the color until this is fixed."
             ), "Error")
             return
         self.txtColor.SetValue(text[0:5] + sr + text[7:])
     event.Skip()
Exemplo n.º 14
0
 def OnbtnRemove(self, event):
     sel = self.datatree.GetSelection()
     if not sel.IsOk():
         return
     if sel == self.datatree.GetRootItem():
         drScrolledMessageDialog.ShowMessage(self, "You can't remove the Root Item.\n", "Mistake")
         return
     t = self.datatree.GetItemText(sel)
     message = "This will remove the item: " + t
     if self.datatree.GetItemText(sel)[0] == '>':
         message = "This will remove all items in folder: " + t + "!"
     answer = wx.MessageBox((message + "\nAre you sure you want to do this?"), "DrPython", wx.YES_NO | wx.ICON_QUESTION)
     if answer == wx.NO:
         return
     try:
         self.datatree.Delete(sel)
         self.datatree.SetModified()
     except:
         drScrolledMessageDialog.ShowMessage(self, ("Something went wrong trying to remove that item....\nWhat's it called....\nOh yes: " + t + "\n"), "Error")
         return
Exemplo n.º 15
0
def SaveDialogSizeAndPosition(dialog, dialogfile, defaultdir=''):
    if config.prefs.rememberdialogsizesandpositions:
        try:
            if not defaultdir:
                defaultdir = config.AppDataDir
            f = file(defaultdir + '/' + dialogfile, 'wb')
            x, y = dialog.GetSizeTuple()
            px, py = dialog.GetPositionTuple()
            f.write(str(x) + '\n' + str(y) + '\n' + str(px) + '\n' + str(py))
            f.close()
        except:
            drScrolledMessageDialog.ShowMessage(dialog,
                                                "Error Saving Dialog Size",
                                                'Error')
Exemplo n.º 16
0
    def OnbtnUpdate(self, event):
        y = 0
        c = self.popupmenu.GetCount()

        popupmenulist = []


        while y < c:
            pop = self.popupmenu.GetString(y)
            if not pop == "<ROOT>":
                popupmenulist.append(pop)
            y = y + 1

        self.parent.popupmenulist = popupmenulist

        if config.prefs.enablefeedback:
            drScrolledMessageDialog.ShowMessage(self, ("Succesfully updated the current instance of EasyPython.\nClick Save to make it permanent."), "Updated Pop Up Menu")
Exemplo n.º 17
0
    def OnbtnAdd(self, event):
        tselection = self.programmenu.GetStringSelection()
        tsel = self.programmenu.GetSelection()
        if tsel == -1:
            drScrolledMessageDialog.ShowMessage(self, "Nothing Selected to Add", "Mistake")
            return

        sel = self.popupmenu.GetSelection()
        if sel == -1:
            sel = 0

        separator = (tselection == "<Insert Separator>")
        if separator:
            tselection = "<Separator>"

        self.popupmenu.InsertItems([tselection], sel+1)
        self.popupmenu.SetSelection(sel+1)
Exemplo n.º 18
0
def LoadDialogSizeAndPosition(dialog, dialogfile, defaultdir=''):
    if config.prefs.rememberdialogsizesandpositions:
        if not defaultdir:
            defaultdir = config.AppDataDir
        sizeposfile = defaultdir + '/' + dialogfile
        try:
            if os.path.exists(sizeposfile):
                f = file(sizeposfile, 'rb')
                text = f.read()
                f.close()
                x, y, px, py = map(int, text.split('\n'))
                dialog.SetSize((x, y))
                dialog.Move(wx.Point(px, py))
        except:
            drScrolledMessageDialog.ShowMessage(dialog, 'Error Loading Dialog Size.  The file: "%s" may be corrupt.'\
                                                % sizeposfile, 'Error')
    dialog.Bind(wx.EVT_CLOSE, dialog.OnCloseW)
Exemplo n.º 19
0
 def OnbtnAddFolder(self, event):
     sel = self.datatree.GetSelection()
     if not sel.IsOk():
         if self.datatree.GetCount() < 2:
             sel = self.datatree.GetRootItem()
         else:
             return
     if self.datatree.GetItemText(sel)[0] == '>':
         d = wx.TextEntryDialog(self, 'Enter Tree Folder:', 'Add Folder', '')
         if d.ShowModal() == wx.ID_OK:
             v = d.GetValue()
             item = self.datatree.AppendItem(self.datatree.GetSelection(), ">" + v)
             self.datatree.SetItemImage(item, 0, wx.TreeItemIcon_Normal)
             self.datatree.SetItemImage(item, 1, wx.TreeItemIcon_Expanded)
             self.datatree.SetModified()
         d.Destroy()
     else:
         drScrolledMessageDialog.ShowMessage(self, "You can only add a folder to another folder.", "Bad Folder Location")
Exemplo n.º 20
0
 def OnbtnGetKey(self, event):
     oldv = self.parent.ShortcutsArray[self.listIndex][self.shortcutIndex]
     d = drGetKeyDialog(self, self.parent.txtIgnore.GetValue(), self.parent)
     d.SetKeyString(oldv)
     d.ShowModal()
     newv = d.GetKeyString()
     d.Destroy()
     alreadytaken = ShortcutIsAlreadyTaken(newv, self.parent.ShortcutsArray, oldv)
     if alreadytaken > -1:
         if alreadytaken == 0:
             takenby = self.parent.parent.ShortcutNames[self.parent.ShortcutsArray[alreadytaken].index(newv)]
         elif alreadytaken == 1:
             takenby = self.parent.parent.STCShortcutNames[self.parent.ShortcutsArray[alreadytaken].index(newv)]
         elif alreadytaken == 2:
             takenby = self.parent.parent.DrScriptShortcutNames[self.parent.ShortcutsArray[alreadytaken].index(newv)]
         else:
             takenby = self.parent.PluginShortcutNameList[alreadytaken-3][self.parent.ShortcutsArray[alreadytaken].index(newv)]
         drScrolledMessageDialog.ShowMessage(self, ('The Shortcut "' + newv + \
         '"\nis already being used by "' + takenby + '".\nDrPython will politely ignore your request.'),\
         "Shortcut Already Taken")
         return
     self.parent.ShortcutsArray[self.listIndex][self.shortcutIndex] = newv
     self.SetShortcut(self.parent.ShortcutsArray[self.listIndex][self.shortcutIndex], self.shortcutIndex, self.listIndex)
Exemplo n.º 21
0
    def OnSelectStyle(self, event):
        current = self.boxStyle.GetSelection()
        seltext = self.boxStyle.GetStringSelection()

        if self.last > -1:
            if self.ChangeSpec == 0:
                self.targetArray[self.last] = self.GetStyleString()
            elif self.ChangeSpec == 1:
                self.targetArray[self.last] = self.GetForeground()
            elif self.ChangeSpec == 2:
                self.targetArray[self.last] = self.GetColorString()
            elif self.ChangeSpec == 3:
                self.targetArray[self.last] = self.GetBackground()

        self.ChangeSpec = 0

        stylestring = self.targetArray[current]
        if (seltext == "Caret Foreground") or (
                seltext == "Long Line Indicator") or (seltext
                                                      == "Indentation Guide"):
            self.ChangeSpec = 1
            stylestring = "fore:" + stylestring
        elif (seltext == "Selection") or (seltext == "Folding"):
            self.ChangeSpec = 2
        elif seltext == "Current Line Highlight":
            self.ChangeSpec = 3
            stylestring = "back:" + stylestring

        self.font = getStyleProperty("face", stylestring)
        if not self.font:
            self.font = getStyleProperty("face", self.targetArray[0])
        self.size = getStyleProperty("size", stylestring)
        if not self.size:
            self.size = getStyleProperty("size", self.targetArray[0])
        self.foreground = getStyleProperty("fore", stylestring)
        if not self.foreground:
            self.foreground = getStyleProperty("fore", self.targetArray[0])
        self.background = getStyleProperty("back", stylestring)
        if not self.background:
            self.background = getStyleProperty("back", self.targetArray[0])
        self.bold = getStyleProperty("bold", stylestring)
        self.italic = getStyleProperty("italic", stylestring)
        self.underline = getStyleProperty("underline", stylestring)

        if self.ChangeSpec > 0:
            self.font = getStyleProperty("face", self.targetArray[0])
            self.size = getStyleProperty("size", self.targetArray[0])
            if self.ChangeSpec == 1:
                self.background = getStyleProperty("back", self.targetArray[0])
            elif self.ChangeSpec == 3:
                self.foreground = getStyleProperty("fore", self.targetArray[0])

        if self.font not in self.FontList:
            f1 = string.capwords(self.font)
            f2 = string.lower(self.font)
            if f1 in self.FontList:
                self.font = f1
            elif f2 in self.FontList:
                self.font = f2

        if self.font not in self.FontList:
            old = self.font
            self.size = '12'
            options = ['Courier', 'Courier 10 Pitch', 'Monospace', 'Sans', '']
            for font in options:
                if font in self.FontList:
                    self.font = font
                    break
            #I don't know why this a traceback: no foreground !!!
            #drScrolledMessageDialog.ShowMessage(self, ("Default font [%s] not found! \nChoosed [%s] instead." %(old,self.font)), "Error")
            print "Default font [%s] not found! \nChoosed [%s] instead." % (
                old, self.font)

        self.txtPreview.StyleResetDefault()
        self.txtPreview.StyleSetSpec(
            wx.stc.STC_STYLE_DEFAULT,
            ("fore:" + self.foreground + ",back:" + self.background +
             ",size:" + self.size + ",face:" + self.font + "," + self.bold +
             "," + self.italic + "," + self.underline))
        self.txtPreview.StyleClearAll()
        self.txtPreview.StartStyling(0, 0xff)

        try:
            #self.boxFonts.SetStringSelection(self.font)
            i = self.boxFonts.FindString(self.font)
            if i < 0:
                i = 0
            self.boxFonts.Select(i)
            #self.boxFonts.EnsureVisible(i) # Bug: Doesn't work
            self.boxFonts.SetFirstItem(i)
        except:
            drScrolledMessageDialog.ShowMessage(self, (
                "Something awful happened trying to \nset the font to the default."
            ), "Error")
            self.boxFonts.SetSelection(0)

        try:
            tsizearray = [
                '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18',
                '19', '20', '21', '22', '23', '24', '25', '26', '27', '28',
                '29', '30'
            ]
            if not self.size in tsizearray:
                self.boxSize.SetValue(self.size)
            else:
                i = tsizearray.index(self.size)
                self.boxSize.SetSelection(i)
        except:
            drScrolledMessageDialog.ShowMessage(self, (
                "Something awful happened trying to \nset the font to the default."
            ), "Error")
            self.boxSize.SetSelection(0)

        self.OnSizeSelect(event)

        self.fgPanel.SetValue(self.foreground)
        self.bgPanel.SetValue(self.background)

        self.chkBold.SetValue((len(self.bold) > 0))
        self.chkItalic.SetValue((len(self.italic) > 0))
        self.chkUnderline.SetValue((len(self.underline) > 0))

        self.boxFonts.Enable(self.ChangeSpec == 0)
        self.boxSize.Enable(self.ChangeSpec == 0)
        self.chkBold.Enable(self.ChangeSpec == 0)
        self.chkItalic.Enable(self.ChangeSpec == 0)
        self.chkUnderline.Enable(self.ChangeSpec == 0)
        if self.ChangeSpec == 1:
            self.fgPanel.Enable(True)
            self.bgPanel.Enable(False)
        elif self.ChangeSpec == 3:
            self.fgPanel.Enable(False)
            self.bgPanel.Enable(True)
        else:
            self.fgPanel.Enable(True)
            self.bgPanel.Enable(True)

        self.last = current
Exemplo n.º 22
0
    def __init__(self,
                 parent,
                 id,
                 title,
                 stylestring,
                 defaultstylestring,
                 ChangeSpec=0):

        wx.Dialog.__init__(self, parent, id, title, wx.DefaultPosition,
                           (-1, -1))

        self.ID_CANCEL = 101
        self.ID_OK = 102

        self.ID_FONTS = 103
        self.ID_SIZE = 104

        self.ID_BOLD = 109
        self.ID_ITALIC = 110
        self.ID_UNDERLINE = 111

        self.Enum = wx.FontEnumerator()
        self.Enum.EnumerateFacenames()
        self.FontList = self.Enum.GetFacenames()
        self.FontList.sort()

        self.OK = False

        self.font = getStyleProperty("face", stylestring)
        if not self.font:
            self.font = getStyleProperty("face", defaultstylestring)
        self.size = getStyleProperty("size", stylestring)
        if not self.size:
            self.size = getStyleProperty("size", defaultstylestring)
        self.foreground = getStyleProperty("fore", stylestring)
        if not self.foreground:
            self.foreground = getStyleProperty("fore", defaultstylestring)
        self.background = getStyleProperty("back", stylestring)
        if not self.background:
            self.background = getStyleProperty("back", defaultstylestring)
        self.bold = getStyleProperty("bold", stylestring)
        self.italic = getStyleProperty("italic", stylestring)
        self.underline = getStyleProperty("underline", stylestring)
        self.txtPreview = wx.stc.StyledTextCtrl(self, id, wx.Point(225, 15),
                                                (225, 150))

        if ChangeSpec > 0:
            self.font = getStyleProperty("face", defaultstylestring)
            self.size = getStyleProperty("size", defaultstylestring)
            if ChangeSpec == 1:
                self.background = getStyleProperty("back", defaultstylestring)
            elif ChangeSpec == 3:
                self.foreground = getStyleProperty("fore", defaultstylestring)

        if self.font not in self.FontList:
            old = self.font
            self.size = '12'
            options = ['Courier', 'Courier 10 Pitch', 'Monospace', 'Sans', '']
            for font in options:
                if font in self.FontList:
                    self.font = font
                    break
            drScrolledMessageDialog.ShowMessage(
                self, ("Default font [%s] not found! \nChoosed [%s] instead." %
                       (old, self.font)), "Error")

        self.txtPreview.SetText("Preview\n()[]{}\n0123")
        self.txtPreview.SetUseHorizontalScrollBar(0)

        self.txtPreview.SetReadOnly(1)
        self.txtPreview.SetMarginWidth(0, 0)
        self.txtPreview.SetMarginWidth(1, 0)
        self.txtPreview.SetMarginWidth(2, 0)

        self.txtPreview.StyleSetSpec(
            wx.stc.STC_STYLE_DEFAULT,
            ("fore:" + self.foreground + ",back:" + self.background +
             ",size:" + self.size + ",face:" + self.font + "," + self.bold +
             "," + self.italic + "," + self.underline))

        self.txtPreview.StyleClearAll()

        self.txtPreview.StartStyling(0, 0xff)

        self.boxFonts = wx.ListBox(self, self.ID_FONTS, wx.Point(10, 10),
                                   (250, 250), self.FontList)

        try:
            #self.boxFonts.SetStringSelection(self.font)
            i = self.boxFonts.FindString(self.font)
            if i < 0:
                i = 0
            self.boxFonts.Select(i)
            #self.boxFonts.EnsureVisible(i) # Bug: Doesn't work
            self.boxFonts.SetFirstItem(i)

        except:
            drScrolledMessageDialog.ShowMessage(self, (
                "Something awful happened trying to \nset the font to the default."
            ), "Error")
            self.boxFonts.SetSelection(0)

        self.boxSize = wx.ComboBox(
            self, self.ID_SIZE, self.size, wx.Point(10, 175), (150, 50), [
                '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18',
                '19', '20', '21', '22', '23', '24', '25', '26', '27', '28',
                '29', '30'
            ])

        self.fgPanel = drColorPanel(self, id, wx.Point(10, 200), (400, 225),
                                    True)
        self.fgPanel.SetValue(self.foreground)
        self.bgPanel = drColorPanel(self, id, wx.Point(220, 200), (400, 225),
                                    False)
        self.bgPanel.SetValue(self.background)

        self.chkBold = wx.CheckBox(self, self.ID_BOLD, "Bold",
                                   wx.Point(10, 345))
        if self.bold:
            self.chkBold.SetValue(1)
        self.chkItalic = wx.CheckBox(self, self.ID_ITALIC, "Italic",
                                     wx.Point(110, 345))
        if self.italic:
            self.chkItalic.SetValue(1)
        self.chkUnderline = wx.CheckBox(self, self.ID_UNDERLINE, "Underline",
                                        wx.Point(210, 345))
        if self.underline:
            self.chkUnderline.SetValue(1)

        if ChangeSpec > 0:
            self.boxFonts.Enable(False)
            self.boxSize.Enable(False)
            self.chkBold.Enable(False)
            self.chkItalic.Enable(False)
            self.chkUnderline.Enable(False)
            if ChangeSpec == 1:
                self.bgPanel.Enable(False)
            elif ChangeSpec == 3:
                self.fgPanel.Enable(False)

        self.btnCancel = wx.Button(self, self.ID_CANCEL, "&Cancel",
                                   wx.Point(5, 0), (-1, -1))
        self.btnOk = wx.Button(self, self.ID_OK, "&Ok", wx.Point(300, 0),
                               (-1, -1))

        #Sizer:

        self.theSizer = wx.FlexGridSizer(0, 2, 5, 1)
        self.styleSizerLeft = wx.BoxSizer(wx.VERTICAL)
        self.styleSizerRight = wx.BoxSizer(wx.VERTICAL)

        self.styleSizerLeft.Add(wx.StaticText(self, -1, "Font:"), 0,
                                wx.ALL | wx.SHAPED, 4)
        self.styleSizerLeft.Add(self.boxFonts, 0, wx.ALL | wx.SHAPED, 4)
        self.styleSizerLeft.Add(wx.StaticText(self, -1, "Size:"), 0,
                                wx.ALL | wx.SHAPED, 4)
        self.styleSizerLeft.Add(self.boxSize, 0, wx.ALL | wx.SHAPED, 4)

        self.styleSizerLeft.Add(self.chkBold, 0, wx.ALL | wx.SHAPED, 4)
        self.styleSizerLeft.Add(wx.StaticText(self, -1, "   "), 0,
                                wx.ALL | wx.SHAPED, 4)
        self.styleSizerLeft.Add(self.chkItalic, 0, wx.ALL | wx.SHAPED, 4)
        self.styleSizerLeft.Add(wx.StaticText(self, -1, "   "), 0,
                                wx.ALL | wx.SHAPED, 4)
        self.styleSizerLeft.Add(self.chkUnderline, 0, wx.ALL | wx.SHAPED, 4)

        self.styleSizerRight.Add(self.txtPreview, 0, wx.ALL | wx.SHAPED, 4)
        self.styleSizerRight.Add(wx.StaticText(self, -1, 'Foreground:'), 0,
                                 wx.ALL | wx.SHAPED, 4)
        self.styleSizerRight.Add(self.fgPanel, 0, wx.ALL | wx.SHAPED, 4)
        self.styleSizerRight.Add(wx.StaticText(self, -1, 'Background:'), 0,
                                 wx.ALL | wx.SHAPED, 4)
        self.styleSizerRight.Add(self.bgPanel, 1, wx.ALL | wx.SHAPED, 4)

        self.theSizer.Add(self.styleSizerLeft, 0, wx.ALL | wx.SHAPED, 4)
        self.theSizer.Add(self.styleSizerRight, 0, wx.ALL | wx.SHAPED, 4)
        self.theSizer.Add(self.btnCancel, 0,
                          wx.ALL | wx.SHAPED | wx.ALIGN_RIGHT, 4)
        self.theSizer.Add(self.btnOk, 0, wx.ALL | wx.SHAPED | wx.ALIGN_LEFT, 4)

        self.SetAutoLayout(True)
        self.SetSizerAndFit(self.theSizer)

        self.btnCancel.SetDefault()

        #End Sizer

        self.Bind(wx.EVT_LISTBOX, self.OnFontSelect, id=self.ID_FONTS)
        self.Bind(wx.EVT_COMBOBOX, self.OnSizeSelect, id=self.ID_SIZE)
        self.Bind(wx.EVT_TEXT, self.OnChangeSize, id=self.ID_SIZE)
        self.Bind(wx.EVT_CHECKBOX, self.OnBold, id=self.ID_BOLD)
        self.Bind(wx.EVT_CHECKBOX, self.OnItalic, id=self.ID_ITALIC)
        self.Bind(wx.EVT_CHECKBOX, self.OnUnderline, id=self.ID_UNDERLINE)
        self.Bind(wx.EVT_BUTTON, self.OnbtnCancel, id=self.ID_CANCEL)
        self.Bind(wx.EVT_BUTTON, self.OnbtnOk, id=self.ID_OK)
Exemplo n.º 23
0
    def LoadPluginShortcutList(self):
        plist = os.listdir(self.parent.pluginsdirectory)

        self.PluginShortcutNameList = []

        self.PluginList = []
        for p in plist:
            i = p.find(".py")
            l = len(p)
            if i > -1 and (i + 3 == l):
                self.PluginList.append("<Plugin>:" + p[:i])

        poplist = []
        #Load shortcuts from plugins.
        for plugin in self.PluginList:
            list = []
            if plugin.find("<Plugin>") > -1:
                pluginfile = os.path.join(self.parent.pluginsdirectory, plugin[plugin.find(':')+1:] + ".py")
                shortcutfile = os.path.join(self.parent.pluginsshortcutsdirectory, plugin[plugin.find(':')+1:] + ".shortcuts.dat")
                list = GetShortcuts(pluginfile, self)
                plist = self.parent.GetPluginLabels(pluginfile, True)
                for p in plist:
                    if not (p in list):
                        list.append(p)
                shortcuts = []
                if list:
                    needtomakefile = 0
                    #If the file does not exist, or is out of date, create it.
                    if not os.path.exists(shortcutfile):
                        needtomakefile = 1
                    else:
                        shortcuts, names, ignorestring = drShortcutsFile.ReadShortcuts(shortcutfile, 0)
                        if len(shortcuts) != len(list):
                            needtomakefile = 2

                    if needtomakefile:
                        try:
                            if list:
                                f = file(shortcutfile, 'w')
                                if needtomakefile == 2:
                                    for s in list:
                                        if s in names:
                                            ix = names.index(s)
                                            f.write("<" + s + "><mod>")
                                            if MatchControl(shortcuts[ix]):
                                                f.write("Control,")
                                            if MatchShift(shortcuts[ix]):
                                                f.write("Shift,")
                                            if MatchAlt(shortcuts[ix]):
                                                f.write("Alt,")
                                            if MatchMeta(shortcuts[ix]):
                                                f.write("Meta")
                                            f.write("</mod><keycode>" + drShortcuts.GetKeycodeStringFromShortcut(shortcuts[ix]) +
                                            "</keycode></" + s + ">\n")
                                        else:
                                            f.write("<" + s + "><mod></mod><keycode></keycode></" + s + ">\n")
                                else:
                                    for s in list:
                                        f.write("<" + s + "><mod></mod><keycode></keycode></" + s + ">\n")
                                f.close()
                                shortcuts, names, ignorestring = drShortcutsFile.ReadShortcuts(shortcutfile, 0)
                            else:
                                shortcuts, names, ignorestring = [], [], ""

                            if plugin.find(':') > -1:
                                plugin = plugin[plugin.find(':')+1:]

                            x = 0
                            for shortcut in shortcuts:
                                try:
                                    i = self.parent.PluginShortcutFunctionNames.index(plugin + ":" + names[x])
                                    self.parent.PluginAction.append(self.parent.PluginShortcutFunctions[i])
                                    self.parent.PluginShortcuts.append(shortcut)
                                except:
                                    pass
                                x += 1
                            if os.path.exists(shortcutfile):
                                shortcuts, names, ignorestring = drShortcutsFile.ReadShortcuts(shortcutfile, 0)
                        except:
                            drScrolledMessageDialog.ShowMessage(self, ("Error Creating Shortcuts For Plugin"), "Plugin Shortcuts Error")
                            return

                if shortcuts:
                    self.ShortcutsArray.append(shortcuts)
                    self.PluginShortcutNameList.append(names)
                else:
                    poplist.append(plugin)

        for popl in poplist:
            try:
                i = self.PluginList.index(popl)
                self.PluginList.pop(i)
            except:
                pass
Exemplo n.º 24
0
    def OnbtnUpdate(self, event):

        self.update()

        if config.prefs.enablefeedback:
            drScrolledMessageDialog.ShowMessage(self, ("Succesfully updated the current instance of DrPython.\nClick Save to make it permanent."), "Updated Shortcuts")
Exemplo n.º 25
0
def ShowMessage(msg, title='EasyPython'):
    drScrolledMessageDialog.ShowMessage(None, msg, title)