Python gtk 模块,Image() 实例源码

我们从Python开源项目中,提取了以下33个代码示例,用于说明如何使用gtk.Image()

项目:Micro-Pi    作者:Bottersnike    | 项目源码 | 文件源码
def __init__(self):
        imageLoc = random.choice(os.listdir(os.path.join(WORKINGDIR, "data", "splashScreens")))
        imageSize = self.get_image_size(open(os.path.join(WORKINGDIR, "data", "splashScreens", imageLoc), 'rb').read())

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_decorated(False)
        self.window.set_title("Micro:Pi")
        self.window.set_icon_from_file(os.path.join(WORKINGDIR, "data", "icon.png"))
        self.window.set_size_request(imageSize[0], -1)
        self.window.set_position(gtk.WIN_POS_CENTER)
        main_vbox = gtk.VBox(False, 1)
        self.window.add(main_vbox)
        hbox = gtk.HBox(False, 0)
        self.img = gtk.Image()
        self.img.set_from_file(os.path.join(WORKINGDIR, "data", "splashScreens", imageLoc))
        main_vbox.pack_start(self.img, True, True)
        self.lbl = gtk.Label('')
        font = pango.FontDescription("Monospace 7")
        self.lbl.modify_font(font)
        main_vbox.pack_end(self.lbl, False, False)
        self.refresh()
        self.window.show_all()
        self.refresh()
项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def insert_icon(self, pageview):
        '''Create widget to choose an icon and insert an icon shortcode.'''

        def _insert(item):
            '''Insert an icon shortcode to the cursor position.'''
            buffer = pageview.view.get_buffer()
            text = '{0}{1}{2}{3}{0}'.format(STRONG_MARKUP, PREFIX, item, POSTFIX)
            buffer.insert_at_cursor(text)

        menu = gtk.Menu()
        icons = sorted([(a, render_icon(b)) for (a,b) in ICONS.iteritems()
                        if a not in RESERVED_ICON_NAMES])
        for name, icon in icons:
            image = gtk.Image()
            image.set_from_pixbuf(icon)
            item = gtk.ImageMenuItem(name)
            item.set_image(image)
            item.set_use_underline(False)
            item.connect('button-release-event', lambda item, _:
                         _insert(item.get_label()))
            menu.append(item)
    menu.popup(None, None, None, 3, 0)
        menu.show_all()
项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def insert_icon(self, pageview):
        '''Create widget to choose an icon and insert an icon shortcode.'''

        def _insert(item):
            '''Insert an icon shortcode to the cursor position.'''
            text = getIconMarkup(item)
            pageview.view.get_buffer().insert_at_cursor(text)

        menu = gtk.Menu()
        icons = sorted([(a, render_icon(b)) for (a,b) in ICONS.iteritems()
                        if a not in RESERVED_ICON_NAMES])
        for name, icon in icons:
            image = gtk.Image()
            image.set_from_pixbuf(icon)
            item = gtk.ImageMenuItem(name)
            item.set_image(image)
            item.set_use_underline(False)
            item.connect('button-release-event', lambda item, _:
                         _insert(item.get_label()))
            menu.append(item)
        menu.popup(None, None, None, 3, 0)
        menu.show_all()
项目:ECoG-ClusterFlow    作者:sugeerth    | 项目源码 | 文件源码
def _image_to_pixbuf(self, im):  
        """
        Creates a pixbuf from an Image object.  Probably unnecessary.  In the future I could just invoke a save
        and load then png instead.

        """

        file1 = StringIO.StringIO()  
        im.save(file1, "ppm")  
        contents = file1.getvalue()  
        file1.close()  
        loader = gtk.gdk.PixbufLoader("pnm")  
        loader.write(contents, len(contents))  
        pixbuf = loader.get_pixbuf()  
        loader.close()  
        return pixbuf
项目:lfde    作者:mv-code    | 项目源码 | 文件源码
def gui_add_task(self, task):
        label = gtk.Label(task.name)
        label.set_alignment(0.0, 0.0)
        row = self.task_count + 1
        col = 0  
        # col_left_attach, col_right_attach, row_top_attach, row_bottom_attach
        self.tbl_tasks.attach(label, col, col + 1, row, row + 1)
        label.show()

        col = 1 
        image = gtk.Image() 
        image.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_MENU)
        image.set_alignment(0.0, 0.0)
        self.tbl_tasks.attach(image, col, col + 1, row, row + 1)
        self.task_images.append(image)

        self.task_count += 1
项目:NativeCAM    作者:FernV    | 项目源码 | 文件源码
def create_nc_toolbar(self):
        if self.nc_toolbar is not None :
            self.nc_toolbar.destroy()
        self.nc_toolbar = gtk.Toolbar()
        self.nc_toolbar.set_style(gtk.TOOLBAR_ICONS)
        self.nc_toolbar.set_can_focus(False)

        count = len(TB_CATALOG)
        for x in range(count) :
            li = TB_CATALOG[x]
            if li == 'separator' :
                self.nc_toolbar.insert(gtk.SeparatorToolItem(), -1)
            else :
                if li[3] is not None :
                    icon = gtk.Image()
                    icon.set_from_pixbuf(get_pixbuf(li[3], quick_access_icon_size))
                    button = gtk.ToolButton(icon_widget = icon, label = _(li[0]))
                else :
                    button = gtk.ToolButton(label = li[0])
                if li[1] is not None :
                    button.set_tooltip_markup(_(li[1]))
                button.connect('clicked', self.add_feature, li[2])
                self.nc_toolbar.insert(button, -1)

        self.main_box.pack_start(self.nc_toolbar, False, False, 0)
