예제 #1
0
파일: KaZait.py 프로젝트: ZvikaZ/KaZait
    def showWindow(self):
        # self.readConfig()

        gtk.rc_add_default_file(resource_path("gtkrc"))
        gtk.widget_set_default_direction(gtk.TEXT_DIR_RTL)

        # Set the Glade file
        self.builder = gtk.Builder()

        translated_glade = resource_path("main.glade")
        self.builder.add_from_file(translated_glade)

        # Get the Main Window, and connect the "destroy" event
        self.window = self.builder.get_object("MainWindow")

        if self.window:
            self.window.connect("destroy", self.destroy)

        self.window.set_border_width(1)

        # self.builder.get_object("notebook1").set_current_page(1)

        # self.add_methods_tree()

        self.builder.connect_signals(self)

        self.my_init()

        self.window.show_all()
예제 #2
0
	def __init__(self):
		self.builder = gtk.Builder() 
		self.builder.add_from_file(localpath + 'zkiosk.ui')
		self.window = self.builder.get_object('window')
		self.browser = self.builder.get_object('Browser') 
		self.webview = webkit.WebView()
		self.browser.add(self.webview)

		#Cambia el user-agent (por cuestión estética y de identificación para estadísticas)
		Settings = self.webview.get_settings()		
		useragent = Settings.get_property("user-agent")
		useragent = useragent.replace(' Safari/',' zombieKiosk/DrunkEngine Safari/')
		Settings.set_property("user-agent",useragent)
		Settings.set_property("enable-plugins",False)
		#cambiando a pantalla completa la ventana
		maxx = gtk.gdk.screen_width() 
		maxy = gtk.gdk.screen_height() 
		self.window.set_size_request(maxx,maxy) 
		
		#Parseamos el archivo del estilo visual
		gtk.rc_reset_styles(self.window.get_settings())
		gtk.rc_parse(theme)
		gtk.rc_add_default_file(theme)
		gtk.rc_reparse_all()
		
		#muestra los elementos de la ventana
		self.window.show_all()
		#-------DEBUG---------
		self.webview.connect("navigation-policy-decision-requested",self.VerUri)
		#conectando los botones y eventos de la ventana a las funciones 
		self.builder.connect_signals(self)
예제 #3
0
def use_theme(style_str):
	"""
	Use the GTK+ style in @style_str,
	or unset if it is None
	"""
	filename = cache_filename()
	if style_str is None:
		filename = cache_filename()
		gtk.rc_set_default_files([f for f in gtk.rc_get_default_files()
		                          if f != filename])
	else:
		with open(filename, "wb") as rcfile:
			rcfile.write(style_str)
		gtk.rc_add_default_file(filename)
	re_read_theme()
예제 #4
0
def use_theme(style_str):
    """
	Use the GTK+ style in @style_str,
	or unset if it is None
	"""
    filename = cache_filename()
    if style_str is None:
        filename = cache_filename()
        gtk.rc_set_default_files(
            [f for f in gtk.rc_get_default_files() if f != filename])
    else:
        with open(filename, "wb") as rcfile:
            rcfile.write(style_str)
        gtk.rc_add_default_file(filename)
    re_read_theme()
예제 #5
0
	def execute(self):
		""""""

		# intialize thread support (hangs on winxp)
		#gtk.gdk.threads_init()

		# load Cillop-Midnite theme
		gtk.rc_add_default_file(resourcePath("themes/Cillop-Midnite/gtk-2.0/gtkrc"))
		settings = gtk.settings_get_default()
		settings.set_string_property("gtk-theme-name", "Cillop-Midnite", "")

		# load icon theme
		theme = gtk.icon_theme_get_default()
		theme.prepend_search_path(resourcePath('themes'))
		settings.set_string_property("gtk-icon-theme-name", "budabot-icon-theme", "")
		gtk.icon_size_register('status-icon-size', 24, 24)

		self.settingModel = SettingModel()
		self.botModel = BotModel(self.settingModel)
		self.botModel.connect('botRemoved', self.onBotRemoved)

		systrayController = SystrayController()

		controlPanelController = ControlPanelController(self.botModel, self.settingModel)
		controlPanelController.connect('action_triggered', self.onControlPanelAction)

		# open control panel when user select 'open' from systray's context menu
		systrayController.connect_object('open_requested', ControlPanelController.show, controlPanelController)
		# opens/closes control panel when user clicks systray icon
		systrayController.connect_object('toggle_requested', ControlPanelController.toggle, controlPanelController)

		# notify systray controller of control panel's visibility
		controlPanelController.connect('visibility_changed', systrayController.onControlPanelVisibilityChanged)

		# connect exit requests to quit()-method
		controlPanelController.connect_object('exit_requested', Application.quit, self)
		systrayController.connect_object('exit_requested', Application.quit, self)

		# show errors to user
		self.settingModel.connect('error', self.onError)

		self.settingModel.load()

		controlPanelController.show()
		# run Twisted + GTK event loop
		reactor.run()
		
		systrayController.hideIcon()
