def __init__(self, box_changed_cb):

        self.box_model = Box_Model()
        self.box_changed_cb = box_changed_cb
        self.ijk_in = None  # Box coordinates
        self.ijk_out = None
        self.mode_name = 'volume subregion'  # For mouse modes panel
        self.bound_button = None
        self.drag_mode = None
        self.rotation_handler = None

        callbacks = (self.mouse_down_cb, self.mouse_drag_cb, self.mouse_up_cb)

        icon_file = 'selectregion.gif'
        if icon_file:
            import os.path
            icon_path = os.path.join(os.path.dirname(__file__), icon_file)
            from PIL import Image
            image = Image.open(icon_path)
            from chimera import chimage
            from chimera import tkgui
            icon = chimage.get(image, tkgui.app)
        else:
            icon = None

        from chimera import mousemodes
        mousemodes.addFunction(self.mode_name, callbacks, icon)
Exemplo n.º 2
0
	def fillInUI(self, parent):
		import Pmw
		from chimera.widgets import ModelOptionMenu
		self.menu = ModelOptionMenu(parent, command=self._menuCB,
			labelpos='w', label_text="Model:")
		self.menu.grid(row=0, sticky='w')

		self.infoArea = None
		self.normMouse = None
		self.clipMouse = [None, None]
		if self.menu.getvalue() is not None:
			self.menu.invoke() # cause callback

		group = Pmw.Group(parent, tag_text="Clip Motion Assignments")
		group.grid(row=2, sticky="nsew")

		self.buttonLabels = []
		self.labelValues = {}
		for mod in ("",) + mousemodes.usedMods:
			for but in mousemodes.usedButtons:
				if mod:
					self.buttonLabels.append(
						mod.lower() + " button " + but)
					self.labelValues[self.buttonLabels[-1]]\
						= (but, (mod,))
				else:
					self.buttonLabels.append("button "+but)
					self.labelValues[self.buttonLabels[-1]]\
						= (but, ())
		self.transMenu = Pmw.OptionMenu(group.interior(),
			command=lambda bname: self._assignmentChange(0, bname),
			initialitem="button 2", items=self.buttonLabels,
			labelpos='n', label_text="Translation")
		self.transMenu.grid(row=0, column=0)
		self.pivotMenu = Pmw.OptionMenu(group.interior(),
			command=lambda bname: self._assignmentChange(1, bname),
			initialitem="button 3", items=self.buttonLabels,
			labelpos='n', label_text="Rotation")
		self.pivotMenu.grid(row=0, column=1)

		mousemodes.addFunction("plane rotate", (
				lambda v, e: self._planeStart(v, e, "rotate"),
				self._planeRot,
				self._planeStop))
		mousemodes.addFunction("plane translate", (
				lambda v, e: self._planeStart(
							v, e, "translate z"),
				self._planeTrans,
				self._planeStop))

		def showCapDialog():
			from SurfaceCap.gui import Capper_Dialog
			from chimera import dialogs
			d = dialogs.display(Capper_Dialog.name)
			d.show_caps.set(True)
		Tkinter.Button(parent, text="Cap clipped surfaces...", pady=0,
			command=showCapDialog).grid(row=3)
