GIMP script-fu, can "file-glob" return only files with particular extentions? - python-2.7

I'm trying to use python-fu in GIMP. I would like pdb.file_glob to return an array of image files in the format I specify. I tried:
myGlob = "*.png|*.PNG|*.jpg|*.JPG|*.gif|*.GIF|*.xcf|*.XCF"
globpath = os.path.join(patternDir, myGlob)
num_files, files = pdb.file_glob(globpath, 0)
But the files array is always empty, I assume because the glob syntax is invalid.
Note that if I use myGlob="*", I get the graphics files I want, but I also get files such as "fake.txt", which I want to exclude.

The doc of all PDB functions can be found via the Python-fu console. Hit the Browse... button and then enter your search in the filter bar at the top of the left pane. This documentation is dynamic, it includes the documentation of any callable plugin/script (as long as authors have written some of course)
The PDB functions for Python are a direct mapping of the script-fu API. In this specific case file_glob() was very recently added to the script-fu API because there is nothing in the base TinyScheme language to do it. In Python, you are better off using the standard Python API, os.walk() or glob.glob()/glob.iglob().
In any case such functions only do simple pattern matching, if you want several extensions you want something like this:
sorted([filename for ext in ['XCF','xcf','jpg','JPG','jpeg','gif','GIF'] for filename in glob.glob('*.'+ext)])
Edit: this is a "comprehension", more or less a loop with the inner instruction outside. You can read it as:
files=[]
for ext in ['XCF','xcf','jpg','JPG','jpeg','gif','GIF']:
for filename in glob.glob('*.'+ext):
list.append(filename)

Related

Boost.Locale translation - Preventing user modifications to dictionaries / embed dictionaries in executable

I use Boost.Locale with ICU backend (internally using GNU gettext) to do the translations. This translation uses dictionaries stored on disk. Search paths are provided through boost's generator class like so:
boost::locale:generator gen;
gen.add_messages_path("path");
By inspecting the boost's source code, this internally later passes the paths to localzation backend through localization_backend::set_option. In case of ICU localization backend implementation that I use, this finally makes the paths to be set in gnu_gettext::messages_info (paths field).
Now as for my question - my requirement is to make sure that the user will not change the texts e.g. by modifying the .mo dictionary file on disk. The reason I use Boost.Locale is its codepage translations support, multiple languages support etc. and I want to keep that, but I don't want the ability for the user to freely define the texts later used in the application. My initial thought was to use the dictionaries "in memory" in some way, e.g. by storing .mo file contents inside executable and pass already read data into the localization_backend somehow. However, after checking how it works internally (described above) it seems that the only supported option is to have the dictionaries read in "real time" as I do the translations, which may include any changes to those files done by the user. It's either that or maybe I'm missing something?
What are my options?
You can use the callback field on gnu_gettext::messages_info to provide a function that will be called instead of loading messages files from disk. From Custom Filesystem Support:
namespace blg = boost::locale::gnu_gettext;
blg::messages_info info;
info.language = "he";
info.country = "IL";
info.encoding="UTF-8";
info.paths.push_back(""); // You need some even empty path
info.domains.push_back(blg::messages_info::domain("my_app"));
info.callback = some_file_loader; // Provide a callback
The callback signature is std::vector<char>(std::string const &file_name, std::string const &encoding). There's an example in the tests; this actually loads from disk, but you can adapt it to return hard-coded data instead.

Reading dates from filenames

I want to extract dates from the suffixes of files in a particular folder. The contents of such a folder look something like:
Packed_Folder_1_2016.06.10
Packed_Folder_1_2016.08.06
Packed_Folder_1_2015.09.03
packed_Folder_1_2015.01.08
... (so on and so forth, always in the same path just different suffixes)
There is no pattern to the dates. I need to make a VS form (2013) to read the name of the files and store the date differences.
Notice how the filenames always follow a pattern? It's always Packed_Folder_1_####.##.##, where the last part is a date.
So what you want to do is list the file names in the folder, and try to find a file that matches the pattern. You could use a regular expression to match the filename (it would be something like R"(Packed_Folder_1_\d{4}\.\d{2}\.\d{2})").
You are talking about Forms, so I am assuming you are able to use Visual C++. If that is the case, you can check FileSystemWatcher Class.
You instantiated it with a given path ( file or directory ), and it will trigger events based on some changes on the target (simple change, creation, rename - you can select which one). You could then update your reference, in case its change suits your needs.

How to correctly assign template file in IntelliJ?

I inherited an old Zope project, and I am also new to Intellij.
Template files got the file ending .xpt (eXtended PageTemplates)
They contain mostly html, but also tal-tags, which either include syntax like person/getName or even "name python: user.getName()".
Currently, those files show white text on black background.
I want those file endings associated with html/xml whatever, so I get a better overview visually.
BUT I really need to keep the Intellij functions like refactor and find usages and so on working, so Intellij finds methods, which are only called inside those templates.
Any help is appreciated!
Go to File -> Settings -> File types. There in Recognized File Types you can find XML files template, then in Registered Patterns add your file pattern: *.xpt

