~ubuntu-branches/debian/stretch/phatch/stretch

« back to all changes in this revision

Viewing changes to phatch/pyWx/gui.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski, Stani M, Piotr Ożarowski
  • Date: 2008-03-06 20:09:11 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080306200911-4w5f664fx4fg6jun
Tags: 0.1.1-1
* New upstream release 

[ Stani M ]
* Short and long description updated

[ Piotr Ożarowski ]
* Add myself to Uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#---Global import
29
29
 
30
30
#import & check wx
 
31
import new, sys
31
32
from wxcheck import ensure
32
33
wx = ensure('2.8','2.6')
33
34
 
36
37
##wxversion.select('2.6')
37
38
##import wx
38
39
 
 
40
#check with other encoding
 
41
##wx.SetDefaultPyEncoding('ISO8859-15')
 
42
 
39
43
#standard library
40
44
import cPickle, webbrowser, os
41
45
    
53
57
from pyWx import dialogs
54
58
from pyWx import plugin
55
59
from clipboard import copy_text
 
60
from unicoding import exception_to_unicode
56
61
 
 
62
WX_ENCODING         = wx.GetDefaultPyEncoding()
57
63
COMMAND_PASTE       = \
58
64
    _('You can paste it as text into the properties of a new launcher.')
59
65
 
 
66
#---theme
 
67
def _theme():
 
68
    if wx.Platform != '__WXGTK__':
 
69
        set_theme('nuovext')
 
70
    
 
71
def set_theme(name='default'):
 
72
    if name == 'nuovext':
 
73
        from pyWx.nuovext import Provider
 
74
        wx.ArtProvider.Push(Provider())
60
75
 
 
76
def _icon(self):
 
77
    self.icon = wx.EmptyIcon()
 
78
    if sys.platform.startswith('win'):
 
79
        image   = images.ICON32GIF
 
80
    else:
 
81
        image   = images.ICON64
 
82
    self.icon.CopyFromBitmap(graphics.bitmap(image))
 
83
    self.SetIcon(self.icon)
 
84
    
61
85
#---Functions
62
86
def findWindowById(id):
63
87
    return wx.GetApp().GetTopWindow().FindWindowById(id)
108
132
    def show_progress(self,title,parent_max,child_max=1,message=''):
109
133
        dlg = dialogs.ProgressDialog(self,title,parent_max,child_max,message)
110
134
    
111
 
    def show_progress_error(self,result,message,details,ignore=True):
 
135
    def show_progress_error(self,result,message,ignore=True):
112
136
        message     += '\n\n'+_('See Tools>Show Log for more details.')
113
 
        errorDlg    = dialogs.ErrorDialog(self,message,details,ignore)
 
137
        errorDlg    = dialogs.ErrorDialog(self,message,ignore)
114
138
        answer      = errorDlg.ShowModal()
115
139
        result['stop_for_errors']   = not errorDlg.future_errors.GetValue()
116
140
        errorDlg.Destroy()
139
163
        if os.path.exists(filename):
140
164
            try:
141
165
                return api.open_actionlist(filename)
 
166
            except KeyError, details:
 
167
                self.show_error(
 
168
                    _('Sorry, you need to install the %s action'
 
169
                    ' for this action list.')\
 
170
                    %exception_to_unicode(details,WX_ENCODING))
 
171
                return
142
172
            except:
143
173
                self.show_error((
144
174
                    _('Sorry, the action list seems incompatible with\n')+\
153
183
                    '\n', 
154
184
                    '\n'.join(data['invalid labels'])
155
185
                    ]))
156
 
        
 
186
 
157
187
 
158
188
class Frame(DialogsMixin,dialogs.BrowseMixin,droplet.Mixin,paint.Mixin,
159
189
        frame.Frame,FrameReceiver):
163
193
    
164
194
    def __init__(self,actionlist,*args,**keyw):
165
195
        frame.Frame.__init__(self,*args,**keyw)
166
 
        self._theme()
 
196
        _theme()
 
197
        self.EnableBackgroundPainting(self.empty)
167
198
        self._menu()
168
199
        self._toolBar() 
169
200
        self._plugin()
170
201
        self.on_menu_file_new()
171
 
        self._icon()
 
202
        _icon(self)
172
203
        self._title()
173
204
        self._description()
174
205
        self._drop()
180
211
    def _plugin(self):
181
212
        plugin.install_frame(self)
182
213
        
183
 
    def _theme(self):
184
 
        if wx.Platform != '__WXGTK__':
185
 
            self.set_theme('nuovext')
186
 
        self.EnableBackgroundPainting(self.empty)
187
 
        
188
 
    def set_theme(self,name='default'):
189
 
        if name == 'nuovext':
190
 
            from pyWx.nuovext import Provider
191
 
            wx.ArtProvider.Push(Provider())
192
 
        
193
214
    def _description(self):
194
215
        self.show_description(False)
195
216
        
196
217
    def _drop(self):
197
218
        self.SetAsFileDropTarget(self.tree,self.on_drop)
198
219
        
199
 
    def _icon(self):
200
 
        _ic = wx.EmptyIcon()
201
 
        #_ic.CopyFromBitmap(graphics.bitmap('ART_PASTE',(48,48)))
202
 
        _ic.CopyFromBitmap(graphics.bitmap(images.ICON))
203
 
        self.SetIcon(_ic)
204
 
        
 
220
 
205
221
    def _menu(self):
206
 
##        #---bitmaps
207
 
##        self.menu_view_description.SetBitmap(
208
 
##            graphics.bitmap('ART_TIP',(16,16)))
209
222
        #export menu
210
223
        self.menu_file_export   = self.menu_file_export_actionlist_to_clipboard.GetMenu()
211
224
        #file history
265
278
        
266
279
    def _toolBar(self):
267
280
        self.tool_bitmap_size   = (32,32)
268
 
        self.frame_toolbar = wx.ToolBar(self, -1)
 
281
        self.frame_toolbar = wx.ToolBar(self, -1,style=wx.TB_FLAT)
269
282
        self.SetToolBar(self.frame_toolbar)
270
283
        self.frame_toolbar.SetToolBitmapSize(self.tool_bitmap_size)
271
284
        self.tools_item = []
272
 
        self.add_tool('ART_FOLDER_OPEN',_("Open"),
 
285
        self.add_tool('ART_FILE_OPEN',_("Open"),
273
286
            _("Open an action list"),self.on_menu_file_open)
274
287
        tools_item  = [
275
288
            self.add_tool('ART_EXECUTABLE_FILE',_("Execute"),
350
363
            self._save(path)
351
364
        dlg.Destroy()
352
365
        
353
 
    def on_menu_file_export_droplet_actionlist_to_clipboard(self, event):
354
 
        if self.is_save_not_ok(): return
355
 
        copy_text(ct.COMMAND_DROP%self.filename)
356
 
        self.show_info(' '.join([
357
 
         _('The droplet command for this actionlist was copied to the clipboard.'),
358
 
         COMMAND_PASTE]))
359
 
 
360
 
    def on_menu_file_export_droplet_recent_to_clipboard(self, event):
361
 
        if self.is_save_not_ok(): return
362
 
        copy_text(ct.COMMAND_RECENT)
363
 
        self.show_info(' '.join([
364
 
         _('The droplet command for this actionlist was copied to the clipboard.'),
365
 
         COMMAND_PASTE]))
366
 
 
367
 
    def on_menu_file_export_droplet_inspector_to_clipboard(self, event):
368
 
        if self.is_save_not_ok(): return
369
 
        copy_text(ct.COMMAND_INSPECTOR)
 
366
    def on_menu_file_export_actionlist_to_clipboard(self, event):
 
367
        if self.is_save_not_ok(): return
 
368
        copy_text(ct.COMMAND['DROP']%self.filename)
 
369
        self.show_info(' '.join([
 
370
         _('The droplet command for this actionlist was copied to the clipboard.'),
 
371
         COMMAND_PASTE]))
 
372
 
 
373
    def on_menu_file_export_recent_to_clipboard(self, event):
 
374
        if self.is_save_not_ok(): return
 
375
        copy_text(ct.COMMAND['RECENT'])
 
376
        self.show_info(' '.join([
 
377
         _('The droplet command for this actionlist was copied to the clipboard.'),
 
378
         COMMAND_PASTE]))
 
379
 
 
380
    def on_menu_file_export_inspector_to_clipboard(self, event):
 
381
        if self.is_save_not_ok(): return
 
382
        copy_text(ct.COMMAND['INSPECTOR'])
370
383
        self.show_info(' '.join([
371
384
         _('The droplet command for the image inspector was copied to the clipboard.'),
372
385
         COMMAND_PASTE]))
433
446
        api.apply_actions(action_list,wx.GetApp().settings)
434
447
        
435
448
    def on_menu_tools_image_inspector(self, event):
436
 
        frame   = imageInspector.SingleFrame(self,size=imageInspector.SIZE)
 
449
        frame   = imageInspector.SingleFrame(self,
 
450
            size    = imageInspector.SIZE,
 
451
            icon    = self.icon)
437
452
        frame.Show()
438
453
        
439
454
    def on_menu_tools_show_log(self,event):
457
472
                    '%s_%s'%(ct.TITLE,_('frame'))       : self,
458
473
                    '%s_%s'%(ct.TITLE,_('actions'))     : self.tree.export_forms,
459
474
                    'unlock'                            : _,
460
 
                    }
 
475
                    },
 
476
                icon    = self.icon,
461
477
            )
