mardi 4 juillet 2023

Saving checkbox state when X item is selected?

I am creating the GUI of a preprocessor to be able to solve flow problems, I need the items that are in the ListWidget to save the state of the checkbox that I want to select

Example of the behavior I require

Is this possible? If so, how would I achieve it?

I tried using the setData method, I wanted to save the state of each checkbox using an array with values ​​of 0 and 1, so every time one of the items was selected, I expected the state to be saved as a value in the array, to later read it when the item is selected again and place the corresponding checkbox as checked.

    self.bordesWindow.ui.listWidgetVarEsc.itemSelectionChanged.connect(self.settingCheckBoxStateBorde)
    self.bordesWindow.ui.listWidgetVarEsc.itemClicked.connect(self.gettingCheckBoxStateValue)

def settingCheckBoxStateBorde(self):
    self.arrayValuesCheckboxesBordes = np.zeros(3)
    self.constDataBordeCheckboxState = Qt.ItemDataRole.UserRole
    item = self.bordesWindow.ui.listWidgetVarEsc.currentItem()
    item.setData(self.constDataBordeCheckboxState, self.arrayValuesCheckboxesBordes)
    if self.bordesWindow.ui.checkBoxVariablesEscValor.isChecked():
        item.data(self.constDataBordeCheckboxState)[0] = 1
    elif self.bordesWindow.ui.checkBoxVariablesEscFlujo.isChecked():
        item.data(self.constDataBordeCheckboxState)[1] = 1
    elif self.bordesWindow.ui.checkBoxVariablesEscConveccion.isChecked():
        item.data(self.constDataBordeCheckboxState)[2] = 1

def gettingCheckBoxStateValue(self):
    item = self.bordesWindow.ui.listWidgetVarEsc.currentItem()
    if item.data(self.constDataBordeCheckboxState)[0] == 1:
        self.bordesWindow.ui.checkBoxVariablesEscValor.setChecked(True)
    elif item.data(self.constDataBordeCheckboxState)[1] == 1:
        self.bordesWindow.ui.checkBoxVariablesEscFlujo.setChecked(True)
    elif item.data(self.constDataBordeCheckboxState)[2] == 1:
        self.bordesWindow.ui.checkBoxVariablesEscConveccion.setChecked(True)



VBA for insert commumn with checkboxes and afterward print checked boxes

I have an Excel file where i want to use VBA to insert a column in front of the excising column A. The file contains other VBA's for generate a list. So, the list can change in numbers of columns and rows. I use below VBA to print, it works just fine. But I want it to do like: Press print bottom, the VBA insert a new column A with check boxes. A Msg box pops up and stay on top (Press OK when you are ready to print), then you can select the lines that you want to print in the check boxes. If you don't select any check boxes the print VBA should print all active lines as it do now, except the new column A with check boxes.

Sub Print()

Call Uden_pre_booking   'Starts the VBA that makes a fresh list

Dim ws3 As Worksheet
Dim EndRow As Long, EndCol As Long

Set ws3 = Sheets("Vis_Oversigt")

EndCol = ws3.Cells(4, 6).Value + 10
EndRow = ws3.Range("B" & Rows.Count).End(xlUp).Row + 2
   
ws3.PageSetup.PrintArea = ws3.Range(Cells(1, 1), Cells(EndRow, EndCol)).Address



ActiveSheet.PrintPreview

End Sub

I have tried several VBA's from different sites, but doesn't manage to get it into a functional VBA.

Hope that someone will help me make a functionally VBA.




lundi 3 juillet 2023

How to handle checkbox change in React.js?

I'm trying to handle change of the value when a check box is clicked. The component loads a response like this:

[
   {
       "id_ver_group": 7,
       "checklist": [
           {
            "check": "Custom ver 1",
            "valor": false,
            "opcional": true
           },
        {
            "check": "Custom ver 2",
            "valor": false,
            "opcional": false
        }
       ],
       "id_ver_group_char": "7",
       "fecha_crea": "2023-07-02T18:07:56.756521"
  },
  {
       "id_ver_group": 6,
       "checklist": [
           {
               "check": "Custom ver 1",
               "valor": false,
               "opcional": true
           },
           {
               "check": "Custom ver 2",
               "valor": false,
               "opcional": false
           },
       ],
       "id_ver_group_char": "7",
       "fecha_crea": "2023-07-02T18:07:56.756521"
  },
]

The response is grouped by "id_ver_group" in an "Accordion" tag where each "checklist" item is displayed in a table, its columns are: "verify" (string), "value" (bool) and "optional " (bool) , the checkbox tag is used to display the "value" and "optional" columns, the latter being read-only. This is the component code:

// imports...
import {
  Accordion,
  AccordionSummary,
  AccordionDetails,
  Typography,
  Table,
  TableHead,
  TableBody,
  TableRow,
  TableCell,
  Checkbox,
  Select,
  InputLabel,
  Button,
} from '@material-ui/core'