Exemplo n.º 3
0
    def fillInUI(self, parent):

        self.default_color = (0, 0, 0.8, 1)

        t = parent.winfo_toplevel()
        self.toplevel_widget = t
        t.withdraw()

        parent.columnconfigure(0, weight=1)
        row = 0

        import Tkinter
        from CGLtk import Hybrid

        mmf = Tkinter.Frame(parent)
        mmf.grid(row=row, column=0, sticky='w')
        row = row + 1

        mb = Hybrid.Option_Menu(mmf, 'Use mouse ', 'button 1', 'button 2',
                                'button 3', 'ctrl button 1', 'ctrl button 2',
                                'ctrl button 3')
        mb.variable.set('ctrl button 3')
        mb.frame.grid(row=0, column=0, sticky='w')
        mb.add_callback(self.bind_mouse_button_cb)
        self.mouse_button = mb

        mbl = Tkinter.Label(mmf, text=' to choose blobs')
        mbl.grid(row=0, column=1, sticky='w')

        crf = Tkinter.Frame(parent)
        crf.grid(row=row, column=0, sticky='ew')
        crf.columnconfigure(1, weight=1)
        row = row + 1

        cl = Tkinter.Label(crf, text='Color blob ')
        cl.grid(row=0, column=0, sticky='w')

        from CGLtk.color import ColorWell
        sc = ColorWell.ColorWell(crf, color=self.default_color)
        sc.grid(row=0, column=1, sticky='w')
        self.blob_color = sc

        msg = Tkinter.Label(parent, anchor='w', justify='left')
        msg.grid(row=row, column=0, sticky='ew')
        row = row + 1
        self.message_label = msg

        callbacks = (self.mouse_down_cb, self.mouse_drag_cb, self.mouse_up_cb)
        icon = self.mouse_mode_icon('pickblob.gif')
        from chimera import mousemodes
        mousemodes.addFunction('pick blobs', callbacks, icon)

        self.bind_mouse_button_cb()
Exemplo n.º 4
0
    def wrap_mouse_modes(self):

        from chimera.mousemodes import addFunction, functionCallables

        mt = {}
        for mode in ('rotate', 'translate x,y', 'translate z'):
            down_cb, drag_cb, up_cb = functionCallables(mode)
            mt[mode] = {'down': down_cb, 'drag': drag_cb, 'up': up_cb}

        m = self.mouse_cb
        for mode in ('rotate', 'translate x,y', 'translate z'):
            callbacks = (lambda v, e, mode=mode: m(v, e, mode, 'down'),
                         lambda v, e, mode=mode: m(v, e, mode, 'drag'),
                         lambda v, e, mode=mode: m(v, e, mode, 'up'))
            addFunction(mode, callbacks)

        return mt
Exemplo n.º 5
0
    def __init__(self):

        self.bound_button = None
        self.mode_name = 'group connected'
        self.region = None
        self.level = None
        self.last_level = None  # Last used grouping level.
        self.last_y = 0
        self.dragging = False
        self.connected = set()
        self.ungrouped_color = (0.8, 0.8, 0.8, 1.0)
        self.background_show_all = True

        from chimera import mousemodes
        callbacks = (self.mouse_down_cb, self.mouse_drag_cb, self.mouse_up_cb)
        icon = None
        mousemodes.addFunction(self.mode_name, callbacks, icon)
Exemplo n.º 6
0
	def __init__(self):
		import os.path
		myDir, junk = os.path.split(__file__)
		addFunction('place text', (self._pickLabel, self._moveLabel,
			None), icon=chimage.get(Image.open(os.path.join(myDir,
						'ilabel.png')), tkgui.app))
		addFunction('place key', (self._startOrGrabKey,
			self._sizeOrMoveKey, None), icon=chimage.get(
			Image.open(os.path.join(myDir, 'key.png')), tkgui.app))

		import Ilabel
		if not Ilabel._ilabelModel:
			Ilabel.IlabelModel()
		self.model = Ilabel._ilabelModel
		ModelessDialog.__init__(self)
		self._sessionHandlerID = chimera.triggers.addHandler(
					SAVE_SESSION, self._saveSession, None)
		self._closeHandlerID = chimera.triggers.addHandler(
					CLOSE_SESSION, self.destroy, None)
		self._beginRestoreHandlerID = chimera.triggers.addHandler(
				BEGIN_RESTORE_SESSION, self.destroy, None)
    def register_mouse_modes(self):

        # mode: (press, motion, release [, double press, double release])
        rotate_funcs = (
            self.start_rotation_cb,
            self.rotation_cb,
            self.stop_rotation_cb
            )
        rotate_icon = mouse_mode_icon('roticon.png')
        from chimera import mousemodes
        mousemodes.addFunction('constrained rotation', rotate_funcs,
                               rotate_icon)

        translate_funcs = (
            self.start_translation_cb,
            self.translation_cb,
            self.stop_translation_cb
            )
        translate_icon = mouse_mode_icon('transicon.png')
        mousemodes.addFunction('constrained translation', translate_funcs,
                               translate_icon)
