[jhbuild: 29/60] [gui] remove old code and make it work as a normal buildscript
- From: Frederic Peters <fpeters src gnome org>
- To: svn-commits-list gnome org
- Subject: [jhbuild: 29/60] [gui] remove old code and make it work as a normal buildscript
- Date: Sat, 6 Jun 2009 09:50:03 -0400 (EDT)
commit 7b9ab7071f4c1991a5d498ee989fbec9a1541af7
Author: Frédéric Péters <fpeters 0d be>
Date: Sun May 17 22:48:03 2009 +0200
[gui] remove old code and make it work as a normal buildscript
---
jhbuild/commands/gui.py | 26 +---
jhbuild/frontends/__init__.py | 2 +-
jhbuild/frontends/gtkui.py | 388 +++--------------------------------------
3 files changed, 25 insertions(+), 391 deletions(-)
diff --git a/jhbuild/commands/gui.py b/jhbuild/commands/gui.py
index 7e91b04..70c12e3 100644
--- a/jhbuild/commands/gui.py
+++ b/jhbuild/commands/gui.py
@@ -24,7 +24,6 @@ import gtk
from jhbuild.commands import Command, register_command
import jhbuild.frontends
-from jhbuild.frontends.gtkui import Configuration, AppWindow
class cmd_gui(Command):
@@ -37,29 +36,8 @@ class cmd_gui(Command):
# request GTK build script.
config.buildscript = 'gtkui'
- gui = AppWindow(config)
- gui.show()
+ build = jhbuild.frontends.get_buildscript(config)
+ build.show()
gtk.main()
- return
-
- configuration = Configuration(config, args)
- (module_list, start_at,
- run_autogen, cvs_update, no_build) = configuration.run()
-
- if start_at:
- while module_list and module_list[0].name != start_at:
- del module_list[0]
-
- if run_autogen:
- config.alwaysautogen = True
- elif not cvs_update:
- config.nonetwork = True
-
- if no_build:
- config.nobuild = True
-
- if module_list != None:
- build = jhbuild.frontends.get_buildscript(config, module_list)
- return build.build()
register_command(cmd_gui)
diff --git a/jhbuild/frontends/__init__.py b/jhbuild/frontends/__init__.py
index ba63ffa..064b302 100644
--- a/jhbuild/frontends/__init__.py
+++ b/jhbuild/frontends/__init__.py
@@ -19,7 +19,7 @@
import sys
-def get_buildscript(config, module_list):
+def get_buildscript(config, module_list=None):
modname = 'jhbuild.frontends.%s' % config.buildscript
__import__(modname)
BuildScript = sys.modules[modname].BUILD_SCRIPT
diff --git a/jhbuild/frontends/gtkui.py b/jhbuild/frontends/gtkui.py
index ce102d3..3508994 100644
--- a/jhbuild/frontends/gtkui.py
+++ b/jhbuild/frontends/gtkui.py
@@ -57,7 +57,8 @@ class AppWindow(gtk.Window, buildscript.BuildScript):
child_pid = None
error_resolution = None
- def __init__(self, config):
+ def __init__(self, config, module_list=None):
+ self.orig_modulelist = module_list
buildscript.BuildScript.__init__(self, config)
self.config = config
gtk.Window.__init__(self)
@@ -120,7 +121,8 @@ class AppWindow(gtk.Window, buildscript.BuildScript):
return iter
def on_delete_event(self, *args):
- gtk.main_quit()
+ if gtk.main_level():
+ gtk.main_quit()
if self.child_pid:
os.kill(self.child_pid, signal.SIGKILL)
sys.exit(0)
@@ -217,12 +219,15 @@ class AppWindow(gtk.Window, buildscript.BuildScript):
self.error_resolution = self.error_resolution_model.get(iter, 1)[0]
def on_build_cb(self, *args):
- modules = [self.modules_list_model.get(
- self.module_combo.get_active_iter(), 0)[0]]
+ if not self.orig_modulelist:
+ modules = [self.modules_list_model.get(
+ self.module_combo.get_active_iter(), 0)[0]]
- self.modulelist = self.module_set.get_module_list(modules,
- self.config.skip, tags = self.config.tags,
- ignore_suggests=self.config.ignore_suggests)
+ self.modulelist = self.module_set.get_module_list(modules,
+ self.config.skip, tags = self.config.tags,
+ ignore_suggests=self.config.ignore_suggests)
+ else:
+ self.orig_modulelist = None
startat = self.modules_list_model.get(self.module_combo.get_active_iter(), 2)[0]
if startat:
@@ -256,6 +261,15 @@ class AppWindow(gtk.Window, buildscript.BuildScript):
def is_build_paused(self):
return False
+ def build(self):
+ if gtk.main_level() == 0 and self.orig_modulelist:
+ # gtkui called from a "normal" command, not from jhbuild gui
+ self.modulelist = self.orig_modulelist
+ self.show()
+ self.build_button.emit('clicked')
+ gtk.main()
+ return buildscript.BuildScript.build(self)
+
def start_build(self):
self.build_button.set_sensitive(False)
self.module_hbox.set_sensitive(False)
@@ -530,362 +544,4 @@ class SelectModulesDialog(gtk.Dialog):
return gtk.RESPONSE_OK
-def get_glade_filename():
- return os.path.join(os.path.dirname(__file__), 'jhbuild.glade')
-
-class Configuration:
- def __init__(self, config, args):
- self.config = config
- self.args = args
-
- localedir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../mo'))
- gtk.glade.bindtextdomain('messages', localedir)
-
- glade_filename = get_glade_filename()
-
- # Fetch widgets out of the Glade
- self.glade = gtk.glade.XML(glade_filename)
- self.window = self.glade.get_widget("ConfigWindow")
- self.meta_modules_list = self.glade.get_widget("ConfigMetaModules")
- self.start_module_menu = self.glade.get_widget("ConfigStartModule")
- self.run_autogen_checkbox = self.glade.get_widget("ConfigRunAutogen")
- self.cvs_update_checkbox = self.glade.get_widget("ConfigCVSUpdate")
- self.no_build_checkbox = self.glade.get_widget("ConfigNoBuild")
- self.start_build_button = self.glade.get_widget("ConfigBuildButton")
- self.cancel_button = self.glade.get_widget("ConfigCancelButton")
-
- # Get settings for the checkboxes, etc
- self._get_default_settings()
-
- # Hook up the buttons / checkboxes
- self.start_build_button.connect('clicked', lambda button: gtk.main_quit())
- self.cancel_button.connect('clicked', lambda button: sys.exit(-1))
- self.run_autogen_checkbox.connect('toggled', self._autogen_checkbox_toggled)
- self.cvs_update_checkbox.connect('toggled', self._cvs_update_checkbox_toggled)
- self.no_build_checkbox.connect('toggled', self._no_build_checkbox_toggled)
- #self.start_module_menu.connect('clicked', self._start_module_menu_clicked)
-
- # Get the list of meta modules
- self.module_set = jhbuild.moduleset.load(config)
- full_module_list = self.module_set.get_full_module_list()
- self.meta_modules = []
- self.name_to_meta_module = {}
- for possible_meta_module in full_module_list:
- if isinstance(possible_meta_module, MetaModule):
- print _("Found meta module %s") % possible_meta_module.name
- self.meta_modules.append(possible_meta_module)
- self.name_to_meta_module[possible_meta_module.name] = possible_meta_module
-
- self.meta_modules.sort(lambda a, b: cmp(a.name.lower(), b.name.lower()))
- self._create_meta_modules_list_view(self.meta_modules)
-
- self._build_start_module_menu()
-
- def run(self):
- self.window.show_all()
- gtk.main()
- self.window.hide()
- self._set_default_settings()
- return (self.module_list, self.start_at_module, self.run_autogen, self.cvs_update,
- self.no_build)
-
- def _get_default_settings(self):
- if have_gconf:
- client = gconf.client_get_default()
- self.run_autogen = client.get_bool("/apps/jhbuild/always_run_autogen")
- self.cvs_update = client.get_bool("/apps/jhbuild/update_from_cvs")
- self.no_build = client.get_bool("/apps/jhbuild/no_build")
- self.selected_modules = client.get_list("/apps/jhbuild/modules_to_build", gconf.VALUE_STRING)
- self.start_at_module = client.get_string("/apps/jhbuild/start_at_module")
- else:
- self.run_autogen = False
- self.cvs_update = True
- self.no_build = False
-
- self.run_autogen_checkbox.set_active(self.run_autogen)
- self.cvs_update_checkbox.set_active(self.cvs_update)
- self.no_build_checkbox.set_active(self.no_build)
-
- def _set_default_settings(self):
- if have_gconf:
- client = gconf.client_get_default()
- client.set_bool("/apps/jhbuild/always_run_autogen", self.run_autogen)
- client.set_bool("/apps/jhbuild/update_from_cvs", self.cvs_update)
- client.set_bool("/apps/jhbuild/no_build", self.no_build)
- client.set_list("/apps/jhbuild/modules_to_build", gconf.VALUE_STRING, self.selected_modules)
- if self.start_at_module:
- client.set_string("/apps/jhbuild/start_at_module", self.start_at_module)
- else:
- client.set_string("/apps/jhbuild/start_at_module", "")
-
- print ("Gconf setting for update from CVS is %d" % self.cvs_update)
-
-
- def _meta_module_toggled(self, cell, path, model):
- iter = model.get_iter((int(path),))
- build = model.get_value(iter, 0)
- build = not build
- model.set(iter, 0, build)
- self.selected_modules = self._get_selected_meta_modules()
- self._build_start_module_menu()
-
- def _create_meta_modules_list_view(self, meta_modules):
- self.model = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING)
- self.meta_modules_list.set_model(self.model)
-
- for module in meta_modules:
- iter = self.model.append()
- if self.selected_modules:
- selected = (module.name in self.selected_modules)
- else:
- selected = False
- self.model.set(iter, 0, selected, 1, module.name)
-
- renderer = gtk.CellRendererToggle()
- renderer.connect('toggled', self._meta_module_toggled, self.model)
- column = gtk.TreeViewColumn(_('Build'), renderer, active=0)
- column.set_clickable(True)
- self.meta_modules_list.append_column(column)
-
- column = gtk.TreeViewColumn(_('Module Group'), gtk.CellRendererText(), text=1)
- self.meta_modules_list.append_column(column)
-
- def _get_selected_meta_modules(self):
- modules = []
- iter = self.model.get_iter_first()
-
- while iter:
- build = self.model.get_value(iter, 0)
- if build:
- name = self.model.get_value(iter, 1)
- module = self.name_to_meta_module[name]
- if module:
- modules.append(module.name)
- iter = self.model.iter_next(iter)
-
- return modules
-
-
- def _build_start_module_menu(self):
- if not self.selected_modules:
- return
-
- self.module_list = self.module_set.get_module_list(self.selected_modules, self.config.skip)
-
- menu = gtk.Menu()
- menu.connect('selection-done', self._start_module_menu_clicked)
-
- selected_item_number = None
- i = 0
- for module in self.module_list:
- menu_item = gtk.MenuItem(module.name)
- menu.append(menu_item)
- if module.name == self.start_at_module:
- selected_item_number = i
- i = i + 1
-
- self.start_module_menu.set_menu (menu)
-
- if selected_item_number:
- self.start_module_menu.set_history(selected_item_number)
- else:
- if self.module_list:
- self.start_at_module = self.module_list[0].name
- else:
- self.start_at_module = None
-
- menu.show_all()
-
- def _start_module_menu_clicked(self, option_menu):
- number = self.start_module_menu.get_history()
- if self.module_list:
- item = self.module_list[number]
- self.start_at_module = item.name
- else:
- self.start_at_module = None
-
- def _autogen_checkbox_toggled(self, checkbox):
- self.run_autogen = not self.run_autogen
-
- def _cvs_update_checkbox_toggled(self, checkbox):
- self.cvs_update = not self.cvs_update
-
- def _no_build_checkbox_toggled(self, checkbox):
- self.no_build = not self.no_build
-
-def optionmenu_get_history(self):
- menu = self.get_menu()
- children = menu.children()
- item = menu.get_active()
-
- for i in range(len(children)):
- if children[i] == item:
- break
-
- return i
-
-class GtkBuildScript(buildscript.BuildScript):
- def __init__(self, config, module_list):
- buildscript.BuildScript.__init__(self, config, module_list)
- self.current_module = None
- self._createWindow()
- if have_gconf:
- self.terminal_command = self._getTerminalCommand()
- else:
- self.terminal_command = "gnome-terminal"
-
- def _getTerminalCommand(self):
- client = gconf.client_get_default()
- command = client.get_string("/desktop/gnome/applications/terminal/exec")
- return command
-
- def message(self, msg, module_num = -1):
- '''shows a message to the screen'''
-
- if module_num == -1:
- module_num = self.module_num
- dialog = gtk.MessageDialog(buttons=gtk.BUTTONS_OK, message_format=msg)
- dialog.run()
- dialog.hide()
- return
-
- def set_action(self, action, module, module_num=-1, action_target=None):
- if module_num == -1:
- module_num = self.module_num
- if not action_target:
- action_target = module.name
- if self.current_module != module and self.current_module != None:
- self.current_module._build_text_buffer = self.build_text
- self.build_text = gtk.TextBuffer(self.tag_table)
- self.build_text_view.set_buffer(self.build_text)
- self.iter = self.build_text.get_end_iter()
- self.current_module = module
-
- num_modules = len(self.modulelist)
- if module_num > 0:
- self.build_progress.set_fraction(module_num / float(num_modules))
- self.build_progress.set_text(_('%d of %d modules')
- % (module_num, num_modules))
-
- self.window.set_title(_('[%(num)d/%(total)d] %(action)s %(module)s')
- % { 'num':module_num, 'total':num_modules, 'action':action, 'module':module.name} )
- self.current_status_label.set_text('%s %s' % (action, module.name))
-
- def _runEventLoop(self):
- while gtk.events_pending():
- gtk.main_iteration()
-
- def _printToBuildOutput(self, output):
- self.iter = self.build_text.get_end_iter()
- self.build_text.insert(self.iter, output)
- self.build_text.move_mark (self.ins_mark, self.iter)
- self.build_text_view.scroll_to_mark (self.ins_mark, 0.0, True, 0.5, 0.5)
-
- def _printToWarningOutput(self, output):
- self.build_text.insert_with_tags_by_name(self.iter, output, "warning")
-
- def _pauseBuild(self):
- return self.pause_button.get_active()
-
- def _makeNonBlocking(self, fd):
- fl = fcntl.fcntl(fd, fcntl.F_GETFL)
- fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NDELAY)
-
-
- def start_build(self):
- self.window.show_all()
- def end_build(self, failures):
- if len(failures) == 0:
- self.message(_('success'))
- else:
- self.message(_('the following modules were not built:\n%s')
- % ', '.join(failures))
- def start_module(self, module):
- # Remember where we are in case something fails
- if have_gconf:
- client = gconf.client_get_default()
- client.set_string("/apps/jhbuild/start_at_module", module)
-
- def handle_error(self, module, state, nextstate, error, altstates):
- '''Ask the user what to do about an error.
-
- Returns one of ERR_RERUN, ERR_CONT or ERR_GIVEUP.''' #"
-
- if not self.config.interact:
- return 'fail'
-
- dialog = gtk.Dialog(_('Error during %(state)s for module %(module)s')
- % {'state':state, 'module':module.name})
- dialog.add_button(_('_Try %s Again') % state, 1)
- dialog.add_button(_('_Ignore Error'), 2)
- dialog.add_button(_('_Skip Module'), 3)
- dialog.add_button(_('_Terminal'), 4)
-
- for i, altstate in enumerate(altstates):
- dialog.add_button(_('Go to %s') % altstate, i + 5)
-
- text_view = gtk.TextView()
- text_view.set_buffer(self.build_text)
- text_view.set_wrap_mode(gtk.WRAP_WORD_CHAR)
-
- scroller = gtk.ScrolledWindow()
- scroller.add(text_view)
- dialog.vbox.pack_start(scroller)
-
- scroller.set_size_request(-1, 250)
- scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- scroller.set_shadow_type(gtk.SHADOW_IN)
- scroller.set_border_width(12)
-
- while True:
-
- #self.message('error during %s for module %s' % (state, module.name))
-
- text_view.scroll_to_iter(self.build_text.get_end_iter(), 0.0, True, 0.5, 0.5)
- dialog.show_all()
-
- val = dialog.run()
-
- if val != 4:
- dialog.hide()
- # If the dialog was destroyed, interpret that as try again.
- if val in (1, gtk.RESPONSE_NONE, gtk.RESPONSE_DELETE_EVENT):
- return state
- elif val == 2:
- return nextstate
- elif val == 3:
- return 'fail'
- elif val == 4:
- command = 'cd %s; %s' % (module.get_builddir(self),
- self.terminal_command)
- os.system(command)
- else:
- return altstates[val - 5]
-
- def _createWindow(self):
- glade_filename = get_glade_filename()
- self.glade = gtk.glade.XML(glade_filename)
-
- self.window = self.glade.get_widget("BuildWindow")
- self.build_progress = self.glade.get_widget("BuildProgressBar")
- self.build_text_view = self.glade.get_widget("BuildText")
- self.current_status_label = self.glade.get_widget("CurrentStatusLabel")
- self.pause_button = self.glade.get_widget("BuildPauseButton")
- self.cancel_button = self.glade.get_widget("BuildCancelButton")
- #self.expander_button = self.glade.get_widget("ExpanderButton")
- #self.expander_arrow = self.glade.get_widget("ExpanderArrow")
-
- self.window.connect('destroy', lambda win: sys.exit())
- self.cancel_button.connect('clicked', lambda button: sys.exit())
- #self.expander_button.connect('activate',
-
- self.tag_table = gtk.TextTagTable()
- self.build_text = gtk.TextBuffer(self.tag_table)
- self.warning_tag = self.build_text.create_tag("warning")
- self.warning_tag.set_property("foreground", "red")
- self.build_text_view.set_buffer(self.build_text)
- self.build_text_view.set_wrap_mode(gtk.WRAP_WORD)
- self.iter = self.build_text.get_end_iter()
- self.ins_mark = self.build_text.create_mark ("jhbuild-mark", self.iter, True);
-
-BUILD_SCRIPT = GtkBuildScript
+BUILD_SCRIPT = AppWindow
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]