samedi 27 août 2016

Checkbox's checked property binding - Polymer

I am trying to bind a Polymer property to the CheckBox's checked property. However, the property's observer never gets fired, besides, the label also never shows any text.

However, I am able to execute a function every time the CheckBox gets clicked.

This is my code:

<link rel="import" href="../../components/polymer/polymer.html">

<dom-module id="check-box-example">
  <template>
    <div>
      <label>
        <template if="">Uncheck</template>
        <template if="">Check</template>
      </label><br>
      <input type="checkbox" checked="" on-click="_checkBoxClicked">Check Box
    </div>
  </template>
  <script>
    Polymer({
      is: 'check-box-example',
      checked: {
        type: Boolean,
        observer: '_checkedChanged'
      },
      _checkBoxClicked: function() {
        console.log("The Check Box was clicked.");
      },
      _checkedChanged: function(newValue, oldValue) {
        console.log("New Checkbox value: " + newValue);
      },
    });
  </script>
</dom-module>

What am I doing wrong? Thanks in advance.




Check Checkbox from other Checkbox Listener in list view

I am trying to check one check box from another checkbox listener in a list view. Here is my Code for the Listview Adapter. The Checkbox listener should be able to check a checkbox in any given position in the listview.

 @Override
public View getView(final int position, View convertView, ViewGroup parent) {
    DataSetTasks tasks = getItem(position);
    final int FinalPos = position + 1;
    final int LastPostition = getCount() -1;
    final int FixedLastPosition = LastPostition +1;

    connectionClass = new ConnectionClass();

    final ViewHolder viewHolder;
    if (convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(getContext());
        convertView = inflater.inflate(R.layout.list_layout_orderprogress, parent, false);
        viewHolder = new ViewHolder();

        viewHolder.TaskName = (TextView) convertView.findViewById(R.id.txtTaskName);
        viewHolder.TaskStart = (CheckBox) convertView.findViewById(R.id.cbxStartTask);
        viewHolder.TaskEnd = (CheckBox) convertView.findViewById(R.id.cbxEndTask);

        viewHolder.TaskStart.setTag(position);
        viewHolder.TaskEnd.setTag(position);
        convertView.setTag(viewHolder);
    }else {
        viewHolder = (ViewHolder) convertView.getTag();
    }

    viewHolder.TaskStart.setClickable(position == 0);

    viewHolder.TaskName.setText(tasks.TaskName);

    viewHolder.TaskStart.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(final CompoundButton checkStart, boolean isChecked) {

                if (checkStart.isChecked()){
                    final int TaskID = (Integer) checkStart.getTag() + 1;

                    new AlertDialog.Builder(getContext())
                            .setTitle("Start Task?")
                            .setMessage("Are you sure you want to start this task?")
                            .setCancelable(false)
                            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {

                                    String DateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH).format(Calendar.getInstance().getTime());

                                    Toast.makeText(getContext(), "" + TaskID, Toast.LENGTH_SHORT).show();


                                    if (TaskID == 1){
                                        viewHolder.TaskEnd.setChecked(position ==3); // This doesn't want to work
                                    }
                                    else {

                                    }
                                    checkStart.setEnabled(false);
                                }
                            })
                            .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.cancel();
                                    checkStart.setChecked(false);
                                }
                            })
                            .show();
                }
            }
        }
    );

Any Help Will be extremely appreciated!!!




how to customize this checkbox to make it look this [correct checkbox ][1] as i am not sure how to do it

        I would like to customize it such that the checkbox color should change on click . 

please refer the link and image and suggest how to achieve this as i am not sure how to do it . [code for checkbox][1] Below is the HTML code for checkbox :

        <div id="container">
            <div id="btnOuterDIV">
                <div id="btnChkbox">
                    <input type="checkbox" id="btnCB" />
                </div>
            </div>
        </div>

        CSS for the checkbox , it should look like the one in image :

        #container  {
    padding:50px;
    }
        #btnOuterDIV{
    height:30px;width:80px;border:1px solid #ccc;border-radius:5px;
    }
        #btnOuterDIV:hover{
    border-color:#888;
    }
        #btnChkbox{
    height:15px;width:15px;padding-top:5px;padding-left:5px;
    }

  [1]: http://ift.tt/2bnWX4D




get checked checkBoxes texts in C#