项目:wahcade    作者:sairuk    | 项目源码 | 文件源码
def __init__(self, WinMain):
        #set main window
        self.WinMain = WinMain
        #build the window
        self.winMessage = gtk.Fixed()
        self.winMessage.set_has_window(True)
        self.imgBackground = gtk.Image()
        self.lblHeading = gtk.Label()
        self.lblMessage = gtk.Label()
        self.lblPrompt = gtk.Label()
        self.lblHeading.set_justify(gtk.JUSTIFY_CENTER)
        self.lblMessage.set_justify(gtk.JUSTIFY_CENTER)
        self.lblPrompt.set_justify(gtk.JUSTIFY_CENTER)
        self.winMessage.add(self.imgBackground)
        self.winMessage.add(self.lblHeading)
        self.winMessage.add(self.lblMessage)
        self.winMessage.add(self.lblPrompt)
        WinMain.fixd.add(self.winMessage)
        self.imgBackground.show()
        self.lblHeading.show()
        self.lblMessage.show()
        self.lblPrompt.show()
        self.winMessage.show()
        #
        self.wait_for_key = False
项目:wahcade    作者:sairuk    | 项目源码 | 文件源码
def display_splash(self):
        """show splash screen"""
        self.splash = gtk.Window()
        self.splash.set_decorated(False)
        self.splash.set_transient_for(self.winMain)
        self.splash.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
        self.splash.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
        self.splash.set_keep_above(True)
        self.splash.set_border_width(self.splash_border_width)
        vbox = gtk.VBox()
        img = gtk.Image()
        self.splash_gfx = os.path.join(CONFIG_DIR, 'layouts', self.layout, 'main-splash.png')
        if os.path.exists(self.splash_gfx):
            self.log_msg('Custom splash found, loading ' + str(self.splash_gfx))
            img.set_from_file(self.splash_gfx)
        else:
            self.splash_gfx = os.path.join(APP_PATH, 'pixmaps', 'wahcade-logo.png')
            self.log_msg('No custom splash found, loading ' + str(self.splash_gfx))
            img.set_from_file(self.splash_gfx)
        if self.splash_show_text == 1:
            lbl = gtk.Label()
            lbl.set_alignment(0.5, 0.5)
            lbl.set_justify(gtk.JUSTIFY_CENTER)
            lbl.set_use_markup(True)
            lbl.set_markup('<big><b>Wah!Cade</b></big>\n%s "%s"' % (VERSION, VERSION_NAME))
            vbox.pack_end(lbl)
        vbox.pack_start(img)
        self.splash.add(vbox)
        self.splash.show_all()
        if not self.tw_api:
            self.twitter_api = self.auth_twitter() ## Auth Twitter during startup
        self.wait_with_events(0.25)
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def _add(self, tab, row, name, editor, text, colindex=0):
        label = gtk.Label(text + ":")
        label.set_alignment(0.0, 0.5)
        label.show()
        tab.attach(label, colindex, colindex + 1, row, row + 1,
                   xoptions=gtk.FILL, yoptions=0, xpadding=6, ypadding=3)

        widget = editor.get_widget()
        widget.show()
        tab.attach(widget, colindex + 1, colindex + 2, row, row + 1,
                   xoptions=gtk.FILL, yoptions=0, xpadding=3, ypadding=3)

        img = gtk.Image()
        img.set_size_request(16, -1)
        img.show()
        tab.attach(img, colindex + 2, colindex + 3, row, row + 1,
                   xoptions=gtk.FILL, yoptions=0, xpadding=3, ypadding=3)

        self._editors[name] = label, editor, img
        return label, editor, img
项目:Micro-Pi    作者:Bottersnike    | 项目源码 | 文件源码
def refreshTree(self):
        folderIcon = gtk.Image().render_icon(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_MENU)
        fileIcon = gtk.Image().render_icon(gtk.STOCK_FILE, gtk.ICON_SIZE_MENU)

        def load(dic, parent=None):
            for i, j in dic.items():
                isFile = j[0]
                if isFile:
                    self.treeStore.append(parent, [fileIcon, i, True])
                else:
                    p = self.treeStore.append(parent, [folderIcon, i, False])
                    load(j[1], p)
        self.treeStore.clear()
        load(self.files)
项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def row_activated(self, path, column):
        if column.get_sort_column_id() != self.ICON_NAME:
            return False

        def set_icon(path, icon_name = None):

            iter = self.model.get_iter(path)
            tag = self.model.get_value(iter, self.TAG_COL)
            tag = unicode(tag) #  to use with non latin characters

            if icon_name:
                self.icons_for_tags[tag] = icon_name
            else:
                self.icons_for_tags.pop(tag, None)
            self.refill_model()
            return True

        menu = gtk.Menu()

        item = gtk.MenuItem('None')
        item.connect('activate', lambda item: set_icon(path))
        menu.append(item)

        icons = sorted([(a, render_icon(b)) for (a,b) in ICONS.iteritems()
                        if a not in RESERVED_ICON_NAMES])
        for name, icon in icons:
            image = gtk.Image()
            image.set_from_pixbuf(icon)
            item = gtk.ImageMenuItem(name)
            item.set_use_underline(False)
            item.set_image(image)
            item.zim_icon_name = name
            item.connect('activate', lambda item: set_icon(path, item.zim_icon_name))
            menu.append(item)

        menu.show_all()
        menu.popup(None, None, None, 3, 0)
