示例#1
0
    def confirm_new_path(self, path):
        """User wants to save to this path. If it's different to the original path,
		check that it doesn't exist and ask for confirmation if it does.
		If document.save_last_stat is set, compare with os.stat for an existing file
		and warn about changes.
		Returns true to go ahead with the save."""
        if not os.path.exists(path):
            return True
        if os.path.isdir(path):
            rox.alert(_("'%s' already exists as a directory.") % path)
            return False
        if path == self.initial_uri:
            if self.document.save_last_stat is None:
                return True  # OK. Nothing to compare with.
            last = self.document.save_last_stat
            stat = os.stat(path)
            msg = []
            if stat.st_mode != last.st_mode:
                msg.append(_("Permissions changed from %o to %o.") % \
                  (last.st_mode, stat.st_mode))
            if stat.st_size != last.st_size:
                msg.append(_("Size was %d bytes; now %d bytes.") % \
                  (last.st_size, stat.st_size))
            if stat.st_mtime != last.st_mtime:
                msg.append(_("Modification time changed."))
            if not msg:
                return True  # No change detected
            return rox.confirm(
                "File '%s' edited by another program since last load/save. "
                "Really save (discarding other changes)?\n\n%s" %
                (path, '\n'.join(msg)), g.STOCK_DELETE)
        return rox.confirm(
            _("File '%s' already exists -- overwrite it?") % path,
            g.STOCK_DELETE, _('_Overwrite'))
示例#2
0
		def resp(dialog, r):
			if r == g.RESPONSE_OK:
				if not self.tmpdir:
					rox.alert("Archive not downloaded yet!")
					return
				unpack_dir = os.path.join(self.tmpdir, 'unpacked')

				url = widgets.get_widget('archive_url').get_text()
				if urlparse.urlparse(url)[1] == '':
					raise Exception('Missing host name in URL "%s"' % url)
				if urlparse.urlparse(url)[2] == '':
					raise Exception('Missing resource part in URL "%s"' % url)
				local_archive = widgets.get_widget('local_archive').get_filename()
				if not local_archive:
					raise Exception('Please select a local file')
				if selection.iter_is_selected(model.get_iter_root()):
					root = unpack_dir
					extract = None
				else:
					_, iter = selection.get_selected()
					extract = model[iter][0]
					root = os.path.join(unpack_dir, extract)

				size = os.path.getsize(local_archive)
				if self.start_offset:
					size -= self.start_offset
				self.create_archive_element(url, self.mime_type, root, extract, size,
						    self.start_offset)
			self.destroy_tmp()
			dialog.destroy()
示例#3
0
文件: saving.py 项目: boube/minino
	def confirm_new_path(self, path):
		"""User wants to save to this path. If it's different to the original path,
		check that it doesn't exist and ask for confirmation if it does.
		If document.save_last_stat is set, compare with os.stat for an existing file
		and warn about changes.
		Returns true to go ahead with the save."""
		if not os.path.exists(path):
			return True
		if os.path.isdir(path):
			rox.alert(_("'%s' already exists as a directory.") % path)
			return False
		if path == self.initial_uri:
			if self.document.save_last_stat is None:
				return True		# OK. Nothing to compare with.
			last = self.document.save_last_stat
			stat = os.stat(path)
			msg = []
			if stat.st_mode != last.st_mode:
				msg.append(_("Permissions changed from %o to %o.") % \
						(last.st_mode, stat.st_mode))
			if stat.st_size != last.st_size:
				msg.append(_("Size was %d bytes; now %d bytes.") % \
						(last.st_size, stat.st_size))
			if stat.st_mtime != last.st_mtime:
				msg.append(_("Modification time changed."))
			if not msg:
				return True		# No change detected
			return rox.confirm("File '%s' edited by another program since last load/save. "
					   "Really save (discarding other changes)?\n\n%s" %
					   (path, '\n'.join(msg)), g.STOCK_DELETE)
		return rox.confirm(_("File '%s' already exists -- overwrite it?") % path,
				   g.STOCK_DELETE, _('_Overwrite'))