예제 #6
0
def main():
    """ creates a HAL component.
        parsees a glade XML file with gtk.builder or libglade
        calls gladevcp.makepins with the specified XML file
        to create pins and register callbacks.
        main window must be called "window1"
    """
    global gladevcp_debug
    (progdir, progname) = os.path.split(sys.argv[0])

    usage = "usage: %prog [options] myfile.ui"
    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()
    parser.add_options(options)

    (opts, args) = parser.parse_args()

    if not args:
        parser.print_help()
        sys.exit(1)

    gladevcp_debug = debug = opts.debug
    xmlname = args[0]

    #if there was no component name specified use the xml file name
    if opts.component is None:
        opts.component = os.path.splitext(os.path.basename(xmlname))[0]

    #try loading as a libglade project
    try:
        builder = gtk.glade.XML(xmlname)
        builder = GladeBuilder(builder)
    except:
        try:
            # try loading as a gtk.builder project
            print "**** GLADE VCP INFO:    Not a libglade project, trying to load as a GTK builder project"
            builder = gtk.Builder()
            builder.add_from_file(xmlname)
        except:
            print "**** GLADE VCP ERROR:    With xml file: %s" % xmlname
            sys.exit(0)

    window = builder.get_object("window1")

    window.set_title(opts.component)

    try:
        halcomp = hal.component(opts.component)
    except:
        print "*** GLADE VCP ERROR:    Asking for a HAL component using a name that already exists."
        sys.exit(0)

    panel = gladevcp.makepins.GladePanel(halcomp, xmlname, builder, None)

    # at this point, any glade HL widgets and their pins are set up.
    handlers = load_handlers(opts.usermod, halcomp, builder, opts.useropts)

    builder.connect_signals(handlers)

    if opts.parent:
        # block X errors since gdk error handling silently exits the
        # program without even the atexit handler given a chance
        gtk.gdk.error_trap_push()

        window = xembed.reparent(window, opts.parent)

        forward = os.environ.get('AXIS_FORWARD_EVENTS_TO', None)
        if forward:
            xembed.keyboard_forward(window, forward)

    window.connect("destroy", on_window_destroy)
    window.show()

    # for window resize and or position options
    if "+" in opts.geometry:
        try:
            j = opts.geometry.partition("+")
            pos = j[2].partition("+")
            window.move(int(pos[0]), int(pos[2]))
        except:
            print "**** GLADE VCP ERROR:    With window position data"
            parser.print_usage()
            sys.exit(1)
    if "x" in opts.geometry:
        try:
            if "+" in opts.geometry:
                j = opts.geometry.partition("+")
                t = j[0].partition("x")
            else:
                t = window_geometry.partition("x")
            window.resize(int(t[0]), int(t[2]))
        except:
            print "**** GLADE VCP ERROR:    With window resize data"
            parser.print_usage()
            sys.exit(1)

    if opts.gtk_workaround:
        # work around https://bugs.launchpad.net/ubuntu/+source/pygtk/+bug/507739
        # this makes widget and widget_class matches in gtkrc and theme files actually work
        dbg("activating GTK bug workaround for gtkrc files")
        for o in builder.get_objects():
            if isinstance(o, gtk.Widget):
                # retrieving the name works only for GtkBuilder files, not for
                # libglade files, so be cautious about it
                name = gtk.Buildable.get_name(o)
                if name: o.set_name(name)

    if opts.gtk_rc:
        dbg("**** GLADE VCP INFO: %s reading gtkrc file '%s'" %
            (opts.component, opts.gtk_rc))
        gtk.rc_add_default_file(opts.gtk_rc)
        gtk.rc_parse(opts.gtk_rc)

    if opts.theme:
        dbg("**** GLADE VCP INFO:    Switching %s to '%s' theme" %
            (opts.component, opts.theme))
        settings = gtk.settings_get_default()
        settings.set_string_property("gtk-theme-name", opts.theme, "")
    # This needs to be done after geometry moves so on dual screens the window maxumizes to the actual used screen size.
    if opts.maximum:
        window.window.maximize()

    if opts.halfile:
        cmd = ["halcmd", "-f", opts.halfile]
        res = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr)
        if res:
            print >> sys.stderr, "'%s' exited with %d" % (' '.join(cmd), res)
            sys.exit(res)

    # User components are set up so report that we are ready
    halcomp.ready()

    if handlers.has_key(signal_func):
        dbg("Register callback '%s' for SIGINT and SIGTERM" % (signal_func))
        signal.signal(signal.SIGTERM, handlers[signal_func])
        signal.signal(signal.SIGINT, handlers[signal_func])

    try:
        gtk.main()
    except KeyboardInterrupt:
        sys.exit(0)
    finally:
        halcomp.exit()

    if opts.parent:
        gtk.gdk.flush()
        error = gtk.gdk.error_trap_pop()
        if error:
            print "**** GLADE VCP ERROR:    X Protocol Error: %s" % str(error)
예제 #7
0
def parse_gtk_rcfiles():
    gtk.rc_add_default_file(get_data_path('gtkrc-2.0'))
    gtk.rc_add_default_file(home("gtkrc-2.0").strpath)
    # we have to force reload the settings
    gtk.rc_reparse_all_for_settings(gtk.settings_get_default(), True)