项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def row_activated(self, path, column):
        if column.get_sort_column_id() != self.ICON_NAME:
            return False

        def set_icon(path, icon_name = None):

            tag = self.model.get_value(self.model.get_iter(path), self.TAG_COL)
            tag = unicode(tag) #  to use with non latin characters

            if icon_name:
                self.icons_for_tags[tag] = icon_name
            else:
                self.icons_for_tags.pop(tag, None)
            self.refill_model()
            return True

        menu = gtk.Menu()

        item = gtk.MenuItem('None')
        item.connect('activate', lambda item: set_icon(path))
        menu.append(item)

        icons = sorted([(a, render_icon(b)) for (a,b) in ICONS.iteritems()
                        if a not in RESERVED_ICON_NAMES])
        for name, icon in icons:
            image = gtk.Image()
            image.set_from_pixbuf(icon)
            item = gtk.ImageMenuItem(name)
            item.set_use_underline(False)
            item.set_image(image)
            item.zim_icon_name = name
            item.connect('activate', lambda item: set_icon(path, item.zim_icon_name))
            menu.append(item)

        menu.show_all()
        menu.popup(None, None, None, 3, 0)
项目:ECoG-ClusterFlow    作者:sugeerth    | 项目源码 | 文件源码
def _create_hmap(self, matrix):

        size = (len(matrix[0]) * self.bsize, len(matrix) * self.bsize)

        red_lightness = self._get_lightness([ x for i in xrange(len(matrix)) for x in matrix[i] if x >= 0 ])
        green_lightness = self._get_lightness([ x for i in xrange(len(matrix)) for x in matrix[i] if x < 0 ])

        im = Image.new('RGBA', size, 'white')
        draw = ImageDraw.Draw(im)

        for row in xrange(len(matrix)):
            for col in xrange(len(matrix[row])):

                if matrix[row][col] < 0:
                    colour = (0,int(abs(matrix[row][col]) * green_lightness),0)
                else:
                    colour = (int(matrix[row][col] * red_lightness),0,0)

                col_size = col * self.bsize
                row_size = row * self.bsize

                bcol_size = self.bsize + col_size
                brow_size = self.bsize + row_size

                draw.polygon([(col_size, row_size),
                              (bcol_size, row_size),
                              (bcol_size, brow_size),
                              (col_size, brow_size)], outline='black', fill=colour)

        return im
项目:ECoG-ClusterFlow    作者:sugeerth    | 项目源码 | 文件源码
def show(self):
        """Opens a GTK window and puts the heatmap in it.  Intelligent enough to work with the GUI as well."""

        window_only = 1 #What needs to be destroyed when the window is destroyed?

        if HMAP_ENABLED and DISPLAY_ENABLED:

            def destroy():

                if window_only:
                    window.destroy()
                else:
                    gtk.main_quit()

            gtk.gdk.threads_enter()
            window = gtk.Window()
            window.set_title("Showing heatmap...")
            window.set_border_width(10)
            window.set_resizable(False)
            window.connect("delete_event", lambda w, e: destroy())

            backbone = gtk.HBox(True)
            image = gtk.Image()
            image.set_from_pixbuf(self._image_to_pixbuf(self.im))
            backbone.pack_start(image)

            window.add(backbone)
            window.show_all()
            gtk.gdk.threads_leave()

            if gtk.main_level() == 0:
                window_only = 0
                gtk.main()

        else:
            raise "HmapError", "Error loading modules or unable to display"
项目:NativeCAM    作者:FernV    | 项目源码 | 文件源码
def create_M_file() :
    p = os.path.join(NCAM_DIR, NGC_DIR, 'M123')
    with open(p, 'wb') as f :
        f.write('#!/usr/bin/env python\n# coding: utf-8\n')

        f.write("import gtk\nimport os\nimport pygtk\npygtk.require('2.0')\nfrom gtk import gdk\n\n")

        f.write("fname = '%s'\n" % os.path.join(NCAM_DIR, CATALOGS_DIR, 'no_skip_dlg.conf'))
        f.write('if os.path.isfile(fname) :\n    exit(0)\n\n')

        f.write("msg = '%s'\n" % _('Stop LinuxCNC program,&#10;toggle the shown button,&#10;then restart'))
        f.write("msg1 = '%s'\n" % _('Skip block not active'))
        f.write("icon_fname = '%s'\n\n" % os.path.join(NCAM_DIR, GRAPHICS_DIR, 'skip_block.png'))

        f.write('dlg = gtk.MessageDialog(parent = None, flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, type = gtk.MESSAGE_WARNING, buttons = gtk.BUTTONS_NONE, message_format = msg1)\n\n')

        f.write("dlg.set_title('NativeCAM')\ndlg.format_secondary_markup(msg)\n\n")

        f.write('dlg.set_image(gtk.Image())\n')
        f.write('dlg.get_image().set_from_pixbuf(gdk.pixbuf_new_from_file_at_size(icon_fname, 80, 80))\n\n')

        f.write('cb = gtk.CheckButton(label = "%s")\n' % _("Do not show again"))
        f.write('dlg.get_content_area().pack_start(cb, True, True, 0)\n')
        f.write('dlg.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK).grab_focus()\n\n')

        f.write('dlg.set_keep_above(True)\ndlg.show_all()\n\ndlg.run()\n')
        f.write("if cb.get_active() :\n    open(fname, 'w').close()\n")
        f.write('exit(0)\n')

    os.chmod(p, 0o755)
    mess_dlg(_('LinuxCNC needs to be restarted now'))
