예제 #1
0
def load_ramp_config_file():
    """
    Reads in ramp files specified in the ramp config file
    in the ramps directory and creates ramps for them

    This allows for ordering of the ramps in the config
    file and for specifying separators
    """
    ramps = []
    home_dir = gview.home_dir
    ramp_dir = gview.get_preference('ramp_directory')
    if ramp_dir is None:
        ramp_dir = os.path.join(home_dir, 'ramps')
    if os.path.isdir(ramp_dir):
        config_path = os.path.join(ramp_dir, 'ramps.cfg')
        if os.path.isfile(config_path):
            #load config file and parse ramps ...
            config = open(config_path)
            lines = config.readlines()
            for line in lines:
                ramp_file = line.strip()
                ramp = load_ramp(os.path.join(ramp_dir, ramp_file))
                if ramp:
                    ramps.append(ramp)
        else:
            return load_ramps()

    return ramps
예제 #2
0
def tempnam( tdir = None, basename = None, extension = None ):
    import gview

    if tdir is None:
        plotfile = gview.get_preference('gvplot_tempfile')
        if plotfile is not None and len(plotfile) > 0:
            if os.path.isdir(plotfile):
                tdir = plotfile
            elif os.path.isdir(os.path.dirname(plotfile)):
                tdir = os.path.dirname(plotfile)
            else:
                tdir = get_tempdir()
        else:
            tdir = get_tempdir()

    if basename is None:
        try:
            pgu.pnm = pgu.pnm + 1
        except:
            pgu.pnm = 1
        basename = 'OBJ_' + str(pgu.pnm)

    if extension is None:
        extension = 'tmp'

    return os.path.join(tdir,basename + '.' + extension)        
예제 #3
0
    def gui_update(self, *args):
        self.updating = True

        # Update the field list.
        fnlist = [_("disabled")]
        if self.layer:
            schema = self.layer.get_parent().get_schema()
            for item in schema:
                fnlist.append(item[0])

        if fnlist != self.old_list:
            self.label_field.set_popdown_strings(fnlist)
            self.old_list = fnlist

        self.label_field.set_active(-1)

        if self.ogrfs_obj:
            font = self.ogrfs_obj.parms['f'].value
            if not font:
                font = gview.get_preference('default-font')
            self.label_font.set_font_name(font)

            tparm = self.ogrfs_obj.parms['t']
            if tparm.role == 'field_name':
                self.label_field.set_active_text(tparm.value)
                if self.shape_obj:
                    text_value = self.shape_obj.get_property(tparm.value,'')
                else:
                    text_value = ''
            else:
                self.label_field.set_active_text("disabled")
                text_value = tparm.value

            color = self.ogrfs_obj.get_color((0.5, 1.0, 0.5, 1.0))
            self.label_color.set_color(color)

            if self.text_entry:
                self.text_entry.set_text(text_value)
                #self.text_entry.set_sensitive(tparm.role != 'field_name')

            if self.enable_offsets:
                dx = float(self.ogrfs_obj.get_parm('dx',0))
                self.x_offset.set_value(dx)
                dy = float(self.ogrfs_obj.get_parm('dy',0))
                self.y_offset.set_value(-dy)

        else:
            self.label_field.set_active_text("disabled")
            self.label_color.set_color( (0.5, 1.0, 0.5, 1.0) )
            if self.enable_offsets:
                self.x_offset.set_value(0.0)
                self.y_offset.set_value(0.0)

        self.updating = False
예제 #4
0
def load_ramps():
    """reads in all the ramp files in the ramps directory and creates ramps for them"""
    ramps = []
    home_dir = gview.home_dir
    ramp_dir = gview.get_preference('ramp_directory')
    if ramp_dir is None:
        ramp_dir = os.path.join(home_dir, 'ramps')
    if os.path.isdir(ramp_dir):
        files = os.listdir(ramp_dir)
        for file in files:
            ramp = load_ramp(os.path.join(ramp_dir, file))
            if ramp:
                ramps.append(ramp)
    return ramps
예제 #5
0
    def set_ogrfs(self, ogrfs_obj, layer=None, fontlist=None, shape_obj=None):
        if layer is not None:
            self.layer = layer

        if ogrfs_obj is None:
            ogrfs_obj = gvogrfs.OGRFeatureStylePart()
            font = gview.get_preference('default-font','Sans 12')
            if self.enable_offsets:
                dx = self.x_offset.get_value()
                dy = self.y_offset.get_value()
            ogrfs_obj.parse('LABEL(t:"",f:"%s",c:#88FF88)' % font)

        self.ogrfs_obj = ogrfs_obj
        self.shape_obj = shape_obj

        self.gui_update()