예제 #8
0
    def __init__(self, no_dialog=False):
        self.settings = EventCore()
        self.gui_is_active = False
        # during initialization any dialog (e.g. "Unit change") is not allowed
        # we set the final value later
        self.no_dialog = True
        self._batch_queue = []
        self._undo_states = []
        self.gui = gtk.Builder()
        gtk_build_file = get_ui_file_location(GTKBUILD_FILE)
        if gtk_build_file is None:
            gtk.main_quit()
        self.gui.add_from_file(gtk_build_file)
        if pycam.Utils.get_platform() == pycam.Utils.PLATFORM_WINDOWS:
            gtkrc_file = get_ui_file_location(GTKRC_FILE_WINDOWS)
            if gtkrc_file:
                gtk.rc_add_default_file(gtkrc_file)
                gtk.rc_reparse_all_for_settings(gtk.settings_get_default(),
                                                True)
        self.window = self.gui.get_object("ProjectWindow")
        self.settings.set("main_window", self.window)
        # show stock items on buttons
        # increase the initial width of the window (due to hidden elements)
        self.window.set_default_size(400, -1)
        # initialize the RecentManager (TODO: check for Windows)
        if False and pycam.Utils.get_platform(
        ) == pycam.Utils.PLATFORM_WINDOWS:
            # The pyinstaller binary for Windows fails mysteriously when trying
            # to display the stock item.
            # Error message: Gtk:ERROR:gtkrecentmanager.c:1942:get_icon_fallback: assertion failed: (retval != NULL)
            self.recent_manager = None
        else:
            try:
                self.recent_manager = gtk.recent_manager_get_default()
            except AttributeError:
                # GTK 2.12.1 seems to have problems with "RecentManager" on
                # Windows. Sadly this is the version, that is shipped with the
                # "appunti" GTK packages for Windows (April 2010).
                # see http://www.daa.com.au/pipermail/pygtk/2009-May/017052.html
                self.recent_manager = None
        # file loading
        self.last_dirname = None
        self.last_task_settings_uri = None
        self.last_model_uri = None
        # define callbacks and accelerator keys for the menu actions
        for objname, callback, data, accel_key in (
            ("LoadTaskSettings", self.load_task_settings_file, None,
             "<Control>t"), ("SaveTaskSettings", self.save_task_settings_file,
                             lambda: self.last_task_settings_uri, None),
            ("SaveAsTaskSettings", self.save_task_settings_file, None,
             None), ("OpenModel", self.load_model_file, None,
                     "<Control>o"), ("Quit", self.destroy, None, "<Control>q"),
            ("GeneralSettings", self.toggle_preferences_window, None,
             "<Control>p"), ("UndoButton", self._restore_undo_state, None,
                             "<Control>z"), ("HelpUserManual", self.show_help,
                                             "User_Manual", "F1"),
            ("HelpIntroduction", self.show_help, "Introduction", None),
            ("HelpSupportedFormats", self.show_help, "SupportedFormats",
             None), ("HelpModelTransformations", self.show_help,
                     "ModelTransformations",
                     None), ("HelpToolTypes", self.show_help, "ToolTypes",
                             None), ("HelpProcessSettings", self.show_help,
                                     "ProcessSettings", None),
            ("HelpBoundsSettings", self.show_help, "BoundsSettings",
             None), ("HelpTaskSetup", self.show_help, "TaskSetup", None),
            ("HelpGCodeExport", self.show_help, "GCodeExport",
             None), ("HelpTouchOff", self.show_help, "TouchOff",
                     None), ("HelpSimulation", self.show_help, "Simulation",
                             None), ("Help3DView", self.show_help, "3D_View",
                                     None), ("HelpServerMode", self.show_help,
                                             "ServerMode", None),
            ("HelpCommandLine", self.show_help, "CommandlineExamples",
             None), ("HelpHotkeys", self.show_help, "KeyboardShortcuts",
                     None), ("ProjectWebsite", self.show_help,
                             "http://pycam.sourceforge.net",
                             None), ("DevelopmentBlog", self.show_help,
                                     "http://fab.senselab.org/pycam", None),
            ("Forum", self.show_help,
             "http://sourceforge.net/projects/pycam/forums", None),
            ("BugTracker", self.show_help,
             "http://sourceforge.net/tracker/?group_id=237831&atid=1104176",
             None),
            ("FeatureRequest", self.show_help,
             "http://sourceforge.net/tracker/?group_id=237831&atid=1104179",
             None)):
            item = self.gui.get_object(objname)
            action = "activate"
            if data is None:
                item.connect(action, callback)
            else:
                item.connect(action, callback, data)
            if accel_key:
                key, mod = gtk.accelerator_parse(accel_key)
                accel_path = "<pycam>/%s" % objname
                item.set_accel_path(accel_path)
                gtk.accel_map_change_entry(accel_path, key, mod, True)
        # LinkButton does not work on Windows: https://bugzilla.gnome.org/show_bug.cgi?id=617874
        if pycam.Utils.get_platform() == pycam.Utils.PLATFORM_WINDOWS:

            def open_url(widget, data=None):
                webbrowser.open(widget.get_uri())

            gtk.link_button_set_uri_hook(open_url)
        # no undo is allowed at the beginning
        self.gui.get_object("UndoButton").set_sensitive(False)
        self.settings.register_event("model-change-before",
                                     self._store_undo_state)
        self.settings.register_event(
            "model-change-after",
            lambda: self.settings.emit_event("visual-item-updated"))
        # set the availability of ODE
        self.enable_ode_control = self.gui.get_object("SettingEnableODE")
        self.settings.add_item("enable_ode",
                               self.enable_ode_control.get_active,
                               self.enable_ode_control.set_active)
        self.settings.register_event("parallel-processing-changed",
                                     self.update_ode_settings)
        # configure drag-n-drop for config files and models
        self.settings.set("configure-drag-drop-func",
                          self.configure_drag_and_drop)
        self.settings.get("configure-drag-drop-func")(self.window)
        # other events
        self.window.connect("destroy", self.destroy)
        self.window.connect("delete-event", self.destroy)
        # the settings window
        self.gui.get_object("CloseSettingsWindow").connect(
            "clicked", self.toggle_preferences_window, False)
        self.gui.get_object("ResetPreferencesButton").connect(
            "clicked", self.reset_preferences)
        self.preferences_window = self.gui.get_object("GeneralSettingsWindow")
        self.preferences_window.connect("delete-event",
                                        self.toggle_preferences_window, False)
        self._preferences_window_position = None
        self._preferences_window_visible = False
        # "about" window
        self.about_window = self.gui.get_object("AboutWindow")
        self.about_window.set_version(VERSION)
        self.gui.get_object("About").connect("activate",
                                             self.toggle_about_window, True)
        # we assume, that the last child of the window is the "close" button
        # TODO: fix this ugly hack!
        self.gui.get_object("AboutWindowButtons").get_children()[-1].connect(
            "clicked", self.toggle_about_window, False)
        self.about_window.connect("delete-event", self.toggle_about_window,
                                  False)
        # menu bar
        uimanager = gtk.UIManager()
        self.settings.set("gtk-uimanager", uimanager)
        self._accel_group = uimanager.get_accel_group()

        # send a "delete" event on "CTRL-w" for every window
        def handle_window_close(accel_group, window, *args):
            window.emit("delete-event", gtk.gdk.Event(gtk.gdk.DELETE))

        self._accel_group.connect_group(ord('w'), gtk.gdk.CONTROL_MASK,
                                        gtk.ACCEL_LOCKED, handle_window_close)
        self.settings.add_item("gtk-accel-group", lambda: self._accel_group)
        for obj in self.gui.get_objects():
            if isinstance(obj, gtk.Window):
                obj.add_accel_group(self._accel_group)
        # preferences tab
        preferences_book = self.gui.get_object("PreferencesNotebook")

        def clear_preferences():
            for child in preferences_book.get_children():
                preferences_book.remove(child)

        def add_preferences_item(item, name):
            preferences_book.append_page(item, gtk.Label(name))

        self.settings.register_ui_section("preferences", add_preferences_item,
                                          clear_preferences)
        for obj_name, label, priority in (("GeneralSettingsPrefTab", "General",
                                           -50), ("ProgramsPrefTab",
                                                  "Programs", 50)):
            obj = self.gui.get_object(obj_name)
            obj.unparent()
            self.settings.register_ui("preferences", label, obj, priority)
        # general preferences
        general_prefs = self.gui.get_object("GeneralPreferencesBox")

        def clear_general_prefs():
            for item in general_prefs.get_children():
                general_prefs.remove(item)

        def add_general_prefs_item(item, name):
            general_prefs.pack_start(item, expand=False, padding=3)

        self.settings.register_ui_section("preferences_general",
                                          add_general_prefs_item,
                                          clear_general_prefs)
        for obj_name, priority in (("SettingEnableODE", 10),
                                   ("TaskSettingsDefaultFileBox", 30)):
            obj = self.gui.get_object(obj_name)
            obj.unparent()
            self.settings.register_ui("preferences_general", None, obj,
                                      priority)
        # set defaults
        self.cutter = None
        # add some dummies - to be implemented later ...
        self.settings.add_item("cutter", lambda: self.cutter)
        main_tab = self.gui.get_object("MainTabs")

        def clear_main_tab():
            while main_tab.get_n_pages() > 0:
                main_tab.remove_page(0)

        def add_main_tab_item(item, name):
            main_tab.append_page(item, gtk.Label(name))

        # TODO: move these to plugins, as well
        self.settings.register_ui_section("main", add_main_tab_item,
                                          clear_main_tab)
        main_window = self.gui.get_object("WindowBox")

        def clear_main_window():
            main_window.foreach(lambda x: main_window.remove(x))

        def add_main_window_item(item, name, **extra_args):
            # some widgets may want to override the defaults
            args = {"expand": False, "fill": False}
            args.update(extra_args)
            main_window.pack_start(item, **args)

        main_tab.unparent()
        self.settings.register_ui_section("main_window", add_main_window_item,
                                          clear_main_window)
        self.settings.register_ui("main_window",
                                  "Tabs",
                                  main_tab,
                                  -20,
                                  args_dict={
                                      "expand": True,
                                      "fill": True
                                  })
        # autoload task settings file on startup
        autoload_enable = self.gui.get_object("AutoLoadTaskFile")
        autoload_box = self.gui.get_object("StartupTaskFileBox")
        autoload_source = self.gui.get_object("StartupTaskFile")

        # TODO: fix the extension filter
        #for one_filter in get_filters_from_list(FILTER_CONFIG):
        #    autoload_source.add_filter(one_filter)
        #    autoload_source.set_filter(one_filter)
        def get_autoload_task_file(autoload_source=autoload_source):
            if autoload_enable.get_active():
                return autoload_source.get_filename()
            else:
                return ""

        def set_autoload_task_file(filename):
            if filename:
                autoload_enable.set_active(True)
                autoload_box.show()
                autoload_source.set_filename(filename)
            else:
                autoload_enable.set_active(False)
                autoload_box.hide()
                autoload_source.unselect_all()

        def autoload_enable_switched(widget, box):
            if not widget.get_active():
                set_autoload_task_file(None)
            else:
                autoload_box.show()

        autoload_enable.connect("toggled", autoload_enable_switched,
                                autoload_box)
        self.settings.add_item("default_task_settings_file",
                               get_autoload_task_file, set_autoload_task_file)

        def disable_gui():
            self.menubar.set_sensitive(False)
            main_tab.set_sensitive(False)

        def enable_gui():
            self.menubar.set_sensitive(True)
            main_tab.set_sensitive(True)

        self.settings.register_event("gui-disable", disable_gui)
        self.settings.register_event("gui-enable", enable_gui)
        # configure locations of external programs
        for auto_control_name, location_control_name, browse_button, key in (
            ("ExternalProgramInkscapeAuto", "ExternalProgramInkscapeControl",
             "ExternalProgramInkscapeBrowse", "inkscape"),
            ("ExternalProgramPstoeditAuto", "ExternalProgramPstoeditControl",
             "ExternalProgramPstoeditBrowse", "pstoedit")):
            self.gui.get_object(auto_control_name).connect(
                "clicked", self._locate_external_program, key)
            location_control = self.gui.get_object(location_control_name)
            self.settings.add_item("external_program_%s" % key,
                                   location_control.get_text,
                                   location_control.set_text)
            self.gui.get_object(browse_button).connect(
                "clicked", self._browse_external_program_location, key)
        # set the icons (in different sizes) for all windows
        gtk.window_set_default_icon_list(*get_icons_pixbuffers())
        # load menu data
        gtk_menu_file = get_ui_file_location(GTKMENU_FILE)
        if gtk_menu_file is None:
            gtk.main_quit()
        uimanager.add_ui_from_file(gtk_menu_file)
        # make the actions defined in the GTKBUILD file available in the menu
        actiongroup = gtk.ActionGroup("menubar")
        for action in [
                action for action in self.gui.get_objects()
                if isinstance(action, gtk.Action)
        ]:
            actiongroup.add_action(action)
        # the "pos" parameter is optional since 2.12 - we can remove it later
        uimanager.insert_action_group(actiongroup, pos=-1)
        # the "recent files" sub-menu
        if not self.recent_manager is None:
            recent_files_menu = gtk.RecentChooserMenu(self.recent_manager)
            recent_files_menu.set_name("RecentFilesMenu")
            recent_menu_filter = gtk.RecentFilter()
            case_converter = pycam.Utils.get_case_insensitive_file_pattern
            for filter_name, patterns in FILTER_MODEL:
                if not isinstance(patterns, (list, set, tuple)):
                    patterns = [patterns]
                # convert it into a mutable list (instead of set/tuple)
                patterns = list(patterns)
                for index in range(len(patterns)):
                    patterns[index] = case_converter(patterns[index])
                for pattern in patterns:
                    recent_menu_filter.add_pattern(pattern)
            recent_files_menu.add_filter(recent_menu_filter)
            recent_files_menu.set_show_numbers(True)
            # non-local files (without "file://") are not supported. yet
            recent_files_menu.set_local_only(False)
            # most recent files to the top
            recent_files_menu.set_sort_type(gtk.RECENT_SORT_MRU)
            # show only ten files
            recent_files_menu.set_limit(10)
            uimanager.get_widget("/MenuBar/FileMenu/OpenRecentModelMenu")\
                    .set_submenu(recent_files_menu)
            recent_files_menu.connect("item-activated",
                                      self.load_recent_model_file)
        else:
            self.gui.get_object("OpenRecentModel").set_visible(False)
        # load the menubar and connect functions to its items
        self.menubar = uimanager.get_widget("/MenuBar")
        # dict of all merge-ids
        menu_merges = {}

        def clear_menu(menu_key):
            for merge in menu_merges.get(menu_key, []):
                uimanager.remove_ui(merge)

        def append_menu_item(menu_key, base_path, widget, name):
            merge_id = uimanager.new_merge_id()
            if widget:
                action_group = widget.props.action_group
                if not action_group in uimanager.get_action_groups():
                    uimanager.insert_action_group(action_group, -1)
                widget_name = widget.get_name()
                item_type = gtk.UI_MANAGER_MENUITEM
            else:
                widget_name = name
                item_type = gtk.UI_MANAGER_SEPARATOR
            uimanager.add_ui(merge_id, base_path, name, widget_name, item_type,
                             False)
            if not menu_key in menu_merges:
                menu_merges[menu_key] = []
            menu_merges[menu_key].append(merge_id)

        def get_menu_funcs(menu_key, base_path):
            append_func = lambda widget, name: \
                    append_menu_item(menu_key, base_path, widget, name)
            clear_func = lambda: clear_menu(menu_key)
            return append_func, clear_func

        for ui_name, base_path in (("view_menu", "/MenuBar/ViewMenu"),
                                   ("file_menu", "/MenuBar/FileMenu"),
                                   ("edit_menu", "/MenuBar/EditMenu"),
                                   ("export_menu",
                                    "/MenuBar/FileMenu/ExportMenu")):
            append_func, clear_func = get_menu_funcs(ui_name, base_path)
            self.settings.register_ui_section(ui_name, append_func, clear_func)
        self.settings.register_ui("file_menu", "Quit",
                                  self.gui.get_object("Quit"), 100)
        self.settings.register_ui("file_menu", "QuitSeparator", None, 95)
        self.settings.register_ui("main_window", "Main", self.menubar, -100)
        # initialize plugins
        self.plugin_manager = pycam.Plugins.PluginManager(core=self.settings)
        self.plugin_manager.import_plugins()
        # some more initialization
        self.reset_preferences()
        # TODO: preferences are not loaded until the new format is stable
        #self.load_preferences()
        #self.load_task_settings()
        self.settings.register_event("notify-file-saved",
                                     self.add_to_recent_file_list)
        self.settings.register_event("notify-file-opened",
                                     self.add_to_recent_file_list)
        # fallback - in case of a failure when opening a model file
        model = pycam.Importers.TestModel.get_test_model()
        self.settings.get("models").add_model(model, "Tiny pyramid")
        # Without this "gkt.main_iteration" loop the task settings file
        # control would not be updated in time.
        while gtk.events_pending():
            gtk.main_iteration()
        autoload_task_filename = self.settings.get(
            "default_task_settings_file")
        if autoload_task_filename:
            self.open_task_settings_file(autoload_task_filename)
        self.update_all_controls()
        self.no_dialog = no_dialog
        if not self.no_dialog:
            # register a logging handler for displaying error messages
            pycam.Utils.log.add_gtk_gui(self.window, logging.ERROR)
            self.window.show()