项目:NativeCAM    作者:FernV    | 项目源码 | 文件源码
def msg_inv(self, msg, msgid):
        msg = msg.replace('&#176;', '°')
        print('\n%(feature_name)s : %(msg)s' % {'feature_name':self.get_name(), 'msg':msg})

        if (("ALL:msgid-0" in EXCL_MESSAGES) or
                ("%s:msgid-0" % (self.get_type()) in EXCL_MESSAGES) or
                (("%s:msgid-%d" % (self.get_type(), msgid)) in EXCL_MESSAGES)) :
            return

        # create dialog with image and checkbox
        dlg = gtk.MessageDialog(parent = None,
            flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
            type = gtk.MESSAGE_WARNING,
            buttons = gtk.BUTTONS_NONE,
            message_format = self.get_name())
        dlg.set_title('NativeCAM')
        dlg.format_secondary_text(msg)
        img = gtk.Image()
        img.set_from_pixbuf(self.get_icon(add_dlg_icon_size))
        dlg.set_image(img)
        cb = gtk.CheckButton(label = _("Do not show again"))
        dlg.get_content_area().pack_start(cb, True, True, 0)
        dlg.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK).grab_focus()

        dlg.set_keep_above(True)
        dlg.show_all()
        dlg.run()
        if cb.get_active() :
            GLOBAL_PREF.add_excluded_msg(self.get_type(), msgid)
        dlg.destroy()
项目:gui-o-matic    作者:mailpile    | 项目源码 | 文件源码
def _main_window_indicator(self, menu_container, icon_container):
        if not self._HAVE_INDICATOR:
            menubar = gtk.MenuBar()
            im = gtk.MenuItem(self.config.get('app_name', 'GUI-o-Matic'))
            im.set_submenu(self.menu)
            menubar.append(im)
            menu_container.pack_start(menubar, False, True)

            icon = gtk.Image()
            icon_container.pack_start(icon, False, True)
            self.main_window['indicator_icon'] = icon
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def extension(self, module, enabled):
    if enabled:
        try:
            ext = module(self)
        except (NotImplementedError, DeprecationWarning), e:
            log.warning('extension skipped: %s', e.message)
            log.debug('extension skipped: %s', module.__file__)
            return [None, None]
        if module.toolbar_icon:
            toolbar = self.widgets['extensions']['toolbar']
            if module.toolbar_icon.endswith(('.png', '.svg')):
                icon_path = os.path.join(os.path.dirname(module.__file__), 'data', module.toolbar_icon)
                if not os.path.isfile(icon_path):
                    icon_path = os.path.join(self.locations['images'], module.toolbar_icon)
                if not os.path.isfile(icon_path):
                    log.error('icon not found: %s', module.toolbar_icon)
                else:
                    icon = gtk.Image()
                    icon.set_from_file(icon_path)
                    ext.toolbar_icon_widget = toolbar.insert_item(None, module.description, None, icon, ext._on_toolbar_icon_clicked, None, -1)
            else:
                ext.toolbar_icon_widget = toolbar.insert_stock(module.toolbar_icon, module.description, None, ext._on_toolbar_icon_clicked, None, -1)
    else:
        ext = None

    return ext
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def create_image_cache(md5sum, gsql):
    poster = gsql.session.query(db.Poster).filter_by(md5sum=md5sum).first()
    if not poster:
        log.warn("poster not available: %s", md5sum)
        return False
    if not poster.data:
        log.warn("poster data not available: %s", md5sum)
        return False

    fn_big = os.path.join(gsql.data_dir, 'posters', md5sum + '.jpg')
    fn_medium = os.path.join(gsql.data_dir, 'posters', md5sum + '_m.jpg')
    fn_small = os.path.join(gsql.data_dir, 'posters', md5sum + '_s.jpg')

    if not os.path.isfile(fn_big):
        f = file(fn_big, 'wb')
        f.write(poster.data)
        f.close()

    image = gtk.Image()
    image.set_from_file(fn_big)

    if not os.path.isfile(fn_medium):
        pixbuf = image.get_pixbuf()
        pixbuf = pixbuf.scale_simple(100, 140, 'bilinear')
        pixbuf.save(fn_medium, 'jpeg', {'quality': '70'})

    if not os.path.isfile(fn_small):
        pixbuf = image.get_pixbuf()
        pixbuf = pixbuf.scale_simple(30, 40, 'bilinear')
        pixbuf.save(fn_small, 'jpeg', {'quality': '70'})

    return True
项目:wahcade    作者:sairuk    | 项目源码 | 文件源码
def __init__(self, WinMain):
        """setup cp viewer window"""
        #set main window
        self.WinMain = WinMain
        self.layout_filename = ''
        self.cpviewer_ok = True
        #open cpviewer viewer ini
        self.cpviewer_ini = MameWahIni(os.path.join(CONFIG_DIR, 'cpviewer.ini'), 'default')
        if os.path.exists(os.path.join(CONFIG_DIR, 'ini', self.WinMain.current_emu + '.cpv')):
            self.cpviewer_ini = MameWahIni(os.path.join(CONFIG_DIR, 'ini', self.WinMain.current_emu + '.cpv'), 'default')
        self.ctrls_ini_filename = self.cpviewer_ini.get('controls_ini_file')
        if not os.path.isfile(self.ctrls_ini_filename):
            self.WinMain.log_msg("Warning: controls file: [%s] does not exist" % (self.ctrls_ini_filename))
            self.cpviewer_ok = False
        self.layout_filename = self.cpviewer_ini.get('viewer_layout')
        if not os.path.exists(self.layout_filename):
            self.WinMain.log_msg("Warning: CPViewer layout file: [%s] does not exist" % (self.layout_filename))
            self.cpviewer_ok = False
        #build gui
        self.winCPViewer = gtk.Fixed()
        self.winCPViewer.set_has_window(True)
        self.imgBackground = gtk.Image()
        self.winCPViewer.add(self.imgBackground)
        self.WinMain.fixd.add(self.winCPViewer)
        self.imgBackground.show()
        self.winCPViewer.show()
        self.ctrls_ini = self.get_controls_ini(self.ctrls_ini_filename)
        if self.ctrls_ini is None:
            self.cpviewer_ok = False
        self.app_number = 0