I have 4 checkBox in my windows form application and I need to get the text of checked checkBox by returning it from a string function but it gives me an exception. The codes of the function are:

 string getPerm()
{
   string perm = "";
   foreach(CheckBox chkb in this.Controls)
   {
       if(chkb.Checked==true)
   {
   perm += chkb.Text + ",";
   }
     return perm;
   }

And I used this function in Show method of messageBox to show the result on click event of a button , one more problem is that I need to delete the last comma from the result... regards




Reffering 2 different custom post types each other by using multi checkboxes [wordpress]

I'm building a website for an artist with Wordpress. In the website, I created 2 custom post types: Works and Exhibitions, to refer each other in each post, so that viewers can understand in which exhibitions an artwork is presented on the artwork post and which artworks are presented in an exhibition on the exhibition post.

I tried using ACF's Post Object to call the list of the custom post types in admin panel. But there was no feature on Post Object with checkboxes.

The image below explains what I want to achieve. enter image description here

What I think the best is to query multi checkbox values on admin post page(Add New Works). Then the artist can choose the exhibitions in which the work is presented and vise versa in an exhibition post. But I couldn't figure out how.

Does anyone have an idea how to achieve this? Any advices would be appreciated.




vendredi 26 août 2016

Controlling Checkboxes in React Js

I have a question in regards to how I should set up nested checkboxes.

I currently have nested data called areas that looks like this:

    [{
        "id": 1,
        "name": "Europe",
        "Countries": [{
            "id": 1,
            "name": "Iceland",
            "Cities": [{
                "id": 1,
                "name": "Selfoss"
            }]
        }, {
            "id": 2,
            "name": "Switzerland",
            "Cities": [{
                "id": 2,
                "name": "Geneva"
            }]
        }]
    }, {
        "id": 2,
        "name": "Asia",
        "Countries": [{
            "id": 3,
            "name": "Japan",
            "cities": [{
                "id": 3,
                "name": "Yokohama"
            }]
        }]
    }]

I need to generate them into nested checkboxes, which I have done successfully:

  const renderCities = Cities => {
    return (
      <div className="city-bar">
        <label>
          <input
              onChange={onChange}
              type="checkbox"/>
        {Cities.name}
        </label>
      </div>
    );
  };

  const showArea = Country => {
    return (
      <div className="country-bar"> 
        <label>
            <input
              onChange={onChange}
              type="checkbox"/>
          {Country.name}
        </label>
        {Country.Cities.map(renderCities)}
      </div>
    );
  };

function onChange(e) {
  console.log('checkbox checked:', (e.target.checked));
}

class AreasBar extends Component {
      constructor(props) {
        super(props);
        this.state = { 
        };
    }

  componentWillMount() {
    this.props.fetchAllAreas(); 
  }

  renderContinents(continent) {
      return(
        <div className="continent-bar">
          <label>
            <input
                onChange={onChange}
                type="checkbox"/>
             {continent.name}
          </label>
          {continent.Countries.map(showArea)}
        </div>
    )
  }

  render() { 
    return(
        <div> 
          {this.props.areas.map(this.renderContinents)}
        </div>
    );
  }
}

This is what I want to do. If a user clicks the checkbox of a parent (like Europe), then all of the countries and cities related to it should show up and be clicked.

This is what I'm thinking of doing and I'm wondering if this approach is acceptable for this scenario.

  1. Bind the onChange handler to the AreasBar component, add an object parameter so we know which object is selected and pass it as a prop to showArea and renderCities
  2. Add an extra field to areas called checked which sees if the checkbox was checked or not
  3. Make all checkboxes controlled and set the checked state to the state of the object in areas
  4. When onChange is called, an action creator is called to set the new checked state of the object



How can I print the checkbox that is clicked in pyqt.

I want to push a button and show the available interfaces, when one is clicked i want to print it

#!/usr/bin/python
from PyQt4 import QtCore, QtGui
from struct import *
import sys
import pcapy
from PyQt4.QtCore import * 
from PyQt4.QtGui import *

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
     _encoding = QtGui.QApplication.UnicodeUTF8
     def _translate(context, text, disambig):
         return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
     def _translate(context, text, disambig):
         return QtGui.QApplication.translate(context, text, disambig)


class Ui_MainWindow(object):

     def setupUi(self, MainWindow):
         MainWindow.setObjectName(_fromUtf8("MainWindow"))
         MainWindow.resize(800, 616)
         self.centralwidget = QtGui.QWidget(MainWindow)
         self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
         self.listInterface = QtGui.QListView(self.centralwidget)
         self.listInterface.setGeometry(QtCore.QRect(230, 150, 256, 192))
         self.listInterface.setObjectName(_fromUtf8("listInterface"))
         self.model = QStandardItemModel(self.listInterface)
         self.btnCapturar = QtGui.QPushButton(self.centralwidget)
         self.btnCapturar.setGeometry(QtCore.QRect(310, 390, 98, 27))
         self.btnCapturar.setObjectName(_fromUtf8("btnCapturar"))
         self.btnCapturar.clicked.connect(self.llenarLista)
         MainWindow.setCentralWidget(self.centralwidget)
         self.menubar = QtGui.QMenuBar(MainWindow)
         self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 25))
         self.menubar.setObjectName(_fromUtf8("menubar"))
         MainWindow.setMenuBar(self.menubar)
         self.statusbar = QtGui.QStatusBar(MainWindow)
         self.statusbar.setObjectName(_fromUtf8("statusbar"))
         MainWindow.setStatusBar(self.statusbar)
         self.retranslateUi(MainWindow)

         QtCore.QMetaObject.connectSlotsByName(MainWindow)

     def retranslateUi(self, MainWindow):
         MainWindow.setWindowTitle(_translate("MainWindow", "Captura", None))
         self.btnCapturar.setText(_translate("MainWindow", "Show", None))

     def llenarLista(self,listWidget):

         devices = pcapy.findalldevs()
         for d in devices:
             item = QStandardItem(d)
         # add a checkbox to it
             item.setCheckable(True)
         # Add the item to the model
             self.model.appendRow(item)
         # Apply the model to the list view
         self.listInterface.setModel(self.model)



if __name__ == "__main__":
     app = QtGui.QApplication(sys.argv)
     MainWindow = QtGui.QMainWindow()
     ui = Ui_MainWindow()
     ui.setupUi(MainWindow)
     MainWindow.show()
     sys.exit(app.exec_())

I have take most of the code from http://ift.tt/2bn2NmM