예제 #9
0
 def readGtkRCFiles(self, *args):
     for file in plugins.findDataPaths([ ".gtkrc-2.0" ], *args):
         gtk.rc_add_default_file(file)
예제 #10
0
  def __init__(self, handle):
    activity.Activity.__init__(self, handle)

    # TODO - clean -  install gettext
    os.chdir(Globals.pwd)  # required for i18n.py to work
    #gettext.install('JokeMachine', './po', unicode=True)
    #presLan_af = gettext.translation("JokeMachine", os.path.join(Globals.pwd, 'po'), languages=['af'])
    #presLan_af.install()
    #locale.setlocale(locale.LC_ALL, 'af')    

    # customize theme
    gtkrc = os.path.join(Globals.pwd, 'resources/gtkrc')
    if os.path.exists(gtkrc):
      logging.debug("Loading resources from %s" % gtkrc)
      gtk.rc_add_default_file(gtkrc)
      settings = gtk.settings_get_default()
      #gtk.rc_reset_styles(settings)
      gtk.rc_reparse_all_for_settings(settings, True)
      logging.debug("Loading resources DONE")

    Globals.set_activity_instance(self)

    logging.debug("Starting the Joke Machine activity")

    # toolbox
    self.__toolbox = activity.ActivityToolbox(self)
    self.set_toolbox(self.__toolbox)

    # main activity frame
    self.__activity_frame = Frame()
    vbox = gtk.VBox()
    vbox.pack_start(self.__activity_frame)
    vbox.show()
    self.set_canvas(vbox)
    self.show_all()

    # Initialize mesh ##########################################################

    # init Presence Service
    self.__presence_service = presenceservice.get_instance()
    try:
      name, path = self.__presence_service.get_preferred_connection()
      self.__telepathy_connection = telepathy.client.Connection(name, path)
      self.__telepathy_initiating = None
    except TypeError:
      logging.debug('Presence service offline')

    # Buddy object for you
    owner = self.__presence_service.get_owner()
    Globals.set_owner(owner)

    self.__session = None  # JokeMachineSession
    self.connect('shared', self.__do_activity_shared)


    # Check if we're joining another instance 
    self.__is_initiator = True
    if self._shared_activity is not None:
      self.alert(_('Joke Machine'), _('Please wait a moment for your buddy\'s Jokebooks to show up'))
      self.__is_initiator = False
      logging.debug('shared:  %s' % self._shared_activity.props.joined)
      # We are joining the activity
      logging.debug('Joined activity')                      
      self.connect('joined', self.__do_activity_joined) 
      self._shared_activity.connect('buddy-joined', self.__do_buddy_joined) 
      self._shared_activity.connect('buddy-left', self.__do_buddy_left) 
      if self.get_shared():
        # We've already joined
        self.__do_activity_joined()
    else:   
      logging.debug('Created activity')    

    # ##########################################################################

    # set default startup page if we're the initiator
    if self.is_initiator: 
      self.set_page(pages.choose.Choose)
