def __init__(self, parent, label, scale, minval, maxval, value, callback): self.box = gtk.HBox(False, 0) self.label = gtk.Label('%s:' % label) self.label.set_alignment(0, 0.5) self.adjustment = gtk.Adjustment(value, minval, maxval, 1, 1, 0) if scale: self.scale = gtk.ScaleButton(1, minval, maxval, 1, ['gtk-index']) self.scale.set_adjustment(self.adjustment) self.spin = gtk.SpinButton(self.adjustment, 0, 0) self.handler = self.adjustment.connect( 'value-changed', lambda x: callback(x.get_value())) # Pack into box. self.box.pack_start(self.label, True, True, 0) gutils.margin(self.box, 20, 1) if scale: self.box.pack_start(self.scale, False, False, 0) self.box.pack_start(self.spin, False, False, 0) # Pack into parent widget. parent.pack_start(self.box, False, False, 0)
def __init__(self, parent, label, buttons): """Create and put on parent. @parent: Parent widget to put in. @label: Text to display. @buttons: """ # Create main widget and add into parent. self.box = gtk.HBox(False, 0) parent.pack_start(self.box, False, False, 0) # Label. if label: label = gtk.Label('%s:' % label) label.set_alignment(0, 0.5) self.box.pack_start(label, True, True, 0) # Margin between label and buttons. gutils.margin(self.box, 20, 1) # Buttons. for properties in reversed(buttons): icon, tooltip, callback = properties button = gtk.Button() button.set_image(gtk.image_new_from_icon_name(icon, 1)) button.set_relief(gtk.RELIEF_NONE) button.set_tooltip_text(tooltip) button.connect('clicked', lambda x,y=callback: y()) self.box.pack_end(button, False)
def dump(self, addlost=False): """Filter sort list, dump to toolbar, and push to config.""" # Alias. plugins = main.plugins.childs # Remove previous stuff. self.box.foreach(gtk.Widget.destroy) self.group = None # Get sort list from config. self.sort = main.config.get('sort', 'toolbar').split(',') # Add lost tools. if addlost: for (toolname, tool) in main.plugins.childs.items(): if toolname not in self.sort: if main.plugins.childs[toolname].type == 'tool': self.sort.append(toolname) # Remove non-plugin from sort list. self.sort = [x for x in self.sort if plugins.has_key(x)] # Remove non-tool plugins from sort list. self.sort = [x for x in self.sort if plugins[x].type == 'tool'] # Dump each item to toolbar. for toolname in self.sort: self.item(toolname) # Margin between buttons and colorboxes. gutils.margin(self.box, 5) # Colorboxes. self.colorwidget = gtk.HBox(True, 0) self.colorframe = gtk.Frame() self.colorbox = gtk.EventBox() self.colorbox.set_size_request(20, 20) self.colorframe.add(self.colorbox) self.colorwidget.pack_start(self.colorframe, False, False, 0) self.box.pack_start(self.colorwidget, False, False, 0) self.colorbox_update() # Show all. self.box.show_all() # Push sort to config. main.config.set('sort', 'toolbar', ','.join(self.sort))
def __init__(self, parent, label, options, selected, callback): # Create main widget and add into parent. self.box = gtk.HBox(False, 0) parent.pack_start(self.box, False, False, 0) # Label. label = gtk.Label('%s:' % label) label.set_alignment(0, 0.5) self.box.pack_start(label, True, True, 0) # Margin between label and combo. gutils.margin(self.box, 20, 1) # Combo box. self.combo = gtk.combo_box_new_text() for option in options: self.combo.append_text(option) self.combo.set_active(selected) self.combo.connect('changed', lambda x: callback(x.get_active())) self.box.pack_start(self.combo, False)
def callback(self): """To do when the plugin is called.""" # Create dialog. self.dialog = gtk.Dialog(self.label) self.dialog.set_modal(True) notebook = gtk.Notebook() notebook.set_border_width(5) self.dialog.vbox.pack_start(notebook) # About tab. about = gtk.VBox(False, 5) splash = gtk.image_new_from_file('%s/about.png' % main.imgpath) copyright = gtk.Label('Copyright © 2008-2010 Marcos Diaz Mencia') version_string = '%s %s (%s)' % (main.version, main.phase, main.level) version = gtk.Label(version_string) about.pack_start(splash) about.pack_start(copyright) about.pack_start(version) gutils.margin(about, 2) notebook.append_page(about, gtk.Label(_('About'))) # Credits tab. credits_text = open('%s/AUTHORS' % main.path).read() credits = self.textviewer(credits_text) notebook.append_page(credits, gtk.Label(_('Credits'))) # License tab. license_text = open('%s/COPYING-BRIEF' % main.path).read() license = self.textviewer(license_text) notebook.append_page(license, gtk.Label(_('License'))) # Connect. self.dialog.connect('response', self.response) self.dialog.connect('destroy', lambda x: self.quit()) # Buttons (auto-connected by response). self.dialog.add_button('gtk-close', 1) # Show. self.dialog.show_all()
def __init__(self, parent, label, maxchar, text, callback): self.box = gtk.HBox(False, 0) label = gtk.Label('%s:' % label) label.set_alignment(0, 0.5) self.entry = gtk.Entry(maxchar) self.entry.set_width_chars(maxchar + 1) self.entry.set_text(text) self.handler = self.entry.connect( 'changed', lambda x: callback(x.get_text())) # Pack into box. self.box.pack_start(label, True, True, 0) gutils.margin(self.box, 20, 1) self.box.pack_start(self.entry, False, False, 0) # Pack into parent widget. parent.pack_start(self.box, False, False, 0)
def __init__(self, parent, label, options, selected, callback): """Create and put on parent. @parent: Parent widget to put in. @label: Text to display. @option: Variable-length list with image names as strings. @selected: Index int to choose selected toggled button. @callback: Callback function to pass index int when toogled.""" # Create main widget and add into parent. self.box = gtk.HBox(False, 0) parent.pack_start(self.box, False, False, 0) # Label. label = gtk.Label('%s:' % label) label.set_alignment(0, 0.5) self.box.pack_start(label, True, True, 0) # Margin between label and buttons. gutils.margin(self.box, 20, 1) # Toggle buttons. self.buttons = [] self.group = None for option in options: button = gtk.RadioButton(self.group, None, False) if not self.group: self.group = button imagepath = '%s/%s.png' % (main.imgpath, option) button.set_image(gtk.image_new_from_file(imagepath)) button.set_relief(gtk.RELIEF_NONE) button.set_mode(False) self.buttons.append(button) button.connect('pressed', lambda x: callback(self.buttons.index(x))) self.box.pack_start(button, False, False, 0) # Set default toggled button. self.buttons[selected].set_active(True)
def callback(self): """To do when the plugin is called.""" # Redirect the output buffer. self.stdout = sys.stdout sys.stdout = self # Create dialog. self.dialog = gtk.Dialog(_('Console')) self.dialog.set_size_request(425, 325) # Create box for dialog except response buttons. self.box = gtk.VBox() self.box.set_border_width(5) self.dialog.vbox.pack_start(self.box) # Create the textview and related. self.scroll = gtk.ScrolledWindow() self.scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) self.adjustment = self.scroll.get_vadjustment() self.view = gtk.TextView() self.view.set_editable(False) self.view.set_cursor_visible(False) self.view.set_left_margin(8) self.view.set_wrap_mode(gtk.WRAP_WORD_CHAR) self.buffer = self.view.get_buffer() self.scroll.add(self.view) self.box.pack_start(self.scroll) # Set the textview style. font = pango.FontDescription("DejaVu Sans Mono 9") self.view.modify_font(font) self.view.modify_base(gtk.STATE_NORMAL, gtk.gdk.Color('#000')) self.view.modify_text(gtk.STATE_NORMAL, gtk.gdk.Color('#fff')) # Throw the welcome message. self.buffer.set_text( 'This is a Python pseudo-interpreter that allow you runtime ' 'introspection into Nathive, enjoy it!\n') self.evaluate('dir(main)') # Add margin between textview and input entry. gutils.margin(self.box, 4) # Create the input entry. self.input = gtk.Entry() focus = self.input.grab_focus self.input.connect('key-press-event', self.keypress) self.input.connect('focus-out-event', lambda x,y: focus()) self.box.pack_start(self.input, False, False) focus() # Connect. self.dialog.connect('response', self.response) self.dialog.connect('destroy', lambda x: self.quit()) # Buttons (auto-connected by response). self.dialog.add_button('gtk-close', 1) # Show. self.dialog.show_all()