📄 np_printplot.py
字号:
#! /usr/bin/env python################################################################################ ## Copyright 2005 University of Cambridge Computer Laboratory. ## ## This file is part of Nprobe. ## ## Nprobe is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## Nprobe is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Nprobe; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## ############################################################################################################################################################### #### Hardcopy np_plot## #### ############################################################################from Tkinter import *import osimport sysfrom signal import *import stringfrom np_widgets import Dialogue, BetterEntryimport np_plotimport tempfileimport commandsimport typesfrom warnings import filterwarnings############################################################################################################################################################LPR_MONO_DEF = 'lpr -Ppalm'LPR_COL_DEF = 'lpr -Ppalm'############################################################################################################################################################## Hardcopy file already exists - over print, cancel, or save as other?#class OverPrint(Dialogue): def body(self, master): #print 'overprint' startrow = 0 if self.msg: Label(master, text=self.msg, bg='grey', fg='red').grid(row=0, columnspan = 2) startrow = 1 self.ents = [] if self.entries: for ent in self.entries: Label(master, text=ent[0], bg='grey').grid(row=startrow) e = BetterEntry(master) e.configure(bg='grey', width = len(ent[1])) e.grid(row=startrow, column=1) e.insert(INSERT, ent[1]) self.ents.append(e) return self.ents[0] def apply(self): if self.results != None: for e in self.ents: self.results.append(e.get())############################################################################################################################################################class PrintParams: pass############################################################################################################################################################class PrintControl(Toplevel): def __init__(self, master, plot=None, params=None, title=None): Toplevel.__init__(self, master) self.transient(master) if title: self.title(title) self.master = master if params: self.params = params if plot: self.plot = plot self.canv = plot.canvasses[plot.canv_curr] self.make_params() self.configure(bg='grey') body = Frame(self, bg='grey') self.initial_focus = self.body(body) body.pack(padx=5, pady=5) body.configure(bg='grey') self.grab_set() if not self.initial_focus: self.initial_focus = self self.protocol("WM_DELETE_WINDOW", self.cancel) ypos = master.winfo_rooty()/2 #self.geometry("+%d+%d" % (master.winfo_rootx(),ypos)) self.initial_focus.focus_set() self.wait_window(self) def body(self, master): p = self.params self.set_ents = [] row = 0 entwi = max([len(p.title), len(p.xlabel), len(p.ylabel), len(p.lpr), len(p.file)]) for set in p.sets: entwi = max([entwi, len(set.path)]) # Title entry Label(master, text='Title', bg='grey').grid(row=row, column=0, sticky=W) self.title_entry = BetterEntry(master) self.title_entry.configure(bg='grey', width=entwi) self.title_entry.grid(row=row, column=1, columnspan=6) self.title_entry.insert(INSERT, p.title) row = row + 1 # Space Label(master, text='', bg='grey').grid(row=row, column=0) row = row + 1 # Xlabel entry Label(master, text='x label', bg='grey').grid(row=row, column=0, sticky=W) self.xlabel_entry = BetterEntry(master) self.xlabel_entry.configure(bg='grey', width=entwi) self.xlabel_entry.grid(row=row, column=1, columnspan=5) self.xlabel_entry.insert(INSERT, p.xlabel) row = row + 1 # Ylabel entry Label(master, text='y label', bg='grey').grid(row=row, column=0, sticky=W) self.ylabel_entry = BetterEntry(master) self.ylabel_entry.configure(bg='grey', width=entwi) self.ylabel_entry.grid(row=row, column=1, columnspan=5) self.ylabel_entry.insert(INSERT, p.ylabel) row = row + 1 # Individual data set labels i = 0 for set in p.sets: Label(master, text='Plot %d' % (i), bg='grey').grid(row=row, column=0, sticky=W) entry = BetterEntry(master) entry.configure(bg='grey', width=entwi) entry.grid(row=row, column=1, columnspan=5) entry.insert(INSERT, set.path) if set.hidden[-1]: entry.configure(state=DISABLED, fg='grey56') self.set_ents.append(entry) i = i + 1 row = row + 1 # Space Label(master, text='', bg='grey').grid(row=row, column=0, sticky=W) row = row + 1 # Hardcopy selector Label(master, text='Hardcopy', bg='grey').grid(row=row, column=0, sticky=W) self.dohard = IntVar() b = Checkbutton(master, text='Print', variable=self.dohard, bg='grey', activeforeground='red', indicatoron=0, activebackground='grey', selectcolor='grey', command=self.hbcb) b.grid(row=row, column=1) #Label(master, text=' Lpr', bg='grey').grid(row=row, column=2) # Colour/mono print selector self.printmode = StringVar() self.printmode.set('mono') self.monoprint = Radiobutton(master, text='Mono', variable=self.printmode, value='mono', command=self.set_printmode, bg='grey', indicatoron=0, selectcolor='grey') self.monoprint.grid(row=row, column=3, sticky=E) self.colprint = Radiobutton(master, text=' Col ', variable=self.printmode, value='col', command=self.set_printmode, bg='grey', indicatoron=0, selectcolor='red') self.colprint.grid(row=row, column=4) # Lpr command self.lpr_entry = BetterEntry(master) self.lpr_entry.configure(bg='grey') self.lpr_entry.grid(row=row, column=5, columnspan=2, sticky=W) self.lpr_entry.insert(INSERT, p.lpr) row = row + 1 # Save postscript selector Label(master, text='Postscript', bg='grey').grid(row=row, column=0, sticky=W) self.dosave = IntVar() b = Checkbutton(master, text='Save', variable=self.dosave, bg='grey', onval=1, offval=0, indicatoron=0, activebackground='grey', activeforeground='blue', selectcolor='grey', command=self.sbcb) b.grid(row=row, column=1) Label(master, text=' File', bg='grey').grid(row=row, column=2) self.file_entry = BetterEntry(master) self.file_entry.configure(bg='grey', width=entwi) self.file_entry.grid(row=row, column=3, columnspan=4) self.file_entry.insert(INSERT, p.file) row = row + 1 # Save raw data selector (only if not stand alone plotter self.dodata = IntVar() self.dodata.set(0) l = Label(master, text='Raw data', bg='grey') b = Checkbutton(master, text='Save', variable=self.dodata, bg='grey', indicatoron=0, activebackground='grey', activeforeground='blue', selectcolor='grey', command=self.dsbcb) L = Label(master, text=' File', bg='grey') e = self.datafile_entry = BetterEntry(master) self.datafile_entry.configure(bg='grey', width=entwi) basedir = os.path.dirname(self.strip_dot(self.plot.path)) basename = os.path.basename(self.plot.path) if self.plot.title: dee = os.path.join(basedir, self.plot.title) else: dee = os.path.join(basedir, basename) if len(self.plot.sets) > 1: dee += '.*' self.datafile_entry.insert(INSERT, dee) # only show if appropriate #if not self.plot.raw_data: if 1: l.grid(row=row, column=0, sticky=W) b.grid(row=row, column=1) L.grid(row=row, column=2) e.grid(row=row, column=3, columnspan=4) row = row + 1 # Space Label(master, text='', bg='grey').grid(row=row, column=0, sticky=W) row = row + 1 # OK/Cancel buttons self.okb = Button(master, text=' OK ', bg='grey', fg='grey56', command = self.ok, state=DISABLED) self.okb.grid(row=row, column=0, columnspan=2) Button(master, text='Cancel', bg='grey', command=self.cancel).grid(row=row, column=2, columnspan=2) # Initialise self.dohard.set(0) self.dohard2 = 1 self.hbcb() # Initialise disabled state self.dosave.set(0) self.dosave2 = 1 self.sbcb() # Initialise disabled state self.dodata.set(0) self.dodata2 = 1 self.dsbcb() # Initialise disabled state return self.title_entry ############################################################################## def set_printmode(self): mode = self.printmode.get() if mode == 'mono': self.params.lpr = LPR_MONO_DEF self.lpr_entry.delete(0, INSERT) self.lpr_entry.insert(INSERT, LPR_MONO_DEF) else: self.params.lpr = LPR_COL_DEF self.lpr_entry.delete(0, INSERT) self.lpr_entry.insert(INSERT, LPR_COL_DEF) ############################################################################## def hbcb(self): # # IntVar associated with button does not work in all circumstances # - patch by toggling normal variable, retain IntVar for button control # if self.dohard2 == 0: self.dohard2 = 1 else: self.dohard2 = 0 self.dohard.set(self.dohard2) val = self.dohard.get() if val == 0: self.lpr_entry.configure(state=DISABLED, fg='grey56') self.monoprint.configure(state=DISABLED, fg='grey56') self.colprint.configure(state=DISABLED, fg='grey56', selectcolor='grey') else: self.lpr_entry.configure(state=NORMAL, fg='black') self.monoprint.configure(state=NORMAL, fg='black') self.colprint.configure(state=NORMAL, fg='black', selectcolor='red') self.set_okb() ############################################################################## def sbcb(self): if self.dosave2 == 0: self.dosave2 = 1 else: self.dosave2 = 0 self.dosave.set(self.dosave2) val = self.dosave.get() if val == 0: self.file_entry.configure(state=DISABLED, fg='grey56') else: self.file_entry.configure(state=NORMAL, fg='black') self.set_okb() ############################################################################## def dsbcb(self): if self.dodata2 == 0: self.dodata2 = 1 else: self.dodata2 = 0 self.dodata.set(self.dodata2) val = self.dodata.get() if val == 0: self.datafile_entry.configure(state=DISABLED, fg='grey56') else: self.datafile_entry.configure(state=NORMAL, fg='black') self.set_okb() ############################################################################## def set_okb(self): if self.dohard.get() or self.dosave.get() or self.dodata.get(): self.okb.configure(fg='black', state=NORMAL) else: self.okb.configure(fg='grey56', state=DISABLED) ############################################################################## def save_data(self):
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -