コード例 #1
0
ファイル: ptable.py プロジェクト: abigelow1/pype2
    def load(self, file=None):
        """
		Load pickled table database - note that the pickled dictionary
		will be unpickled, but only those values referenced in the table
		will actually be used.	The rest (ie, obsolete) are discarded.
		This way you can safely inherit from previous modules w/o
		accumulating excess garbage.
		"""
        if file is None:
            file = self._file

        if self._load(file=file) == 1:
            return

        if self.altfile:
            if self._load(file=pype.subjectrc(self.altfile)) == 1:
                Logger('warning: loaded %s\n' % \
                    pype.subjectrc(self.altfile))
                return

        try:
            initialdir = pype.subjectrc('')
        except KeyError:
            initialdir = os.getcwd()

        while 1:
            (file, mode) = Open(initialdir=initialdir,
                                initialfile=self.tablename)
            if file is None:
                warn('Warning', 'Using defaults for "%s".\n' % self.tablename)
                return
            if self._load(file=file) == 1:
                sys.stderr.write("Loaded params from '%s'\n" % file)
                return
コード例 #2
0
ファイル: ptable.py プロジェクト: mazerj/pype2
	def load(self, file=None):
		"""
		Load pickled table database - note that the pickled dictionary
		will be unpickled, but only those values referenced in the table
		will actually be used.	The rest (ie, obsolete) are discarded.
		This way you can safely inherit from previous modules w/o
		accumulating excess garbage.
		"""
		if file is None:
			file = self._file

		if self._load(file=file) == 1:
			return

		if self.altfile:
			if self._load(file=pype.subjectrc(self.altfile)) == 1:
				Logger('warning: loaded %s\n' % \
					   pype.subjectrc(self.altfile))
				return

		try:
			initialdir = pype.subjectrc('')
		except KeyError:
			initialdir = os.getcwd()

		while 1:
			(file, mode) = Open(initialdir=initialdir,
									 initialfile=self.tablename)
			if file is None:
				warn('Warning',
					 'Using defaults for "%s".\n' % self.tablename)
				return
			if self._load(file=file) == 1:
				sys.stderr.write("Loaded params from '%s'\n" % file)
				return
コード例 #3
0
ファイル: userdpy.py プロジェクト: mazerj/pype3
	def loadpoints_ascii(self, filename=None, merge=None):
		"""
		Load points from ascii file.
		One point per line containing X and Y position in
		pixels separated by commas or spaces
		"""
		if filename is None:
			from pype import subjectrc
			(filename, mode) = filebox.Open(initialdir=subjectrc(),
											pattern="*.asc",
											text='Load points from ASCII file')
			if filename is None:
				return
		try:
			fp = open(filename, 'r')
		except IOError:
			return

		if not merge:
			self.clearpoints()

		while 1:
			l = fp.readline()
			if not l:
				break
			if string.find(l, ',') >= 0:
				l = l.split(',')
			else:
				l = l.split()
			px = int(l[0])
			py = int(l[1])
			x = int(round(px + (self.w/2.0)))
			y = int(round((self.h/2.0) - py))
			self.addpoint(x, y)
		fp.close()
コード例 #4
0
ファイル: userdpy.py プロジェクト: mazerj/pype3
	def loadpoints(self, filename=None, merge=None):
		"""Load points from file (pickle file make by savepoints)"""
		if filename is None:
			from pype import subjectrc
			(filename, mode) = filebox.Open(initialdir=subjectrc(),
											pattern="*.pts",
											text='Load points from save file')
			if filename is None:
				return
		try:
			file = open(filename, 'r')
			newpoints = cPickle.load(file)
			file.close()
		except IOError:
			return
		except EOFError:
			return

		if not merge:
			self.clearpoints()

		for n in range(len(newpoints)):
			if len(newpoints[n]) == 3:
				(px, py, t) = newpoints[n]
			else:
				(px, py, t, tb) = newpoints[n]
			x = int(round(px + (self.w/2.0)))
			y = int(round((self.h/2.0) - py))
			self.addpoint(x, y)
コード例 #5
0
ファイル: ptable.py プロジェクト: mazerj/pype3
	def load(self, file=None):
		"""
		Load pickled table database - note that the pickled dictionary
		will be unpickled, but only those values referenced in the table
		will actually be used.	The rest (ie, obsolete) are discarded.
		This way you can safely inherit from previous modules w/o
		accumulating excess garbage.
		"""
		if file is None:
			file = self._file

		if self._load(file=file) == 1:
			return

		if not self._allowalt:
			return

		try:
			initialdir = pype.subjectrc('')
		except KeyError:
			initialdir = os.getcwd()

		while 1:
			(file, mode) = Open(initialdir=initialdir,
								initialfile=self.tablename,
								text='No saved parameter\n'+
								'Select task to inherit params or\n'+
								'Cancel to accept defaults.')
			if file is None:
				return
			if self._load(file=file) == 1:
				sys.stderr.write("Loaded params from '%s'\n" % file)
				return
