Changeset 1452

Show
Ignore:
Timestamp:
07/03/08 16:02:17 (5 months ago)
Author:
rob
Message:

Fixed #476 and #477: Added user directory for saved themes
* changed the Fonts class to use a style directory rather than the single styles.ess file
* changed editra.util.GetResourceFiles? to look at peppy font directory
* changed stcmixin.GetStyleSheet? to find user styles
* added additional dialog after the style editor to save the file to a (possibly) new name
* moved the global_style_set hack into Fundamental, which seems to solve the background color problems
* synced with Editra svn 54481

Location:
trunk/peppy
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/configprefs.py

    r1423 r1452  
    6565            d = self.dir 
    6666        return os.path.exists(d) 
     67     
     68    def contents(self, subdir): 
     69        path = self.fullpath(subdir) 
     70        if os.path.exists(path): 
     71            return path, os.listdir(path) 
     72        return None, [] 
    6773 
    6874    def open(self, name, mode='r'): 
  • trunk/peppy/editra/ed_style.py

    r1446 r1452  
    2121 
    2222__author__ = "Cody Precord <cprecord@editra.org>" 
    23 __svnid__ = "$Id: ed_style.py 54467 2008-07-02 19:51:00Z CJP $" 
    24 __revision__ = "$Revision: 54467 $" 
     23__svnid__ = "$Id: ed_style.py 54472 2008-07-03 03:28:11Z CJP $" 
     24__revision__ = "$Revision: 54472 $" 
    2525 
    2626#--------------------------------------------------------------------------# 
     
    341341        """ 
    342342        sty_dict = dict() 
    343         for key in self.GetStyleSet().keys(): 
     343        for key in DefaultStyleDictionary().keys(): 
    344344            if key in ('select_style', 'whitespace_style'): 
    345345                sty_dict[key] = NullStyleItem() 
     
    424424        return fore 
    425425 
     426    def GetCurrentStyleSetName(self): 
     427        """Get the name of the currently set style 
     428        @return: string 
     429 
     430        """ 
     431        return self.style_set 
     432 
    426433    def GetDefaultBackColour(self, as_hex=False): 
    427434        """Gets the background color of the default style and returns 
     
    527534        elif not StyleMgr.STYLES.has_key(style_sheet): 
    528535            self.LOG("[ed_style][warn] Style sheet %s does not exists" % style_sheet) 
     536            # Reset to default style 
     537            Profile_Set('SYNTHEME', 'default') 
    529538            self.SetStyles('default', DefaultStyleDictionary()) 
    530539            return False 
     
    699708 
    700709        # For any undefined tags load them as empty items 
    701         for key in DefaultStyleDictionary().keys(): 
    702             if key not in style_dict: 
    703                 style_dict[key] = StyleItem() 
     710#        for key in DefaultStyleDictionary().keys(): 
     711#            if key not in style_dict: 
     712#                style_dict[key] = StyleItem() 
    704713 
    705714        return style_dict 
     
    766775 
    767776            self.style_set = name 
     777            defaultd = DefaultStyleDictionary() 
     778            dstyle = style_dict.get('default_style', None) 
     779            if dstyle is None: 
     780                style_dict['default_style'] = defaultd['default_style'] 
     781 
    768782            # Set any undefined styles to match the default_style 
    769             for tag, item in DefaultStyleDictionary().iteritems(): 
     783            for tag, item in defaultd.iteritems(): 
    770784                if tag not in style_dict: 
    771785                    if tag in ['select_style', 'whitespace_style']: 
    772786                        style_dict[tag] = NullStyleItem() 
    773                     elif tag in ['foldmargin_style']: 
     787                    else: 
    774788                        style_dict[tag] = style_dict['default_style'] 
    775                     else: 
    776                         style_dict[tag] = item 
    777789 
    778790            StyleMgr.STYLES[name] = self.PackStyleSet(style_dict) 
  • trunk/peppy/editra/profiler.py

    r1444 r1452  
    1414            return font 
    1515        elif index == 'SYNTHEME': 
    16             theme = 'Default' 
     16            theme = app.fonts.classprefs.editra_style_theme 
    1717            return theme 
    1818    except: 
     
    2121    return None 
    2222 
    23 def Profile_Set(index, val, fmt): 
     23def Profile_Set(index, val, fmt=None): 
     24    app = wx.GetApp() 
     25    if index == 'SYNTHEME': 
     26        app.fonts.classprefs.editra_style_theme = val 
    2427    return None 
  • trunk/peppy/editra/stcmixin.py

    r1448 r1452  
    288288        self.LOG(syn_lst) 
    289289        valid_settings = list() 
    290          
    291         # Here's the global hack to fix the problem the first time styles are 
    292         # modified by the style dialog. 
    293         if self.global_style_set: 
    294             self.style_set = self.global_style_set 
    295         self.dprint(self.style_set) 
    296290         
    297291        for syn in syn_lst: 
     
    369363 
    370364        """ 
     365        self.dprint("current=%s" % self.style_set) 
    371366        self.StyleDefault() 
    372367        self.SetMargins(0, 0) 
     
    396391 
    397392        """ 
     393        self.dprint("requested=%s current=%s" % (spec_style, self.style_set)) 
    398394        if spec_style != self.style_set: 
    399395            self.LoadStyleSheet(self.GetStyleSheet(spec_style), force=True) 
     
    463459                style = sheet 
    464460                break 
    465         dprint(style) 
     461        user = wx.GetApp().fonts.getStylePath(style) 
     462        if os.path.exists(user): 
     463            self.dprint("found user style %s at %s" % (style, user)) 
     464            return user 
    466465        sysp = os.path.join(util.GetResourceDir('styles'), style) 
    467466        if os.path.exists(sysp): 
     467            self.dprint("found system style %s at %s" % (style, sysp)) 
    468468            return sysp 
     469        self.dprint("didn't find %s" % style) 
    469470#        user = os.path.join(ed_glob.CONFIG['STYLES_DIR'], style) 
    470471#        sysp = os.path.join(ed_glob.CONFIG['SYS_STYLES_DIR'], style) 
  • trunk/peppy/editra/style_editor.py

    r1449 r1452  
    379379                self.styles_new = DuplicateStyleDict(self.styles_orig) 
    380380                self.preview.SetStyles('preview', self.styles_new, nomerge=True) 
    381                 self.preview.UpdateBaseStyles() 
     381                self.preview.UpdateAllStyles('preview') 
    382382 
    383383                # For some reason this causes the text display to refresh 
  • trunk/peppy/editra/util.py

    r1444 r1452  
    2323    return rec_dir 
    2424 
    25 def GetResourceFiles(resource, trim=True, get_all=False, title=True): 
     25def GetResourceFiles(resource, trim=True, get_all=False, title=False): 
    2626    """Gets a list of resource files from a directory and trims the 
    2727    file extentions from the names if trim is set to True (default). 
     
    3939    rec_dir = GetResourceDir(resource) 
    4040    rec_list = list() 
    41     if not os.path.exists(rec_dir): 
    42         return -1 
    43     else: 
     41    if get_all: 
     42        user_dir, user_files = wx.GetApp().config.contents(resource) 
     43        #dprint("path=%s contents=%s" % (user_dir, user_files)) 
     44        for rec in user_files: 
     45            if os.path.isfile(os.path.join(user_dir, rec)): 
     46                if trim: 
     47                    rec = rec.split(u".")[0] 
     48                if title: 
     49                    rec = rec.title() 
     50                rec_list.append(rec) 
     51    if os.path.exists(rec_dir): 
    4452        recs = os.listdir(rec_dir) 
    4553        #dprint(recs) 
     
    5159                    rec = rec.title() 
    5260                rec_list.append(rec) 
    53         rec_list.sort() 
    54         return list(set(rec_list)) 
     61    return list(set(rec_list)) 
    5562     
    5663def GetExtension(file_str): 
  • trunk/peppy/fundamental.py

    r1448 r1452  
    137137    #: Default class preferences that relate to all instances of this major mode 
    138138    default_classprefs = ( 
    139         StrParam('editra_style_sheet', '', 'Mode specific filename in the config directory containing Editra style sheet information.  Used to override default styles with custom styles for this mode.'), 
    140139        BoolParam('use_tab_characters', False, 
    141140                  'True: insert tab characters when tab is pressed.  False: insert the equivalent number of spaces instead.', local=True), 
     
    326325        self.SetStyleFont(wx.GetApp().fonts.classprefs.secondary_editing_font, False) 
    327326        self.dprint("font styling done in %0.5fs" % (time.time() - start)) 
     327 
     328        # Here's the global hack to fix the problem the first time styles are 
     329        # modified by the style dialog. 
     330        if self.global_style_set and self.global_style_set != self.style_set: 
     331            self.style_set = self.global_style_set 
     332            self.dprint("Changing style to global style %s" % self.style_set) 
    328333        self.ConfigureLexer(self.editra_lang) 
    329         self.dprint("styleSTC (if True) done in %0.5fs" % (time.time() - start)) 
     334        self.dprint("ConfigureLexer done in %0.5fs" % (time.time() - start)) 
    330335        self.has_stc_styling = True 
    331336        self.setEmacsAndVIM() 
  • trunk/peppy/main.py

    r1448 r1452  
    55""" 
    66 
    7 import os, sys, imp, platform, random, string 
     7import os, sys, imp, platform, random, string, time 
    88import __builtin__ 
    99 
     
    7878        FontParam('primary_editing_font', None, 'Font name of the primary editing font', fullwidth=True), 
    7979        FontParam('secondary_editing_font', None, 'Font name of the secondary scintilla font', fullwidth=True), 
    80         StrParam('editra_style_sheet', 'styles.ess', 'Filename in the config directory containing Editra style sheet information'), 
     80        StrParam('editra_style_theme', 'Default', 'Current Editra style theme'), 
    8181    ) 
    8282    if wx.Platform == "__WXMAC__": 
     
    8484    else: 
    8585        default_fontsize = 10 
     86     
     87    first_time = True 
    8688 
    8789    def __init__(self): 
     
    9395            self.classprefs.secondary_editing_font = wx.Font(self.default_fontsize, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL) 
    9496 
     97    def getStylePath(self, name=None): 
     98        c = wx.GetApp().config 
     99        path = c.fullpath('styles') 
     100        if not os.path.exists(path): 
     101            c.create('styles') 
     102            #dprint("created %s" % path) 
     103             
     104            # Handle conversion from old-style 'styles.ess' to new style 
     105            # directory of style files 
     106            if self.__class__.first_time: 
     107                source = c.fullpath('styles.ess') 
     108                #dprint("Looking for %s to rename" % source) 
     109                if os.path.exists(source): 
     110                    dest = os.path.join(path, '%s.ess' % time.strftime("%Y%m%d", time.localtime(time.time()))) 
     111                    os.rename(source, dest) 
     112                self.__class__.first_time = False 
     113        if name: 
     114            if not name.endswith(".ess"): 
     115                name += ".ess" 
     116            path = os.path.join(path, name) 
     117        return path 
     118 
    95119    def getStyleFile(self, mode=None): 
    96         if mode: 
    97             # Find style sheet override if the mode specifies it 
    98             filename = mode.classprefs.editra_style_sheet 
    99         else: 
    100             filename = '' 
    101         if not filename: 
    102             filename = self.classprefs.editra_style_sheet 
    103         pathname = wx.GetApp().getConfigFilePath(filename) 
     120        pathname = self.getStylePath(self.classprefs.editra_style_theme) 
    104121        #dprint(pathname) 
    105122        return pathname 
  • trunk/peppy/plugins/editra_styleeditor.py

    r1446 r1452  
    3838        retval = dlg.ShowModal() 
    3939        if retval == wx.ID_OK: 
    40             styles = ed_style.MergeStyles(dlg.preview.BlankStyleDictionary(), dlg.styles_new) 
    41             dlg.preview.SetStyles(stylesheet, styles, True) 
    42             EditraSTCMixin.global_style_set = stylesheet 
    43             sheet = dlg.GenerateStyleSheet() 
    44             dprint(sheet) 
    45             fh = wx.GetApp().config.open(stylesheet, 'wb') 
    46             fh.write(sheet) 
    47             Publisher().sendMessage('peppy.preferences.changed') 
     40            # Find style name from controls within the dialog 
     41            ctrl = dlg.FindWindowById(style_editor.ed_glob.ID_PREF_SYNTHEME) 
     42            tag = ctrl.GetStringSelection() 
     43            ctrl = dlg.FindWindowById(wx.ID_NEW) 
     44            if ctrl.GetValue(): 
     45                tag = "untitled" 
     46            dlg2 = wx.TextEntryDialog( 
     47                self.frame, message="Save Style Sheet", defaultValue=tag, 
     48                style=wx.OK|wx.CANCEL) 
     49            retval = dlg2.ShowModal() 
     50            tag = dlg2.GetValue() 
     51            if not tag: 
     52                tag = "untitled" 
     53            dlg2.Destroy() 
     54             
     55            if retval == wx.ID_OK: 
     56                #dprint("Saving style to %s" % tag) 
     57                filename = wx.GetApp().fonts.getStylePath(tag) 
     58 
     59                styles = ed_style.MergeStyles(dlg.preview.BlankStyleDictionary(), dlg.styles_new) 
     60                dlg.preview.SetStyles(filename, styles, True) 
     61                EditraSTCMixin.global_style_set = filename 
     62                sheet = dlg.GenerateStyleSheet() 
     63                #dprint(sheet) 
     64                fh = open(filename, 'wb') 
     65                fh.write(sheet) 
     66                wx.GetApp().fonts.classprefs.editra_style_theme = tag 
     67                Publisher().sendMessage('peppy.preferences.changed') 
    4868        elif retval == wx.ID_SAVE: 
    4969            dprint("Save!")