working on it ...


Explore Public Snippets

Sort by

Found 5,768 snippets matching: button

    public by WadeCantley  4690241  56  7  0

    iOS - Swift - Add a Done button to a Keyboard Tool Bar

    Adding a done button to the keyboard tool bar and working within the textField delegate to make that happen. In this situation the keyboard is a number pad which doesn't have its own done button.
    //MARK: - Helper Methods
    // This is called to remove the first responder for the text field.
    func resign() {
    // This triggers the textFieldDidEndEditing method that has the textField within it.  
    //  This then triggers the resign() method to remove the keyboard.
    //  We use this in the "done" button action.
    func endEditingNow(){
    //MARK: - Delegate Methods
    // When clicking on the field, use this method.
    func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
        // Create a button bar for the number pad
        let keyboardDoneButtonView = UIToolbar()
        // Setup the buttons to be put in the system.
        let item = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Bordered, target: self, action: Selector("endEditingNow") )
        var toolbarButtons = [item]
        //Put the buttons into the ToolBar and display the tool bar
        keyboardDoneButtonView.setItems(toolbarButtons, animated: false)
        textField.inputAccessoryView = keyboardDoneButtonView
        return true
    // What to do when a user finishes editting
    func textFieldDidEndEditing(textField: UITextField) {
        //nothing fancy here, just trigger the resign() method to close the keyboard.
    // Clicking away from the keyboard will remove the keyboard.
    override func touchesBegan(touches: (NSSet!), withEvent event: (UIEvent!)) {
    // called when 'return' key pressed. return NO to ignore.
    // Requires having the text fields using the view controller as the delegate.
    func textFieldShouldReturn(textField: UITextField!) -> Bool {
        // Sends the keyboard away when pressing the "done" button
        return true

    public by lbottaro  5987  44  7  0

    How to dynamically add a button to a GUI mask in python using PyQt4

    This code shows how to add some dynamic GUI controls (in this case QPushButton) to a GUI main window. In this example when user clicks on a button, the new buttons are created and put into the main window.
    import sys
    from PyQt4 import QtGui
    import os
    class Test(QtGui.QMainWindow):  
        def __init__(self):
            super(Test, self).__init__()
        def initUI(self):
            YDrive = QtGui.QAction("Y", self)
            self.toolbar = self.addToolBar('Exit')
            self.setGeometry(300, 300, 250, 150)
            self.setWindowTitle('Message box')    
        def buttonClicked(self):
            print "clicked"
        def setYDir(self):
            myWorkDrive = "/tmp"
            shows = os.listdir(myWorkDrive)
            i = 0
            for elements in shows:
                btn1 = QtGui.QPushButton(elements, self)
                btn1.move(30, 50 + i)
                i += 30
            self.resize(self.width(), 50 + i)
    if __name__ == '__main__':
        app = QtGui.QApplication([])
        t = Test()

    public by lbottaro  6576  6  8  0

    How to create a simple button in python using GUI PyQt4

    Using PyQt4 python module, you can easily add a QtGui.QPushButton as interactive button in your mask. Constructor QPushButton(string text, QWidget parent = None). The 'text' parameter is the text displayed on the button. The 'parent' is a widget, onto which we place the button. Thanks to
    import sys
    from PyQt4 import QtGui, QtCore
    class GUI_Example(QtGui.QWidget):
        def __init__(self):
            super(GUI_Example, self).__init__()
        def initUI(self):               
            qbtn = QtGui.QPushButton('Quit', self)
            qbtn.move(55, 55)       
            self.setGeometry(300, 300, 250, 150)
            self.setWindowTitle('Quit button')    
    def main():
        app = QtGui.QApplication(sys.argv)
        ex = GUI_Example()
    if __name__ == '__main__':

    public by JKCPR  3042  5  5  1

    SCSS button power @mixin

    one $color variable generates all buttons by @mixin and color @functions also leverages %placeholders and %placeholder-selectors
    //core values
    $primary: #0085B7;
    $success: adjust_hue($primary, 260);
    $warning: saturate(adjust_hue($primary, 188), 43);
    $alert: lighten(saturate(adjust_hue($primary, 162), 12), 1);
    // function
    @function em($target, $context:$font-size){
      @return ($target/$context) * 1em;
    //!default values
    $button-colour: $primary !default;
    $button-text-color: white !default;
    $button-line-height: 32 !default;
    $button-border-radius: 3 !default;
    $button-padding: 30 !default;
    $button-font-size: 24 !default;
    $button-weight: bold !default;
    //the btn mixin
    @mixin default-button($color: $button-text-color,
      $line-height: $button-line-height,
      $radius: $button-border-radius,
      $padding: $button-padding,
      $font-size: $button-font-size,
      $weight: $button-weight){
      color: $color;
      line-height: em($line-height);
      border-radius: em($radius);
      padding: 0 em($padding);
      font-size: em($font-size);
      font-weight: $weight;
    @mixin flat-button($color: $button-color){
      $highlight-color: lighten($color, 50%);
      $shadow-color: grayscale(transparentize($color, 0.1));
      background-color: $color;
      border: 1px solid darken($color, 10%);
      text-shadow: 0px 1px 1px darken($color, 20%);
      box-shadow: 0 em(2) em(6) 0 $shadow-color;
        background-color: darken($color, 5%);
        text-shadow: 1px 1px 1px darken($highlight-color, 5%);
    //placeholder selector
      @include default-button;
      @extend %default-button;
      @include flat-button($primary);  
      @extend %default-button;
      @include flat-button($success);
      @extend %default-button;
      @include flat-button($warning);
      @extend %default-button;
      @include flat-button($alert);

    public by fabio.nosenzo  2008  2  5  1

    How to create facebook like button

    Include the JavaScript SDK on your page once, ideally right after the opening <body> tag.
    This script uses the app ID of your app:
    <div id="fb-root"></div>
    <script>(function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); = id;
      js.src = "//";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>
    Place the code for your plugin wherever you want the plugin to appear on your page.
    <div class="fb-like" data-href="" data-send="true" data-width="450" data-show-faces="true" data-font="arial"></div>	

    public by MatteoP  2972  3  6  0

    Disable "close" button on form

    Just add this code in a form class to disable the close button on the top right
    private const int CP_NOCLOSE_BUTTON = 0x200;
    protected override CreateParams CreateParams
           CreateParams myCp = base.CreateParams;
           myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON ;
           return myCp;

    public by alien  2345  0  4  0


      <Button guid="guidToolWindow1PackageCmdSet" id="ToolWindow1CommandId" priority="0x0100" type="Button">
        <Parent guid="guidSHLMainMenu" id="IDG_VS_TOOLS_OTHER2"/>
        <Icon guid="guidImages" id="bmpPic1" />
    </Buttons>// Enter here the actual content of the snippet.            

    public by gatling_laser  1978  2  6  0

    Starter Pack: Game Button

    For simple games where creating a 2D array of JButtons will get you through those pesky calculations.
    import javax.swing.*; 
    import java.awt.*; 
    import java.awt.event.*;
    import java.util.*;
    Simple extended JButton with x and y values for making a 2D game board.
    public class GameButton extends JButton {
    	private int x;
    	private int y;
    	public GameButton(int xPos, int yPos) {
    		x = xPos;
    		y = yPos;
    	//Returning the X and Y positions.
    	public int getXPos() { return x; }
    	public int getYPos() { return y; }

    public by lbottaro  22105  137  9  3

    How to programmatically create a Microsoft Word document in csharp

    This code shows how to simply create a doc using csharp and Microsoft Office Word library. 1) You need to add a reference to Microsoft.Office.Interop library in your project solution. 2) Add the following line to the end of the list of using directives: using Word = Microsoft.Office.Interop.Word; using System.Reflection; 3) Now you are
    private void button1_Click(object sender, EventArgs e)
              object oMissing = System.Reflection.Missing.Value;
               object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
               //Start Word and create a new document.
               Word._Application oWord;
               Word._Document oDoc;
               oWord = new Word.Application();
               oWord.Visible = true;
               oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
                   ref oMissing, ref oMissing);
               //Insert a paragraph at the beginning of the document.
               Word.Paragraph oPara1;
               oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
               oPara1.Range.Text = "Heading 1";
               oPara1.Range.Font.Bold = 1;
               oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
               //Insert a paragraph at the end of the document.
               Word.Paragraph oPara2;
               object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oPara2 = oDoc.Content.Paragraphs.Add(ref oRng);
               oPara2.Range.Text = "Heading 2";
               oPara2.Format.SpaceAfter = 6;
               //Insert another paragraph.
               Word.Paragraph oPara3;
               oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oPara3 = oDoc.Content.Paragraphs.Add(ref oRng);
               oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:";
               oPara3.Range.Font.Bold = 0;
               oPara3.Format.SpaceAfter = 24;
               //Insert a 3 x 5 table, fill it with data, and make the first row
               //bold and italic.
               Word.Table oTable;
               Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oTable = oDoc.Tables.Add(wrdRng, 3, 5, ref oMissing, ref oMissing);
               oTable.Range.ParagraphFormat.SpaceAfter = 6;
               int r, c;
               string strText;
               for (r = 1; r <= 3; r++)
                   for (c = 1; c <= 5; c++)
                       strText = "r" + r + "c" + c;
                       oTable.Cell(r, c).Range.Text = strText;
               oTable.Rows[1].Range.Font.Bold = 1;
               oTable.Rows[1].Range.Font.Italic = 1;
               //Add some text after the table.
               Word.Paragraph oPara4;
               oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oPara4 = oDoc.Content.Paragraphs.Add(ref oRng);
               oPara4.Range.Text = "And here's another table:";
               oPara4.Format.SpaceAfter = 24;
               //Insert a 5 x 2 table, fill it with data, and change the column widths.
               wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oTable = oDoc.Tables.Add(wrdRng, 5, 2, ref oMissing, ref oMissing);
               oTable.Range.ParagraphFormat.SpaceAfter = 6;
               for (r = 1; r <= 5; r++)
                   for (c = 1; c <= 2; c++)
                       strText = "r" + r + "c" + c;
                       oTable.Cell(r, c).Range.Text = strText;
               oTable.Columns[1].Width = oWord.InchesToPoints(2); //Change width of columns 1 & 2
               oTable.Columns[2].Width = oWord.InchesToPoints(3);
               //Keep inserting text. When you get to 7 inches from top of the
               //document, insert a hard page break.
               object oPos;
               double dPos = oWord.InchesToPoints(7);
               oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertParagraphAfter();
                   wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                   wrdRng.ParagraphFormat.SpaceAfter = 6;
                   wrdRng.InsertAfter("A line of text");
                   oPos = wrdRng.get_Information
               while (dPos >= Convert.ToDouble(oPos));
               object oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
               object oPageBreak = Word.WdBreakType.wdPageBreak;
               wrdRng.Collapse(ref oCollapseEnd);
               wrdRng.InsertBreak(ref oPageBreak);
               wrdRng.Collapse(ref oCollapseEnd);
               wrdRng.InsertAfter("We're now on page 2. Here's my chart:");
               //Insert a chart.
               Word.InlineShape oShape;
               object oClassType = "MSGraph.Chart.8";
               wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing,
                   ref oMissing, ref oMissing, ref oMissing,
                   ref oMissing, ref oMissing, ref oMissing);
               //Demonstrate use of late bound oChart and oChartApp objects to
               //manipulate the chart object with MSGraph.
               object oChart;
               object oChartApp;
               oChart = oShape.OLEFormat.Object;
               oChartApp = oChart.GetType().InvokeMember("Application",
                   BindingFlags.GetProperty, null, oChart, null);
               //Change the chart type to Line.
               object[] Parameters = new Object[1];
               Parameters[0] = 4; //xlLine = 4
               oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty,
                   null, oChart, Parameters);
               //Update the chart image and quit MSGraph.
                   BindingFlags.InvokeMethod, null, oChartApp, null);
                   BindingFlags.InvokeMethod, null, oChartApp, null);
               //... If desired, you can proceed from here using the Microsoft Graph 
               //Object model on the oChart and oChartApp objects to make additional
               //changes to the chart.
               //Set the width of the chart.
               oShape.Width = oWord.InchesToPoints(6.25f);
               oShape.Height = oWord.InchesToPoints(3.57f);
               //Add text after the chart.
               wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               wrdRng.InsertAfter("THE END.");
               //Close this form.

    public by lbottaro  13308  66  8  0

    Using lambda function to pass extra argument to slots using PyQt4 python

    When programming with PyQt is useful to pass extra arguments to slots callback methods, in order to execute some code when a UI control's action is invoked. In this example you can see the usage of lambda expression to pass the extra argument to the method invoked when pressing a button. Thanks to
    self.greeting = QLabel('', self)
    # Create the build button with its caption
    self.build_button = QPushButton('&Build Greeting', self)
    # Connect the button's clicked signal to AddControl
    self.build_button.clicked.connect(lambda: self.AddControl('fooData'))
    def AddControl(self, name):
        self.greeting.setText('%s!' % (name))
    • Public Snippets
    • Channels Snippets