示例#4
0
	def line_yank_chain(self):
		op, exit = self.line_menu_line
		next = getattr(op, exit)
		if not next:
			rox.alert('Nothing to yank!')
			return
		self.clipboard = next.to_doc()
		print "Yanked", self.clipboard
示例#5
0
	def line_del_chain(self):
		op, exit = self.line_menu_line
		next = getattr(op, exit)
		if not next:
			rox.alert('Nothing to delete!')
			return
		self.clipboard = next.to_doc()
		op.unlink(exit)
示例#6
0
文件: loading.py 项目: jfmc/logen
	def xds_load_from_stream(self, name, type, stream):
		"""Called when we get any data sent via drag-and-drop in any way (local
		file or remote application transfer). You should override this and do
		something with the data. 'name' may be None (if the data is unnamed),
		a leafname, or a full path or URI. 'type' is the MIME type, or None if
		unknown."""
		alert('Got some data, but missing code to handle it!\n\n(name="%s";type="%s")'
			% (name, type))
示例#7
0
文件: main.py 项目: rox-desktop/memo
 def check():
     call = proxy.get_object('/').get_pid()
     yield call, tasks.TimeoutBlocker(2)
     if call.happened:
         pid = call.get_response()
         rox.alert('Memo is already running (PID = %d)!' % pid)
         os._exit(1)
     g.main_quit()
示例#8
0
	def add_requires(self):
		elem = self.get_selected()
		if elem.namespaceURI == XMLNS_INTERFACE:
			if elem.localName not in ('group', 'implementation'):
				elem = elem.parentNode
			if elem.localName in ('group', 'implementation'):
				Requires(self, parent = elem)
				return
		rox.alert('Select a group or implementation!')
示例#9
0
	def login_died(status):
		global login_child
		login_child = None
		if status != 0:
			rox.alert(_("Your login script ('%s') failed. "
				"I'll give you an xterm to try and fix it. ROX-Session "
				"itself is running fine though - run me a second time "
				"to logout."))
			os.spawnlp(os.P_NOWAIT, 'xterm', 'xterm')
示例#10
0
    def xds_load_from_stream(self, name, type, stream):
        """Called when we get any data sent via drag-and-drop in any way (local
		file or remote application transfer). You should override this and do
		something with the data. 'name' may be None (if the data is unnamed),
		a leafname, or a full path or URI. 'type' is the MIME type, or None if
		unknown."""
        alert(
            'Got some data, but missing code to handle it!\n\n(name="%s";type="%s")'
            % (name, type))
示例#11
0
		def activate(entry):
			expr = entry.get_text()
			frame = selected_frame()
			try:
				info(`eval(expr, frame.f_locals, frame.f_globals)`)
			except:
				extype, value = sys.exc_info()[:2]
				brief = ''.join(traceback.format_exception_only(extype, value))
				alert(brief)
			entry.grab_focus()
示例#12
0
文件: debug.py 项目: jfmc/logen
 def activate(entry):
     expr = entry.get_text()
     frame = selected_frame()
     try:
         info(` eval(expr, frame.f_locals, frame.f_globals) `)
     except:
         type, value = sys.exc_info()[:2]
         brief = "".join(traceback.format_exception_only(type, value))
         alert(brief)
     entry.grab_focus()
示例#13
0
		def get_keygen_out():
			errors = ''
			while True:
				yield signing.InputBlocker(child.stderr)
				data = os.read(child.stderr.fileno(), 100)
				if not data:
					break
				errors += data
			self.update_key_model()
			if errors:
				rox.alert('Errors from terminal: %s' % errors)
示例#14
0
 def edit(b):
     sel = self.list.get_selection()
     memos = []
     for iter in memo_list:
         if sel.iter_is_selected(iter):
             m = memo_list.get_memo_by_iter(iter)
             memos.append(m)
     if len(memos) != 1:
         rox.alert(_('You need to select exactly one memo first!'))
         return
     from EditBox import EditBox
     EditBox(memos[0]).show()
示例#15
0
		def modify():
			if op.action[0] == 'do_search' or op.action[0] == 'do_global':
				t = editables[0].get_text()
				print "Checking", t
				from Ft.Xml.XPath import XPathParser
				if t.find('@CURRENT@') == -1:
					try:
						XPathParser.new().parse(t)
					except:
						alert('Invalid search pattern!')
						return
			i = 0
			for e in editables:
				i += 1
				if e:
					op.action[i] = e.get_text()
			op.changed()
			print "Done editing!"
			win.destroy()