예제 #6
0
    def __init__(self, view):
        gtk.Window.__init__(self)
        self.set_title(_("Print"))
        self.connect('delete-event',self.close)
        self.view = view
        self.command = gview.get_preference('print_command', 'lpr')

        cgroup = gtk.VBox(spacing=6)
        cgroup.set_border_width(5)
        self.add(cgroup)
        frame = gtk.Frame()
        cgroup.pack_start(frame, expand=False)

        table = gtk.Table()
        table.set_row_spacings(6)
        table.set_border_width(5)
        frame.add(table)

        # Setup Driver Option Menu
        driver_label = pgu.Label(_("Driver:"))
        table.attach(driver_label, 0,1,0,1, yoptions=gtk.SHRINK)
        if os.name == 'nt':
            drivers = ("PostScript", "TIFF", "PNG", "Windows Print Driver", "GIF")
        else:
            drivers = ("PostScript", "TIFF", "PNG", "GIF")
        self.driver = pgu.ComboText(strings=drivers, action=self.update_cb)
        table.attach(self.driver, 1,2,0,1, yoptions=gtk.SHRINK)

        # Setup Device Option Menu
        device_label = pgu.Label(_("Device:"))
        table.attach(device_label, 0,1,1,2, yoptions=gtk.SHRINK)
        self.device = pgu.ComboText(strings=(_("File"), _("Spool to Printer")), action=self.device_cb)
        table.attach(self.device, 1,2,1,2, yoptions=gtk.SHRINK)

        # Setup File/Command entry.
        self.file_label = pgu.Label(_("File:"))
        table.attach(self.file_label, 0,1,2,3, yoptions=gtk.SHRINK)
        self.file = gtk.Entry()
        table.attach(self.file, 1,2,2,3, yoptions=gtk.SHRINK)

        # Setup Output Type
        self.output_label = pgu.Label(_("Output type:"))
        table.attach(self.output_label, 0,1,3,4, yoptions=gtk.SHRINK)
        self.output = pgu.ComboText(strings=(_("Greyscale"), _("Color")))
        table.attach(self.output, 1,2,3,4, yoptions=gtk.SHRINK)

        # Setup Paper Type
        self.paper_label = pgu.Label(_("Paper:"))
        table.attach(self.paper_label, 0,1,4,5, yoptions=gtk.SHRINK)
        sizes = []
        for entry in paper_sizes:
            sizes.append(entry[0])
        self.paper = pgu.ComboText(strings=sizes, action=self.update_cb)
        table.attach(self.paper, 1,2,4,5, yoptions=gtk.SHRINK)

        # Setup Scale slider
        self.scale_label = pgu.Label(_("Scale:"))
        table.attach(self.scale_label, 0,1,5,6, yoptions=gtk.SHRINK)
        self.scale_adjustment = gtk.Adjustment(1, 0, 1.25, 0.05, 0.05, 0.05)
        self.scale_slider = gtk.HScale(self.scale_adjustment)
        table.attach(self.scale_slider, 1,2,5,6, yoptions=gtk.SHRINK)

        # Setup Resolution spinner
        resolution_label = pgu.Label(_("Resolution:"))
        table.attach(resolution_label, 0,1,6,7, yoptions=gtk.SHRINK)
        self.resolution_adjustment = gtk.Adjustment(1, 0, 10, 0.1, 0.1, 0.1)
        self.resolution_spinner = gtk.SpinButton(self.resolution_adjustment, climb_rate=0.1, digits=1)
        self.resolution_spinner.connect('changed', self.resolution_cb)
        table.attach(self.resolution_spinner, 1,2,6,7, yoptions=gtk.SHRINK)

        # Setup Size entries
        size_label = pgu.Label(_("Image size:"))
        table.attach(size_label,0,1,7,8, yoptions=gtk.SHRINK)
        size_box = gtk.HBox(spacing=5)

        self.xsize_entry = gtk.Entry()
        self.xsize_entry.connect('activate', self.resolution_cb)
        self.xsize_entry.connect('leave-notify-event', self.resolution_cb)
        size_box.pack_start(self.xsize_entry)
        size_box.pack_start(gtk.Label("x"))

        self.ysize_entry = gtk.Entry()
        self.ysize_entry.connect('activate', self.resolution_cb)
        self.ysize_entry.connect('leave-notify-event', self.resolution_cb)
        size_box.pack_start(self.ysize_entry)
        table.attach(size_box, 1,2,7,8, yoptions=gtk.SHRINK)

        # Add Print, and Close button(s)
        btn_box = gtk.HBox(homogeneous=True, spacing=20)

        but = gtk.Button(stock=gtk.STOCK_PRINT)
        but.connect('clicked',self.print_cb)
        btn_box.pack_start(but, expand=False)

        but = gtk.Button(stock=gtk.STOCK_CLOSE)
        but.connect('clicked',self.close)
        btn_box.pack_start(but, expand=False)

        cgroup.pack_end(btn_box, expand=False)

        # Initialize values.
        # lazy
        prefs = gview.get_preference
        pref = prefs('print_driver', -1)
        self.driver.set_active(int(pref))
        if os.name == 'nt':
            self.driver.set_active(DR_WINPRINT)

        pref = prefs('print_device', -1)
        self.device.set_active(int(pref))

        if self.device.get_active() == DV_FILE:
            self.set_default_filename()
        else:
            self.file.set_text(self.command)

        pref = prefs('print_paper', -1)
        self.paper.set_active(int(pref))

        pref = prefs('print_output', -1)
        self.output.set_active(int(pref))

        pref = prefs('print_resolution')
        if pref:
            resolution = float(pref)
            self.resolution_adjustment.set_value(resolution)
            width = int(self.view.get_width() * resolution + 0.5)
            height = int(self.view.get_height() * resolution + 0.5)
            self.xsize_entry.set_text(str(width))
            self.ysize_entry.set_text(str(height))

        self.set_paper_size()
        self.scale_adjustment.set_value(1.0)

        if 'CIETMAP_HOME' in os.environ:
            topic = "Pages/Printing.htm"
            self.filename = 'cietmap.ps'
        else:
            topic = "gvprint.html"
            self.filename = 'openev.ps'
        set_help_topic(self, topic)
        # Show
        self.show_all()
        self.update_cb()