Let's say you use Microsoft Word and there's a feature missing that you would like. What are your choices?
Now let's say you use open-source software, maybe a Python editor like SPE, and you notice that a desired feature is missing. What are your choices?
Okay, so maybe the last alternative requires some programming expertise. But at least you have a choice !
For some time now, I've been missing a feature in SPE: "Save a Copy". Different from "Save" and "Save As", this feature enables to take a snapshot of a file and save it under a different name, but then continue to work on the original. It's very handy for software files: you make a copy just before starting to work on a new feature that may break your existing code.
Implementing this feature was relatively straightforward: I looked in the code to find the menu item for File > Save, then created a File > Save a Copy entry. I then found the code for the Save As menu item, and copied it and saved it as a Save a Copy function. Then, I made a couple of edits to the function (or method, if you prefer). First off, I invoked the save method so that your current working file is saved. Then, I made use of the Save As method to get the name and location of the file that you want to save to. Finally, I simply copied the existing file to the new filename.
Doing all of this took a little over an hour - on an application I had never seen before. I made changes to 4 different files. To wrap it up, I submitted the change as a patch to the developer so that it can be included in his next release.
This, to me, reflects the power and the beauty of open-source software.
For the coders out there, here are the patches, generated by running diff on the original and modified versions of the files.
diff _spe_old/Child.py _spe/Child.py
12c12
< import codecs, compiler, inspect, os, sys, re, thread, time, types
---
> import codecs, compiler, inspect, os, sys, re, shutil, thread, time, types
391c395,412
<
---
>
> def saveCopy(self):
> """firstly save the current file, then make a copy of it"""
> self.save(self.fileName)
> defaultDir = os.path.dirname(self.fileName)
> dlg = wx.FileDialog(self, "Save a Copy - www.stani.be",
> defaultDir = defaultDir,
> wildcard = info.WILDCARD,
> style = wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR)
> if dlg.ShowModal() == wx.ID_OK:
> path = dlg.GetPaths()[0]
> try:
> shutil.copyfile(self.fileName, path)
> except IOError:
> self.parentPanel.messageError("Sorry, I was unable to copy %s to %s" % (
> self.fileName, path))
> dlg.Destroy()
>
diff _spe_old/Menu.py _spe/Menu.py
277a278,281
> def menu_save_copy(self, event=None):
> """File > Save a Copy..."""
> self.app.childActive.saveCopy()
>
diff _spe_old/Menu.wxg _spe/Menu.wxg
28a29,33
> <label>Save a&Copy...\tCtrl+Alt+S</label>
> <id>SAVECOPY</id>
> <handler>menu_save_copy</handler>
> </item>
> <item>
diff _spe_old/wxgMenu.py _spe/wxgMenu.py
13a14,15
>
> SAVECOPY,
46c48
< [wx.NewId() for x in range(81)]
---
> [wx.NewId() for x in range(82)]
253a256
> self.file.Append(SAVECOPY, _("Save a &Copy..."), "", wx.ITEM_NORMAL)
389a393
> self.Bind(wx.EVT_MENU, self.menu_save_copy, id=SAVECOPY)
498a503,505
> def menu_save_copy(self, event): # wxGlade: Bar.<event_handler>
> event.Skip()
Posted by midtoad on 2006-02-28 14:35:10.
Categories:
linux, general
|