示例#16
0
	def edit_properties(self, path = None, element = None):
		assert not (path and element)

		if element:
			pass
		elif path is None:
			element = self.get_selected()
		else:
			element = self.impl_model[path][1]

		if element.namespaceURI != XMLNS_INTERFACE:
			rox.alert("Sorry, I don't known how to edit %s elements!" % element.namespaceURI)

		if element.localName in ('group', 'implementation'):
			ImplementationProperties(self, element)
		elif element.localName == 'requires':
			Requires(self, parent = element.parentNode, element = element)
		else:
			rox.alert("Sorry, I don't known how to edit %s elements!" % element.localName)
示例#17
0
	def tool_play(self, button = None):
		from View import InProgress, Done
		if not self.view.exec_point:
			if self.view.rec_point:
				self.view.set_exec(self.view.rec_point)
				self.view.set_rec(None)
			else:
				rox.alert('No playback point!')
				return
		# Step first, in case we're on a breakpoint
		self.view.single_step = 1
		try:
			self.view.do_one_step()
		except InProgress:
			self.view.single_step = 0
			return
		except Done:
			pass
		self.view.single_step = 0
		self.view.sched()
示例#18
0
    def xds_data_received(self, widget, context, x, y, selection, info, time):
        "Called when we get some data. Internal."
        if selection.data is None:
            # Timeout?
            context.drop_finish(False, time)
            return

        if info == TARGET_RAW:
            try:
                self.xds_load_from_selection(selection, context.rox_leafname)
            except:
                context.drop_finish(False, time)
                raise
            context.drop_finish(True, time)
            return 1
        if info != TARGET_URILIST:
            return 0

        uris = extract_uris(selection.data)
        if not uris:
            alert("Nothing to load!")
            context.drop_finish(False, time)
            return 1

        try:
            try:
                self.xds_load_uris(uris)
            except RemoteFiles:
                if len(uris) != 1 or not provides(context,
                                                  'application/octet-stream'):
                    raise
                widget.drag_get_data(context, 'application/octet-stream', time)
                return 1  # Don't do drag_finish
        except:
            context.drop_finish(False, time)
            rox.report_exception()
        else:
            context.drop_finish(True, time)

        return 1
示例#19
0
	def box(self, top, ops):
		block = top.parent
		print "Boxed in", block

		assert ops

		next = fail = None
		
		for op in ops:
			if op.next and op.next not in ops:
				if next: rox.alert("New block can't have two next exits!")
				next = op
			if op.fail and op.fail not in ops:
				if fail: rox.alert("New block can't have two fail exits!")
				fail = op

		if len(ops) == 1:
			if not rox.confirm('Put this node in a new block?', 'Create block'):
				return
		elif not rox.confirm('Put these %d nodes in a new block?' % len(ops),
						'Create block'):
				return

		new_exits = (next and next.op.next, fail and fail.op.fail)

		if next: next.op.unlink('next', may_delete = False)
		if fail: fail.op.unlink('fail', may_delete = False)

		new = Block(block)
		prev = top.prev
		if prev.next == top: exit = 'next'
		else: exit = 'fail'
		prev.unlink(exit, may_delete = 0)
		prev.link_to(new, exit)
		
		top.set_parent(None)
		top.set_parent(new)
		new.start.link_to(top, 'next')
		if new_exits[0]: new.link_to(new_exits[0], 'next')
		if new_exits[1]: new.link_to(new_exits[1], 'fail')