项目:wahcade    作者:sairuk    | 项目源码 | 文件源码
def setup_menu(self, mnu_items, mnu_pixmaps, activate_cb):
        """returns a gtk menu object
        Parameters:
            mnu_items   : List of menu item names (either a string, a gtk stock item or '_sep_' for a separator)
            mnu_pixmaps : List of pixmaps (filename, a gtk stock icon or None)
            activate_cb : Callback function for menu activation
        Returns:
            Reference to the constructed gtk.Menu
        """
        mnu = gtk.Menu()
        for i in range(len(mnu_items)):
            #separator or menu item?
            if mnu_items[i] != '_sep_':
                #menu item
                mnuItem = gtk.ImageMenuItem(stock_id=mnu_items[i])
                img = gtk.Image()
                if mnu_pixmaps[i]:
                    if mnu_pixmaps[i][:4] == 'gtk-' and '.' not in mnu_pixmaps[i]:
                        #stock icon
                        img.set_from_stock(mnu_pixmaps[i], gtk.ICON_SIZE_MENU)
                    else:
                        #file icon
                        img.set_from_pixbuf(self.get_pixbuf(mnu_pixmaps[i], gtk.ICON_SIZE_MENU))
                    img.show()
                    mnuItem.set_image(img)
                mnuItem.connect('activate', activate_cb)
                mnuItem.set_name(mnu_items[i])
            else:
                #separator
                mnuItem = gtk.SeparatorMenuItem()
            #add item to menu
            mnuItem.show()
            mnu.append(mnuItem)
        #done
        return mnu
项目:gimp-fanim    作者:douglasvini    | 项目源码 | 文件源码
def button_stock(stock,size):
        """
        Return a button with a image from stock items.
        """
        b = gtk.Button()
        img = gtk.Image()
        img.set_from_stock(stock,size)
        b.set_image(img)
        return b
项目:gimp-fanim    作者:douglasvini    | 项目源码 | 文件源码
def toggle_button_stock(stock,size):
        """
        Return a button with a image from stock items 
        """
        b = gtk.ToggleButton()
        img = gtk.Image()
        img.set_from_stock(stock,size)
        b.set_image(img)
        return b
项目:gimp-fanim    作者:douglasvini    | 项目源码 | 文件源码
def _setup(self):
        self.thumbnail = gtk.Image()
        self.label = gtk.Label(self.layer.name)
        # creating the fix button, to anchor background frames.
        self._fix_button = Utils.toggle_button_stock(gtk.STOCK_MEDIA_RECORD,20)
        self._fix_button.set_tooltip_text("toggle fixed visibility.")

        # update fixed variable
        self.fixed = Utils.is_frame_fixed(self.layer)
        #images
        pin_img = gtk.Image()
        pin_img.set_from_stock(gtk.STOCK_YES,20)
        pin_img2 = gtk.Image()
        pin_img2.set_from_stock(gtk.STOCK_MEDIA_RECORD,20)

        self._fix_button_images = [pin_img,pin_img2]

        ## connect
        self._fix_button.connect('clicked',self.on_toggle_fix)

        if self.fixed:
            self._fix_button.set_image(self._fix_button_images[0])
            self._fix_button.set_active(True)
        else :
            self._fix_button.set_image(self._fix_button_images[1])
            self._fix_button.set_active(False)

        frame = gtk.Frame()
        layout = gtk.VBox()
        # add frame to this widget
        self.add(frame)

        # add layout manager to the frame
        frame.add(layout)

        layout.pack_start(self.label)
        layout.pack_start(self._fix_button)
        layout.pack_start(self.thumbnail)
        self._get_thumb_image()
项目:gimp-fanim    作者:douglasvini    | 项目源码 | 文件源码
def _setup_generalbar(self):
        stock_size = gtk.ICON_SIZE_BUTTON
        general_bar = gtk.HBox()

        b_about = Utils.button_stock(gtk.STOCK_ABOUT,stock_size)

        b_to_gif = Utils.button_stock(gtk.STOCK_CONVERT,stock_size)
        b_to_sprite = Utils.button_stock(gtk.STOCK_MISSING_IMAGE,stock_size)

        # TODO implement export button

        b_quit = Utils.button_stock(gtk.STOCK_QUIT,stock_size)

        # callbacks
        b_quit.connect('clicked',self.destroy)
        b_about.connect('clicked',self.on_about)

        b_to_gif.connect('clicked',self.create_formated_version,'gif')
        b_to_sprite.connect('clicked',self.create_formated_version,'spritesheet')

        # tooltips
        b_about.set_tooltip_text("About FAnim")
        b_quit.set_tooltip_text("Exit")
        b_to_gif.set_tooltip_text("Create a formated Image to export as gif animation")
        b_to_sprite.set_tooltip_text("Create a formated Image to export as spritesheet")

        # add to the disable on play list
        w = [b_about, b_to_gif,b_to_sprite, b_quit]
        map(lambda x: self.widgets_to_disable.append(x),w)

        # packing everything in gbar
        map(lambda x: general_bar.pack_start(x,False,False,0),w)

        return general_bar