コード例 #6
0
ファイル: userdpy.py プロジェクト: abigelow1/pype2
    def loadpoints_ascii(self, filename=None, merge=None):
        """
		Load points from ascii file.
		One point per line containing X and Y position in
		pixels separated by commas or spaces
		"""
        if filename is None:
            from pype import subjectrc
            (filename, mode) = filebox.Open(initialdir=subjectrc(),
                                            pattern="*.asc")
            if filename is None:
                return
        try:
            fp = open(filename, 'r')
        except IOError:
            return

        if not merge:
            self.clearpoints()

        while 1:
            l = fp.readline()
            if not l:
                break
            if string.find(l, ',') >= 0:
                l = string.split(l, ",")
            else:
                l = string.split(l)
            px = int(l[0])
            py = int(l[1])
            x = int(round(px + (self.w / 2.0)))
            y = int(round((self.h / 2.0) - py))
            self.addpoint(x, y)
        fp.close()
コード例 #7
0
ファイル: userdpy.py プロジェクト: abigelow1/pype2
    def loadpoints(self, filename=None, merge=None):
        """Load points from file (pickle file make by savepoints)"""
        if filename is None:
            from pype import subjectrc
            (filename, mode) = filebox.Open(initialdir=subjectrc(),
                                            pattern="*.pts")
            if filename is None:
                return
        try:
            file = open(filename, 'r')
            newpoints = cPickle.load(file)
            file.close()
        except IOError:
            return
        except EOFError:
            return

        if not merge:
            self.clearpoints()

        for n in range(len(newpoints)):
            if len(newpoints[n]) == 3:
                (px, py, t) = newpoints[n]
            else:
                (px, py, t, tb) = newpoints[n]
            x = int(round(px + (self.w / 2.0)))
            y = int(round((self.h / 2.0) - py))
            self.addpoint(x, y)
コード例 #8
0
ファイル: userdpy.py プロジェクト: mazerj/pype3
	def savepoints(self, filename=None):
		"""Save points to file"""

		if filename is None:
			from pype import subjectrc
			(filename, mode) = filebox.SaveAs(initialdir=subjectrc(),
											  pattern="*.pts", append=None,
											  text='Save points to file')
		if filename:
			file = open(filename, 'w')
			cPickle.dump(self.points, file)
			file.close()
コード例 #9
0
ファイル: userdpy.py プロジェクト: abigelow1/pype2
    def savepoints(self, filename=None):
        """Save points to file"""

        if filename is None:
            from pype import subjectrc
            (filename, mode) = filebox.SaveAs(initialdir=subjectrc(),
                                              pattern="*.pts",
                                              append=None)
        if filename:
            file = open(filename, 'w')
            cPickle.dump(self.points, file)
            file.close()
コード例 #10
0
ファイル: ptable.py プロジェクト: mazerj/pype2
	def __init__(self, parent, table, file=None, altfile=None,
				 decorate=1, locks=1):
		"""Parameter management table class"""
		self._table = table
		self._entries = {}
		self._locks = {}

		self.tablename = 'noname'

		if file:
			try:
				self._file = pype.subjectrc(file)
			except KeyError:
				self._file = file
			self.tablename = file
		else:
			self._file = None

		self.altfile = altfile

		f = Frame(parent)
		f.pack(expand=0, fill=X, side=TOP)
		self.frame = f
		if self._file:
			Button(f, text='Save',
				   command=self.save).pack(expand=0, fill=X, side=LEFT)

		if decorate:
			Button(f, text="View",
				   command=self.view).pack(expand=0, fill=X, side=LEFT)

		f = Pmw.ScrolledFrame(parent, usehullsize=1)

		f.pack(expand=1, fill=BOTH)
		self.balloon = Pmw.Balloon(parent, master=1, relmouse='both')

		entries = []
		self.names = []
		for slot in self._table:
			(name, default, validate, descr, runlock) = _unpack_slot(slot)
			lf = Frame(f.interior())
			lf.pack(expand=1, fill=X)
			if default is None:
				e = Label(lf, text=name, bg='yellow', anchor=W)
				e.pack(expand=1, fill=X)
			elif None and type(validate) is types.TupleType:
				e = Pmw.RadioSelect(lf,
								   labelpos = 'w',
								   label_text = name + ':')
				e.pack(expand=0, fill=X)
				for o in validate:
					e.add(o)
				e.invoke(default)
			elif type(validate) is types.TupleType:
				e = Pmw.ComboBox(lf,
								 labelpos = 'w',
								 label_text = name + ':',
								 scrolledlist_items = validate)
				e.pack(anchor=W)
				e.selectitem(default)
				self._entries[name] = e
				e.component('entry').configure(state=DISABLED)
			else:
				e = Pmw.EntryField(lf,
								   labelpos = 'w',
								   label_text = name + ':',
								   validate = validate,
								   value = default)
				if descr:
					self.balloon.bind(e, descr)
				else:
					self.balloon.bind(e, "???")
				e.component('entry').configure(bg='white', width=75)
				tmpf = Frame(lf, height=12, width=12)
				tmpf.pack_propagate(0)
				tmpf.pack(side=LEFT)
				if locks:
					if runlock == _KEEPLOCKED:
						lockbut = Label(tmpf, text = '')
					else:
						lockbut = Button(tmpf, text = '',\
										 command=lambda n=name: \
										 self.lockfield(n, toggle=1))
					lockbut.pack(fill=BOTH, expand=1)

					if runlock == _KEEPLOCKED:
						# usr can NEVER set this value!
						e.component('entry').configure(state=DISABLED)
						e.component('label').configure(fg='red')
						lockbut.configure(state=DISABLED)
				self._entries[name] = e
				entries.append(e)
				self.names.append(e)
				e.pack(expand=1, anchor=W, fill=X, side=RIGHT)

		f.update_idletasks()
		h = f.component('frame').winfo_reqheight()
		sh = f.component('frame').winfo_screenheight()
		x = int(min(0.75 * sh, 1.20*h))
		f.configure(hull_width=500, hull_height=x)

		Pmw.alignlabels(entries)

		if self._file:
			self.load()
