File: colors.py

package info (click to toggle)
gnat-gps 4.3-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 49,096 kB
  • ctags: 20,461
  • sloc: ada: 274,120; ansic: 154,849; python: 9,890; tcl: 9,812; sh: 8,192; xml: 7,970; cpp: 4,737; yacc: 3,520; makefile: 2,136; lex: 2,043; java: 1,638; perl: 302; awk: 265; sed: 161; asm: 14; fortran: 2; lisp: 1
file content (30 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## This script sets the background color of .adb files and .ads files
## automatically when they are loaded.
## It demonstrates the use of hooks, and the setting of preferences in GPS

import GPS

def set_bg_color (hook_name, file):
   name = file.name()
   if name [len(name) - 4 :] == ".adb":
      GPS.Editor.set_background_color (file.name(), GPS.Preference ("custom-adb-file-color").get())
   elif name [len(name) - 4 :] == ".ads":
      GPS.Editor.set_background_color (file.name(), GPS.Preference ("custom-ads-file-color").get())



GPS.parse_xml ("""
   <preference name="custom-adb-file-color"
               label="Background color for .adb files"
               page="Editor:Fonts &amp; Colors"
               default="yellow"
               type="color" />
   <preference name="custom-ads-file-color"
               label="Background color for .ads files"
               page="Editor:Fonts &amp; Colors"
               default="red"
               type="color" />
""")

GPS.Hook ("file_edited").add (set_bg_color)