예제 #11
0
파일: Project.py 프로젝트: I--Fox--I/pycam
 def __init__(self, no_dialog=False):
     self.settings = EventCore()
     self.gui_is_active = False
     # during initialization any dialog (e.g. "Unit change") is not allowed
     # we set the final value later
     self.no_dialog = True
     self._batch_queue = []
     self._undo_states = []
     self.gui = gtk.Builder()
     gtk_build_file = get_ui_file_location(GTKBUILD_FILE)
     if gtk_build_file is None:
         gtk.main_quit()
     self.gui.add_from_file(gtk_build_file)
     if pycam.Utils.get_platform() == pycam.Utils.PLATFORM_WINDOWS:
         gtkrc_file = get_ui_file_location(GTKRC_FILE_WINDOWS)
         if gtkrc_file:
             gtk.rc_add_default_file(gtkrc_file)
             gtk.rc_reparse_all_for_settings(gtk.settings_get_default(), True)
     self.window = self.gui.get_object("ProjectWindow")
     self.settings.set("main_window", self.window)
     # show stock items on buttons
     # increase the initial width of the window (due to hidden elements)
     self.window.set_default_size(400, -1)
     # initialize the RecentManager (TODO: check for Windows)
     if False and pycam.Utils.get_platform() == pycam.Utils.PLATFORM_WINDOWS:
         # The pyinstaller binary for Windows fails mysteriously when trying
         # to display the stock item.
         # Error message: Gtk:ERROR:gtkrecentmanager.c:1942:get_icon_fallback: assertion failed: (retval != NULL)
         self.recent_manager = None
     else:
         try:
             self.recent_manager = gtk.recent_manager_get_default()
         except AttributeError:
             # GTK 2.12.1 seems to have problems with "RecentManager" on
             # Windows. Sadly this is the version, that is shipped with the
             # "appunti" GTK packages for Windows (April 2010).
             # see http://www.daa.com.au/pipermail/pygtk/2009-May/017052.html
             self.recent_manager = None
     # file loading
     self.last_dirname = None
     self.last_task_settings_uri = None
     self.last_model_uri = None
     # define callbacks and accelerator keys for the menu actions
     for objname, callback, data, accel_key in (
             ("LoadTaskSettings", self.load_task_settings_file, None, "<Control>t"),
             ("SaveTaskSettings", self.save_task_settings_file, lambda: self.last_task_settings_uri, None),
             ("SaveAsTaskSettings", self.save_task_settings_file, None, None),
             ("OpenModel", self.load_model_file, None, "<Control>o"),
             ("Quit", self.destroy, None, "<Control>q"),
             ("GeneralSettings", self.toggle_preferences_window, None, "<Control>p"),
             ("UndoButton", self._restore_undo_state, None, "<Control>z"),
             ("HelpUserManual", self.show_help, "User_Manual", "F1"),
             ("HelpIntroduction", self.show_help, "Introduction", None),
             ("HelpSupportedFormats", self.show_help, "SupportedFormats", None),
             ("HelpModelTransformations", self.show_help, "ModelTransformations", None),
             ("HelpToolTypes", self.show_help, "ToolTypes", None),
             ("HelpProcessSettings", self.show_help, "ProcessSettings", None),
             ("HelpBoundsSettings", self.show_help, "BoundsSettings", None),
             ("HelpTaskSetup", self.show_help, "TaskSetup", None),
             ("HelpGCodeExport", self.show_help, "GCodeExport", None),
             ("HelpTouchOff", self.show_help, "TouchOff", None),
             ("HelpSimulation", self.show_help, "Simulation", None),
             ("Help3DView", self.show_help, "3D_View", None),
             ("HelpServerMode", self.show_help, "ServerMode", None),
             ("HelpCommandLine", self.show_help, "CommandlineExamples", None),
             ("HelpHotkeys", self.show_help, "KeyboardShortcuts", None),
             ("ProjectWebsite", self.show_help, "http://pycam.sourceforge.net", None),
             ("DevelopmentBlog", self.show_help, "http://fab.senselab.org/pycam", None),
             ("Forum", self.show_help, "http://sourceforge.net/projects/pycam/forums", None),
             ("BugTracker", self.show_help, "http://sourceforge.net/tracker/?group_id=237831&atid=1104176", None),
             ("FeatureRequest", self.show_help, "http://sourceforge.net/tracker/?group_id=237831&atid=1104179", None)):
         item = self.gui.get_object(objname)
         action = "activate"
         if data is None:
             item.connect(action, callback)
         else:
             item.connect(action, callback, data)
         if accel_key:
             key, mod = gtk.accelerator_parse(accel_key)
             accel_path = "<pycam>/%s" % objname
             item.set_accel_path(accel_path)
             gtk.accel_map_change_entry(accel_path, key, mod, True)
     # LinkButton does not work on Windows: https://bugzilla.gnome.org/show_bug.cgi?id=617874
     if pycam.Utils.get_platform() == pycam.Utils.PLATFORM_WINDOWS:
         def open_url(widget, data=None):
             webbrowser.open(widget.get_uri())
         gtk.link_button_set_uri_hook(open_url)
     # no undo is allowed at the beginning
     self.gui.get_object("UndoButton").set_sensitive(False)
     self.settings.register_event("model-change-before",
             self._store_undo_state)
     self.settings.register_event("model-change-after",
             lambda: self.settings.emit_event("visual-item-updated"))
     # set the availability of ODE
     self.enable_ode_control = self.gui.get_object("SettingEnableODE")
     self.settings.add_item("enable_ode", self.enable_ode_control.get_active,
             self.enable_ode_control.set_active)
     self.settings.register_event("parallel-processing-changed",
             self.update_ode_settings)
     # configure drag-n-drop for config files and models
     self.settings.set("configure-drag-drop-func",
             self.configure_drag_and_drop)
     self.settings.get("configure-drag-drop-func")(self.window)
     # other events
     self.window.connect("destroy", self.destroy)
     self.window.connect("delete-event", self.destroy)
     # the settings window
     self.gui.get_object("CloseSettingsWindow").connect("clicked", self.toggle_preferences_window, False)
     self.gui.get_object("ResetPreferencesButton").connect("clicked", self.reset_preferences)
     self.preferences_window = self.gui.get_object("GeneralSettingsWindow")
     self.preferences_window.connect("delete-event", self.toggle_preferences_window, False)
     self._preferences_window_position = None
     self._preferences_window_visible = False
     # "about" window
     self.about_window = self.gui.get_object("AboutWindow")
     self.about_window.set_version(VERSION)
     self.gui.get_object("About").connect("activate", self.toggle_about_window, True)
     # we assume, that the last child of the window is the "close" button
     # TODO: fix this ugly hack!
     self.gui.get_object("AboutWindowButtons").get_children()[-1].connect("clicked", self.toggle_about_window, False)
     self.about_window.connect("delete-event", self.toggle_about_window, False)
     # menu bar
     uimanager = gtk.UIManager()
     self.settings.set("gtk-uimanager", uimanager)
     self._accel_group = uimanager.get_accel_group()
     # send a "delete" event on "CTRL-w" for every window
     def handle_window_close(accel_group, window, *args):
         window.emit("delete-event", gtk.gdk.Event(gtk.gdk.DELETE))
     self._accel_group.connect_group(ord('w'), gtk.gdk.CONTROL_MASK,
             gtk.ACCEL_LOCKED, handle_window_close)
     self.settings.add_item("gtk-accel-group", lambda: self._accel_group)
     for obj in self.gui.get_objects():
         if isinstance(obj, gtk.Window):
             obj.add_accel_group(self._accel_group)
     # preferences tab
     preferences_book = self.gui.get_object("PreferencesNotebook")
     def clear_preferences():
         for child in preferences_book.get_children():
             preferences_book.remove(child)
     def add_preferences_item(item, name):
         preferences_book.append_page(item, gtk.Label(name))
     self.settings.register_ui_section("preferences",
             add_preferences_item, clear_preferences)
     for obj_name, label, priority in (
             ("GeneralSettingsPrefTab", "General", -50),
             ("ProgramsPrefTab", "Programs", 50)):
         obj = self.gui.get_object(obj_name)
         obj.unparent()
         self.settings.register_ui("preferences", label, obj, priority)
     # general preferences
     general_prefs = self.gui.get_object("GeneralPreferencesBox")
     def clear_general_prefs():
         for item in general_prefs.get_children():
             general_prefs.remove(item)
     def add_general_prefs_item(item, name):
         general_prefs.pack_start(item, expand=False, padding=3)
     self.settings.register_ui_section("preferences_general",
             add_general_prefs_item, clear_general_prefs)
     for obj_name, priority in (("SettingEnableODE", 10),
             ("TaskSettingsDefaultFileBox", 30)):
         obj = self.gui.get_object(obj_name)
         obj.unparent()
         self.settings.register_ui("preferences_general", None,
                 obj, priority)
     # set defaults
     self.cutter = None
     # add some dummies - to be implemented later ...
     self.settings.add_item("cutter", lambda: self.cutter)
     main_tab = self.gui.get_object("MainTabs")
     def clear_main_tab():
         while main_tab.get_n_pages() > 0:
             main_tab.remove_page(0)
     def add_main_tab_item(item, name):
         main_tab.append_page(item, gtk.Label(name))
     # TODO: move these to plugins, as well
     self.settings.register_ui_section("main", add_main_tab_item,
             clear_main_tab)
     main_window = self.gui.get_object("WindowBox")
     def clear_main_window():
         main_window.foreach(lambda x: main_window.remove(x))
     def add_main_window_item(item, name, **extra_args):
         # some widgets may want to override the defaults
         args = {"expand": False, "fill": False}
         args.update(extra_args)
         main_window.pack_start(item, **args)
     main_tab.unparent()
     self.settings.register_ui_section("main_window", add_main_window_item,
             clear_main_window)
     self.settings.register_ui("main_window", "Tabs", main_tab, -20,
             args_dict={"expand": True, "fill": True})
     # autoload task settings file on startup
     autoload_enable = self.gui.get_object("AutoLoadTaskFile")
     autoload_box = self.gui.get_object("StartupTaskFileBox")
     autoload_source = self.gui.get_object("StartupTaskFile")
     # TODO: fix the extension filter
     #for one_filter in get_filters_from_list(FILTER_CONFIG):
     #    autoload_source.add_filter(one_filter)
     #    autoload_source.set_filter(one_filter)
     def get_autoload_task_file(autoload_source=autoload_source):
         if autoload_enable.get_active():
             return autoload_source.get_filename()
         else:
             return ""
     def set_autoload_task_file(filename):
         if filename:
             autoload_enable.set_active(True)
             autoload_box.show()
             autoload_source.set_filename(filename)
         else:
             autoload_enable.set_active(False)
             autoload_box.hide()
             autoload_source.unselect_all()
     def autoload_enable_switched(widget, box):
         if not widget.get_active():
             set_autoload_task_file(None)
         else:
             autoload_box.show()
     autoload_enable.connect("toggled", autoload_enable_switched,
             autoload_box)
     self.settings.add_item("default_task_settings_file",
             get_autoload_task_file, set_autoload_task_file)
     def disable_gui():
         self.menubar.set_sensitive(False)
         main_tab.set_sensitive(False)
     def enable_gui():
         self.menubar.set_sensitive(True)
         main_tab.set_sensitive(True)
     self.settings.register_event("gui-disable", disable_gui)
     self.settings.register_event("gui-enable", enable_gui)
     # configure locations of external programs
     for auto_control_name, location_control_name, browse_button, key in (
             ("ExternalProgramInkscapeAuto",
             "ExternalProgramInkscapeControl",
             "ExternalProgramInkscapeBrowse", "inkscape"),
             ("ExternalProgramPstoeditAuto",
             "ExternalProgramPstoeditControl",
             "ExternalProgramPstoeditBrowse", "pstoedit")):
         self.gui.get_object(auto_control_name).connect("clicked",
                 self._locate_external_program, key)
         location_control = self.gui.get_object(location_control_name)
         self.settings.add_item("external_program_%s" % key,
                 location_control.get_text, location_control.set_text)
         self.gui.get_object(browse_button).connect("clicked",
                 self._browse_external_program_location, key)
     # set the icons (in different sizes) for all windows
     gtk.window_set_default_icon_list(*get_icons_pixbuffers())
     # load menu data
     gtk_menu_file = get_ui_file_location(GTKMENU_FILE)
     if gtk_menu_file is None:
         gtk.main_quit()
     uimanager.add_ui_from_file(gtk_menu_file)
     # make the actions defined in the GTKBUILD file available in the menu
     actiongroup = gtk.ActionGroup("menubar")
     for action in [action for action in self.gui.get_objects()
             if isinstance(action, gtk.Action)]:
         actiongroup.add_action(action)
     # the "pos" parameter is optional since 2.12 - we can remove it later
     uimanager.insert_action_group(actiongroup, pos=-1)
     # the "recent files" sub-menu
     if not self.recent_manager is None:
         recent_files_menu = gtk.RecentChooserMenu(self.recent_manager)
         recent_files_menu.set_name("RecentFilesMenu")
         recent_menu_filter = gtk.RecentFilter()
         case_converter = pycam.Utils.get_case_insensitive_file_pattern
         for filter_name, patterns in FILTER_MODEL:
             if not isinstance(patterns, (list, set, tuple)):
                 patterns = [patterns]
             # convert it into a mutable list (instead of set/tuple)
             patterns = list(patterns)
             for index in range(len(patterns)):
                 patterns[index] = case_converter(patterns[index])
             for pattern in patterns:
                 recent_menu_filter.add_pattern(pattern)
         recent_files_menu.add_filter(recent_menu_filter)
         recent_files_menu.set_show_numbers(True)
         # non-local files (without "file://") are not supported. yet
         recent_files_menu.set_local_only(False)
         # most recent files to the top
         recent_files_menu.set_sort_type(gtk.RECENT_SORT_MRU)
         # show only ten files
         recent_files_menu.set_limit(10)
         uimanager.get_widget("/MenuBar/FileMenu/OpenRecentModelMenu")\
                 .set_submenu(recent_files_menu)
         recent_files_menu.connect("item-activated",
                 self.load_recent_model_file)
     else:
         self.gui.get_object("OpenRecentModel").set_visible(False)
     # load the menubar and connect functions to its items
     self.menubar = uimanager.get_widget("/MenuBar")
     # dict of all merge-ids
     menu_merges = {}
     def clear_menu(menu_key):
         for merge in menu_merges.get(menu_key, []):
             uimanager.remove_ui(merge)
     def append_menu_item(menu_key, base_path, widget, name):
         merge_id = uimanager.new_merge_id()
         if widget:
             action_group = widget.props.action_group
             if not action_group in uimanager.get_action_groups():
                 uimanager.insert_action_group(action_group, -1)
             widget_name = widget.get_name()
             item_type = gtk.UI_MANAGER_MENUITEM
         else:
             widget_name = name
             item_type = gtk.UI_MANAGER_SEPARATOR
         uimanager.add_ui(merge_id, base_path, name, widget_name, item_type,
                 False)
         if not menu_key in menu_merges:
             menu_merges[menu_key] = []
         menu_merges[menu_key].append(merge_id)
     def get_menu_funcs(menu_key, base_path):
         append_func = lambda widget, name: \
                 append_menu_item(menu_key, base_path, widget, name)
         clear_func = lambda: clear_menu(menu_key)
         return append_func, clear_func
     for ui_name, base_path in (("view_menu", "/MenuBar/ViewMenu"),
             ("file_menu", "/MenuBar/FileMenu"),
             ("edit_menu", "/MenuBar/EditMenu"),
             ("export_menu", "/MenuBar/FileMenu/ExportMenu")):
         append_func, clear_func = get_menu_funcs(ui_name, base_path)
         self.settings.register_ui_section(ui_name, append_func, clear_func)
     self.settings.register_ui("file_menu", "Quit",
             self.gui.get_object("Quit"), 100)
     self.settings.register_ui("file_menu", "QuitSeparator", None, 95)
     self.settings.register_ui("main_window", "Main", self.menubar, -100)
     # initialize plugins
     self.plugin_manager = pycam.Plugins.PluginManager(core=self.settings)
     self.plugin_manager.import_plugins()
     # some more initialization
     self.reset_preferences()
     # TODO: preferences are not loaded until the new format is stable
     #self.load_preferences()
     #self.load_task_settings()
     self.settings.register_event("notify-file-saved",
             self.add_to_recent_file_list)
     self.settings.register_event("notify-file-opened",
             self.add_to_recent_file_list)
     # fallback - in case of a failure when opening a model file
     model = pycam.Importers.TestModel.get_test_model()
     self.settings.get("models").add_model(model, "Tiny pyramid")
     # Without this "gkt.main_iteration" loop the task settings file
     # control would not be updated in time.
     while gtk.events_pending():
         gtk.main_iteration()
     autoload_task_filename = self.settings.get("default_task_settings_file")
     if autoload_task_filename:
         self.open_task_settings_file(autoload_task_filename)
     self.update_all_controls()
     self.no_dialog = no_dialog
     if not self.no_dialog:
         # register a logging handler for displaying error messages
         pycam.Utils.log.add_gtk_gui(self.window, logging.ERROR)
         self.window.show()