462
478
        self.shell.Show(event.IsChecked())
463
479
        
497
513
        dlg = about.Dialog(self,
498
514
            title                   = '%(version)s'%ct.INFO,
499
515
            logo                    = graphics.bitmap(images.LOGO),
500
 
            description             = ct.INFO['description'],
 
516
            description             = _('PHoto bATCH Processor & Renamer'),
501
517
            website                 = ct.INFO['url'],
502
518
            credits                 = all_credits(),
503
519
            license                 = ct.LICENSE,
556
572
                    method      = self.on_drop,
557
573
                    label       = self.droplet_label_format(os.path.splitext(
558
574
                                    os.path.basename(self.filename))[0]),
559
 
                    label_colour= wx.BLUE,
560
 
                    label_pos   = (35, 60),
561
 
                    label_angle = 315,
 
575
                    label_colour= wx.Colour(156,166,165),
 
576
                    label_pos   = (73, 40),
 
577
                    label_angle = 360-20,
562
578
                    pos         = self.GetPosition(),
563
579
                    auto        = True,
564
580
                    OnShow      = self.on_show_droplet,
665
681
        self.dirty  = ('','*')[value]
666
682
        self._title()
667
683
        
 
684
    #---droplet
 
685
    def get_droplet_folder(self):
 
686
        folder = self.show_dir_dialog(
 
687
            defaultPath = self.get_setting('droplet_path'),
 
688
            message=_('Choose the folder for the droplet'))
 
689
        if folder:
 
690
            self.set_setting('droplet_path',folder)
 
691
        return folder
 
692
    
 
693
    def menu_file_export_droplet(self,method,*args,**keyw):
 
694
        folder      = self.get_droplet_folder()
 
695
        if folder is None:
 
696
            return
 
697
        try:
 
698
            create_phatch_droplet(self.filename,folder)
 
699
            self.show_info(_('Phatch successfully created the droplet.'))
 
700
        except Exception, details:
 
701
            reason  = exception_to_unicode(details,WX_ENCODING)
 
702
            self.show_error(_('Phatch could not create the droplet:')+'\n\n'\
 
703
                +reason)
 
704
        
 
705
    def install_menu_item(self,menu,name,label,method,tooltip="",
 
706
            style=wx.ITEM_NORMAL):
 
707
        #item
 
708
        item        = wx.MenuItem(menu, -1,label, tooltip, style)
 
709
        setattr(self,name,item)
 
710
        menu.InsertItem(0,item) 
 
711
        #method
 
712
        method_name = 'on_'+name
 
713
        method      = new.instancemethod(method,self, self.__class__)
 
714
        setattr(self, method_name, method)
 
715
        #bind item & method
 
716
        self.Bind(wx.EVT_MENU, method,item)
 
717
        #return id
 
718
        return item.GetId()
 
719
 
668
720
#---Image Inspector
669
721
class ImageInspectorApp(wx.App):
670
722
    def __init__(self,paths,*args,**keyw):
673
725
        
674
726
    def OnInit(self):
675
727
        wx.InitAllImageHandlers()
 
728
        _theme()
676
729
        if not self.paths: self.paths = ['']
677
730
        for path in self.paths:
678
731
            frame   = imageInspector.SingleFrame(None,filename=path,
679
732
                    size=imageInspector.SIZE)
 
733
            _icon(frame)
680
734
            frame.Show()
681
735
        self.SetTopWindow(frame)
682
736
        return 1
725
779
        self.SetTopWindow(frame)
726
780
        return 1
727
781
    
728
 
    def get_library_files(self):
 
782
    def get_action_list_files(self):
729
783
        global_library  = glob.glob(os.path.join(
730
 
            self.settings["PHATCH_LIBRARY_PATH"],'*'+ct.EXTENSION))
 
784
            self.settings["PHATCH_ACTIONLISTS_PATH"],'*'+ct.EXTENSION))
731
785
        local_library   = glob.glob(os.path.join(
732
 
            ct.LIBRARY_PATH,'*'+ct.EXTENSION))
 
786
            ct.USER_ACTIONLISTS_PATH,'*'+ct.EXTENSION))
733
787
        return global_library+local_library
734
788
    
735
789
    def get_action_list(self,file_list):
736
790
        if not file_list:
737
 
            file_list   = self.get_library_files()
 
791
            file_list   = self.get_action_list_files()
738
792
        d   = {}
739
793
        for f in file_list:
740
794
            d[api.title(f)] = f