项目:Micro-Pi    作者:Bottersnike    | 项目源码 | 文件源码
def addNotebookPage(self, title, content, path):
        area = gtk.ScrolledWindow()
        area.set_policy(gtk.POLICY_ALWAYS, gtk.POLICY_ALWAYS)
        area.show()

        txtB = gtkSourceView.Buffer()
        txtB.begin_not_undoable_action()
        txtB.set_style_scheme(self.style_scheme)

        language = self.getLanguage(title)

        txtB.set_highlight_matching_brackets(True)
        if language is not None:
            txtB.set_highlight_syntax(True)
            txtB.set_language(language)

        txtB.set_text(content)
        txtB.place_cursor(txtB.get_start_iter())
        txtB.set_modified(False)
        txtB.end_not_undoable_action()

        text = SourceView(txtB)
        text.set_tab_width(self.tabWidth)
        text.set_insert_spaces_instead_of_tabs(False)
        text.set_show_right_margin(True)
        text.set_show_line_marks(True)
        text.set_auto_indent(self.autoIndent)
        text.set_show_line_numbers(self.lineNumbers)
        text.show()
        text.modify_font(pango.FontDescription('Monospace 10'))
        area.add(text)


        top = gtk.HBox()

        title = gtk.Label(title)
        title.show()
        top.set_tooltip_text(path)


        top.pack_start(title, True, True, 0)
        butt = gtk.Button()
        img = gtk.Image()
        img.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
        img.show()
        butt.set_image(img)
        butt.connect_object("clicked", self.closePage, area)
        top.pack_end(butt, False, False, 0)

        butt.show()
        top.show()

        self.notebook.insert_page(area, top, 0)

        pages = self.notebook.get_n_pages()
        self.notebook.set_current_page(0)
项目:Micro-Pi    作者:Bottersnike    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        self.window = gtk.Window()
        self.window.set_title("Create An Image")
        self.window.set_icon_from_file(os.path.join(WORKINGDIR, "data", "icon.png"))
        colour = gtk.gdk.color_parse(DARKCOL)
        self.window.modify_bg(gtk.STATE_NORMAL, colour)

        self.vvbox = gtk.VBox()
        self.table = gtk.Table(5, 5)
        self.table.set_border_width(2)
        self.table.set_row_spacings(2)
        self.table.set_col_spacings(2)
        self.buttons = {}

        for y in range(5):
            for x in range(5):
                eb = gtk.EventBox()
                i = gtk.Image()
                i.set_from_file(os.path.join(WORKINGDIR, "data", "selected.png"))
                i.show()
                eb.add(i)
                eb.hide()
                eb.modify_bg(gtk.STATE_NORMAL, colour)
                eb.connect_object("button-press-event", self.togglePart, (x, y))

                eb2 = gtk.EventBox()
                i2 = gtk.Image()
                i2.set_from_file(os.path.join(WORKINGDIR, "data", "unselected.png"))
                i2.show()
                eb2.add(i2)
                eb2.show()
                eb2.modify_bg(gtk.STATE_NORMAL, colour)
                eb2.connect_object("button-press-event", self.togglePart, (x, y))

                self.buttons[(x, y)] = (eb, eb2)

                self.table.attach(eb, x, x + 1, y, y + 1)
                self.table.attach(eb2, x, x + 1, y, y + 1)

        self.table.show()
        self.vvbox.pack_start(self.table)
        hbox = gtk.HBox()
        self.confirmButton = gtk.Button("Okay")
        self.confirmButton.show()
        self.confirmButton.connect("clicked", self.okay)
        hbox.pack_start(self.confirmButton, True, False)
        cancelButton = gtk.Button("Cancel")
        cancelButton.connect("clicked", self.destroy)
        cancelButton.show()
        hbox.pack_end(cancelButton, True, False)
        hbox.show()
        self.vvbox.pack_start(hbox)
        self.vvbox.show()
        self.window.add(self.vvbox)
        self.onOkay = None

        self.running = True
        self.destoryed = False
项目:ECoG-ClusterFlow    作者:sugeerth    | 项目源码 | 文件源码
def __init__(self, clust_data, labels = None, bsize = 10, tree_space = 200):

        self.space = tree_space

        colours = ['blue', 'green', 'red', 'cyan', 'magenta', 'brown', 'orange']
        self.colour_map = self._init_colours(colours, [ x.cluster_id for x in clust_data.datapoints ])

        if labels is None:
            labels = [ clust_data.datapoints[x].sample_id for x in clust_data.reorder_indices ]

        try:
            self.font = ImageFont.load('courR08.pil') #Copyright (c) 1987 Adobe Systems, Inc., Portions Copyright 1988 Digital Equipment Corp.
        except IOError:
            self.font = None

        if len(clust_data.consensus_matrix) != len(labels):
            raise ValueError, "Number of columns and column label arrays have different lengths!"

        Hmap.__init__(self, clust_data.consensus_matrix, bsize = bsize) #Creates image in self.im if HMAP_ENABLED

        if self.im is not None:

            old_draw = ImageDraw.Draw(self.im)

            self.max_textsize = 0
            for label in labels:
                self.max_textsize = max(self.max_textsize, old_draw.textsize(label, font=self.font)[0])

            del old_draw #Keep GC from keeping the old image around

            if clust_data.tree is None:
                self.space = self.max_textsize + 5

            #Prepare
            newsize = (self.im.size[1] + self.space, self.im.size[0])  #To hold our rotated copy and some text
            im = Image.new('RGBA', newsize, 'white')

            #Trick to make vertical text when we're done, and add tree space
            im.paste(self.im.rotate(-90), (0, 0, self.im.size[1], self.im.size[0]))

            self.im = im
            self.draw = ImageDraw.Draw(self.im)

            #Actual work
            self._add_cluster_labels(labels)

            if clust_data.tree is not None:
                self._draw_dendogram(clust_data.tree)

            #Finish
            self.im = self.im.rotate(90)
项目:NativeCAM    作者:FernV    | 项目源码 | 文件源码
def add_catalog_items(self, menu_add):

        def add_to_menu(grp_menu, path) :
            for ptr in range(len(path)) :
                try :
                    p = path[ptr]
                    if p.tag.lower() in ["menu", "menuitem", "group", "sub"] :
                        name = p.get("name") if "name" in p.keys() else ""
                        a_menu_item = gtk.ImageMenuItem(_(name))

                        tooltip = _(p.get("tool_tip")) if "tool_tip" in p.keys() else None
                        if (tooltip is not None) and (tooltip != '') :
                            a_menu_item.set_tooltip_markup(_(tooltip))

                        icon = p.get('icon')
                        if icon is not None :
                            img = gtk.Image()
                            img.set_from_pixbuf(get_pixbuf(icon, add_menu_icon_size))
                            a_menu_item.set_image(img)

                        src = p.get('src')
                        if src is not None :
                            a_menu_item.connect("activate", self.add_feature, src)

                        grp_menu.append(a_menu_item)

                        if p.tag.lower() in ['menu', "group"] :
                            a_menu = gtk.Menu()
                            a_menu_item.set_submenu(a_menu)
                            add_to_menu(a_menu, p)

                    elif p.tag.lower() == "separator":
                        grp_menu.append(gtk.SeparatorMenuItem())
                except:
                    pass

        if self.catalog.tag != 'ncam_ui' :
            mess_dlg(_('Menu is old format, no toolbar defined.\nUpdate to new format'))
            add_to_menu(menu_add, self.catalog)
        else :
            for _ptr in range(len(self.catalog)) :
                _p = self.catalog[_ptr]
                if _p.tag.lower() in ["menu", "group"] :
                    add_to_menu(menu_add, _p)
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def file_chooser(title, action=None, buttons=None, name='', folder=os.path.expanduser('~'), picture=False, backup=False):
    if mac:
        if "SAVE" in str(action):
            if backup:
                status, filename, path = macutils.saveDialog(['zip'])
            else:
                status, filename, path = macutils.saveDialog()
        else:
            status, filename, path = macutils.openDialog(['zip'])
        if status:
            if filename.lower().endswith('.zip'):
                pass
            else:
                filename = filename+".zip"
            return filename, path
        else:
            return False 
    else:
        dialog = gtk.FileChooserDialog(title=title, action=action, buttons=buttons)
        dialog.set_default_response(gtk.RESPONSE_OK)
        if name:
            dialog.set_current_name(name)
        if folder:
            dialog.set_current_folder(folder)
        mfilter = gtk.FileFilter()
        if picture:
            preview = gtk.Image()
            dialog.set_preview_widget(preview)
            dialog.connect("update-preview", update_preview_cb, preview)
            mfilter.set_name(_("Images"))
            mfilter.add_mime_type("image/png")
            mfilter.add_mime_type("image/jpeg")
            mfilter.add_mime_type("image/gif")
            mfilter.add_pattern("*.[pP][nN][gG]")
            mfilter.add_pattern("*.[jJ][pP][eE]?[gG]")
            mfilter.add_pattern("*.[gG][iI][fF]")
            mfilter.add_pattern("*.[tT][iI][fF]{1,2}")
            mfilter.add_pattern("*.[xX][pP][mM]")
            dialog.add_filter(mfilter)
        elif backup:
            mfilter.set_name(_('backups'))
            mfilter.add_pattern('*.[zZ][iI][pP]')
            mfilter.add_pattern('*.[gG][rR][iI]')
            mfilter.add_pattern('*.[dD][bB]')
            dialog.add_filter(mfilter)
        mfilter = gtk.FileFilter()
        mfilter.set_name(_("All files"))
        mfilter.add_pattern("*")
        dialog.add_filter(mfilter)


        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            filename = dialog.get_filename()
        elif response == gtk.RESPONSE_CANCEL:
            filename = None
        else:
            return False
        path = dialog.get_current_folder()
        dialog.destroy()
        return filename, path
项目:linux-pentest-util    作者:fikr4n    | 项目源码 | 文件源码
def _create_legend(self):
        icons = (
            (gtk.STOCK_FILE, 'Class'),
            (gtk.STOCK_EXECUTE, 'Method'),
            (gtk.STOCK_SELECT_FONT, 'Field'),
            (gtk.STOCK_DELETE, 'Declaration not found'),
            (gtk.STOCK_INFO, 'Miscellaneous (info)'),
            (u'?', 'Direct call – e.g. static, private, etc'),
            (u'?', 'Virtual call (? + ?)'),
            (u'?', 'Virtual call (indirect) which could be performed because '
                'of polymorphism'),
            (u'?', 'Virtual call (direct only) which does not actually '
                'performed – e.g. interface method'),
            (u'?', 'Super call (? + ?)'),
            (u'?', 'Super call (indirect) because direct super does not '
                'declare the method'),
            (u'?', 'Super call (direct only) which does not actually '
                'performed – e.g. not declared here'),
        )
        table = gtk.Table(7, 5)
        table.set_border_width(8)
        table.set_row_spacings(8)
        table.set_col_spacings(8)
        separator = gtk.VSeparator()
        table.attach(separator, 2, 3, 0, 7, 0)
        x, y = 0, 0
        for icon, desc in icons:
            if len(icon) == 1:
                image = gtk.Label(icon)
            else:
                image = gtk.Image()
                image.set_from_stock(icon, gtk.ICON_SIZE_MENU)
            image.set_alignment(1, 0.5)
            label = gtk.Label(desc)
            label.set_alignment(0, 0.5)
            table.attach(image, x + 0, x + 1, y, y + 1, gtk.FILL)
            table.attach(label, x + 1, x + 2, y, y + 1, gtk.FILL)
            y += 1
            if y == 5 and x == 0:
                x, y = 3, 0
        frame = gtk.Frame('Legend')
        frame.add(table)
        return frame