Exemplo n.º 8
0
    def __init__(self, seg_dialog):
        """__init__(seg_dialog) - initialize and add mouse callbacks.

        Creates a box region selector for use in simple segmentation.
        """

        self.box_model = Box_Model()
        self.seg_dialog = seg_dialog
        self.xyz_in = None
        self.xyz_out = None
        self.mode_name = 'seg box region'
        self.bound_button = None
        self.drag_button = None

        callbacks = (self.mouse_down_cb, self.mouse_drag_cb,
                     self.mouse_up_cb)

        icon_file = None

        from chimera import mousemodes
        mousemodes.addFunction(self.mode_name, callbacks, icon_file)
Exemplo n.º 9
0
    def __init__(self):
        import os.path
        myDir, junk = os.path.split(__file__)
        addFunction('place text', (self._pickLabel, self._moveLabel, None),
                    icon=chimage.get(
                        Image.open(os.path.join(myDir, 'ilabel.png')),
                        tkgui.app))
        addFunction('place key',
                    (self._startOrGrabKey, self._sizeOrMoveKey, None),
                    icon=chimage.get(
                        Image.open(os.path.join(myDir, 'key.png')), tkgui.app))

        import Ilabel
        if not Ilabel._ilabelModel:
            Ilabel.IlabelModel()
        self.model = Ilabel._ilabelModel
        ModelessDialog.__init__(self)
        self._sessionHandlerID = chimera.triggers.addHandler(
            SAVE_SESSION, self._saveSession, None)
        self._closeHandlerID = chimera.triggers.addHandler(
            CLOSE_SESSION, self.destroy, None)
        self._beginRestoreHandlerID = chimera.triggers.addHandler(
            BEGIN_RESTORE_SESSION, self.destroy, None)
