~osomon/phatch/extract-all-metadata

« back to all changes in this revision

Viewing changes to gui.py

  • Committer: stani
  • Date: 2007-06-12 17:18:53 UTC
  • Revision ID: spe.stani.be@gmail.com-20070612171853-cndnqupa2o42iai4
gettext support, major rewrite

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
"""
15
15
import wxcheck
16
16
wx = wxcheck.ensure('2.8','2.6')
 
17
 
 
18
import cPickle, gettext, os
 
19
 
 
20
def choose_language(app,language='default',path='locale',unicode=True):
 
21
    languages   = [x for x in os.listdir(path)]+['en_EN']
 
22
    lang_id     = getattr(wx,'LANGUAGE_'+language.upper())
 
23
    locale      = wx.Locale(lang_id)
 
24
    canonical   = locale.GetCanonicalName()[:2]
 
25
    if not (canonical in languages or canonical[:2] in languages):
 
26
        canonical = 'en'
 
27
        lang_id     = wx.LANGUAGE_ENGLISH
 
28
        del locale 
 
29
        locale      = wx.Locale(lang_id)
 
30
    locale.Init(lang_id)
 
31
    gettext.install(app, path, unicode=unicode)
 
32
    i18n = gettext.translation(app, path, languages=[canonical])
 
33
    i18n.install()
 
34
 
 
35
choose_language('phatch')
17
36
    
18
 
import cPickle, os
19
37
import images
20
38
 
21
39
import convertWxg as wxGlade
32
50
        self.shell = wx.py.crust.Crust(self, -1, 
33
51
            intro='%(title)s '%ct.INFO) 
34
52
        self.shell.shell.interp.locals.update({
35
 
            'phatch_application'    : wx.GetApp(),
36
 
            'phatch_frame'          : parent,
37
 
            'phatch_actions'        : parent.tree.export_actions,
 
53
            'phatch_'+_('application')  : wx.GetApp(),
 
54
            'phatch_'+_('frame')        : parent,
 
55
            'phatch_'+_('actions')      : parent.tree.export_actions,
38
56
        })
39
57
        self.Bind(wx.EVT_CLOSE,self.on_close,self)
40
58
        
188
206
    #---wildcard
189
207
    def wildcard(self):
190
208
        extensions  = self.get_selected_extensions()
191
 
        selected    = self._wildcard_list('All selected image types',
 
209
        selected    = self._wildcard_list(_('All selected image types'),
192
210
                        extensions)
193
 
        default     = self._wildcard_list('All default image types',
 
211
        default     = self._wildcard_list(_('All default image types'),
194
212
                        ct.IMAGE_EXTENSIONS)
195
213
        result      = [selected,default]
196
 
        result.extend(['%s images|%s|'%(ext,self._wildcard_extension(ext)) 
 
214
        result.extend(['%s '+_('images')+'|%s|'\
 
215
                    %(ext,self._wildcard_extension(ext)) 
197
216
                    for ext in extensions])
198
217
        return ''.join(result)
199
218
    
234
253
        
235
254
    def GetItem(self, n):
236
255
        action  = self.actions[n]
237
 
        return action.label,action.summary, action.bitmap
 
256
        return _(action.label),_(action.summary), action.bitmap
238
257
    
239
258
    def GetStringSelection(self):
240
259
        return self.actions[self.list.GetSelection()].label 
265
284
        
266
285
class DropletFrame(wx.Frame):
267
286
    def __init__(self, parent):
268
 
        wx.Frame.__init__(self, parent, -1, "Shaped Window",
 
287
        wx.Frame.__init__(self, parent, -1, _("Drag & Drop")+' - '+ct.TITLE,
269
288
                         style =
270
289
                           wx.FRAME_SHAPED
271
290
                         | wx.SIMPLE_BORDER
290
309
 
291
310
        if wx.Platform != "__WXMAC__":
292
311
            #wxMac clips the tooltip to the window shape, YUCK!!!
293
 
            self.SetToolTipString(
 
312
            self.SetToolTipString(_(
294
313
                "Drop any files and/or folders on this Phatch droplet\n"
295
314
                "to batch process them.\n"
296
 
                "Right-click or double-click to switch to normal view.")
 
315
                "Right-click or double-click to switch to normal view."))
297
316
        if wx.Platform == "__WXGTK__":
298
317
            #wxGTK requires that the window be created before you can
299
318
            #set its shape, so delay the call to SetWindowShape until
470
489
    def on_menu_file_new(self, event=None):
471
490
        self.tree.close_popup()
472
491
        self._set_filename(ct.UNKNOWN)
473
 
        self.description.SetValue(ct.DESCRIPTION)
 
492
        self.description.SetValue(ct.ACTION_LIST_DESCRIPTION)
474
493
        self._new()
475
494
        self.enable_menu_toolbar(False)
476
495
        
597
616
            image_files  = base.get_image_files(self.settings['path'],
598
617
                extensions, self.settings['recursive'])
599
618
        except base.PathError, error:
600
 
            self.show_message(_("Sorry, '%s' is not a valid path."%\
601
 
                error.filename))
 
619
            self.show_message(_('Sorry')+', "%s" '%error.filename+
 
620
                _('is not a valid path')+'.')
602
621
            return
603
622
        #Check if all the images are valid
604
623
        if self.settings['check_images_first']:
635
654
            image_files              = valid
636
655
        #Check if there are files
637
656
        if not image_files:
638
 
            self.show_message(_("Sorry, no files found."))
 
657
            self.show_message(_("Sorry")+", "+_("no files found")+".")
639
658
            return
640
659
        #Start progress dialog
641
660
        nActions    = len(actions)
673
692
            return result
674
693
        
675
694
    def progress_message_filename(self,filename):
676
 
        return 'In: %s\nFile: %s'%os.path.split(filename)
 
695
        dirname, basename   = os.path.split(filename)
 
696
        return _('In')+': '+dirname+'\n'+_('File')+': '+basename
677
697
        
678
698
    def show_error_dialog(self,label,details):
679
699
        errorDlg    = ErrorDialog(self)
680
 
        errorDlg.SetTitle('Error: '+label)
 
700
        errorDlg.SetTitle(_('Error')+': '+label)
681
701
        errorDlg.details.SetValue(details.strip())
682
702
        answer      = errorDlg.ShowModal()
683
703
        stop_for_errors = not errorDlg.future_errors.GetValue()
735
755
            except:
736
756
                self.show_message(
737
757
                    _('Sorry, the action list seems to be incompatible\n'
738
 
                    'with the current version (%(version)s) of %(title)s.'%\
739
 
                    ct.INFO))
 
758
                    'with the current version (%(version)s) of %(title)s.')%\
 
759
                    ct.INFO)
740
760
                return
741
761
            self.description.SetValue(data['description'])
742
762
            if self.tree.append_actions(data['actions']):
789
809
        if last_action.is_valid_last_action():
790
810
            return False
791
811
        self.show_message(
792
 
            _("There should be a 'Save' action at the end.\n"
793
 
            "Phatch will add one for you, please check its settings."))
 
812
            _("There should be a 'Save' action at the end.")+" "+
 
813
            _("Phatch will add one for you, please check its settings."))
794
814
        self.tree.append_action_by_label_to_last('Save')
795
815
        return True
796
816
 
822
842
    def on_close(self,event=None):
823
843
        if self.dirty:
824
844
            answer = self.show_message(
825
 
                _('Save last changes before closing to\n"%s"?'%self.filename),
 
845
                _('Before closing, save last changes to')+
 
846
                    '\n"%s"?'%self.filename,
826
847
                style   = wx.YES_NO|wx.CANCEL|wx.ICON_EXCLAMATION,
827
848
            )
828
849
            if answer == wx.ID_CANCEL:
882
903
    
883
904
def findWindowById(id):
884
905
    return wx.GetApp().GetTopWindow().FindWindowById(id)
885
 
    
 
906
 
 
907
 
886
908
def main():
887
 
    import gettext
888
 
    gettext.install("app") # replace with the appropriate catalog name
889
 
 
890
909
    app = App(0)
891
910
    app.MainLoop()
892
911