Example #1
0
def choose_dir(title, default):
	sel = gtk.FileSelection(title)
	sel.set_has_separator(False)
	sel.set_filename(default)
	while True:
		resp = sel.run()
		if resp == gtk.RESPONSE_OK:
			build_dir = sel.get_filename()
			if not os.path.exists(build_dir):
				sel.destroy()
				return build_dir
			alert(sel, _("'%s' already exists") % build_dir)
		else:
			sel.destroy()
			return None
Example #2
0
def get_build_options(parent, message):
	box = gtk.MessageDialog(parent, 0, gtk.MESSAGE_QUESTION,
				gtk.BUTTONS_CANCEL, message)

	button = ButtonMixed(gtk.STOCK_GO_FORWARD, 'Force')
	button.show()
	box.add_action_widget(button, 2)

	button = ButtonMixed(gtk.STOCK_CLEAR, 'Clean')
	button.set_flags(gtk.CAN_DEFAULT)
	button.show()
	box.add_action_widget(button, 1)

	box.set_position(gtk.WIN_POS_CENTER)
	box.set_title(_('Confirm:'))
	box.set_default_response(1)
	resp = box.run()
	box.destroy()

	if resp == 1:
		return ['--clean']
	elif resp == 2:
		return ['--force']
	return None
Example #3
0
 def get_dir_callback(default_dir):
     compile_dir = gui_support.choose_dir(
         _('Create build directory'), default_dir)
     if compile_dir:
         return compile_dir
     raise SafeException("Cancelled at user's request")
Example #4
0
	def __init__(self, interface):
		assert interface
		gtk.Dialog.__init__(self, _("Compile '%s'") % interface.split('/')[-1])	# No rsplit on Python 2.3
		self.set_has_separator(False)
		self.set_default_size(gtk.gdk.screen_width() / 2, gtk.gdk.screen_height() / 2)

		def add_action(stock, name, resp):
			if not hasattr(gtk, stock):
				stock = 'STOCK_YES'
			button = ButtonMixed(getattr(gtk, stock), name)
			button.set_flags(gtk.CAN_DEFAULT)
			self.add_action_widget(button, resp)
			return button

		add_action('STOCK_PROPERTIES', '_Setup', RESPONSE_SETUP)
		add_action('STOCK_CONVERT', '_Build', RESPONSE_BUILD)
		add_action('STOCK_ADD', '_Register', RESPONSE_REGISTER)
		add_action('STOCK_NETWORK', '_Publish', RESPONSE_PUBLISH)

		self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CANCEL)

		self.set_default_response(RESPONSE_BUILD)

		self.buffer = gtk.TextBuffer()
		self.tv = gtk.TextView(self.buffer)
		self.tv.set_left_margin(4)
		self.tv.set_right_margin(4)
		self.tv.set_wrap_mode(gtk.WRAP_WORD)
		swin = gtk.ScrolledWindow()
		swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
		swin.add(self.tv)
		swin.set_shadow_type(gtk.SHADOW_IN)
		self.vscroll = swin.get_vadjustment()
		self.tv.set_editable(False)
		self.tv.set_cursor_visible(False)
		self.vbox.pack_start(swin, True, True, 0)

		self.vbox.show_all()
	
		self.connect('delete-event', lambda box, dev: True)

		def response(box, resp):
			if resp == RESPONSE_SETUP:
				def done_setup():
					self.add_msg('Now use Build to compile the chosen source code.')
				self.run_command((sys.executable, main_path, 'setup'), done_setup)
			elif resp == RESPONSE_BUILD:
				def done_build():
					self.add_msg('\nBuild successful. Now register or publish the build.')
				def build_failed():
					self.add_msg('\nIf the messages displayed above indicate a missing dependency (e.g. no C compiler '
						     "or a library that isn't available through Zero Install) then install it using your "
						     'normal package manager and click on Build again. Note that for libraries you often '
						     'need the -dev version of the package. '
						     '\nOtherwise, please notify the developers of this problem (this will transmit '
						     'the contents of the build/build-failure.log file):')
					end = self.buffer.get_end_iter()
					anchor = self.buffer.create_child_anchor(end)
					align = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
					button = ButtonMixed(gtk.STOCK_YES, 'Notify developers')
					align.add(button)
					align.set_padding(8, 8, 8, 8)
					align.show_all()
					self.tv.add_child_at_anchor(align, anchor)
					self.add_msg('\n')
					def report_bug(button):
						def done_notify():
							self.add_msg("\nReport sent. Thank you! (note: you won't get a reply, as "
								"no contact details were sent; write to the project's mailing "
								"list if you want to discuss the problem)")
						self.run_command((sys.executable, main_path, 'report-bug'), done_notify)
					button.connect('clicked', report_bug)
				buildenv = BuildEnv()
				changes = buildenv.get_build_changes()
				if changes:
					options = get_build_options(box, '\n'.join(changes) + '\n\nIt would be best to do a clean (full) build.')
				else:
					options = []
				if options is not None:
					box.run_command([sys.executable, main_path, 'build'] + options, done_build, build_failed)
			elif resp == RESPONSE_REGISTER:
				buildenv = BuildEnv()

				iface = iface_cache.get_interface(interface)
				reader.update_from_cache(iface)

				# Register using the feed-for, if available
				real_iface = iface
				for uri in iface.feed_for or []:
					real_iface = iface_cache.get_interface(uri)
					self.add_msg("Registering as a feed for %s" % real_iface.uri)
					break
				else:
					if os.path.isabs(iface.uri):
						self.add_msg("Warning: no <feed-for> in local feed %s!" % iface.uri)

				feed = buildenv.local_iface_file
				for f in real_iface.feeds or []:
					if f.uri == feed:
						self.add_msg("Feed '%s' is already registered for interface '%s'!\n" % (feed, real_iface.uri))
						return
				box.buffer.insert_at_cursor("Registering feed '%s'\n" % feed)
				real_iface.extra_feeds.append(model.Feed(feed, arch = None, user_override = True))
				writer.save_interface(real_iface)
				box.buffer.insert_at_cursor("Done. You can now close this window.\n")
			elif resp == RESPONSE_PUBLISH:
				buildenv = BuildEnv()
				box = PublishBox(self, buildenv)
				resp = box.run()
				box.destroy()
				if resp == gtk.RESPONSE_OK:
					def done_publish():
						self.add_msg("\nYou can use '0publish --local' to add this "
							"into the main feed. If you don't have a main feed then this "
							"will create one. See "
							"http://0install.net/injector-packagers.html for more information.")
					self.run_command((sys.executable, main_path,
						'publish', box.archive_dir.get_text()), done_publish)
			elif resp == gtk.RESPONSE_CANCEL or resp == gtk.RESPONSE_DELETE_EVENT:
				if self.kill_child(): return
				self.destroy()
			else:
				self.add_msg('Unknown response: %s' % resp)
				
		self.connect('response', response)

		self.system_tag = self.buffer.create_tag('system', foreground = 'blue', background = 'white')
		self.add_msg(instructions)
		self.set_responses_sensitive()
Example #5
0
			def get_dir_callback(default_dir):
				compile_dir = gui_support.choose_dir(_('Create build directory'), default_dir)
				if compile_dir:
					return compile_dir
				raise SafeException("Cancelled at user's request")