예제 #12
0
파일: fanim.py 프로젝트: avrj/gimp-fanim
    def _setup_widgets(self):
        """
        create all the window staticaly placed widgets.
        """
        #load the saved setting before start.
        self.set_settings(Utils.load_conffile(CONF_FILENAME))

        # basic window definitions
        self.connect("destroy", self.destroy)
        self.connect("focus_in_event", self.on_window_focus)
        self.connect("configure_event", self.on_window_resize)

        self.set_default_size(self.win_size[0], self.win_size[1])
        self.set_keep_above(True)

        #self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
        self.move(self.win_pos[0], self.win_pos[1])

        # parse gimp theme gtkrc
        gtkrc_path = self._get_theme_gtkrc(gimp.personal_rc_file('themerc'))

        if os.name != 'nt':  # try apply the theme by parse a gtkrc file if is not a windows system.
            gtk.rc_parse(gtkrc_path)
        else:  # if error occur them parse the file in another way.
            gtk.rc_add_default_file(gtkrc_path)
            gtk.rc_reparse_all()

        # start creating basic layout
        base = gtk.VBox()

        # commands bar widgets
        cbar = gtk.HBox()
        cbar.pack_start(self._setup_playbackbar(), False, False, 10)
        cbar.pack_start(self._setup_editbar(), False, False, 10)
        cbar.pack_start(self._setup_onionskin(), False, False, 10)
        cbar.pack_start(self._setup_config(), False, False, 10)
        cbar.pack_start(self._setup_generalbar(), False, False, 10)

        # frames bar widgets
        self.frame_bar = gtk.HBox()
        scroll_window = gtk.ScrolledWindow()
        scroll_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_window.add_with_viewport(self.frame_bar)
        scroll_window.set_size_request(-1, 140)

        # mount the widgets together
        base.pack_start(cbar, False, False, 0)
        base.pack_start(scroll_window, True, True, 0)
        self.add(base)

        # invert the image so onionskin can be used propely, with backward frames be
        # above the actual frame, sinse GIMP upper layers are firstly visible they cant
        # be backward frames.
        pdb.script_fu_reverse_layers(self.image, None)
        # scan all layers
        self._scan_image_layers()
        self.active = 0
        self.on_goto(None, GIMP_ACTIVE)

        # finalize showing all widgets
        self.show_all()
