Commit d87bf129 authored by sumpfralle's avatar sumpfralle

implemented case-insensitive file patterns for GTK FileChooserDialog


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1217 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 507d2a4e
...@@ -587,10 +587,15 @@ class ProjectGui(object): ...@@ -587,10 +587,15 @@ class ProjectGui(object):
recent_files_menu = gtk.RecentChooserMenu(self.recent_manager) recent_files_menu = gtk.RecentChooserMenu(self.recent_manager)
recent_files_menu.set_name("RecentFilesMenu") recent_files_menu.set_name("RecentFilesMenu")
recent_menu_filter = gtk.RecentFilter() recent_menu_filter = gtk.RecentFilter()
for filter_name, filter_patterns in FILTER_MODEL: case_converter = pycam.Utils.get_case_insensitive_file_pattern
if not isinstance(filter_patterns, (list, set, tuple)): for filter_name, patterns in FILTER_MODEL:
filter_patterns = [filter_patterns] if not isinstance(patterns, (list, set, tuple)):
for pattern in filter_patterns: patterns = [patterns]
# convert it into a mutable list (instead of set/tuple)
patterns = list(patterns)
for index in range(len(patterns)):
patterns[index] = case_converter(patterns[index])
for pattern in patterns:
recent_menu_filter.add_pattern(pattern) recent_menu_filter.add_pattern(pattern)
recent_files_menu.add_filter(recent_menu_filter) recent_files_menu.add_filter(recent_menu_filter)
recent_files_menu.set_show_numbers(True) recent_files_menu.set_show_numbers(True)
...@@ -600,7 +605,8 @@ class ProjectGui(object): ...@@ -600,7 +605,8 @@ class ProjectGui(object):
recent_files_menu.set_sort_type(gtk.RECENT_SORT_MRU) recent_files_menu.set_sort_type(gtk.RECENT_SORT_MRU)
# show only ten files # show only ten files
recent_files_menu.set_limit(10) recent_files_menu.set_limit(10)
uimanager.get_widget("/MenuBar/FileMenu/OpenRecentModelMenu").set_submenu(recent_files_menu) uimanager.get_widget("/MenuBar/FileMenu/OpenRecentModelMenu")\
.set_submenu(recent_files_menu)
recent_files_menu.connect("item-activated", recent_files_menu.connect("item-activated",
self.load_recent_model_file) self.load_recent_model_file)
else: else:
......
...@@ -23,6 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,6 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import os import os
import pycam.Plugins import pycam.Plugins
import pycam.Utils
def _get_filters_from_list(filter_list): def _get_filters_from_list(filter_list):
...@@ -35,7 +36,8 @@ def _get_filters_from_list(filter_list): ...@@ -35,7 +36,8 @@ def _get_filters_from_list(filter_list):
if not isinstance(file_extensions, (list, tuple)): if not isinstance(file_extensions, (list, tuple)):
file_extensions = [file_extensions] file_extensions = [file_extensions]
for ext in file_extensions: for ext in file_extensions:
current_filter.add_pattern(ext) current_filter.add_pattern(
pycam.Utils.get_case_insensitive_file_pattern(ext))
result.append(current_filter) result.append(current_filter)
return result return result
......
...@@ -59,6 +59,19 @@ def get_platform(): ...@@ -59,6 +59,19 @@ def get_platform():
else: else:
return PLATFORM_UNKNOWN return PLATFORM_UNKNOWN
def get_case_insensitive_file_pattern(pattern):
""" Convert something like "*.svg" into "*.[sS][vV][gG]" - as it is
required for GTK's FileFilter.
"""
result = []
char_match = re.compile(r"[a-zA-Z]")
for char in pattern:
if char_match.match(char):
result.append("[%s%s]" % (char.lower(), char.upper()))
else:
result.append(char)
return "".join(result)
class URIHandler(object): class URIHandler(object):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment