Thursday 11 February 2021

PyQt5 Drag and Drop QGroupBox

 Custom QGroupBox for drag-and-drop in Python PyQt5.

I prefer this over the "file open" dialog, as it's much faster. And the user probably already has the window open that they are working with, so there is no need to navigate to it again.

It looks like this (with some CSS):




The code:

class QGroupBoxDrop(QGroupBox):

def __init__(self):
super().__init__()
self.setAcceptDrops(True)
self.paths = []
self.hbox = QHBoxLayout()
self.setLayout(self.hbox)
self.label = QLineEdit()
self.label.setAttribute(Qt.WA_MacShowFocusRect, 0)
self.hbox.addWidget(self.label)
self.setTitle("Drag and Drop")

def dropEvent(self, droppedstuff):
droppedEvent = droppedstuff
mimeData = droppedEvent.mimeData()
mimeData.hasUrls()
urls = droppedstuff.mimeData().urls()
if droppedstuff.mimeData().hasUrls():
droppedstuff.accept()
else:
droppedstuff.ignore()
for item in urls:
self.path = item.toLocalFile().rstrip("/")
self.label.setText(self.path)
pass

def dragEnterEvent(self, enteredstuff):
enteredstuff.accept()
pass

def dragMoveEvent(self, movedstuff):
movedstuff.accept()
pass
Written by Spencer.


rpi little touch screen

Follow this guy's article:https://www.raspberrypi.org/forums/viewtopic.php?t=143581
but on my raspbian there is a bug so Option "Calibration" and Option "SwapAxes" does not work so I had to instead do this:
Option "TransformationMatrix" "-1.09 0 1.06 0 -1.16 1.06 0 0 1"
This works quite well.
Otherwise im running it at CEA mode 2 720x480 60HZ 4:3 with no Overscan and no Pixel Doubling. Things are small on it but readable.

Wednesday 25 September 2013

how to make PHP execute a shell script as a certain user

the first thing would be to add the user to the sudoers list with visudo.
this is the bash:
sudo -u USERNAME COMMAND
so then this is the PHP script:
shell_exec('sudo -u USERNAME COMMAND');
so then put this in context:
<?php
    $result=shell_exec('COMMAND');
    echo ($result);
?>

Friday 16 August 2013

Grep Print Only After Match

http://stackoverflow.com/questions/12682715/grep-print-only-after-match


how to write only a specific range of characters into a variable, and stuff.

Specify range of characters:

variablea="noyesno"
variableb=${variablea:2:3}
echo $variableb

this will pring "yes"


Skip first and last characters. Independent of string length:

variablea="xsomethingx"
variableb="${variablea:1:${#variablea}-2}"
echo $variableb

this will print "something"

how to ignore cp overwrite

see answers here: http://stackoverflow.com/questions/8488253/linux-how-to-ignore-cp-overwrite

Screenshot of thread after break:

bad substitution

Make sure that you are using bash:
put #/bin/bash as the first line of the file, or run the command: "bash scriptname.sh"