示例#20
0
文件: loading.py 项目: jfmc/logen
	def xds_data_received(self, widget, context, x, y, selection, info, time):
		"Called when we get some data. Internal."
		if selection.data is None:
			# Timeout?
			context.drop_finish(False, time)
			return

		if info == TARGET_RAW:
			try:
				self.xds_load_from_selection(selection, context.rox_leafname)
			except:
				context.drop_finish(False, time)
				raise
			context.drop_finish(True, time)
			return 1
		if info != TARGET_URILIST:
			return 0

		uris = extract_uris(selection.data)
		if not uris:
			alert("Nothing to load!")
			context.drop_finish(False, time)
			return 1

		try:
			try:
				self.xds_load_uris(uris)
			except RemoteFiles:
				if len(uris) != 1 or not provides(context, 'application/octet-stream'):
					raise
				widget.drag_get_data(context, 'application/octet-stream', time)
				return 1	# Don't do drag_finish
		except:
			context.drop_finish(False, time)
			rox.report_exception()
		else:
			context.drop_finish(True, time)

		return 1
示例#21
0
        def delete(b):
            sel = self.list.get_selection()
            memos = []
            for iter in memo_list:
                if sel.iter_is_selected(iter):
                    m = memo_list.get_memo_by_iter(iter)
                    memos.append(m)
            if not memos:
                rox.alert(_('You need to select some memos first!'))
                return
            l = len(memos)
            if l == 1:
                message = _("Really delete memo '%s'?") % memos[0].brief
            else:
                message = _('Really delete %d memos?') % l

            box = g.MessageDialog(None, 0, g.MESSAGE_QUESTION,
                                  g.BUTTONS_CANCEL, message)

            if rox.confirm(message, g.STOCK_DELETE):
                for m in memos:
                    memo_list.delete(m, update=0)
                memo_list.notify_changed()
示例#22
0
def manage_session(test_mode):
    log.init()

    if not mydbus.dbus_version_ok and not xxmlrpc.working:
        rox.alert(problem_msg)

    set_up_environment()
    session.init()
    children.init()
    session_dbus.init()  # Start even if DBus is too old, for session bus
    xml_settings = settings.init()

    if mydbus.dbus_version_ok:
        service = dbus.service.BusName(constants.session_service,
                                       bus=session_dbus.get_session_bus())
        SessionObject3x(service)

    # This is like the D-BUS service, except using XML-RPC-over-X
    xml_service = xxmlrpc.XXMLRPCServer(constants.session_service)
    xml_service.add_object('/Session', XMLSessionObject())
    xml_service.add_object('/Settings', xml_settings)

    try:
        if test_mode:
            print "Test mode!"
            print "Started", os.system(
                "(/bin/echo hi >&2; sleep 4; date >&2)&")
            print "OK"
        else:
            try:
                wm.start()
            except:
                rox.report_exception()

        g.main()
    finally:
        session_dbus.destroy()
示例#23
0
	def stop_recording(self):
		if self.rec_point:
			self.set_exec(self.rec_point)
			self.set_rec(None)
		else:
			alert("Not recording!")
示例#24
0
	def record_at_point(self):
		if not self.exec_point:
			alert("No current point!")
			return
		self.set_rec(self.exec_point)
		self.set_exec(None)