export function AddEditChecklist(props) {
     
const { Tanques, onClose, onRefetch } = props
const { Successful, errores } = alertas()
const { Data, getBaseVer } = useVerificaciones()
const { addTankVer, updateTankVer } = useTanques()
const { OperadorDB, getOperadorDB } = useOperador()
const [selectedOperator, setSelectedOperator] = useState('');
const [isOperatorSelected, setIsOperatorSelected] = useState(true);

const [selectedGroup, setSelectedGroup] = useState(null);
  const [selectedGroupIndex, setSelectedGroupIndex] = useState(null);

  useEffect(() => {
    getOperadorDB()
    getBaseVer()
  }, []);

  const [data, setData] = useState([]);

  useEffect(() => {
    setData(Data?.map(item => ({
      ...item,
      checklist: item.checklist.map(checklistItem => ({
        ...checklistItem,
        valor: false  
      }))
    })) || []);
  }, [OperadorDB, Data]);

  const handleAccordionChange = (groupId) => {
    setSelectedGroupIndex(groupId); 
    setSelectedGroup(groupId)
    
    if (selectedGroup === groupId) {
      setSelectedGroup(null); 
    } else {
      setSelectedGroup(groupId); 
    }
  };

// check box handle
  const handleCheckboxChange = (groupId, itemIndex, checklistItem) => {
    setData((prevData) => {
      const updatedData = [...prevData];
      const groupData = updatedData[groupId];

      if (groupData && groupData[itemIndex]) {
        checklistItem.valor = !checklistItem.valor; 
      }

      return updatedData;
    });
  };

  // group data by id
  const groupedData = data ? data.reduce((groups, item) => {
    const groupId = item.id_ver_group;
    if (!groups[groupId]) {
      groups[groupId] = [];
    }
    groups[groupId].push(item);
    return groups;
  }, {}) : {};
// handleSubmit...

return (
    <>
      {/* checklist */}
      {Object.keys(groupedData).map((groupId) => (
        <Accordion
          key={groupId}
          expanded={selectedGroup === groupId}
          onChange={() => handleAccordionChange(groupId)}
        >
          <AccordionSummary expandIcon={<ExpandMoreIcon />}>
            <Typography variant="h6">Conjunto de verificaciones # {groupId}</Typography>
          </AccordionSummary>
          <AccordionDetails>
            <div>
              {groupedData[groupId].map((item, index) => (
                <div key={item.id_ver_group}>
                  <Table>
                    <TableHead>
                      <TableRow>
                        <TableCell><strong>Verificación</strong></TableCell>
                        <TableCell><strong>¿Cumple?</strong></TableCell>
                        <TableCell><strong>¿Opcional? (no modificable)</strong></TableCell>
                      </TableRow>
                    </TableHead>
                    {item.checklist.map((checklistItem) => (
                      <TableBody key={checklistItem.check}>
                        <TableRow>
                          <TableCell>
                            {checklistItem.check}
                          </TableCell>
                          <TableCell>
                            <Checkbox
                              checked={checklistItem.valor}
                              name={checklistItem.check}
                              onChange={() => handleCheckboxChange(groupId, index, checklistItem)}
                            />
                          </TableCell>
                          <TableCell>
                            <Checkbox
                              readOnly
                              checked={checklistItem.opcional}
                              name={checklistItem.check}
                            />
                          </TableCell>
                        </TableRow>
                      </TableBody>
                    ))}
                  </Table>
                </div>
              ))}
            </div>
          </AccordionDetails>
        </Accordion>
      ))}
      <br></br>
      <Divider></Divider>
      <br></br>
      <Button variant="contained" color="primary" onClick={handleSubmit}>
        Save
      </Button>
    </>
  )
} 

Doing some research, I was able to come up with something to handle the checkbox changing, but the checkbox doesn't change its value when clicked. I really don't know how to solve this. Any help is appreciated.




How to make this CSS switch color background change in enabled / disabled sate?

I have a CSS switch like this:

* { box-sizing: border-box; }
.switch { appearance: none; padding: 9px 18px; border-radius: 13px; background: radial-gradient(circle 9px, #007722 100%, transparent 100%) transparent -9px; border: 1px solid #007722; }
.switch:checked { background-position: 9px; }
<input type="checkbox" class="switch"></div>

How to make that, disabled, it stays with a transparent background, but once enabled, it has another background?

Example:

enter image description here




Android Studio change checkbox result when changing language in app

I made an app where a user can check a box(checkbox). Also the app can be translated in 2 languages by code. How can I also make the result of the checkbox(true/false) to be translated when you change the language of the app?

I have not found something similar anywhere online.




dimanche 2 juillet 2023

Looker Studio Table with interactive Checkbox column

I'd like to create a Pipeline table that has a checkbox column which can be ticked in order to create a sum so you can instantly see what value from the Pipeline to commit to forecast. Hence, the table would need to be interactive.

The optimal solution would be that this sum can also be used as a metric, e.g. to deduct from the current Gap to target or to add to the current Bookings and divide by the target.

Does anyone know any solution that could accomplish this?

Honestly I have not tried anything specifically yet as I do not have a clue where to look at.

Thanks a lot and have a good weekend, Stefan




samedi 1 juillet 2023

Using flask_table to make a checkbox input column

The DonationTable class I am using to show data. In the derived DonationRegisterTable class I want to have a checkbox instead of a BoolCol so user can edit the table. Is there a way to have a checkbox as a column using flask_table?

from flask_table import Table, BoolCol, Col, ButtonCol


class DonationTable(Table):
    classes = ["table", "table-bordered"]

    id = Col("Id", show=False)
    account_id = Col("Account ID", show=False)
    month = Col("Month")
    year = Col("Year")
    paid = BoolCol("Paid")


class DonationRegisterTable(DonationTable):
    # I want this to be a checkbox
    paid = ButtonCol("Paid", "register_donation", url_kwargs=dict(account_id='account_id'))