예제 #13
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)

        # TODO - clean -  install gettext
        os.chdir(Globals.pwd)  # required for i18n.py to work
        #gettext.install('JokeMachine', './po', unicode=True)
        #presLan_af = gettext.translation("JokeMachine", os.path.join(Globals.pwd, 'po'), languages=['af'])
        #presLan_af.install()
        #locale.setlocale(locale.LC_ALL, 'af')

        # customize theme
        gtkrc = os.path.join(Globals.pwd, 'resources/gtkrc')
        if os.path.exists(gtkrc):
            logging.debug("Loading resources from %s" % gtkrc)
            gtk.rc_add_default_file(gtkrc)
            settings = gtk.settings_get_default()
            #gtk.rc_reset_styles(settings)
            gtk.rc_reparse_all_for_settings(settings, True)
            logging.debug("Loading resources DONE")

        Globals.set_activity_instance(self)

        logging.debug("Starting the Joke Machine activity")

        # toolbox
        self.__toolbox = activity.ActivityToolbox(self)
        self.set_toolbox(self.__toolbox)

        # main activity frame
        self.__activity_frame = Frame()
        vbox = gtk.VBox()
        vbox.pack_start(self.__activity_frame)
        vbox.show()
        self.set_canvas(vbox)
        self.show_all()

        # Initialize mesh ##########################################################

        # init Presence Service
        self.__presence_service = presenceservice.get_instance()
        try:
            name, path = self.__presence_service.get_preferred_connection()
            self.__telepathy_connection = telepathy.client.Connection(
                name, path)
            self.__telepathy_initiating = None
        except TypeError:
            logging.debug('Presence service offline')

        # Buddy object for you
        owner = self.__presence_service.get_owner()
        Globals.set_owner(owner)

        self.__session = None  # JokeMachineSession
        self.connect('shared', self.__do_activity_shared)

        # Check if we're joining another instance
        self.__is_initiator = True
        if self._shared_activity is not None:
            self.alert(
                _('Joke Machine'),
                _('Please wait a moment for your buddy\'s Jokebooks to show up'
                  ))
            self.__is_initiator = False
            logging.debug('shared:  %s' % self._shared_activity.props.joined)
            # We are joining the activity
            logging.debug('Joined activity')
            self.connect('joined', self.__do_activity_joined)
            self._shared_activity.connect('buddy-joined',
                                          self.__do_buddy_joined)
            self._shared_activity.connect('buddy-left', self.__do_buddy_left)
            if self.get_shared():
                # We've already joined
                self.__do_activity_joined()
        else:
            logging.debug('Created activity')

        # ##########################################################################

        # set default startup page if we're the initiator
        if self.is_initiator:
            self.set_page(pages.choose.Choose)
