Ejemplo n.º 1
0
 def TryLoadFile(self, path):
     try:
         yield self.LoadFile(path)
         self.EmptyUndoBuffer()
         yield True
     except Exception as e:
         dialogs.error(self.dialog_parent, "Error opening file:\n\n%s" % e)
         yield False
Ejemplo n.º 2
0
 def NewFolder(self, node, name):
     path = os.path.join(node.path, name)
     try:
         yield async_call(os.mkdir, path)
         if self.IsExpanded(node.item):
             self.SelectLater(node.item, name)
     except OSError, e:
         dialogs.error(self, str(e))
Ejemplo n.º 3
0
 def OnReplace(self, evt):
     details = self.GetFindDetails(True)
     if details:
         try:
             if not details.Replace(self.editor):
                 dialogs.info(self, "Pattern not found: '%s'" % details.find, "Replace")
         except re.error as e:
             dialogs.error(self, "Error: %s." % str(e).capitalize())
Ejemplo n.º 4
0
def shell_copy(srcpath, dstpath, parent=None):
    if destination_is_same(srcpath, dstpath):
        return
    if ask_copy_file(parent, srcpath, dstpath):
        try:
            yield async_call(shutil.copy2, srcpath, dstpath)
        except Exception as e:
            dialogs.error(parent, "Error copying file:\n\n%s" % e)
Ejemplo n.º 5
0
 def OnExport(self, evt):
     path = dialogs.get_file_to_save(self, wildcard=commands_wildcard, context="commands")
     if path:
         if not path.endswith(commands_ext) and "." not in path:
             path = path + commands_ext
         try:
             commands = clean_commands(self.GetCommands())
             write_settings(path, commands)
         except Exception as e:
             dialogs.error(self, "Error exporting commands file:\n\n%s" % e)
Ejemplo n.º 6
0
 def Save(self):
     if self.path:
         try:
             yield self.WriteFile(self.path)
             self.env.add_monitor_path(self.path)
             yield True
         except Exception as e:
             dialogs.error(self.dialog_parent, "Error saving file '%s'\n\n%s" % (self.path, e))
             raise
     else:
         yield (yield self.SaveAsInSameTab())
Ejemplo n.º 7
0
 def RenameNode(self, node, name):
     newpath = os.path.join(os.path.dirname(node.path), name)
     if newpath != node.path:
         try:
             if (yield async_call(os.path.exists, newpath)):
                 if not dialogs.ask_overwrite(self, newpath):
                     return
             yield async_call(fileutil.rename, node.path, newpath)
             self.SelectLater(self.GetItemParent(node.item), name)
         except OSError, e:
             dialogs.error(self, str(e))
Ejemplo n.º 8
0
 def OnOK(self, evt):
     for field_name, getter_func in self._fields:
         ctrl = getattr(self, "field_" + field_name)
         try:
             value = getter_func(ctrl)
         except Exception as e:
             ctrl.SetFocus()
             dialogs.error(self, "Error: %s" % e)
             return
         self.command[field_name] = value
     evt.Skip()
Ejemplo n.º 9
0
Archivo: main.py Proyecto: shaurz/devo
    def Startup(self, args):
        from dialogs import dialogs
        try:
            import async_wx
            from app_instance import AppListener, get_app_instance
            from fileutil import get_user_config_dir, mkpath
            from log_file import get_log_file

            async_wx.set_wx_scheduler()

            config_dir = get_user_config_dir("devo")
            try:
                mkpath(config_dir)
            except OSError as e:
                message = "Failed to create Devo configuration directory:\n\n" + str(e)
                dialogs.error(None, message, "Initialization Error")
                return False

            if not args.new_instance:
                instance = get_app_instance("devo")
                if instance:
                    try:
                        if instance.call("process_args", args.raw_args, os.getcwd()):
                            return False
                    except Exception:
                        pass

                self.listener = AppListener("devo", DevoAppHandler(self))

            if hasattr(sys, "frozen"):
                log_filename = os.path.join(config_dir, "errors.log")
                self.log_file = get_log_file(log_filename)
                sys.stdout, self.stdout = self.log_file, sys.stdout
                sys.stderr, self.stderr = self.log_file, sys.stderr

            from mainframe import MainFrame
            self.mainframe = MainFrame.__new__(MainFrame, args)
            self.mainframe.__init__(args)
            self.SetTopWindow(self.mainframe)

            self.Bind(wx.EVT_END_SESSION, self.OnEndSession)

            return True

        except Exception:
            message = "Devo failed to initialize due to the following error:\n\n" + traceback.format_exc()
            if self.mainframe:
                try:
                    self.mainframe.Destroy()
                except Exception:
                    pass
            dialogs.error(None, message, "Initialization Error")
            return False
