def gen_items(space, covariate): # Create an item bank to store the items. # Setting the property "sizeHint" increases allocation efficiency bank = gobject.new(oscats.ItemBank, sizeHint=N_ITEMS) # Create the items for i in range(N_ITEMS): # First we create an IRT model container for our item # We have to specify which dimensions to be used with the "dims" array # (in this case, we use both of the dimensions of the space) model = gobject.new(oscats.ModelL2p, space=space, dims=dims, covariates=covariate) # Then, set the parameters. Here there are 4: # Discrimination on two dimensions, difficulty, and covariate coef. model.set_param_by_name("Diff", oscats.oscats_rnd_normal(sqrt(3))) model.set_param_by_name("Discr.Cont.1", oscats.oscats_rnd_uniform_range(0, 1)) model.set_param_by_name("Discr.Cont.2", oscats.oscats_rnd_uniform_range(0, 2)) model.set_param_by_name(COVARIATE_NAME, oscats.oscats_rnd_uniform_range(0.5, 1.5)) # Create an item based on this model item = gobject.new(oscats.Item) item.set_model(item.get_default_model(), model) # Add the item to the item bank bank.add_item(item) # Since Python is garbage collected, we don't have to worry about # reference counting. return bank
def activate(self, shell): try: entry_type = VkontakteEntryType() shell.props.db.register_entry_type(entry_type) except NotImplementedError: # backward compatibility with 0.12 version entry_type = shell.props.db.entry_register_type("VkontakteEntryType") # Set the source's icon width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR) icon = gtk.gdk.pixbuf_new_from_file_at_size(DATA_DIR+"/vk_small.png", width, height) # rhythmbox api break up (0.13.2 - 0.13.3) if hasattr(rb, 'rb_source_group_get_by_name'): source_group = rb.rb_source_group_get_by_name("library") self.source = gobject.new(VkontakteSource, name=_("Vkontakte"), shell=shell, icon=icon, plugin=self, entry_type=entry_type, source_group=source_group) shell.register_entry_type_for_source(self.source, entry_type) shell.append_source(self.source, None) else: source_group = rb.rb_display_page_group_get_by_id ("library") self.source = gobject.new(VkontakteSource, name=_("Vkontakte"), shell=shell, plugin=self, pixbuf=icon, entry_type=entry_type) shell.register_entry_type_for_source(self.source, entry_type) shell.append_display_page(self.source, source_group) ui = shell.get_ui_manager() self.uid = ui.add_ui_from_string(popup_ui) ui.ensure_update() self.source.initialise()
def read_items(f, contSpace, binSpace): # Create an item bank to store the items. # Setting the property "sizeHint" increases allocation efficiency bank = gobject.new(oscats.ItemBank, sizeHint=N_ITEMS) f.readline() # header line count = 0 for line in f.readlines(): (a, b, c, slip, guess, attrStr) = line.split("\t") # Create the item count += 1 item = gobject.new(oscats.Item, id=str(count)) # Create the 3PL model model = gobject.new(oscats.ModelL3p, space=contSpace) model.set_param_by_name("Discr.Cont.1", float(a)) # The difficulty parameter in the input file is specified as the # traditional IRT difficulty: logit P(x) = a(theta-b); but, # OscatsModelL3p uses the parameterization: logit P(x) = a*theta - b, # so we have to multiply here, accordingly. model.set_param_by_name("Diff", float(a) * float(b)) model.set_param_by_name("Guess", float(c)) # Set the model item.set_model_by_name("3PL", model) # Create the DINA model dim = binSpace.get_dim_by_name("Bin.1") + attrStr.find('1') model = gobject.new(oscats.ModelDina, space=binSpace, dims=[dim]) model.set_param_by_name("Slip", float(slip)) model.set_param_by_name("Guess", float(guess)) # Set the model item.set_model_by_name("DINA", model) # Add the item to the item bank bank.add_item(item) if (count != N_ITEMS): warn("Expected %d items, but only read %d." % (N_ITEMS, count)) return bank
def __init__(self, parent=None, unsaved=[]): gtk.MessageDialog.__init__(self, parent=parent, flags=gtk.DIALOG_MODAL, type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_NONE, message_format=_("%d files have unsaved changes") % 1) self.format_secondary_markup("Choose the files you want to save:") #self.props.default_height = 640 self.add_button (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) self.add_button (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) self.add_button (gtk.STOCK_SAVE, gtk.RESPONSE_OK) self.set_default_response (gtk.RESPONSE_OK) frame = gobject.new(gtk.Frame, shadow_type = gtk.SHADOW_IN) self.label.parent.add(frame) frame.show() tv = gobject.new (gtk.TreeView, model=self.__create_model(unsaved), headers_visible=False) frame.add(tv) tv.show() col = gtk.TreeViewColumn ("", gtk.CellRendererToggle(), active=0) tv.append_column(col) cell = gtk.CellRendererText() col = gtk.TreeViewColumn ("", cell) col.set_cell_data_func (cell, self.__cell_data_func) tv.append_column(col)
def __init__(self, pipe, log_view): self.__pipe = pipe self.__log_view = log_view tag_table = log_view.buffer.get_tag_table() self.__tag = gtk.TextTag() self.__good_tag = gobject.new(gtk.TextTag, weight = pango.WEIGHT_BOLD, foreground = "darkgreen", paragraph_background = "lightgreen") self.__bad_tag = gobject.new(gtk.TextTag, weight = pango.WEIGHT_BOLD, foreground = "darkred", paragraph_background = "pink") # for warnings, etc. self.__ugly_tag = gobject.new(gtk.TextTag, #weight = pango.WEIGHT_BOLD, foreground = "red") tag_table.add(self.__tag) tag_table.add(self.__good_tag) tag_table.add(self.__bad_tag) tag_table.add(self.__ugly_tag) pipe_util.start_reader(pipe) self.__reader_task = gobject.timeout_add(20, self.__reader_tick)
def read_items(f, contSpace, binSpace) : # Create an item bank to store the items. # Setting the property "sizeHint" increases allocation efficiency bank = gobject.new(oscats.ItemBank, sizeHint=N_ITEMS) f.readline() # header line count = 0 for line in f.readlines() : (a, b, c, slip, guess, attrStr) = line.split("\t") # Create the item count += 1 item = gobject.new(oscats.Item, id=str(count)) # Create the 3PL model model = gobject.new(oscats.ModelL3p, space=contSpace) model.set_param_by_name("Discr.Cont.1", float(a)) # The difficulty parameter in the input file is specified as the # traditional IRT difficulty: logit P(x) = a(theta-b); but, # OscatsModelL3p uses the parameterization: logit P(x) = a*theta - b, # so we have to multiply here, accordingly. model.set_param_by_name("Diff", float(a)*float(b)) model.set_param_by_name("Guess", float(c)) # Set the model item.set_model_by_name("3PL", model) # Create the DINA model dim = binSpace.get_dim_by_name("Bin.1") + attrStr.find('1') model = gobject.new(oscats.ModelDina, space=binSpace, dims=[dim]) model.set_param_by_name("Slip", float(slip)) model.set_param_by_name("Guess", float(guess)) # Set the model item.set_model_by_name("DINA", model) # Add the item to the item bank bank.add_item(item) if (count != N_ITEMS) : warn("Expected %d items, but only read %d." % (N_ITEMS, count)) return bank
def test_get_renderers(self): reg = mafw.Registry.get_instance() x1 = gobject.new(MyRendererPlugin, uuid = 'MyRendererPlugin1') x2 = gobject.new(MyRendererPlugin, uuid = 'MyRendererPlugin2') reg.add_extension(x1) reg.add_extension(x2) self.assertEquals(set(reg.get_renderers()), set([x1, x2]))
def __init__(self, pipe, log_view): self.__log_view = log_view tag_table = log_view.buffer.get_tag_table() self.__tag = gtk.TextTag() self.__good_tag = gobject.new(gtk.TextTag, weight=pango.WEIGHT_BOLD, foreground="darkgreen", paragraph_background="lightgreen") self.__bad_tag = gobject.new(gtk.TextTag, weight=pango.WEIGHT_BOLD, foreground="darkred", paragraph_background="pink") # for warnings, etc. self.__ugly_tag = gobject.new( gtk.TextTag, #weight = pango.WEIGHT_BOLD, foreground="red") tag_table.add(self.__tag) tag_table.add(self.__good_tag) tag_table.add(self.__bad_tag) tag_table.add(self.__ugly_tag) self.__watch_id = gobject.io_add_watch( pipe, gobject.IO_IN | gobject.IO_PRI | gobject.IO_ERR | gobject.IO_HUP, self.__on_output)
def create_pref_section(title, wlabels=[], custom=[]): vbox = gtk.VBox(spacing=6) label = gobject.new(gtk.Label, label="<b>%s</b>" % title, use_markup=True, xalign=0) vbox.pack_start(label, expand=False) label.show() align = gobject.new(gtk.Alignment, left_padding=12) vbox.pack_start(align, expand=False) align.show() table = gobject.new(gtk.Table, n_rows=len(wlabels) + len(custom), n_columns=2, row_spacing=6, column_spacing=12) align.add(table) table.show() for i in range(len(wlabels)): l, widget = wlabels[i] label = gobject.new(gtk.Label, label=l, xalign=0) widget.connect("notify::sensitive", on_pref_widget_notify_sensitive) widget.set_data("pref-label", label) if l is not None: table.attach(label, 0, 1, i, i + 1, xoptions=gtk.FILL, yoptions=gtk.FILL) table.attach(widget, 1, 2, i, i + 1, xoptions=gtk.EXPAND | gtk.FILL, yoptions=gtk.FILL) else: table.attach(widget, 0, 2, i, i + 1, xoptions=gtk.EXPAND | gtk.FILL, yoptions=gtk.FILL) table.show_all() return vbox
def __create_page3(self): page = gobject.new(gtk.Alignment, xalign=0.5, yalign=0.5, xscale=0, yscale=0, border_width=12) vbox = gtk.VBox(spacing=12) page.add(vbox) label = gobject.new(gtk.Label, label=_("..."), justify=gtk.JUSTIFY_FILL, use_markup=True, wrap=True, xalign=0) self.__size_group.add_widget(label) vbox.pack_start(label, expand=False) label = gobject.new( gtk.Label, label=_("Setup complete, ready to start."), justify=gtk.JUSTIFY_FILL, use_markup=True, wrap=True, xalign=0, ) self.__size_group.add_widget(label) vbox.pack_start(label, expand=False) page.show_all() self.append_page(page) self.set_page_title(page, "Complete") self.set_page_complete(page, True) self.set_page_type(page, gtk.ASSISTANT_PAGE_CONFIRM)
def __create_page1(self): page = gobject.new(gtk.Alignment, xalign=0.5, yalign=0.5, xscale=0, yscale=0, border_width=12) # page = gtk.Alignment(0.5, 0.5) vbox = gtk.VBox(spacing=12) page.add(vbox) label = gobject.new(gtk.Label, label=_("..."), justify=gtk.JUSTIFY_FILL, use_markup=True, wrap=True, xalign=0) vbox.pack_start(label, expand=False) label = gobject.new( gtk.Label, label=_("So, let's set some initial stuff."), justify=gtk.JUSTIFY_FILL, use_markup=True, wrap=True, xalign=0, ) self.__size_group.add_widget(label) vbox.pack_start(label, expand=False) page.show_all() self.append_page(page) self.set_page_title(page, _("Sced setup")) self.set_page_complete(page, True) self.set_page_type(page, gtk.ASSISTANT_PAGE_INTRO)
def __init__(self, pipe, log_view): self.__log_view = log_view tag_table = log_view.buffer.get_tag_table() self.__tag = gtk.TextTag() self.__good_tag = gobject.new(gtk.TextTag, weight = pango.WEIGHT_BOLD, foreground = "darkgreen", paragraph_background = "lightgreen") self.__bad_tag = gobject.new(gtk.TextTag, weight = pango.WEIGHT_BOLD, foreground = "darkred", paragraph_background = "pink") # for warnings, etc. self.__ugly_tag = gobject.new(gtk.TextTag, #weight = pango.WEIGHT_BOLD, foreground = "red") tag_table.add(self.__tag) tag_table.add(self.__good_tag) tag_table.add(self.__bad_tag) tag_table.add(self.__ugly_tag) self.__watch_id = gobject.io_add_watch(pipe, gobject.IO_IN | gobject.IO_PRI | gobject.IO_ERR | gobject.IO_HUP, self.__on_output)
def test_get_sources(self): reg = mafw.Registry.get_instance() x1 = gobject.new(MySourcePlugin, name='source1', uuid=uuid4()) x2 = gobject.new(MySourcePlugin, uuid=uuid4(), name='source2') reg.add_extension(x1) reg.add_extension(x2) self.assertEquals(set(reg.get_sources()), set([x1, x2]))
def my_print_setup_cb(widget): notebook = gtk.Notebook() # GnomePrintPaperSelector */ paper_selector = gnomeprint.ui.PaperSelector(app.active_doc.config, 0) paper_selector.set_size_request(200, 400) label = gobject.new(gtk.Label, label="P_aper", use_underline=True) notebook.append_page(paper_selector, label) # GnomePrintPaperSelector */ paper_selector = gnomeprint.ui.PaperSelector(app.active_doc.config, 0) paper_selector.set_size_request(200, 400) label = gobject.new(gtk.Label, label="_foo", use_underline=True) notebook.append_page(paper_selector, label) # Dialog dialog = gtk.Dialog("Printer Setup", None, 0, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) dialog.vbox.pack_start(notebook, True, True, 0) dialog.show_all() response = dialog.run() dialog.destroy()
def test_list_plugins(self): reg = mafw.Registry.get_instance() x1 = gobject.new(MyRendererPlugin, uuid=uuid4(), name='list1') x2 = gobject.new(MySourcePlugin, uuid=uuid4(), name='list2') reg.add_extension(x1) reg.add_extension(x2) self.assertEquals(set(reg.list_plugins()), set([x1, x2]))
def gen_items(space, covariate) : # Create an item bank to store the items. # Setting the property "sizeHint" increases allocation efficiency bank = gobject.new(oscats.ItemBank, sizeHint=N_ITEMS) # Create the items for i in range(N_ITEMS) : # First we create an IRT model container for our item # We have to specify which dimensions to be used with the "dims" array # (in this case, we use both of the dimensions of the space) model = gobject.new(oscats.ModelL2p, space=space, dims=dims, covariates=covariate) # Then, set the parameters. Here there are 4: # Discrimination on two dimensions, difficulty, and covariate coef. model.set_param_by_name("Diff", oscats.oscats_rnd_normal(sqrt(3))) model.set_param_by_name("Discr.Cont.1", oscats.oscats_rnd_uniform_range(0, 1)) model.set_param_by_name("Discr.Cont.2", oscats.oscats_rnd_uniform_range(0, 2)) model.set_param_by_name(COVARIATE_NAME, oscats.oscats_rnd_uniform_range(0.5, 1.5)) # Create an item based on this model item = gobject.new(oscats.Item) item.set_model(item.get_default_model(), model) # Add the item to the item bank bank.add_item(item) # Since Python is garbage collected, we don't have to worry about # reference counting. return bank
def test_get_renderers(self): reg = mafw.Registry.get_instance() x1 = gobject.new(MyRendererPlugin, uuid=uuid4(), name='renderer1') x2 = gobject.new(MyRendererPlugin, uuid=uuid4(), name='renderer2') reg.add_extension(x1) reg.add_extension(x2) x = reg.get_renderers() self.assertEquals(set(x), set([x1, x2]))
def activate(self, shell): self.db = shell.props.db self.entry_type = AmpacheEntryType() self.entry_type.can_sync_metadata = True self.entry_type.sync_metadata = None self.entry_type.category = rhythmdb.ENTRY_STREAM theme = gtk.icon_theme_get_default() rb.append_plugin_source_path(theme, "/icons/") width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR) #icon = rb.try_load_icon(theme, "ampache", width, 0) group = rb.rb_display_page_group_get_by_id ("shared") if not group: group = rb.rb_source_group_register ( "ampache", self.config.get("group"), rb.SOURCE_GROUP_CATEGORY_FIXED, ) self.source = gobject.new ( AmpacheBrowser, entry_type=self.entry_type, plugin=self, name=self.config.get("name"), shell=shell, ) self.config.set("icon_filename", self.find_file(self.config.get("icon"))) #icon = rb.try_load_icon(theme, "ampache", width, 0) icon = gtk.gdk.pixbuf_new_from_file_at_size(self.config.get("icon_filename"), width, height) self.source = gobject.new (AmpacheBrowser, shell=shell, entry_type=self.entry_type, plugin=self, name=self.config.get("name"), pixbuf=icon) self.source.activate(self.config) shell.register_entry_type_for_source(self.source, self.entry_type) shell.append_display_page(self.source, group) ui_manager = shell.get_ui_manager() action = gtk.Action('RefetchAmpache', _('_Re-fetch Ampache Library'), _('Update the local ampache library'), "") action.connect ('activate', self.refetch_ampache, shell) action_group = gtk.ActionGroup ('RefetchAmpacheGroup') action_group.add_action(action) ui_manager.insert_action_group(action_group, -1) self.uid = ui_manager.add_ui_from_string(ui_str) ui_manager.ensure_update()
def __init__(self, title=None): self.__title_text = None gtk.widget_push_composite_child() self.__title = gobject.new(gtk.Label, visible=True, xalign=0, yalign=0.5) self.__indent = gobject.new(gtk.Label, visible=True, label=' ') gtk.widget_pop_composite_child() gtk.Bin.__init__(self) self.__title.set_parent(self) self.__indent.set_parent(self) if title is not None: self.props.title = title
def test_scrollbars_in_subclass_init(): ''' Ensure that the scrolled windows scrollbars are ``None`` within a subclass __init__ method. ''' class Test124(gtk.ScrolledWindow): def __init__(self): super(Test124, self).__init__() assert not self.get_hscrollbar() assert not self.get_vscrollbar() gobject.type_register(Test124) gobject.new(Test124)
def test_subclass_init_calls_add(): ''' Ensure that adding items to a scrolled window within a subclass __init__ method works. :bug: #438114 ''' class MyScrolledWindow(gtk.ScrolledWindow): def __init__(self): super(MyScrolledWindow, self).__init__() self.add(gtk.TextView()) gobject.type_register(MyScrolledWindow) gobject.new(MyScrolledWindow)
def get_file_from_filechooser(main, folder=False, save_file=False, save_to=None): if folder: open_action = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER else: open_action = gtk.FILE_CHOOSER_ACTION_OPEN if platform.FREMANTLE: if save_file: dlg = gobject.new(hildon.FileChooserDialog, \ action=gtk.FILE_CHOOSER_ACTION_SAVE) else: dlg = gobject.new(hildon.FileChooserDialog, \ action=open_action) elif platform.MAEMO: if save_file: args = ( main.main_window, gtk.FILE_CHOOSER_ACTION_SAVE ) else: args = ( main.main_window, open_action ) dlg = hildon.FileChooserDialog( *args ) else: if save_file: args = ( _('Select file to save playlist to'), None, gtk.FILE_CHOOSER_ACTION_SAVE, (( gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_SAVE, gtk.RESPONSE_OK )) ) else: args = ( _('Select podcast or audiobook'), None, open_action, (( gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OPEN, gtk.RESPONSE_OK )) ) dlg = gtk.FileChooserDialog(*args) current_folder = os.path.expanduser(main.config.get("options", "default_folder")) if current_folder is not None and os.path.isdir(current_folder): dlg.set_current_folder(current_folder) if save_file and save_to is not None: dlg.set_current_name(save_to) if dlg.run() == gtk.RESPONSE_OK: filename = dlg.get_filename() main.config.set("options", "default_folder", dlg.get_current_folder()) else: filename = None dlg.destroy() return filename
def popup(text, bgcolor=None, fgcolor=None, fontdesc=None, use_markup=False): assert isinstance(fontdesc, pango.FontDescription) win = gtk.Window(gtk.WINDOW_POPUP) win.set_border_width(0) frame = gobject.new(gtk.Frame, shadow_type=gtk.SHADOW_ETCHED_OUT, visible=True) win.add(frame) label = gobject.new(gtk.Label, use_markup=True, label=text, visible=True) label.modify_font(fontdesc) frame.add(label) win.show() win.width, win.height = win.allocation.width, win.allocation.height return win
def _create_object(type_id, attrs, root): if type_id == 'GtkMenuItem': action_name = attrs.pop('action', None) if action_name: action_map = root.get_data('shakya:actions') print root, action_map action = action_map[str(action_name)] item = action.create_menu_item() item.set_data('shakya:action', action) else : label = attrs.pop('label', None) item = gtk.MenuItem(label=label) return item elif type_id == 'GtkToolButton': action_name = attrs.pop('action', None) if action_name: action_map = root.get_data('shakya:actions') print root, action_map action = action_map[str(action_name)] item = action.create_tool_item() item.set_data('shakya:action', action) else : label = attrs.pop('label', None) item = gtk.ToolButton() return item else: return gobject.new(type_id)
def __call__(self, window): action = gobject.new( moo.Action, name="CProjectBuildConfiguration", label="Build Configuration", no_accel="True" ) action.project = self.project action.connect("connect-proxy", self.connect_proxy) return action
def testIntToStr(self): obj = new(PropertyObject, construct_only=1) self.assertEqual(obj.props.construct_only, '1') obj.set_property('construct', '2') self.assertEqual(obj.props.construct, '2') obj.props.normal = 3 self.assertEqual(obj.props.normal, '3')
def testConstructOnly(self): obj = new(PropertyObject, construct_only="123") self.assertEqual(obj.props.construct_only, "123") self.assertRaises(TypeError, setattr, obj.props, 'construct_only', '456') self.assertRaises(TypeError, obj.set_property, 'construct-only', '456')
def recurse(node): global removed_properties for child in node.childNodes: if child.nodeType != child.ELEMENT_NODE: recurse(child) continue class_ = child.getAttribute('class') if class_: type_ = builder.get_type_from_name(class_) object = gobject.new(type_) for property in gobject.list_properties(type_): try: default = object.get_property(property.name) except TypeError, te: default = None for child_node in child.childNodes: if getattr(child_node, 'tagName', None) == 'property' \ and child_node.getAttribute('name') == property.name: if check_default(default, get_text(child_node.childNodes)): removed_properties += 1 child.removeChild(child_node) child_node.unlink() recurse(child)
def testNormal(self): obj = new(PropertyObject, normal="123") self.assertEqual(obj.props.normal, "123") obj.set_property('normal', '456') self.assertEqual(obj.props.normal, "456") obj.props.normal = '789' self.assertEqual(obj.props.normal, "789")
def __init__(self, parent): gtk.Dialog.__init__(self, parent=parent, title=_("Sced Preferences"), buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE), flags=gtk.DIALOG_NO_SEPARATOR) self.set_resizable(False) notebook = gobject.new(gtk.Notebook, border_width=6) self.vbox.add(notebook) notebook.show() page = self.__create_general_page() notebook.append_page(page, gtk.Label(_("General"))) page.show() page = self.__create_editing_page() notebook.append_page(page, gtk.Label(_("Editor"))) page.show() page = self.__create_page_recording() notebook.append_page(page, gtk.Label(_("Recording"))) page.show() self.__update_prefs()
def activate(self, shell): print "activating pandora plugin" db = shell.props.db try: entry_type = db.entry_register_type("PandoraEntryType") except AttributeError: entry_type = rhythmdb.EntryType() width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR) icon = gtk.gdk.pixbuf_new_from_file_at_size(self.find_file("pandora.png"), width, height) self.source = gobject.new (PandoraSource, shell=shell, plugin=self, name=_("Pandora"), icon=icon, entry_type=entry_type) shell.append_source(self.source, None) shell.register_entry_type_for_source(self.source, entry_type) # hack, should be done within gobject constructor self.source.init() self.pec_id = shell.get_player().connect_after('playing-song-changed', self.playing_entry_changed)
def read_examinees(f, contSpace, binSpace): count = 0 ret = [] for line in f.readlines(): (theta, attrStr) = line.split("\t") theta = float(theta) attrStr = attrStr.strip() # Create the examinee count += 1 e = gobject.new(oscats.Examinee, id=str(count)) # Set "true" continuous theta dim = contSpace.get_dim_by_name("Cont.1") point = oscats.Point(space=contSpace) point.set_cont(dim, theta) e.set_theta_by_name("trueTheta", point) # Set "true" binary alpha dim = binSpace.get_dim_by_name("Bin.1") point = oscats.Point(space=binSpace) for k in range(N_ATTR): point.set_bin(dim, attrStr[k] == '1') dim += 1 e.set_theta_by_name("trueAlpha", point) ret.append(e) if (count != N_EXAMINEES): warn("Expected %d examinees, but read in %d." % (N_EXAMINEES, count)) return ret
def _create_new_object(type_name, pnode): att = {} obj = None print 'new:', type_name isAction = gobject.type_is_a(type_name, 'GtkAction') isActionGroup = gobject.type_is_a(type_name, 'GtkActionGroup') isMenuItem = gobject.type_is_a(type_name, 'GtkMenuItem') isToolItem = gobject.type_is_a(type_name, 'GtkToolItem') if isAction or isActionGroup: att = _conly_properties(pnode, type_name) elif isMenuItem or isToolItem: _id = node = pnode.parentNode.getAttribute('action') if not _id == '': dic = _top_node(pnode).loader.dic act = dic[int(_id)] if isMenuItem: obj = act.create_menu_item() elif isToolItem: obj = act.create_tool_item() obj.set_data('shakya:action', act) if not obj: obj = gobject.new(type_name, **att) if gobject.type_is_a(obj, gtk.Widget): obj.hide() return obj
def save_as(self): fsm = hildon.FileSystemModel() # fc = hildon.FileChooserDialog(self, gtk.FILE_CHOOSER_ACTION_SAVE,fsm) fc = gobject.new(hildon.FileChooserDialog, action=gtk.FILE_CHOOSER_ACTION_SAVE) if self.filepath != None : fc.set_current_folder(os.path.dirname(self.filepath)) else: fc.set_current_folder(self._parent._last_opened_folder) fc.set_show_hidden(True) fc.set_do_overwrite_confirmation(False) fp = self.filepath if fp == None: fp = 'Untitled' self.set_title(os.path.basename(fp)) self._parent._last_opened_folder = os.path.dirname(fp) fc.set_property('autonaming',False) fc.set_property('show-files',True) # fc.set_current_folder(os.path.dirname(fp)) fc.set_current_name(os.path.basename(fp)) # fc.set_extension('py') if fc.run()==gtk.RESPONSE_OK: filepath = fc.get_filename() fc.destroy() if type(filepath) == str: # fix #19 - fix #23 self.save_file(filepath) manager = gtk.recent_manager_get_default() manager.add_item('file://'+filepath) else: note = osso.SystemNote(self._parent.context) result = note.system_note_dialog('An error occurs saving file :\n'+str(filepath)) else: fc.destroy()
def run(self): if (self.__dlg_type == self.TYPE_OPEN): action = gtk.FILE_CHOOSER_ACTION_OPEN elif (self.__dlg_type == self.TYPE_SAVE): action = gtk.FILE_CHOOSER_ACTION_SAVE else: action = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER if (platforms.MAEMO4 or platforms.MAEMO5): dlg = gobject.new(hildon.FileChooserDialog, action = action) else: dlg = gtk.FileChooserDialog(parent = None, action = action, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) dlg.set_title(self.__title) #print dir(dlg) #print dlg.get_safe_folder_uri() if (self.__dlg_type == self.TYPE_SAVE): dlg.set_current_name(self.__filename) dlg.set_current_folder(_MYDOCS) # run() is prone for deadlocks. emtpy event queue first while (gtk.events_pending()): gtk.main_iteration(True) response = dlg.run() if (response == gtk.RESPONSE_OK): self.__selection = dlg.get_filename() dlg.destroy()
def testEnum(self): obj = new(PropertyObject) self.assertEqual(obj.props.enum, Gio.SocketType.STREAM) self.assertEqual(obj.enum, Gio.SocketType.STREAM) obj.enum = Gio.SocketType.DATAGRAM self.assertEqual(obj.props.enum, Gio.SocketType.DATAGRAM) self.assertEqual(obj.enum, Gio.SocketType.DATAGRAM) obj.props.enum = Gio.SocketType.STREAM self.assertEqual(obj.props.enum, Gio.SocketType.STREAM) self.assertEqual(obj.enum, Gio.SocketType.STREAM) obj.props.enum = 2 self.assertEqual(obj.props.enum, Gio.SocketType.DATAGRAM) self.assertEqual(obj.enum, Gio.SocketType.DATAGRAM) obj.enum = 1 self.assertEqual(obj.props.enum, Gio.SocketType.STREAM) self.assertEqual(obj.enum, Gio.SocketType.STREAM) self.assertRaises(TypeError, setattr, obj, 'enum', 'foo') self.assertRaises(TypeError, setattr, obj, 'enum', object()) self.assertRaises(TypeError, gobject.property, type=Gio.SocketType) self.assertRaises(TypeError, gobject.property, type=Gio.SocketType, default=Gio.SocketProtocol.TCP) self.assertRaises(TypeError, gobject.property, type=Gio.SocketType, default=object()) self.assertRaises(TypeError, gobject.property, type=Gio.SocketType, default=1)
def testUTF8(self): obj = new(PropertyObject, construct_only=UNICODE_UTF8) self.assertEqual(obj.props.construct_only, TEST_UTF8) obj.set_property('construct', UNICODE_UTF8) self.assertEqual(obj.props.construct, TEST_UTF8) obj.props.normal = UNICODE_UTF8 self.assertEqual(obj.props.normal, TEST_UTF8)
def testConstruct(self): obj = new(PropertyObject, construct="123") self.assertEqual(obj.props.construct, "123") obj.set_property('construct', '456') self.assertEqual(obj.props.construct, "456") obj.props.construct = '789' self.assertEqual(obj.props.construct, "789")
def read_examinees(f, contSpace, binSpace) : count = 0 ret = [] for line in f.readlines() : (theta, attrStr) = line.split("\t") theta = float(theta) attrStr = attrStr.strip() # Create the examinee count += 1 e = gobject.new(oscats.Examinee, id=str(count)) # Set "true" continuous theta dim = contSpace.get_dim_by_name("Cont.1") point = oscats.Point(space=contSpace) point.set_cont(dim, theta) e.set_theta_by_name("trueTheta", point) # Set "true" binary alpha dim = binSpace.get_dim_by_name("Bin.1") point = oscats.Point(space=binSpace) for k in range(N_ATTR) : point.set_bin(dim, attrStr[k] == '1') ; dim += 1 e.set_theta_by_name("trueAlpha", point) ret.append(e) if (count != N_EXAMINEES) : warn("Expected %d examinees, but read in %d." % (N_EXAMINEES, count)) return ret
def activate(self, shell): print "activating sample python plugin" db = shell.get_property("db") model = db.query_model_new_empty() self.source = gobject.new (PythonSource, shell=shell, name=_("Python Source"), query_model=model) shell.append_source(self.source, None)
def detected_media_server(self, client, udn): self.info("found upnp server %s (%s)" % (client.device.get_friendly_name(), udn)) """ don't react on our own MediaServer""" if hasattr(self, 'server') and client.device.get_id() == str( self.server.uuid): return db = self.shell.props.db group = rb.rb_display_page_group_get_by_id("shared") entry_type = CoherenceDBEntryType(client.device.get_id()[5:]) db.register_entry_type(entry_type) from UpnpSource import UpnpSource source = gobject.new(UpnpSource, shell=self.shell, entry_type=entry_type, plugin=self, client=client, udn=udn) self.sources[udn] = source self.shell.append_display_page(source, group)
def __create_page2(self): page = gobject.new(gtk.Alignment, xalign=0.5, yalign=0.5, xscale=0, yscale=0, border_width=12) vbox = gtk.VBox(spacing=18) page.add(vbox) label = gobject.new( gtk.Label, label=_( "Here you must specify, the runtime directory, where SuperCollider will store it's synth definition files (the synthdefs). Typically this is a directory, where you'll also keep your code and related files. The runtime directory must contain a <b>synthdefs</b> folder and optionally a <b>sounds</b> folder (most examples use samples from the sounds/ dir)." ), justify=gtk.JUSTIFY_FILL, use_markup=True, wrap=True, xalign=0, ) self.__size_group.add_widget(label) vbox.pack_start(label, expand=False, fill=False) hbox = gtk.HBox(spacing=12) vbox.pack_start(hbox) label = gtk.Label(_("Runtime directory:")) hbox.pack_start(label, expand=False, fill=False) self.__fc_button = gobject.new( gtk.FileChooserButton, title=_("Choose working directory"), action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER ) hbox.add(self.__fc_button) self.__fc_button.connect("selection-changed", self.__on_filechooser_selection_changed) hbox = gtk.HBox(spacing=12) vbox.pack_start(hbox, expand=False) self.__warning_image = gtk.image_new_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG) hbox.pack_start(self.__warning_image, expand=False, fill=False) self.__warning_label = gobject.new(gtk.Label, justify=gtk.JUSTIFY_FILL, use_markup=True, wrap=True, xalign=0) self.__size_group.add_widget(self.__warning_label) hbox.pack_start(self.__warning_label, expand=False) self.__runtimedir_page = page page.show_all() self.append_page(page) self.set_page_title(page, _("Working directory")) self.__update_page2()
def testGobjectNew(self): entry = gobject.new(ProxyEntry) self.assertEqual(entry.get_property('data_type'), None) entry = gobject.new(ProxyEntry, data_type=int) entry.set_property("data-type", str) self.assertEqual(entry.get_property('data_type'), 'str') while gtk.events_pending(): gtk.main_iteration() self.assertEqual(entry.get_property('data_type'), 'str') entry = gobject.new(ProxyEntry, data_type=int) self.assertEqual(entry.get_property('data_type'), 'int') entry.set_property("data-type", str) while gtk.events_pending(): gtk.main_iteration() self.assertEqual(entry.get_property('data_type'), 'str')
def __call__(self, window): action = gobject.new(moo.Action, name="CProjectBuildConfiguration", label="Build Configuration", no_accel="True") action.project = self.project action.connect('connect-proxy', self.connect_proxy) return action
def gen_items(space): # Create an item bank to store the items. # Setting the property "sizeHint" increases allocation efficiency bank = gobject.new(oscats.ItemBank, sizeHint=N_ITEMS) for i in range(N_ITEMS): # First we create an IRT model container for our item # Defaults to unidimensional, using the first dimension of space model = gobject.new(oscats.ModelL1p, space=space) # Then, set the parameters. Here there is only one, the difficulty (b). model.set_param_by_index(0, oscats.oscats_rnd_normal(1)) # Create an item based on this model item = gobject.new(oscats.Item) item.set_model(item.get_default_model(), model) # Add the item to the item bank bank.add_item(item) # Since Python is garbage collected, we don't have to worry about # reference counting. return bank
def plugin_album(self, songs): win = gtk.Dialog(title='ReplayGain', buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) win.set_default_size(400, 300) win.set_border_width(6) swin = gtk.ScrolledWindow() win.vbox.pack_start(swin) swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) swin.set_shadow_type(gtk.SHADOW_IN) from qltk.views import HintedTreeView model = gtk.ListStore(object, str, int, str, str) view = HintedTreeView(model) swin.add(view) # Create a view of title/progress/gain/peak for each track + album col = gtk.TreeViewColumn('Track', gobject.new(gtk.CellRendererText, ellipsize=pango.ELLIPSIZE_END), text=1) col.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE) col.set_expand(True) col.set_fixed_width(120) view.append_column(col) col = gtk.TreeViewColumn('Progress', gtk.CellRendererProgress(), value=2) col.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE) view.append_column(col) col = gtk.TreeViewColumn('Gain', gtk.CellRendererText(), text=3) col.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE) view.append_column(col) col = gtk.TreeViewColumn('Peak', gtk.CellRendererText(), text=4) col.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE) view.append_column(col) for s in songs: model.append([s, s('~tracknumber~title~version'), 0, "-", "-"]) model.append([None, "Full Album", 0, "-", "-"]) win.vbox.show_all() win.present() win.finished = False # kick off the analysis analysis = Analysis(win, view, model) analysis.next_song() # wait for the dialog to be closed while not win.finished: gtk.main_iteration() win.hide() win.destroy()
def activate(self, shell): self.shell = shell # so the source can update the progress bar self.db = shell.get_property("db") self.entry_type = self.db.entry_register_type("MagnatuneEntryType") # allow changes which don't do anything self.entry_type.can_sync_metadata = True self.entry_type.sync_metadata = None theme = gtk.icon_theme_get_default() rb.append_plugin_source_path(theme, "/icons") width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR) icon = rb.try_load_icon(theme, "magnatune", width, 0) group = rb.rb_source_group_get_by_name("stores") self.source = gobject.new(MagnatuneSource, shell=shell, entry_type=self.entry_type, source_group=group, icon=icon, plugin=self) shell.register_entry_type_for_source(self.source, self.entry_type) shell.append_source(self.source, None) # Add the source to the list manager = shell.get_player().get_property('ui-manager') # Add the popup menu actions self.action_group = gtk.ActionGroup('MagnatunePluginActions') action = gtk.Action('MagnatuneDownloadAlbum', _('Download Album'), _("Download this album from Magnatune"), 'gtk-save') action.connect( 'activate', lambda a: self.shell.get_property("selected-source"). download_album()) self.action_group.add_action(action) action = gtk.Action('MagnatuneArtistInfo', _('Artist Information'), _("Get information about this artist"), 'gtk-info') action.connect( 'activate', lambda a: self.shell.get_property("selected-source"). display_artist_info()) self.action_group.add_action(action) action = gtk.Action('MagnatuneCancelDownload', _('Cancel Downloads'), _("Stop downloading purchased albums"), 'gtk-stop') action.connect( 'activate', lambda a: self.shell.get_property("selected-source"). cancel_downloads()) action.set_sensitive(False) self.action_group.add_action(action) manager.insert_action_group(self.action_group, 0) self.ui_id = manager.add_ui_from_string(popup_ui) self.pec_id = shell.get_player().connect('playing-song-changed', self.playing_entry_changed) manager.ensure_update()