示例#25
0
	def soap_send(self):
		copy = node_to_xml(self.get_current())
		env = copy.documentElement
		from Ft.Xml.Lib.Nss import GetAllNs
		nss = GetAllNs(env)
		for p, u in self.model.namespaces.uri.iteritems():
			if p in nss:
				assert nss[p] == u
			elif p not in ('xml', 'xmlns'):
				env.setAttributeNS(XMLNS_NAMESPACE, 'xmlns:%s' % p, u)

		if env.namespaceURI != SOAPENV_NS:
			alert("Not a SOAP-ENV:Envelope (bad namespace)")
			raise Done()
		if env.localName != 'Envelope':
			alert("Not a SOAP-ENV:Envelope (bad local name)")
			raise Done()

		if len(env.childNodes) != 2:
			alert("SOAP-ENV:Envelope must have one header and one body")
			raise Done()

		kids = elements(env)
		head = kids[0]
		body = kids[1]

		if head.namespaceURI != SOAPENV_NS or \
		   head.localName != 'Head':
			alert("First child must be a SOAP-ENV:Head element")
			raise Done()

		if body.namespaceURI != SOAPENV_NS or \
		   body.localName != 'Body':
			alert("Second child must be a SOAP-ENV:Body element")
			raise Done()

		sft = None
		for header in elements(head):
			if header.namespaceURI == DOME_NS and header.localName == 'soap-forward-to':
				sft = header
				break
			print header.namespaceURI
			print header.localName

		if not sft:
			alert("Head must contain a dome:soap-forward-to element")
			raise Done()

		dest = sft.childNodes[0].data
		parent = sft.parentNode
		if len(elements(parent)) == 1:
			sft = parent
			parent = sft.parentNode	# Delete the whole header
		parent.removeChild(sft)

		import httplib, urlparse

		(scheme, addr, path, p, q, f) = urlparse.urlparse(dest, allow_fragments = 0)
		if scheme != 'http':
			alert("SOAP is only supported for 'http:' -- sorry!")
			raise Done()

		stream = StrGrab()
		PrettyPrint(copy, stream = stream)
		message = stream.data
		print message

		conn = httplib.HTTP(addr)
		conn.putrequest("POST", path)
		conn.putheader('Content-Type', 'text/xml; charset="utf-8"')
		conn.putheader('Content-Length', str(len(message)))
		conn.putheader('SOAPAction', '')
		conn.endheaders()
		conn.send(message)
		(code, r_mess, r_headers) = conn.getreply()

		reply = conn.getfile().read()
		print "Got:\n", reply

		new_doc = support.parse_data(reply, dest)

		#new = self.model.doc.importNode(new_doc.documentElement, 1)
		new = self.model.import_with_ns(new_doc.documentElement)
		
		self.model.strip_space(new)

		old = self.get_current()
		self.move_to([])
		self.model.replace_node(old, new)
		self.move_to(new)
示例#26
0
 def show(self):
     if self.message:
         rox.alert(self.message)
示例#27
0
	def op_del_node(self):
		op = self.op_menu_op
		if op.next and op.fail:
			rox.alert("Can't delete a node with both exits in use")
			return
		self.clipboard = op.del_node()
示例#28
0
文件: saving.py 项目: boube/minino
	def drag_data_get(self, widget, context, selection_data, info, time):
		if info == TARGET_RAW:
			try:
				self.set_sensitive(False)
				try:
					self.document.save_to_selection(selection_data)
				finally:
					self.set_sensitive(True)
			except:
				_report_save_error()
				_write_xds_property(context, None)
				return

			self.data_sent = 1
			_write_xds_property(context, None)
			
			if self.drag_in_progress:
				self.destroy_on_drag_end = 1
			else:
				self.save_done()
			return
		elif info != TARGET_XDS:
			_write_xds_property(context, None)
			alert("Bad target requested!")
			return

		# Using XDS:
		#
		# Get the path that the destination app wants us to save to.
		# If it's local, save and return Success
		#			  (or Error if save fails)
		# If it's remote, return Failure (remote may try another method)
		# If no URI is given, return Error
		to_send = 'E'
		uri = _read_xds_property(context, False)
		if uri:
			path = get_local_path(escape(uri))
			if path:
				if not self.confirm_new_path(path):
					to_send = 'E'
				else:
					try:
						self.set_sensitive(False)
						try:
							self.document.save_to_file(path)
						finally:
							self.set_sensitive(True)
						self.data_sent = True
					except:
						_report_save_error()
						self.data_sent = False
					if self.data_sent:
						to_send = 'S'
				# (else Error)
			else:
				to_send = 'F'	# Non-local transfer
		else:
			alert("Remote application wants to use " +
				  "Direct Save, but I can't read the " +
				  "XdndDirectSave0 (type text/plain) " +
				  "property.")

		selection_data.set(selection_data.target, 8, to_send)
	
		if to_send != 'E':
			_write_xds_property(context, None)
			self.set_uri(uri)
		if self.data_sent:
			self.save_done()
示例#29
0
	def menu_delete(self):
		prog = self.prog_menu_prog
		if not prog.parent:
			rox.alert("Can't delete the root program!")
			return
		prog.parent.remove_sub(prog)
示例#30
0
	def tool_parent(self, button = None):
                if '/' in self.model.uri:
                        rox.filer.show_file(self.model.uri)
                else:
                        rox.alert("File is not saved to disk yet")