Exemplo n.º 10
0
	def fillInUI(self, parent):
		self.distances = []
		self.angleInfo = []

		self.numMolecules = len(chimera.openModels.list(
						modelTypes=[chimera.Molecule]))
		chimera.triggers.addHandler('Molecule', self._molChange, None)
		chimera.triggers.addHandler('PseudoBond', self._psbChange, None)
		chimera.triggers.addHandler('Atom', self._atomChange, None)
		chimera.triggers.addHandler('Model', self._modelChange, None)
		distanceMonitor.updateCallbacks.append(self._distUpdateCB)

		self.notebook = Pmw.NoteBook(parent,
						raisecommand=self._nbRaiseCB,
						lowercommand=self._nbLowerCB)
		self.notebook.pack(fill='both', expand=1)

		self.interfaces = {}
		for pn in pageNames:
			pageID = pn
			## when more tabs shown, maybe do this...
			#if '/' in pn:
			#	parts = pn.split('/')
			#	pn = "/ ".join(parts)
			#if ' ' in pn:
			#	parts = pn.split(' ')
			#	pn = '\n'.join(parts)
			self.notebook.add(pageID, tab_text=pn)

		dp = self.notebook.page(DISTANCES)
		from CGLtk.Table import SortableTable
		self.distTable = SortableTable(dp)
		self.distTable.grid(row=0, column=0, sticky='nsew', rowspan=7)
		dp.columnconfigure(0, weight=1)
		dp.rowconfigure(4, weight=1)
		dp.rowconfigure(5, weight=1)
		self.distTable.addColumn("ID", "id", format="%d")
		self.distTable.addColumn("Atom 1",
				lambda d, s=self: s.atomLabel(d.atoms[0]))
		self.distTable.addColumn("Atom 2",
				lambda d, s=self: s.atomLabel(d.atoms[1]))
		self.distTable.addColumn("Distance", "distance", font="TkFixedFont")
		self.distTable.setData(self.distances)
		self.distTable.launch(browseCmd=self._distTableSelCB)

		self.distButtons = Pmw.ButtonBox(dp, padx=0)
		self.distButtons.add("Create", command=self._createDistance)
		self.distButtons.add("Remove", command=self._removeDistance)

		# remove the extra space around buttons allocated to indicate
		# which button is the 'default', so that buttons stack closely
		for but in range(self.distButtons.numbuttons()):
			self.distButtons.button(but).config(default='disabled')
		self.distButtons.alignbuttons()
		self.distButtons.grid(row=1, column=1)

		self.distLabelChoice = Pmw.RadioSelect(dp, pady=0,
			buttontype='radiobutton',
			command=self._distLabelModeChange, orient='vertical',
			labelpos='w', label_text="Labels")
		self.distLabelChoice.grid(row=2, column=1)
		self.distLabelChoice.add("None", highlightthickness=0)
		self.distLabelChoice.add("ID", highlightthickness=0)
		self.distLabelChoice.add("Distance", highlightthickness=0)
		self.distLabelChoice.invoke("Distance")

		self.distPrecisionChoice = Pmw.Counter(dp, datatype={
			'counter': self._distPrecisionChange}, labelpos='w',
			label_text="Decimal places", entry_width=1,
			entry_pyclass=PrecisionEntry,
			entryfield_value=str(precision()))
		self.distPrecisionChoice.grid(row=3, column=1)

		self.showUnitsVar = Tkinter.IntVar(dp)
		self.showUnitsVar.set(showUnits())
		Tkinter.Checkbutton(dp, text="Show Angstrom symbol",
			variable=self.showUnitsVar,
			command=self._showUnitsChangeCB).grid(row=4, column=1)

		self.distSelectsAtomsVar = Tkinter.IntVar(dp)
		self.distSelectsAtomsVar.set(False)
		Tkinter.Checkbutton(dp, variable=self.distSelectsAtomsVar,
			text="Choosing in table\nselects atoms\n(and pseudobond)"
			).grid(row=5, column=1)

		from chimera.pbgPanel import attributesCmd
		Tkinter.Button(dp, text="Display options...", command=
			lambda dm=distanceMonitor: attributesCmd([dm])
			).grid(row=6, column=1)

		for d in distanceMonitor.pseudoBonds:
			self.newDistance(d)

		atp = self.notebook.page(ANGLES)
		from CGLtk.Table import SortableTable
		self.angleTable = SortableTable(atp)
		self.angleTable.grid(row=0, column=0, sticky='nsew', rowspan=4)
		atp.columnconfigure(0, weight=1)
		atp.rowconfigure(2, weight=1)
		for i in range(4):
			self.angleTable.addColumn("Atom %d" % (i+1), lambda atoms, s=self,
					i=i: i >= len(atoms) and "N/A" or s.atomLabel(atoms[i]))
		self.angleTable.addColumn("Angle/Torsion",
			lambda atoms, s=self: s._angleLabel(atoms), font="TkFixedFont")
		self.angleTable.setData(self.angleInfo)
		self.angleTable.launch(browseCmd=self._angleTableSelCB)

		self._osHandler = None
		self.angleButtons = Pmw.ButtonBox(atp, padx=0)
		self.angleButtons.add("Create", command=self._createAngle)
		self.angleButtons.add("Remove", command=self._removeAngle,
							state='disabled')
		# remove the extra space around buttons allocated to indicate
		# which button is the 'default', so that buttons stack closely
		for but in range(self.angleButtons.numbuttons()):
			self.angleButtons.button(but).config(default='disabled')
		self.angleButtons.alignbuttons()
		self.angleButtons.grid(row=0, column=1)

		self.anglePrecisionChoice = Pmw.Counter(atp, datatype={
			'counter': self._anglePrecisionChange}, labelpos='w',
			label_text="Decimal places", entry_width=1,
			entry_pyclass=PrecisionEntry,
			entryfield_value=str(prefs[ANGLE_PRECISION]))
		self.anglePrecisionChoice.grid(row=1, column=1)

		self.angleSelectsComponentsVar = Tkinter.IntVar(atp)
		self.angleSelectsComponentsVar.set(True)
		Tkinter.Checkbutton(atp, variable=self.angleSelectsComponentsVar,
			text="Choosing in table selects\ncomponent atoms/bonds"
			).grid(row=3, column=1)

		brp = self.notebook.page(BONDROTS)
		self.rotations = []
		self.rotInfo = {}

		labeledButton = Pmw.LabeledWidget(brp, labelpos="e",
				label_text="selected bond as torsion")
		labeledButton.grid(row=0, column=0, columnspan=2)
		self.createRotButton = Tkinter.Button(labeledButton.interior(),
			text="Activate", command=self._createRotation, pady=0)
		self.createRotButton.grid()

		tableFrame = Tkinter.Frame(brp, pady="0.1i")
		tableFrame.grid(row=1, column=0, columnspan=2, sticky='ns')
		from CGLtk.Table import ScrolledTable
		self.rotTable = ScrolledTable(tableFrame, hscrollmode='none')
		self.rotTable.setColumnTitle(0, "ID")
		self.rotTable.setColumnTitle(1, "Near")
		self.rotTable.setColumnTitle(2, "Bond")
		self.rotTable.setColumnTitle(3, "Far")
		self.angleTitle = Tkinter.StringVar(parent)
		self.angleTitle.set("Torsion")
		self.rotTable.setColumnTitle(4, self.angleTitle,
						pyclass=Tkinter.Button, pady=0,
						command=self._toggleAngleType)
		brp.rowconfigure(1, weight=1)
		brp.columnconfigure(0, weight=1)
		brp.columnconfigure(1, weight=1)
		tableFrame.rowconfigure(0, weight=1)
		tableFrame.columnconfigure(0, weight=1)
		self.rotTable.columnconfigure(4, weight=1)
		self.rotTable.grid(row=0, column=0, sticky='news')

		self.dialSizeLabels = ["small", "medium", "large"]
		Pmw.OptionMenu(tableFrame,
			items=self.dialSizeLabels, labelpos='w',
			initialitem=self.dialSizeLabels[prefs[ROT_DIAL_SIZE]],
			label_text="Dial size:", command=self._dialSizeChangeCB,
			).grid(row=1, column=0, sticky='e')

		f = Tkinter.Frame(brp)
		f.grid(row=2, column=0, columnspan=2)
		self.mouseModeVar = Tkinter.IntVar(f)
		self.mouseModeVar.set(False)
		self.needTorWidgets = []
		self.needTorWidgets.append(Tkinter.Checkbutton(f, text="Rotate",
			variable=self.mouseModeVar, command=self._mouseModeCB))
		self.needTorWidgets[-1].grid(row=0, column=0)
		self.rotModeTorsMenu = Pmw.OptionMenu(f)
		self.rotModeTorsMenu.grid(row=0, column=1)
		self.needTorWidgets.append(self.rotModeTorsMenu)
		self.buttonLabels = []
		self.labelValues = {}
		for mod in ("",) + mousemodes.usedMods:
			for but in mousemodes.usedButtons:
				if mod:
					self.buttonLabels.append(
						mod.lower() + " button " + but)
					self.labelValues[self.buttonLabels[-1]]\
						= (but, (mod,))
				else:
					self.buttonLabels.append("button "+but)
					self.labelValues[self.buttonLabels[-1]]\
						= (but, ())
		self._modeButton = self.buttonLabels[0]
		self.rotModeButMenu = Pmw.OptionMenu(f, labelpos='w',
			command=self._modeButtonCB,
			label_text="using", items=self.buttonLabels)
		self.rotModeButMenu.grid(row=0, column=2)
		self.needTorWidgets.append(self.rotModeButMenu)

		self.rotLabelChoice = Pmw.RadioSelect(brp, pady=0,
			buttontype='radiobutton', hull_pady=".1i",
			command=self._rotLabelModeChange, orient='vertical',
			labelpos='w', label_text="Labels")
		self.rotLabelChoice.grid(row=3, rowspan=2, column=0)
		self.rotLabelChoice.add("None", highlightthickness=0)
		self.rotLabelChoice.add("ID", highlightthickness=0)
		self.rotLabelChoice.add("Name", highlightthickness=0)
		self.rotLabelChoice.add("Angle", highlightthickness=0)
		self.rotLabelChoice.invoke(prefs[ROT_LABEL])

		self.torsionPrecisionChoice = Pmw.Counter(brp, datatype={
			'counter': self._torsionPrecisionChange}, labelpos='w',
			label_text="Decimal places", entry_width=1,
			entry_pyclass=PrecisionEntry,
			entryfield_value=str(prefs[TORSION_PRECISION]))
		self.torsionPrecisionChoice.grid(row=3, column=1)

		self.showDegreeSymbolVar = Tkinter.IntVar(brp)
		self.showDegreeSymbolVar.set(prefs[SHOW_DEGREE_SYMBOL])
		Tkinter.Checkbutton(brp, text="Show degree symbol",
			variable=self.showDegreeSymbolVar,
			command=self._showDegreeSymbolChangeCB).grid(
							row=4, column=1)

		self.setTorWidgetsState("disabled")

		mousemodes.addFunction("rotate bond", (lambda v, e:
			v.recordPosition(e.time, e.x, e.y, "rotate"),
			self._mouseSphere,
			lambda v, e: v.setCursor(None)))

		if GEOMETRIES in pageNames:
			gp = self.notebook.page(GEOMETRIES)
			from Geometry import GeometryInterface
			self.interfaces[GEOMETRIES] = GeometryInterface(gp, self.status)

		if METALS in pageNames:
			mp = self.notebook.page(METALS)
			from Metals import MetalsInterface
			self.interfaces[METALS] = MetalsInterface(mp,
								self.status)
		self.notebook.setnaturalsize()
  def register_resize_mouse_mode(self):

    from chimera.mousemodes import addFunction
    callbacks = (self.mouse_down_cb, self.mouse_drag_cb, self.mouse_up_cb)
    addFunction('resize surfaces', callbacks)