Ejemplo n.º 10
0
 def _ReplaceSelected(self, editor):
     text = editor.GetSelectedText()
     if text:
         if self.regexp:
             try:
                 repl = self.rx_find.sub(self.replace, editor.GetSelectedText(), 1)
                 editor.ReplaceSelection(repl)
             except re.error, e:
                 dialogs.error(editor, "Replace error:\n\n" + str(e).capitalize())
                 return False
         else:
             editor.ReplaceSelection(self.replace)
Ejemplo n.º 11
0
 def SaveAsInNewTab(self):
     path = self.env.get_file_to_save(path=os.path.dirname(self.path))
     if path:
         path = os.path.realpath(path)
         editor = self.env.new_editor(path)
         editor.SetText(self.GetText())
         try:
             yield editor.WriteFile(path)
         except Exception as e:
             dialogs.error(self.dialog_parent, "Error saving file '%s'\n\n%s" % (path, e))
             raise
         else:
             editor.SetPath(path)
Ejemplo n.º 12
0
 def SaveAsInSameTab(self):
     path = self.env.get_file_to_save(path=os.path.dirname(self.path))
     if path:
         path = os.path.realpath(path)
         try:
             yield self.WriteFile(path)
         except Exception as e:
             dialogs.error(self.dialog_parent, "Error saving file '%s'\n\n%s" % (path, e))
             raise
         else:
             self.SetPath(path)
             yield True
     yield False
Ejemplo n.º 13
0
 def OnImport(self, evt):
     path = dialogs.get_file_to_open(self, wildcard=commands_wildcard, context="commands")
     if path:
         try:
             commands = read_settings(path)
             if isinstance(commands, dict):
                 commands = commands.get("commands", [])
             if isinstance(commands, list):
                 for command in commands:
                     if isinstance(command, dict) and "name" in command:
                         self.cmdlist.Append(command["name"], command)
         except Exception as e:
             dialogs.error(self, "Error importing commands file:\n\n%s" % e)
Ejemplo n.º 14
0
 def GetFindDetails(self, show_error=False):
     try:
         return FindReplaceDetails(
             find = self.combo_find.GetValue(),
             find_history = get_combo_history(self.combo_find),
             replace = self.combo_replace.GetValue(),
             replace_history = get_combo_history(self.combo_replace),
             case = self.check_case.GetValue(),
             reverse = self.check_reverse.GetValue(),
             regexp = self.check_regexp.GetValue())
     except re.error as e:
         if show_error:
             dialogs.error(self,
                 "Invalid regular expression: %s." % str(e).capitalize())
Ejemplo n.º 15
0
 def OnReplaceAll(self, evt):
     details = self.GetFindDetails(True)
     if not details:
         return
     try:
         count = details.ReplaceAll(self.editor)
     except re.error as e:
         dialogs.error(self, "Error: %s." % str(e).capitalize())
     else:
         if count > 0:
             dialogs.info(self,
                 "Replaced %d instances of '%s'" % (count, details.find),
                 "Replace All")
         else:
             dialogs.info(self,
                 "Pattern not found: '%s'" % details.find,
                 "Replace All")
Ejemplo n.º 16
0
def shell_move(srcpath, dstpath, parent=None):
    if destination_is_same(srcpath, dstpath):
        return
    if ask_move_file(parent, srcpath, dstpath):
        dstfile = os.path.join(dstpath, os.path.basename(srcpath))
        if os.path.exists(dstfile):
            if not ask_overwrite_file(parent, dstfile):
                return
            try:
                os.remove(dstfile)
            except Exception as e:
                dialogs.error(parent, "Error overwriting file file:\n\n%s" % e)
                return
        try:
            yield async_call(shutil.move, srcpath, dstpath)
        except Exception as e:
            dialogs.error(parent, "Error moving file:\n\n%s" % e)
Ejemplo n.º 17
0
 def shell_open(self, path):
     try:
         self.cm.add(async_call(fileutil.shell_open, path, workdir=os.path.dirname(path)))
     except OSError as e:
         dialogs.error(self, str(e))
Ejemplo n.º 18
0
def shell_remove(path, parent=None):
    if ask_delete_file(parent, path):
        try:
            yield async_call(remove, path)
        except Exception as e:
            dialogs.error(parent, "Error deleting file:\n\n%s" % e)