예제 #14
0
def parse_gtk_rcfiles():
    gtk.rc_add_default_file(get_data_path('gtkrc-2.0'))
    gtk.rc_add_default_file(home("gtkrc-2.0").strpath)
    # we have to force reload the settings
    gtk.rc_reparse_all_for_settings(gtk.settings_get_default(), True)
예제 #15
0
    if opts.gtk_workaround:
        # work around https://bugs.launchpad.net/ubuntu/+source/pygtk/+bug/507739
        # this makes widget and widget_class matches in gtkrc and theme files actually work
        dbg("activating GTK bug workaround for gtkrc files")
        for o in builder.get_objects():
            if isinstance(o, gtk.Widget):
                # retrieving the name works only for GtkBuilder files, not for
                # libglade files, so be cautious about it
                name = gtk.Buildable.get_name(o)
                if name: o.set_name(name)

    if opts.gtk_rc:
        dbg("**** GLADE VCP INFO: %s reading gtkrc file '%s'" %
            (opts.component, opts.gtk_rc))
        gtk.rc_add_default_file(opts.gtk_rc)
        gtk.rc_parse(opts.gtk_rc)

    if opts.theme:
        dbg("**** GLADE VCP INFO:    Switching %s to '%s' theme" %
            (opts.component, opts.theme))
        settings = gtk.settings_get_default()
        settings.set_string_property("gtk-theme-name", opts.theme, "")

    # This needs to be done after geometry moves so on dual screens the window maxumizes to the actual used screen size.
    if opts.maximum:
        window.window.maximize()

    if opts.halfile:
        cmd = ["halcmd", "-f", opts.halfile]
        res = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr)
예제 #16
0
        return file
    else:
        return os.path.join(get_bundle_path(), file)


def pixbuf(file, size=None):
    if size:
        out = gtk.gdk.pixbuf_new_from_file_at_size(path(file), size, size)
    else:
        out = gtk.gdk.pixbuf_new_from_file(path(file))
    return out


def scale(pixbuf, size=THUMB_SIZE):
    return pixbuf.scale_simple(size, size, gtk.gdk.INTERP_BILINEAR)


EMPTY_FILENAME = 'images/pics/empty.png'
EMPTY_ORIG = pixbuf(EMPTY_FILENAME)
EMPTY_THUMB = scale(EMPTY_ORIG)

CUSTOM_FRAME_ORIG = pixbuf('images/pics/custom.png')
CUSTOM_FRAME_THUMB = scale(CUSTOM_FRAME_ORIG)

# customize theme
gtkrc = os.path.join(get_bundle_path(), 'gtkrc')
gtk.rc_add_default_file(gtkrc)
settings = gtk.settings_get_default()
gtk.rc_reset_styles(settings)
gtk.rc_reparse_all_for_settings(settings, True)
예제 #17
0
            sys.exit(1)

    if opts.gtk_workaround:
        # work around https://bugs.launchpad.net/ubuntu/+source/pygtk/+bug/507739
        # this makes widget and widget_class matches in gtkrc and theme files actually work
        dbg( "activating GTK bug workaround for gtkrc files")
        for o in builder.get_objects():
            if isinstance(o, gtk.Widget):
                # retrieving the name works only for GtkBuilder files, not for
                # libglade files, so be cautious about it
                name = gtk.Buildable.get_name(o)
                if name: o.set_name(name)

    if opts.gtk_rc:
        dbg( "**** GLADE VCP INFO: %s reading gtkrc file '%s'" %(opts.component,opts.gtk_rc))
        gtk.rc_add_default_file(opts.gtk_rc)
        gtk.rc_parse(opts.gtk_rc)

    if opts.theme:
        dbg("**** GLADE VCP INFO:    Switching %s to '%s' theme" %(opts.component,opts.theme))
        settings = gtk.settings_get_default()
        settings.set_string_property("gtk-theme-name", opts.theme, "")

    # This needs to be done after geometry moves so on dual screens the window maxumizes to the actual used screen size.
    if opts.maximum:
        window.window.maximize()
    if opts.always_above_flag:
        window.set_keep_above(True)
    if opts.halfile:
        if opts.halfile[-4:] == ".tcl":
            cmd = ["haltcl", opts.halfile]
예제 #18
0
파일: main.py 프로젝트: Wuodan/inguma
print "Starting Inguma, running on:"
print "  Python version:"
print "\n".join("    "+x for x in sys.version.split("\n"))
print "  GTK version:", ".".join(str(x) for x in gtk.gtk_version)
print "  PyGTK version:", ".".join(str(x) for x in gtk.pygtk_version)
print

# Threading initializer
if sys.platform == "win32":
    gobject.threads_init()
else:
    gtk.gdk.threads_init()

# Load the theme (this fixes a bug on windows)
if sys.platform == "win32":
    gtk.rc_add_default_file('lib' + os.sep + 'ui' + os.sep + 'data' + os.sep + 'inguma_gtkrc')

# splash!
from lib.ui.splash import Splash
splash = Splash()

# Import ui modules
splash.push(("Loading UI modules"))
import lib.ui.core as core
import lib.ui.kbwin as kbwin
import lib.ui.output_manager as om
import lib.ui.graphTBar as graphTBar
import lib.ui.kbtree as kbtree
import lib.ui.nodeMenu as nodeMenu
import lib.ui.altNodeMenu as altNodeMenu
import lib.ui.graphMenu as graphMenu