コード例 #11
0
ファイル: ptable.py プロジェクト: mazerj/pype3
	def __init__(self, parent, table, file=None,
				 decorate=1, locks=1, allowalt=True, loadable=1):
		"""Parameter management table class"""

		if parent is None and table is None: return

		self._parent = parent
		self._table = table
		self._entries = {}
		self._locks = {}
		self._file = file
		self._allowalt = allowalt

		# got to check for duplicates before this table's added
		# into the global list.
		for slot in self._table:
			(name, default, validate, descr, runlock) = _unpack_slot(slot)
			if default is not None:
				found = self.find(name, show=0)
				for (duptab, dupname, duprow) in found:
					if name == dupname:
						Logger('ptable: ''%s'' dup in %s - priority '
							   'to %s\n' % (name, duptab.tablename, file))
		ParamTable._list.append(self)

		self.tablename = 'noname'

		if file:
			try:
				self._file = pype.subjectrc(file)
			except KeyError:
				self._file = file
			self.tablename = file
		else:
			self._file = None

		self.balloon = Pmw.Balloon(parent, master=1, relmouse='both')

		f = Frame(parent)
		f.pack(expand=0, fill=X, side=TOP)
		self.frame = f

		if self._file:
			Button(f, text='Save',
				   command=self.save).pack(expand=0, fill=X, side=LEFT)
		if decorate:
			Button(f, text="View",
				   command=self.view).pack(expand=0, fill=X, side=LEFT)
			
		if loadable:
			Button(f, text="Load (<-datafile)",
				   command=self.frompypefile).pack(expand=0, fill=X, side=LEFT)

			
		f = Pmw.ScrolledFrame(parent)
		f.pack(expand=1, fill=BOTH)

		entries = []
		self.names = []
		nrow = 0
		for slot in self._table:
			nrow = nrow + 1
			(name, default, validate, descr, runlock) = _unpack_slot(slot)

			lf = Frame(f.interior())
			lf.pack(expand=1, fill=X)
			if default is None and validate is None:
				e = Label(lf, text=name, bg='yellow', anchor=W)
				e.pack(expand=1, fill=X)
			elif isinstance(validate, types.TupleType):
				tmpf = Frame(lf, height=12, width=12)
				tmpf.pack(side=LEFT)
				e = Pmw.RadioSelect(lf,
									buttontype = 'radiobutton',
									labelpos = 'w',
									label_text = name + ':',
									pady=0, padx=2)
				e.pack(anchor=W)
				for v in validate:
					e.add(v)
				e.invoke(default)
				self._entries[name] = e
				entries.append(e)
			elif isinstance(validate, types.DictType):
				tmpf = Frame(lf, height=12, width=12)
				tmpf.pack(side=LEFT)
				e = Pmw.RadioSelect(lf,
									buttontype = 'radiobutton',
									labelpos = 'w',
									label_text = name + ':',
									pady=0, padx=2)
				if descr:
					self.balloon.bind(e, '%d: %s' % (nrow, descr))
				else:
					self.balloon.bind(e, '%d: %s' % (nrow, '???'))
				e.pack(anchor=W)
				for v in validate:
					e.add(v)
				e.invoke(default)
				self._entries[name] = e
				self._entries[(name,'dict')] = validate
				entries.append(e)
			else:
				e = Pmw.EntryField(lf,
								   labelpos = 'w',
								   label_text = name + ':',
								   validate = validate,
								   value = default)
				if descr:
					self.balloon.bind(e, '%d: %s' % (nrow, descr))
				else:
					self.balloon.bind(e, '%d: %s' % (nrow, '???'))
				e.component('entry').configure(bg='white', width=75)
				tmpf = Frame(lf, height=12, width=12)
				tmpf.pack_propagate(0)
				tmpf.pack(side=LEFT)
				if locks:
					if runlock == _KEEPLOCKED:
						lockbut = Label(tmpf, text = '')
					else:
						lockbut = Button(tmpf, text = '',
										 command=lambda n=name:
												self.lockfield(n, toggle=1))
					lockbut.pack(fill=BOTH, expand=1)

					if runlock == _KEEPLOCKED:
						# usr can NEVER set this value!
						e.component('entry').configure(state=DISABLED)
						e.component('label').configure(fg='red')
						lockbut.configure(state=DISABLED)
				self._entries[name] = e
				entries.append(e)
				self.names.append(e)
				e.pack(expand=1, anchor=W, fill=X, side=RIGHT)
			if descr and descr[0] == '*':
				# self-proclaimed override param (ie, hides another)
				e.component('label').config(fg='blue')
		Pmw.alignlabels(entries)

		if self._file:
			self.load()
