working on it ...

Filters

Explore Public Snippets

Sort by

Found 524 snippets matching: suggestions

    public by cghersi modified Jul 2, 2014  7403  1  7  2

    Java SWT: Combobox with AutoSuggestion feature

    This component can be safely used when you want to have a combobox with the capability to display automatic filtered suggestions based on the text already entered. It uses a couple of callback actions so that the caller can specify what to do when ENTER key is hit and how to load suggestions. The call back actions are specified by a simple interf
    package com.snip2code.ui.swt;
    
    import java.util.List;
    import java.util.Random;
    
    import org.apache.log4j.Logger;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.custom.StackLayout;
    import org.eclipse.swt.events.FocusAdapter;
    import org.eclipse.swt.events.FocusEvent;
    import org.eclipse.swt.events.KeyAdapter;
    import org.eclipse.swt.events.KeyEvent;
    import org.eclipse.swt.events.MouseAdapter;
    import org.eclipse.swt.events.MouseEvent;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.graphics.Rectangle;
    import org.eclipse.swt.layout.FillLayout;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Event;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Listener;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Table;
    import org.eclipse.swt.widgets.TableItem;
    import org.eclipse.swt.widgets.Text;
    
    import com.snip2code.utils.Utils;
    
    
    /**
     * (c) 2011 snip2code inc.
     * This software is property of snip2code inc. Use or reproduction without permission is prohibited 
     *
     * This widget creates a textfield with an autosuggestion feature.
     * The list of suggestion is shown when the user clicks on the text field or starts typing in the text field
     */
    public class AutoSuggestionComposite extends Composite {
    
    	protected static Logger log = Logger.getLogger(AutoSuggestionComposite.class);
    	
    	private Composite textBoxStackPanel;
    	private StackLayout textboxLayout;
    	private Text textBox;
    	private Label tooltip;
    	private Shell popupShell;
    	private Table table;
    	private String tooltipMsg;
    
    	private ICallback<String, List<String>> loadSuggestionAction;
    	private ICallback<String, String> onEnterAction;
    	
    	private String text;
    	private int numOfDisplayedSuggestions;
    	
    	private static final String POPUPVISIB = "$$$POPUP_VISIB";
    	
    	private String uniqueID; //used to differentiate AutoSuggestion composites in the same dialog
    	private static Random rdn = new Random();
    	
    	/**
    	 * Create the dialog.
    	 * @param parent
    	 * @param style
    	 * @param tooltipMsg message to display when no input is entered
    	 * @param numOfDisplayedSuggestions masimum number of items suggested in the popup of suggestions
    	 * @param loadSuggestionAction callback to routine that loads the suggestions for autocomplete
    	 * @param onEnterAction callback when enter is pressed on the textbox
    	 */
    	public AutoSuggestionComposite(Composite parent, int style, String tooltipMsg, int numOfDisplayedSuggestions, 
    			ICallback<String, List<String>> loadSuggestionAction, ICallback<String, String> onEnterAction) {
    		super(parent, style);
    
    		textboxLayout = new StackLayout();
    		this.loadSuggestionAction = loadSuggestionAction;
    		this.onEnterAction = onEnterAction;
    		this.numOfDisplayedSuggestions = numOfDisplayedSuggestions;
    		this.tooltipMsg = tooltipMsg;
    		
    		uniqueID = rdn.nextInt() + tooltipMsg;
    		
    		createDialogArea();
    	}
    	
    	private void createDialogArea() {
    		this.setBackground(SWTUIUtilities.WHITE);
    		GridLayout gridLayout = new GridLayout();
    		gridLayout.marginHeight = 0;
    		gridLayout.marginWidth = 0;
    		this.setLayout(gridLayout);
    
    		//Panel with textbox and tooltip:
    		textBoxStackPanel = new Composite(this, SWT.NONE);
    		textBoxStackPanel.setLayout(textboxLayout);
    		GridData gdPanel = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    		gdPanel.verticalIndent = 2;
    		textBoxStackPanel.setLayoutData(gdPanel);
    		
    		tooltip = new Label(textBoxStackPanel, SWT.NONE);
    		tooltip.setBackground(SWTUIUtilities.WHITE);
    		tooltip.setForeground(SWTUIUtilities.LIGHT_GREY);
    		tooltip.setFont(SWTUIUtilities.LBL_TEXT);
    		tooltip.setText(" " + tooltipMsg); //manual horizontal indent, cause StackLayout doesn't allow this feature
    		tooltip.addMouseListener(new MouseAdapter() {
    			@Override
    			public void mouseDown(MouseEvent e) {
    				setControlVisib(textBox, true);
    				textBoxStackPanel.layout();
    				textBox.setFocus();
    				loadSuggestions(null);
    			}
    		});
    		
    		textBox = new Text(textBoxStackPanel, SWT.NONE);
    		textBox.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    		textBox.setFont(SWTUIUtilities.LBL_TEXT);
    		textBox.setBackground(SWTUIUtilities.WHITE);
    		textBox.setData(POPUPVISIB, uniqueID);
    		
    		//popup for suggestions:
    		popupShell = new Shell(getShell().getDisplay(), SWT.ON_TOP);
    		popupShell.setLayout(new FillLayout());
    		popupShell.setData(POPUPVISIB, uniqueID);
    		popupShell.setBackground(SWTUIUtilities.WHITE);
    		table = new Table(popupShell, SWT.SINGLE);
        	table.getVerticalBar().setVisible(false);
    		table.setFont(SWTUIUtilities.LBL_TEXT);
    		table.setData(POPUPVISIB, uniqueID);
    		for (int i = 0; i < numOfDisplayedSuggestions; i++) {
    			new TableItem(table, SWT.NONE);
    		}
    		
    		//Key Listener for Keyboards events:
    		textBox.addKeyListener(new KeyAdapter() {
    			@Override
    			public void keyReleased(KeyEvent e) {
    				boolean loadSuggestions = true;
    				saveInput();
    				switch (e.keyCode) {
    					case SWT.ARROW_DOWN:
    						int index = (table.getSelectionIndex() + 1) % table.getItemCount();
    						table.setSelection(index);
    						e.doit = false;
    						break;
    					case SWT.ARROW_UP:
    						index = table.getSelectionIndex() - 1;
    						if (index < 0) 
    							index = table.getItemCount() - 1;
    						table.setSelection(index);
    						e.doit = false;
    						break;
    					case SWT.CR:
    					case SWT.LF:
    					case 16777296: //enter in numeric keypad
    						if (popupShell.isVisible() && table.getSelectionIndex() != -1) {
    							textBox.setText(table.getSelection()[0].getText());
    						}
    						
    						loadSuggestions = false;
    						execEnterAction();
    
    						break;
    					case SWT.ESC:
    						popupShell.setVisible(false);
    						break;
    				}
    
    				//only for printable characters, load search history:
    				if (loadSuggestions && (e.keyCode < 256))
    					loadSuggestions(textBox.getText());
    				
    				log.debug("End of key listener");
    			}
    		});
    		
    		//make sure the input entered in the text box is saved and ready to use:
    		textBox.addFocusListener(new FocusAdapter() {
    			@Override
    			public void focusLost(FocusEvent e) {
    				log.debug("Focus lost by textbox of autosugg from " + tooltipMsg);
    				saveInput();
    				checkTooltipVisib();
    				handleFocusLost();
    			}
    			
    			@Override
    			public void focusGained(FocusEvent e) {
    				if (isDisposed() || getShell().isDisposed() || getShell().getDisplay().isDisposed()) 
    					return;
    				log.debug("Focus gained by textbox of autosugg from " + tooltipMsg);
    				loadSuggestions(textBox.getText());
    			}
    		});
    		textBox.addSelectionListener(new SelectionAdapter() {
    			@Override
    			public void widgetSelected(SelectionEvent e) {
    				checkTooltipVisib();
    			}
    		});
    		
    		table.addListener(SWT.DefaultSelection, new Listener() {
    			public void handleEvent(Event event) {
    				textBox.setText(table.getSelection()[0].getText());
    				execEnterAction();
    			}
    		});
    		
    		//hide the popup of suggestions if the focus is out:
    		Listener focusOutListener = new Listener() {
    			public void handleEvent(Event event) {
    				handleFocusLost();
    			}
    		};
    		table.addListener(SWT.FocusOut, focusOutListener);
    		textBox.addListener(SWT.FocusOut, focusOutListener);
    		textBoxStackPanel.addListener(SWT.FocusOut, focusOutListener);
    		popupShell.addListener(SWT.FocusOut, focusOutListener);
    		this.addListener(SWT.FocusOut, focusOutListener);
    
    		getShell().addListener(SWT.Move, new Listener() {
    			public void handleEvent(Event event) {
    				popupShell.setVisible(false);
    				checkTooltipVisib();
    			}
    		});
    		
    		checkTooltipVisib();
    	}
    	
    	private void handleFocusLost() {
    		/* async is needed to wait until focus reaches its new Control */
    		if (isDisposed() || getShell().isDisposed() || getShell().getDisplay().isDisposed()) 
    			return;
    		getShell().getDisplay().asyncExec(new Runnable() {
    			public void run() {
    				log.debug("Running handleFocusLost for " + tooltipMsg);
    				if (isDisposed() || getShell().isDisposed() || getShell().getDisplay().isDisposed()) 
    					return;
    				Control control = getShell().getDisplay().getFocusControl();
    				log.debug("handleFocusLost for " + tooltipMsg + ": control is " + control + ";uniqueID:" + uniqueID);
    				if ((control == null) || (control.getData(POPUPVISIB) == null) || 
    					!control.getData(POPUPVISIB).toString().equals(uniqueID)) {
    					popupShell.setVisible(false);
    				}					
    			}
    		});
    	}
    	
    	/**
    	 * Determines the visibility of textbox content vs tooltip when the textbox is empty
    	 */
    	public void checkTooltipVisib() {
    		if (Utils.isNullOrEmpty(textBox.getText())) 
    			setControlVisib(tooltip, true);
    		else
    			setControlVisib(textBox, true);
    		textBoxStackPanel.layout();
    	}
    	
    	private void execEnterAction() {
    		saveInput();
    		popupShell.setVisible(false);
    		onEnterAction.exec(text);
    	}
    	
        private void loadSuggestions(String prefix) {
        	log.debug("loading suggestions for " + prefix);
    
    //		if (Utils.isNullOrEmpty(prefix))
    //			return;
        	
        	Rectangle textBounds = getShell().getDisplay().map(textBoxStackPanel, null, textBox.getBounds());
        	
    		//load suggestions:
        	List<String> suggestions = loadSuggestionAction.exec(prefix);
        	log.debug("loaded " + suggestions.size() + " suggestions");
        	
        	table.setItemCount(suggestions.size());
    		TableItem[] items = table.getItems();
    		int maxWidthOfItem = 0;
    		log.debug("Changing " + items.length + " items in TablePopup");
    		for (int i = 0; i < items.length; i++) {
    			if (i < suggestions.size()) {
    				String sugg = suggestions.get(i);
    				if (!Utils.isNullOrEmpty(sugg)) {
    					items[i].setText(sugg);
    					int w = items[i].getBounds().width;
    					if (w > maxWidthOfItem)
    						maxWidthOfItem = w;
    				}
    			}
    		}
    //		//avoid the display of horizontal scrollbar when not needed (10 is the width of the scrollbar)
    //		if ((maxWidthOfItem + 10) < textBounds.width)
    //			table.pack();
    		
    		//23 pixels is the height of 1 item in the drop down list; 
    		//always add a blank line at the end of the list to improve readability
    		int popupHeight = (suggestions.size() + 1) * 23; 
    		log.debug("popupHeight for [" + this.tooltipMsg + "]:" + popupHeight);
    		if (popupHeight <= 46)
    			popupHeight = 46; 
    	
    		//set a cap to the maximum height of the popup (17 lines):
    		if (popupHeight > 391) {
    			popupHeight = 391;
    			table.getVerticalBar().setVisible(true);
    		} else {
    			//avoid the display of horizontal scrollbar when not needed (10 is the width of the scrollbar)
    			if ((maxWidthOfItem + 10) < textBounds.width)
    				table.pack();
    			table.getVerticalBar().setVisible(false);
    		}
    		
    		log.debug("setBounds popup:" + textBounds.x + ";" + (textBounds.y + textBounds.height + 4) + ";" + 
    					textBounds.width + ";" + popupHeight);
    		popupShell.setBounds(textBounds.x, textBounds.y + textBounds.height + 4, textBounds.width, popupHeight);
    		popupShell.setVisible(true);		
        }
        
    	private void setControlVisib(Control c, boolean visible) {
    		if (c == null)
    			return;
    		
    		if (visible) 
    			textboxLayout.topControl = c;
    	}
    	
    	private void saveInput() {
    		text = textBox.getText();
    		if (text == null)
    			text = "";
    		text = text.trim();
    	}
    	
    	/**
    	 * Returns the content of the textbox
    	 */
    	public String getText() {
    		return text;
    	}
    	
    	/**
    	 * Sets the content of the textbox
    	 */
    	public void setText(String text) {
    		this.text = text;
    		textBox.setText(text);
    		setControlVisib(textBox, true);
    	}
    	
    	/**
    	 * Hides the popup of suggestions
    	 */
    	public void hideSuggestions() {
    		popupShell.setVisible(false);
    	}
    	
    	@Override
    	public void dispose() {
    		if (popupShell != null) {
    			hideSuggestions();
    			popupShell.dispose();
    		}
    
    		super.dispose();
    	}
    }

    public by davis modified Jun 1, 2016  1087  1  3  0

    Atom autocomplete suggestions on tab

    Atom autocomplete suggestions on tab: tab-completion.coffee
    {Point} = require 'atom'
    
    atom.commands.add 'atom-text-editor', 'custom:tabcomplete', (e) ->
      editor = atom.workspace.getActiveTextEditor()
      cursor = editor.getLastCursor()
    
      {row, column} = cursor.getBufferPosition()
      precedingCharacter = editor.getTextInBufferRange([[row, column - 1], [row, column]])
    
      if /\S/.test(precedingCharacter)
        autocomplete = atom.packages.getActivePackage('autocomplete-plus')
        return unless autocomplete?
    
        manager = autocomplete.mainModule.activate()
        manager.shouldDisplaySuggestions = true
        manager.findSuggestions(true)
      else
        e.abortKeyBinding()
    
    
    

    public by Piers Mainwaring modified May 8, 2015  918  0  3  0

    Atom autocomplete suggestions on tab

    Atom autocomplete suggestions on tab: tab-completion.coffee
    {Point} = require 'atom'
    
    atom.commands.add 'atom-text-editor', 'custom:tabcomplete', (e) ->
      editor = atom.workspace.getActiveTextEditor()
      cursor = editor.getLastCursor()
    
      {row, column} = cursor.getBufferPosition()
      precedingCharacter = editor.getTextInBufferRange([[row, column - 1], [row, column]])
    
      if /\S/.test(precedingCharacter)
        autocomplete = atom.packages.getActivePackage('autocomplete-plus')
        return unless autocomplete?
    
        manager = autocomplete.mainModule.activate()
        manager.shouldDisplaySuggestions = true
        manager.findSuggestions(true)
      else
        e.abortKeyBinding()
    
    
    

    public by msdn modified Jan 12, 2015  1155  0  6  0

    CancelChanges: Method called to "invoke" the Screen's Interface method (CancelChanges) to explicitly cancel the changes

    Method called to "invoke" the Screen's Interface method (CancelChanges) to explicitly cancel the changes The IScreenObject representing the screen Screen here cannot be converter to a concrete IScreenWithListAndCurrentObject. For this reason Reflection is used. This is a "weakness" of the implementation. Any suggestions would be greatly ap
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Base.SL.Contracts;
    using Microsoft.LightSwitch.Framework.Base;
    using Microsoft.LightSwitch.Details.Framework.Base;
    using Microsoft.LightSwitch.Presentation.Extensions;
    using Microsoft.LightSwitch.Client;
    using Microsoft.LightSwitch.Presentation;
    using Microsoft.LightSwitch.Presentation.Implementation;
    using System.Reflection;
    using Microsoft.LightSwitch.Runtime.Shell.Framework;
    
    /// <summary>
    /// Method called to "invoke" the Screen's Interface method (CancelChanges) to explicitly cancel the changes
    /// </summary>
    /// <param name="screen">The IScreenObject representing the screen</param>
    /// <remarks>Screen here cannot be converter to a concrete  IScreenWithListAndCurrentObject<TEntity, TDetails>.
    /// For this reason Reflection is used.
    /// This is a "weakness" of the implementation. Any suggestions would be greatly appreciated.</remarks>
    private static void CancelChanges(IScreenObject screen)
    {
        MethodInfo mi = screen.GetType().GetMethod("CancelChanges");
        if (mi == null)
            return;
        mi.Invoke(screen, null);
    }

    external by aswearin modified Sep 24, 2015  320  0  3  0

    Coursera Week 6 mini-project - in progress - suggestions welcome

    Coursera Week 6 mini-project - in progress - suggestions welcome: Coursera_BlackJack_InProgress.txt
    # Mini-project #6 - Blackjack
    
    import simplegui
    import random
    
    # load card sprite - 936x384 - source: jfitz.com
    CARD_SIZE = (72, 96)
    CARD_CENTER = (36, 48)
    card_images = simplegui.load_image("http://storage.googleapis.com/codeskulptor-assets/cards_jfitz.png")
    
    CARD_BACK_SIZE = (72, 96)
    CARD_BACK_CENTER = (36, 48)
    card_back = simplegui.load_image("http://storage.googleapis.com/codeskulptor-assets/card_jfitz_back.png")    
    
    # initialize some useful global variables
    in_play = False
    outcome = ""
    score = 0
    
    # define globals for cards
    SUITS = ('C', 'S', 'H', 'D')
    RANKS = ('A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K')
    VALUES = {'A':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':10, 'Q':10, 'K':10}
    
    
    # define card class
    class Card:
        def __init__(self, suit, rank):
            if (suit in SUITS) and (rank in RANKS):
                self.suit = suit
                self.rank = rank
            else:
                self.suit = None
                self.rank = None
                print "Invalid card: ", suit, rank
    
        def __str__(self):
            return self.suit + self.rank
    
        def get_suit(self):
            return self.suit
    
        def get_rank(self):
            return self.rank
    
        def draw(self, canvas, pos):
            card_loc = (CARD_CENTER[0] + CARD_SIZE[0] * RANKS.index(self.rank), 
                        CARD_CENTER[1] + CARD_SIZE[1] * SUITS.index(self.suit))
            canvas.draw_image(card_images, card_loc, CARD_SIZE, [pos[0] + CARD_CENTER[0], pos[1] + CARD_CENTER[1]], CARD_SIZE)
            
    # define hand class
    class Hand:
        def __init__(self):
            self.cards = []
            
        def __str__(self):
            text = "Hand contains"
            for i in range(len(self.cards)):
                text += ' ' + str(self.cards[i])
            return text
    
        def add_card(self, card):
            self.cards.append(card)
    
    #HELP! I am not setting up the logic correctly here.        
        def get_value(self):
            # count aces as 1, if the hand has an ace, then add 10 to hand value if it doesn't bust
            # compute the value of the hand, see Blackjack video
            def get_value(self):
                hand_value = 0
            self.hand = ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']
            for card in self.hand:
                hand_value += VALUES[card.rank()]
                if card.rank('A') == 0:
                    return hand_value
                if card.rank('A') >= 1:
                    return hand_value + 10
    
       
        def draw(self, canvas, pos):
            pass	# draw a hand on the canvas, use the draw method for cards
    
    # define deck class 
    class Deck:
        def __init__(self):
            self.deck = []
            for i in range(len(SUITS)):
                for j in range(len(RANKS)):
                    self.deck.append(Card(SUITS[i],RANKS[j]))
                    
        def shuffle(self):
            random.shuffle(self.deck)
    
        def deal_card(self):
             return self.deck.pop(0)
        
        def __str__(self):
            text = "Deck contains"
            for i in range(len(self.deck)):
                text += ' ' + str(self.deck[i])
            return text
    
    #define event handlers for buttons
    def deal():
        global deck, outcome, in_play, score, hand_player, hand_dealer
        in_play = True
        hand_player = Hand()
        hand_dealer = Hand()
        deck = Deck()
        deck.shuffle()
        
        hand_player.add_card(deck.deal_card())
        hand_player.add_card(deck.deal_card())
        hand_dealer.add_card(deck.deal_card())
        hand_dealer.add_card(deck.deal_card())
        
        print hand_player
        print hand_dealer
    
    #End progress so far
    
    def hit():
        pass	# replace with your code below
     
        # if the hand is in play, hit the player
       
        # if busted, assign a message to outcome, update in_play and score
           
    def stand():
        pass	# replace with your code below
       
        # if hand is in play, repeatedly hit dealer until his hand has value 17 or more
    
        # assign a message to outcome, update in_play and score
    
    # draw handler    
    def draw(canvas):
        # test to make sure that card.draw works, replace with your code below
        
        card = Card("S", "A")
        card.draw(canvas, [300, 300])
    
    
    # initialization frame
    frame = simplegui.create_frame("Blackjack", 600, 600)
    frame.set_canvas_background("Green")
    
    #create buttons and canvas callback
    frame.add_button("Deal", deal, 200)
    frame.add_button("Hit",  hit, 200)
    frame.add_button("Stand", stand, 200)
    frame.set_draw_handler(draw)
    
    
    # get things rolling
    deal()
    frame.start()
    
    
    # remember to review the gradic rubric
    
    

    external by bdiegel modified Jan 14, 2015  228  2  3  0

    Android combined recent and custom search suggestions

    Android combined recent and custom search suggestions: android_combined_search_suggestions.java
    /**
     * It's possible to combine recent and custom search suggestions. One way is to
     * write a custom provider that extends SearchRecentSuggestionsProvider. If the
     * custom provider has the same columns as SearchRecentSuggestionsProvider
     * then the cursors can be easily 'merged'.
     *
     * In the .query() method of custom search provider, return the combined results:
     */
    Cursor recentCursor = super.query(uri, projection, sel, selArgs, sortOrder);
    Cursor[] cursors = new Cursor[] { recentCursor, customCursor};
    return new MergeCursor(cursors);
    
    // details: http://stackoverflow.com/questions/11329535/recent-searches-are-not-displayed-custom-suggestions-are
    
    

    external by Narrat modified Jun 6, 2014  229  0  3  0

    Wesnoth-devel PKGBuild suggestions

    Wesnoth-devel PKGBuild suggestions: wesnoth-devel PKGBUILD
    # Maintainer: Andrea Tarocchi <valdar@email.it>
    
    pkgname=wesnoth-devel
    pkgver=1.11.15
    pkgrel=1
    pkgdesc="development version of a turn-based strategy game on a fantasy world"
    arch=('i686' 'x86_64')
    url="http://www.wesnoth.org/"
    license=('GPL')
    depends=('pango>=1.14.8' 'sdl_ttf>=2.0.8' 'sdl_net>=1.2.7' 'sdl_mixer>=1.2.7' 'sdl_image>=1.2.7' 'fribidi>=0.10.9' 'dbus-core' 'python2' 'fontconfig>=2.4.1' 'boost-libs' 'lua')
    makedepends=('boost>=1.36.0' 'scons>=0.98.3')
    install=${pkgname}.install
    source=("http://downloads.sourceforge.net/sourceforge/wesnoth/wesnoth-$pkgver.tar.bz2"
      "${pkgname}.desktop"
      "wesnoth_editor-devel.desktop"
      "wesnoth-devel-icon.xpm"
      "wesnoth-devel_editor-icon.xpm") 
    md5sums=('d21a63ca364b3579f1b487b8d0a1b817'
      'a906eae5d541a51de77038469b1f794b'
      'b9de9e7ee16f757aa406466657c274a9'
      'b73f4fdefd3e7daa158cce278f11be64'
      '931e7443fe37b2862ca59f65ded74a0b')
    
    
    prepare() {
      cd "${srcdir}/wesnoth-$pkgver"
    
      #Patching due to boost rebase (x86_64 architectur) 
      #[http://gna.org/bugs/?18399 https://bugzilla.redhat.com/show_bug.cgi?id=724818 https://svn.boost.org/trac/boost/ticket/5279]
      #patch -p1 < ../../boost_rebase.diff
    }
    
    build() { 
      cd "${srcdir}/wesnoth-$pkgver"
     
      scons prefix=/usr program_suffix=-devel datadirname=wesnoth-devel prefsdir=.wesnoth-devel fifodir=/var/run/wesnothd-devel \
      localedir=/usr/share/locale docdir=/usr/share/doc/wesnoth-devel mandir=/usr/share/man/wesnoth-devel python_site_packages_dir=usr/lib/python2.7/site-packages/wesnoth all
    }
    
    package(){
     cd "${srcdir}/wesnoth-$pkgver"
     scons destdir=${pkgdir} install
     
     #INSTALLING of menu entry and icons:
     install -D -m644 ../../wesnoth-devel.desktop ${pkgdir}/usr/share/applications/wesnoth-devel.desktop
     install -D -m644 ../../wesnoth-devel-icon.xpm ${pkgdir}/usr/share/pixmaps/wesnoth-devel-icon.xpm
     install -D -m644 ../../wesnoth-devel-icon.xpm ${pkgdir}/usr/share/icons/wesnoth-devel-icon.xpm
     
     install -D -m644 ../../wesnoth_editor-devel.desktop ${pkgdir}/usr/share/applications/wesnoth_editor-devel.desktop
     install -D -m644 ../../wesnoth-devel_editor-icon.xpm ${pkgdir}/usr/share/pixmaps/wesnoth-devel_editor-icon.xpm
     install -D -m644 ../../wesnoth-devel_editor-icon.xpm ${pkgdir}/usr/share/icons/wesnoth-devel_editor-icon.xpm
     
     chmod +x ${pkgdir}/var/run/wesnothd-devel
     chmod o+r ${pkgdir}/var/run/wesnothd-devel
     
     rm -f ${pkgdir}/usr/share/applications/wesnoth.desktop
     rm -f ${pkgdir}/usr/share/applications/wesnoth_editor.desktop
     rm -f ${pkgdir}/usr/share/icons/wesnoth-icon.png
     rm -f ${pkgdir}/usr/share/icons/wesnoth_editor-icon.png
    }
    
    

    external by Max Vorobev modified Jul 10, 2016  82  0  1  0

    AutoCompleteTextView that delays sending requests to adapter (needed if suggestions are being queried from external API). Also shows progress bar when loading suggestions.

    AutoCompleteTextView that delays sending requests to adapter (needed if suggestions are being queried from external API). Also shows progress bar when loading suggestions.: DelayAutoCompleteTextView.java
    import android.content.Context;
    import android.os.Handler;
    import android.os.Message;
    import android.util.AttributeSet;
    import android.view.View;
    import android.widget.AutoCompleteTextView;
    import android.widget.ProgressBar;
    
    
    public class DelayAutoCompleteTextView extends AutoCompleteTextView {
    
        private static final int MESSAGE_TEXT_CHANGED = 100;
        private static final int DEFAULT_AUTOCOMPLETE_DELAY = 750;
    
        private int mAutoCompleteDelay = DEFAULT_AUTOCOMPLETE_DELAY;
        private ProgressBar mLoadingIndicator;
    
        private final Handler mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                DelayAutoCompleteTextView.super.performFiltering((CharSequence) msg.obj, msg.arg1);
            }
        };
    
        public DelayAutoCompleteTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public void setLoadingIndicator(ProgressBar progressBar) {
            mLoadingIndicator = progressBar;
        }
    
        public void setAutoCompleteDelay(int autoCompleteDelay) {
            mAutoCompleteDelay = autoCompleteDelay;
        }
    
        @Override
        protected void performFiltering(CharSequence text, int keyCode) {
            if (mLoadingIndicator != null) {
                mLoadingIndicator.setVisibility(View.VISIBLE);
            }
            mHandler.removeMessages(MESSAGE_TEXT_CHANGED);
            mHandler.sendMessageDelayed(mHandler.obtainMessage(MESSAGE_TEXT_CHANGED, text), mAutoCompleteDelay);
        }
    
        @Override
        public void onFilterComplete(int count) {
            if (mLoadingIndicator != null) {
                mLoadingIndicator.setVisibility(View.GONE);
            }
            super.onFilterComplete(count);
        }
    }
    
    // code sample
    location.setLoadingIndicator((ProgressBar)findViewById(R.id.progress_bar_id));
    
    

    external by NotYou64 modified Dec 16, 2016  15  0  1  0

    An amazing name generator that is not a GUI because I am a noob programmer! Any suggestions? Don't email me! Just comment in the section down below that is for suggestions and stuff!

    An amazing name generator that is not a GUI because I am a noob programmer! Any suggestions? Don't email me! Just comment in the section down below that is for suggestions and stuff!: amazingNameGenerator.py
    #!/usr/bin/python2.7
    
    """Cole D... HA! YOU TRIED TO SEE WHAT MY NAME IS! I'M NOT FALLING FOR THAT!
    age 12
    amazing programmer
    such a boss
    11-17-16"""
    
    #imports
    import random
    import time
    
    #arrays
    objects = ["Diary", "Bottle", "Water", "Packet", "Chewing Gum", "Tissue", "Glasses", "Watch", "Photo", "Camera", "Stamp", "Postcard", "Dictionary", "Coin", "Brush", "Credit Card", "Key", "Phone", "Wallet", "Button", "Umbrella", "Pen", "Pencil", "Lighter", "Cigarette", "Match", "Lipstick", "Purse", "Case", "Paper Clip", "Scissors", "Rubber", "File", "Passport", "Driving Licence", "Comb", "Notebook", "Laptop", "Rubbish", "Mirror", "Painkiller", "Sunscreen", "Toothbrush", "Battery", "Light Bulb", "Alarm Clock"]
    actionVerbs = ["Built", "Bargaining", "Adjusting", "Anticipating", "Aiding", "Boosted", "Confirmed", "Connected", "Capturing", "Caring", "Deducting", "Conserving", "Detailed", "Comfortable", "Debugging", "Defending", "Dispatched", "Educated", "Established", "Enlarged", "Focused", "Enforced", "Fixed", "Generated", "Furnished", "Funded", "Innovative", "Invented", "Identified", "Increased", "Labled", "Logged", "Influenced", "Insecure", "Maintained", "Mastered", "Merged", "Motivated", "Measured", "Observed", "Overseen", "Raised"]
    allDefiningStuff = ["Stupid", "Human", "Small", "Able", "Big", "High", "Little", "Last", "Bad", "Adorable", "Beautiful", "Clean", "Elegant", "Fancy", "Glamorous", "Handsome", "Long", "Magnificent", "Old-fashioned", "Plain", "Pathetic", "Sparkling", "Ugliest", "Unsightly", "Wide-eyed", "Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Gray", "Black", "White",  "Better", "Dead", "Famous", "Gifted", "Helpful", "Important", "Mushy", "Odd", "Powerful", "Rich", "Shy", "Tender", "Uninterested", "Vast", "Wrong", "Old", "Built", "Bargaining", "Adjusting", "Anticipating", "Aiding", "Boosted", "Confirmed", "Connected", "Capturing", "Caring", "Deducting", "Conserving", "Detailed", "Comfortable", "Debugging", "Defending", "Dispatched", "Educated", "Established", "Enlarged", "Focused", "Enforced", "Fixed", "Generated", "Furnished", "Funded", "Innovative", "Invented", "Identified", "Increased", "Labled", "Logged", "Influenced", "Insecure", "Maintained", "Mastered", "Merged", "Motivated", "Measured", "Observed", "Overseen", "Raised"]
    animals = ["Penguin", "Hound", "Elephant", "Frog", "Baboon", "Dog", "Toad", "Bear", "Owl", "Shark", "Bat", "Tiger", "Beetle", "Beagle", "Chicken", "Alligator", "Tortoise", "Bulldog", "Lizard", "Salamander", "Cat", "Unicorn", "Centipede", "Chimpanzee", "Cheetah", "Deer", "Dodo Bird", "Duck", "Otter", "Mole", "Mongoose", "Monkey"]
    
    #nickname types
    class nicknameTypes(object):
        def adjective(self, a, b, c):
            print"what is your name?"
            adNum = random.randrange(0,92)
            myName = raw_input()
    
            if myName == 'cole' or myName == "Cole":
                print"Your nickname is Cole the Super Amazing, smart, Cool guy that is better than everybody else"
                time.sleep(1)
                playAgain(a, b, c)
    
            #a = allDefiningStuff
            nickname = (myName.title()  + " the " + a[adNum])
            print("Your nickname is " + nickname)
    
        def adjectiveAnimal(self, a, b, c):
            adNum = random.randrange(0,92)
            anNum = random.randrange(0,32)
            print"what is your name?"
            myName = raw_input()
    
            if myName == 'cole' or myName == "Cole":
                print"Your nickname is Cole the Amazing Unicorn"
                time.sleep(1)
                playAgain(a, b, c)
    
            #a = allDefiningStuff     b = animals
            nickname = (myName.title() + " the " + a[adNum] + " " + b[anNum])
            print("Your nickname is " + nickname)
    
        def adjectiveObject(self, a, b, c):
            print"what is your name?"
            myName = raw_input()
    
            if myName == 'cole' or myName == "Cole":
                print"Your nickname is Cole the Amazing Enigma Machine"
                time.sleep(1)
                playAgain(a, b, c)
    
            adNum = random.randrange(0,92)
            adObj = random.randrange(0,42)
            #a = allDefiningStuff     b = objects
            nickname = (myName.title() + " the " + a[adNum] + " " + b[adObj])
            print("Your nickname is " + nickname)
    
        def nameAnimal(self, a, b, c):
            print"what is your name?"
            myName = raw_input()
    
            if myName == 'Cole' or myName == "cole":
                print"Your nickname is Cole the Unicorn"
                time.sleep(1)
                playAgain(a, b, c)
    
            anNum = random.randrange(0,32)
            #a = animals
            nickname = (myName.title() + " the " + a[anNum])
            print("your nickname is " + nickname)
    
    #        def nameObjects(self, a)
    
    #play again function
    def playAgain(a, b, c):
        print"Would you like another nickname?"
        playagain = raw_input()
    
        if playagain == 'yes' or playagain == 'Yes':
            print"Thought so"
            time.sleep(1)
            main(a, b, c)
    
        if playagain == "no" or playagain == 'No':
            print"well skrew you too"
            for i in range(1,1000000):
                print 1000000 - i
                time.sleep(1)
    
    #function
    def main(a, b, c):
        global n
        n = nicknameTypes()
        print"                                         "
        print"What kind of nickname would you like?(1-4)"
        print"nickname types:"
        print"  1:  adjective"
        print"  formatting: yourName the randomAdjective"
        print' '
        print"  2:  adjective animal"
        print"  formatting: yourName the randomAdjective randomAnimal"
        print' '
        print"  3:  adjective object"
        print"  formatting: yourName the randomAdjective randomObject"
        print' '
        print"  4:  animal"
        print"  formatting: yourName the randomAnimal"
        print' '
        ask(a, b, c)
    
    #fuction that asks the type of nickname
    def ask(a, b, c):
        type = int(input())
    
        n = nicknameTypes()
    
        things = False
    
        if type == 1:
            things = True
            n.adjective(a, b, c)
    
        if type == 2:
            things = True
            n.adjectiveAnimal(a, b, c)
    
        if type == 3:
            things = True
            n.adjectiveObject(a, b, c)
    
        if type == 4:
            things = True
            n.nameAnimal(a, b, c)
    
        elif things == False:
            print"What was that?"
            ask(allDefiningStuff, animals, objects)
    
        time.sleep(1)
        playAgain(a, b, c)
    
    #start of actually doing things
    print("Hola! I'm a stalker so I know that the date is " + time.strftime("%m/%d/%Y"))
    print"Do you wanna know how I know that?"
    wannaKnow = raw_input()
    
    if wannaKnow == 'yes' or wannaKnow == "Yes":
        print"Because I'm a god"
        time.sleep(1)
    
    if wannaKnow == 'no' or wannaKnow == 'No':
        print'well skrew you too'
        time.sleep(1)
    
    main(allDefiningStuff, animals, objects)
    
    

    external by Sachbearbeiter modified Feb 2, 2015  148  0  2  0

    D8: Theming examples: Theme: New more specific suggestions for the image.html.twig template ... *http://drupal.stackexchange.com/questions/137652/override-image-formatter-html-twig/141340#141340 **Drupal 8 is still Beta - improvements through API modif...

    D8: Theming examples: Theme: New more specific suggestions for the image.html.twig template ... *http://drupal.stackexchange.com/questions/137652/override-image-formatter-html-twig/141340#141340 **Drupal 8 is still Beta - improvements through API modifications are possible!: theme.php
    /**
     * Implements hook_theme_suggestions_HOOK_alter().
     */
    function MYTHEME_theme_suggestions_image_formatter_alter(array &$suggestions, array $variables) {
      $entity = $variables['item']->getEntity();
      $field_name = $variables['item']->getParent()->getName();
      $suggestions[] = 'image_formatter__' . $entity->getEntityTypeId() . '__' . $entity->bundle() . '__' . $field_name;
    }
    
    
    • Public Snippets
    • Channels Snippets