Exemplo n.º 12
0
    def fillInUI(self, parent):
        import Pmw
        from chimera.widgets import ModelOptionMenu
        self.menu = ModelOptionMenu(parent,
                                    command=self._menuCB,
                                    labelpos='w',
                                    label_text="Model:")
        self.menu.grid(row=0, sticky='w')

        self.infoArea = None
        self.normMouse = None
        self.clipMouse = [None, None]
        if self.menu.getvalue() is not None:
            self.menu.invoke()  # cause callback

        group = Pmw.Group(parent, tag_text="Clip Motion Assignments")
        group.grid(row=2, sticky="nsew")

        self.buttonLabels = []
        self.labelValues = {}
        for mod in ("", ) + mousemodes.usedMods:
            for but in mousemodes.usedButtons:
                if mod:
                    self.buttonLabels.append(mod.lower() + " button " + but)
                    self.labelValues[self.buttonLabels[-1]]\
                     = (but, (mod,))
                else:
                    self.buttonLabels.append("button " + but)
                    self.labelValues[self.buttonLabels[-1]]\
                     = (but, ())
        self.transMenu = Pmw.OptionMenu(
            group.interior(),
            command=lambda bname: self._assignmentChange(0, bname),
            initialitem="button 2",
            items=self.buttonLabels,
            labelpos='n',
            label_text="Translation")
        self.transMenu.grid(row=0, column=0)
        self.pivotMenu = Pmw.OptionMenu(
            group.interior(),
            command=lambda bname: self._assignmentChange(1, bname),
            initialitem="button 3",
            items=self.buttonLabels,
            labelpos='n',
            label_text="Rotation")
        self.pivotMenu.grid(row=0, column=1)

        mousemodes.addFunction("plane rotate",
                               (lambda v, e: self._planeStart(v, e, "rotate"),
                                self._planeRot, self._planeStop))
        mousemodes.addFunction(
            "plane translate",
            (lambda v, e: self._planeStart(v, e, "translate z"),
             self._planeTrans, self._planeStop))

        def showCapDialog():
            from SurfaceCap.gui import Capper_Dialog
            from chimera import dialogs
            d = dialogs.display(Capper_Dialog.name)
            d.show_caps.set(True)

        Tkinter.Button(parent,
                       text="Cap clipped surfaces...",
                       pady=0,
                       command=showCapDialog).grid(row=3)