コード例 #12
0
ファイル: ptable.py プロジェクト: abigelow1/pype2
    def __init__(self,
                 parent,
                 table,
                 file=None,
                 altfile=None,
                 decorate=1,
                 locks=1):
        """Parameter management table class"""
        self._table = table
        self._entries = {}
        self._locks = {}

        self.tablename = 'noname'

        if file:
            try:
                self._file = pype.subjectrc(file)
            except KeyError:
                self._file = file
            self.tablename = file
        else:
            self._file = None

        self.altfile = altfile

        f = Frame(parent)
        f.pack(expand=0, fill=X, side=TOP)
        self.frame = f
        if self._file:
            Button(f, text='Save', command=self.save).pack(expand=0,
                                                           fill=X,
                                                           side=LEFT)

        if decorate:
            Button(f, text="View", command=self.view).pack(expand=0,
                                                           fill=X,
                                                           side=LEFT)

        f = Pmw.ScrolledFrame(parent, usehullsize=1)

        f.pack(expand=1, fill=BOTH)
        self.balloon = Pmw.Balloon(parent, master=1, relmouse='both')

        entries = []
        self.names = []
        for slot in self._table:
            (name, default, validate, descr, runlock) = _unpack_slot(slot)
            lf = Frame(f.interior())
            lf.pack(expand=1, fill=X)
            if default is None:
                e = Label(lf, text=name, bg='yellow', anchor=W)
                e.pack(expand=1, fill=X)
            elif None and type(validate) is types.TupleType:
                e = Pmw.RadioSelect(lf, labelpos='w', label_text=name + ':')
                e.pack(expand=0, fill=X)
                for o in validate:
                    e.add(o)
                e.invoke(default)
            elif type(validate) is types.TupleType:
                e = Pmw.ComboBox(lf,
                                 labelpos='w',
                                 label_text=name + ':',
                                 scrolledlist_items=validate)
                e.pack(anchor=W)
                e.selectitem(default)
                self._entries[name] = e
                e.component('entry').configure(state=DISABLED)
            else:
                e = Pmw.EntryField(lf,
                                   labelpos='w',
                                   label_text=name + ':',
                                   validate=validate,
                                   value=default)
                if descr:
                    self.balloon.bind(e, descr)
                else:
                    self.balloon.bind(e, "???")
                e.component('entry').configure(bg='white', width=75)
                tmpf = Frame(lf, height=12, width=12)
                tmpf.pack_propagate(0)
                tmpf.pack(side=LEFT)
                if locks:
                    if runlock == _KEEPLOCKED:
                        lockbut = Label(tmpf, text='')
                    else:
                        lockbut = Button(tmpf, text = '',\
                             command=lambda n=name: \
                             self.lockfield(n, toggle=1))
                    lockbut.pack(fill=BOTH, expand=1)

                    if runlock == _KEEPLOCKED:
                        # usr can NEVER set this value!
                        e.component('entry').configure(state=DISABLED)
                        e.component('label').configure(fg='red')
                        lockbut.configure(state=DISABLED)
                self._entries[name] = e
                entries.append(e)
                self.names.append(e)
                e.pack(expand=1, anchor=W, fill=X, side=RIGHT)

        f.update_idletasks()
        h = f.component('frame').winfo_reqheight()
        sh = f.component('frame').winfo_screenheight()
        x = int(min(0.75 * sh, 1.20 * h))
        f.configure(hull_width=500, hull_height=x)

        Pmw.alignlabels(entries)

        if self._file:
            self.load()