Possible to add tags to custom file?

For MS Office files, like a docx file, image files etc you can set searchable tags from properties in Windows Explorer, see image.
If I have my own custom file format, how can I add that to the details page of my file?
I've been looking at shell extensions, but that doesn't seem to be the way to go. My custom file format is a compound file, so basically a zip archive.
And if it is a shell extension that I should use to enable that for my own custom file, then please which one is it? I've been looking at "The Complete Idiot's Guide to Writing Shell Extensions" but I didn't find anything there, only how to add a new property page.
I'm using MFC.
Thanks!
For Vista and later:
1) Create shell extension implements IPropertyStore, IPropertyStoreCapabilities and IInitializeWithStream. if your cannot work with stream implement IInitializeWithFile instead of IInitializeWithStream. A lot of details.
2) IPropertyStore.GetCount must return number of properties you need. In case you described it must return 1.
3) IPropertyStore.GetAt must return PKEY of your properties. In case you described it must return PKEY_Keywords.
4) Inside IPropertyStore.GetValue you must read your Tags from your zip file and return them in function result.
5) Inside IPropertyStore.SetValue you must store new value in internal memory storage.
6) Inside IPropertyStore.Commin you must store new value from internal memory storage to your real zip file.
7) IPropertyStoreCapabilities.IsPropertyWritable must return S_OK if you want user to edit your property.
8) Create reg value:
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\.myzip]
"FullDetails"="prop:System.PropGroup.Description;System.Keywords;System.PropGroup.FileSystem;System.ItemNameDisplay;System.ItemTypeText;System.ItemFolderPathDisplay;System.Size;System.DateCreated;System.DateModified;System.FileAttributes;*System.OfflineAvailability;*System.OfflineStatus;*System.SharedWith;*System.FileOwner;*System.ComputerName"
You can try to replace HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations.myzip with HKEY_CLASSES_ROOT.myzip. Don`t forget to change .myzip to your extension.
9) Enjoy the result:
For XP:
1) Create shell extension implements IColumnProvider. Part VIII of The Complete Idiot's Guide to Writing Shell Extensions.
2) If you want user to edit your Tags you must create Property Sheet shell extension.

Magento - locate specific core files

I am familiar with theming and using template hints in the Magento back office to locate .phtml files.
What I am not really familiar with are the core files such as app/code/core/Mage/Catalog/Model
What I need to do is override a core file like I would a core phtml file by copying it to 'my theme'.
I basically want to amend some labels which appear on the order summary page of the Magento checkout process - domain.com/checkout/cart/
I followed the trail to the phtml files using template hints. Within the app/design/frontend/default/mytheme/template/checkout/cart I found the code
renderTotals(); ?>
Now I managed, by accident, to stumble upon two of the files I wanted to change:
/httpdocs/app/code/local/Mage/Sales/Model/Quote/Address/Total/Grand.php
/httpdocs/app/code/local/Mage/Sales/Model/Quote/Address/Total/Shipping.php
I made local copies of these files (http://www.magentocommerce.com/wiki/how_to/how_to_create_a_local_copy_of_app_code_core_mage) to override the default labels, like I would if I was overriding a template file.
My question is, how can you locate core files which pertain to the 'stuff' you want to change, located in function calls such as renderTotals(); ?> in the phtml files?
Not being able to pinpoint stuff like I can with template hints is slowing me down, and I am struggling to find a solution as I am not up on all the vocab surrounding Magento yet.
Hope this makes sense and thanks in advance!
From the same settings page where you turn on Template Path Hints, also turn on the "Add Block Names to Hints" setting. This will show you PHP class names such as: Mage_Sales_Model_Quote_Address_Total_Grand to which you can deduce the folder path (underscores represent a subfolder, and the last piece represents the file name).
If you're getting a block such as Mage_Sales_Model_Quote_Address_Total_Default then sometimes it just takes a little common sense to see that it's pulling in other files from the same folder (such as Grand.php and Shipping.php). But there are generally only a couple files in the same folder, so this is pretty easy to see.
As Sid Vel said, a good Search Project functionality is helpful. But if you find yourself looking at Abstract.php of some class, often you need to look in a subfolder in that directory with the proper name to find the concrete implementations. But still, it gets you very close to where you need to be.
I always use Dreamweaver's site / directory search function. It will scan through all the files in the Core folder and tell you where the function is from. In your case, I would search for "renderTotals". You need to enable PHTML editing in Dreamweaver.
Most IDE's will allow this kind of search option. In Aptana you can Ctrl + Click on the function to open the file it is coming from. Magento takes ages to index itself on Aptana, due to its sheer size.