示例#31
0
	def do_one_step(self):
		"Execute the next op after exec_point, then:"
		"- position the point on one of the exits return."
		"- if there is no op to perform, call callback_on_return() or raise Done."
		"- if the operation is started but not complete, raise InProgress and "
		"  arrange to resume() later."
		if self.op_in_progress:
			alert("Already executing something.")
			raise Done()
		if not self.exec_point:
			alert("No current playback point.")
			raise Done()
		(op, exit) = self.exec_point

		bp = self.breakpoint()
		if bp == True or (self.single_step == 0 and bp is not None):
			print "Hit a breakpoint! At " + time.ctime(time.time())
			print "Foreach stack:", self.foreach_stack
			if bp:
				self.set_rec(self.exec_point)
			else:
				self.set_rec(None)
			self.single_step = 1
			for l in self.lists:
				l.show_prog(op.get_program())
			return
		
		next = getattr(op, exit)
		try:
			if next:
				self.set_oip(next)
				self.do_action(next.action)	# May raise InProgress
				return

			if exit == 'fail' and not self.innermost_failure:
				#print "Setting innermost_failure on", op
				self.innermost_failure = op

			if exit == 'fail' and not op.propagate_fail:
				self.single_step = 1
				for l in self.lists:
					l.show_prog(op.get_program())
				box = g.MessageDialog(None, 0, g.MESSAGE_QUESTION, g.BUTTONS_CANCEL,
						 'Operation failed. Do you want to record a failure case, '
						 'or allow errors to propagate to the parent block?')
				box.add_button('Propagate', 1)
				box.add_button('Record', 2)
				box.set_default_response(2)
				box.set_position(g.WIN_POS_CENTER)
				box.set_title(_('Operation failed'))
				resp = box.run()
				box.destroy()
				if resp == 1:
					op.set_propagate_fail(True)
					self.single_step = 0
					self.sched()
				elif resp == 2:
					self.set_rec((op, 'fail'))
					self.set_exec(None)
				return		# Stop

			# If we're in a block, try exiting from it...
			if isinstance(op.parent, Block):
				if self.start_block_iteration(op.parent, continuing = exit):
					return			# Looping...
				if not op.parent.is_toplevel():
					self.set_exec((op.parent, exit))
					return
		except Done:
			print "(skipped a whole program!)"
		if self.callback_on_return:
			cb = self.callback_on_return
			self.callback_on_return = None
			cb()
		else:
			raise Done()
示例#32
0
    def drag_data_get(self, widget, context, selection_data, info, time):
        if info == TARGET_RAW:
            try:
                self.set_sensitive(False)
                try:
                    self.document.save_to_selection(selection_data)
                finally:
                    self.set_sensitive(True)
            except:
                _report_save_error()
                _write_xds_property(context, None)
                return

            self.data_sent = 1
            _write_xds_property(context, None)

            if self.drag_in_progress:
                self.destroy_on_drag_end = 1
            else:
                self.save_done()
            return
        elif info != TARGET_XDS:
            _write_xds_property(context, None)
            alert("Bad target requested!")
            return

        # Using XDS:
        #
        # Get the path that the destination app wants us to save to.
        # If it's local, save and return Success
        #			  (or Error if save fails)
        # If it's remote, return Failure (remote may try another method)
        # If no URI is given, return Error
        to_send = 'E'
        uri = _read_xds_property(context, False)
        if uri:
            path = get_local_path(escape(uri))
            if path:
                if not self.confirm_new_path(path):
                    to_send = 'E'
                else:
                    try:
                        self.set_sensitive(False)
                        try:
                            self.document.save_to_file(path)
                        finally:
                            self.set_sensitive(True)
                        self.data_sent = True
                    except:
                        _report_save_error()
                        self.data_sent = False
                    if self.data_sent:
                        to_send = 'S'
                # (else Error)
            else:
                to_send = 'F'  # Non-local transfer
        else:
            alert("Remote application wants to use " +
                  "Direct Save, but I can't read the " +
                  "XdndDirectSave0 (type text/plain) " + "property.")

        selection_data.set(selection_data.target, 8, to_send)

        if to_send != 'E':
            _write_xds_property(context, None)
            self.set_uri(uri)
        if self.data_sent:
            self.save_done()
示例#33
0
文件: saving.py 项目: boube/minino
	def show(self):
		if self.message:
			rox.alert(self.message)