项目:wahcade    作者:sairuk    | 项目源码 | 文件源码
def __init__(self, WinMain):
        #set main window
        self.WinMain = WinMain
        self.layout_filename = ''
        self.histview_ok = True
        #open history viewer ini
        self.histview_ini = MameWahIni(os.path.join(CONFIG_DIR, 'histview.ini'), 'default', '0.16')
        if os.path.exists(os.path.join(CONFIG_DIR, 'ini', self.WinMain.current_emu + '.his')):
            self.cpviewer_ini = MameWahIni(os.path.join(CONFIG_DIR, 'ini', self.WinMain.current_emu + '.his'), 'default')
        if not os.path.isfile(self.histview_ini.get('history_dat_file')):
            self.WinMain.log_msg("Warning: history file: [%s] does not exist" % (
                self.histview_ini.get('history_dat_file')))
            self.histview_ok = False
        self.layout_filename = self.histview_ini.get('history_layout')
        if not os.path.isfile(self.layout_filename):
            self.WinMain.log_msg("Warning: history layout: [%s] does not exist" % (self.layout_filename))
            self.histview_ok = False
        #build the window
        self.winHistory = gtk.Fixed()
        self.winHistory.set_has_window(True)
        self.imgBackground = gtk.Image()
        self.lblHeading = gtk.Label()
        self.sclHistory = ScrollList()
        self.winHistory.add(self.imgBackground)
        self.winHistory.add(self.make_evb_widget(self.lblHeading))
        self.winHistory.add(self.sclHistory.fixd)
        WinMain.fixd.add(self.winHistory)
        self.imgBackground.show()
        self.lblHeading.show()
        self.winHistory.show()
        #build list
        self.lsHistory = []
        self.sclHistory.auto_update = True
        self.sclHistory.display_limiters = self.WinMain.wahcade_ini.getint('show_list_arrows', 0)
        #widgets
        self._histview_items = [
            (8, self.lblHeading),
            (21, self.sclHistory)]
        #get history
        self.history = self.read_history(self.histview_ini.get('history_dat_file'))
        #app number
        self.app_number = 0
项目:gimp-fanim    作者:douglasvini    | 项目源码 | 文件源码
def _setup_playbackbar(self):
        playback_bar = gtk.HBox()
        button_size = 30
        stock_size = gtk.ICON_SIZE_BUTTON

        # play button
        ## image
        image_play = gtk.Image()
        image_play.set_from_stock(gtk.STOCK_MEDIA_PLAY,stock_size)
        image_pause = gtk.Image()
        image_pause.set_from_stock(gtk.STOCK_MEDIA_PAUSE,stock_size)
        ## append the images to a list to be used later on
        self.play_button_images.append(image_play)
        self.play_button_images.append(image_pause)
        ## button
        b_play = gtk.Button()
        b_play.set_image(image_play)
        b_play.set_size_request(button_size,button_size)

        b_tostart = Utils.button_stock(gtk.STOCK_MEDIA_PREVIOUS,stock_size)
        b_toend = Utils.button_stock(gtk.STOCK_MEDIA_NEXT,stock_size)
        b_prev = Utils.button_stock(gtk.STOCK_MEDIA_REWIND,stock_size)
        b_next = Utils.button_stock(gtk.STOCK_MEDIA_FORWARD,stock_size)

        b_repeat = Utils.toggle_button_stock(gtk.STOCK_REFRESH,stock_size)

        # connecting the button with callback
        b_play.connect('clicked',self.on_toggle_play)
        b_repeat.connect('toggled',self.on_replay)

        b_next.connect('clicked',self.on_goto,NEXT,True)
        b_prev.connect('clicked',self.on_goto,PREV,True)
        b_toend.connect('clicked',self.on_goto,END,True)
        b_tostart.connect('clicked',self.on_goto,START,True)


        # add to the disable on play list
        w = [b_repeat,b_prev,b_next,b_tostart,b_toend]
        map(lambda x: self.widgets_to_disable.append(x),w)
        self.play_bar = playback_bar

        # set the tooltips
        b_play.set_tooltip_text("Animation play/pause")
        b_repeat.set_tooltip_text("Animation replay active/deactive")
        b_prev.set_tooltip_text("To the previous frame")
        b_next.set_tooltip_text("To the next frame")
        b_tostart.set_tooltip_text("To the start frame")
        b_toend.set_tooltip_text("To the end frame")

        # packing everything in gbar
        playback_bar.pack_start(b_tostart,False,False,0)
        playback_bar.pack_start(b_prev,False,False,0)
        playback_bar.pack_start(b_play,False,False,0)
        playback_bar.pack_start(b_next,False,False,0)
        playback_bar.pack_start(b_toend,False,False,0)
        playback_bar.pack_start(b_repeat,False,False,0)

        return playback_bar