Blog | LordVan's Page / Bloghttps://blog.lordvan.com/blog/2024-03-29T08:43:06.334159+00:00If you were looking for something specific you probably got redirected here from an old link to my (now gone) drupal blog. I migrated all the pages & blog entries to this blog, so just use the search here to find what you were looking for.some PyQt5 ..2020-03-20T13:16:22.127014+00:002024-03-29T06:28:31.927384+00:00lordvanhttps://blog.lordvan.com/blog/author/lordvan/https://blog.lordvan.com/blog/some-pyqt5/<p>So i wanted a (very simple) GUI for my python program .. and i want it to run on Linux but also windows..</p>
<p>Looking at the choices (Kivy, PyQt, pygtk) I found PyQt to be the most complete toolkit (I want a treeview with more columns later on which is something that kivy doesn'T seem to have). - PyGTK has that too but under windows that is a bit more of a pain to get running (from prior experience).</p>
<p>So I went and tried PyQt5 for the first time (last time I used PyQt it was Version 4 still so been a while ..)</p>
<p>It's fairly easy to get running with PYCharm (Community Edition) just go to the project settings and install the PyQt5 module -- don'T forget the stubs (for some reason installing from the popup hint did not work for me so I did it manually).</p>
<p>I installed qtdesigner too, but couldn'T figure out how to best use it with pycharm immediately so I just put together my (very simple) GUI the old way for now.</p>
<p>The purpose is simple:</p>
<ol>
<li>pick a base directory</li>
<li>pick a text file with a list of filenames [also picks the file'S directory as source)</li>
<li>verify it makes sense (the text file and source directory need to be within the base directory</li>
<li>[[ This is in a seperate module and has been used from the command line before ]] find all files from the text file in the base directory, compare to the source one and then save the result (and output it to a textfile and / or QPlainTextEdit later .. maybe will add TreeView at some point but not right now)</li>
</ol>
<p>so just for anyone wanting to just get a basic idea of how to do this here some source code without much explaination (fairly self explainatory if you are familiar with python and GUI toolkits imho):</p>
<pre>import sys
# from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QApplication, QLabel, QWidget, QPushButton, QGridLayout, QLineEdit, QFileDialog,
QPlainTextEdit, QTreeWidget) # QErrorMessage)
from file_find_compare import FileFindCompare
DEBUG = False
class PyFindFileCompare(QWidget):
# widgets
base_dir = None
inp_file = None
out_text = None
btn_base_dir = None
btn_inp_file = None
btn_start = None
tv_out = None
_out_file = None
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
layout = QGridLayout()
layout.addWidget(QLabel(text='Basisordner: '), 0, 0)
self.base_dir = QLineEdit()
self.base_dir.setReadOnly(True)
self.base_dir.setText('//server/Daten')
layout.addWidget(self.base_dir, 0, 1)
self.btn_base_dir = QPushButton('Basisordner auswählen: ')
layout.addWidget(self.btn_base_dir, 0, 2)
self.btn_base_dir.clicked.connect(self.get_basedir)
layout.addWidget(QLabel(text='Eingabedatei: '), 1, 0)
self.inp_file = QLineEdit()
self.inp_file.setReadOnly(True)
self.inp_file.setText('//server/Daten')
layout.addWidget(self.inp_file, 1, 1)
self.btn_inp_file = QPushButton('Eingabedatei auswählen')
self.btn_inp_file.setDisabled(True)
layout.addWidget(self.btn_inp_file, 1, 2)
self.btn_inp_file.clicked.connect(self.get_inp_file)
self.btn_start = QPushButton('Start')
self.btn_start.setDisabled(True)
layout.addWidget(self.btn_start, 2, 2)
self.btn_start.clicked.connect(self.start_search)
self.out_text = QPlainTextEdit()
self.out_text.setReadOnly(True)
layout.addWidget(self.out_text, 3, 0, 1, 3)
self.tv_out = QTreeWidget()
self.tv_out.hide()
layout.addWidget(self.tv_out, 4, 0, 1, 3)
self.setLayout(layout)
self.setFixedWidth(900)
self.setMinimumHeight(500)
self.show()
def get_basedir(self):
bdir = str(QFileDialog.getExistingDirectory(self,
"Basisordner auswählen",
self.base_dir.text()
))
if bdir:
self.base_dir.setText(bdir)
# we got a valid input path so enable the input file button
self.btn_inp_file.setDisabled(False)
if DEBUG:
self.out_text.appendPlainText('got base dir: %s' % self.base_dir.text())
if self.inp_file.text() != '':
self.inp_file.setText(self.base_dir.text())
def get_inp_file(self):
# stop the user from changing the base dir to avoid weird issues
# TODO: make it more user friendly later
self.btn_base_dir.setDisabled(True)
infile = str(QFileDialog.getOpenFileName(self,
"Eingabedatei auswählen",
self.inp_file.text(),
'*.txt'
)[0]
)
if infile:
if infile.find(self.base_dir.text()) != 0:
self.out_text.appendPlainText('Fehler: Die Eingabedatei muß im Basisverzeichnis oder unterordner liegen!')
return
else:
self.btn_start.setDisabled(False)
self.inp_file.setText(infile)
self._out_file = self.inp_file.text().replace('.txt', '_output.txt')
if DEBUG:
self.out_text.appendPlainText('got input file: %s' % self.inp_file.text())
self.out_text.appendPlainText('output filename: %s' % self._out_file)
def start_search(self):
# just to be save disable both other buttons
self.btn_inp_file.setDisabled(True)
self.btn_inp_file.setDisabled(True)
ffc = FileFindCompare(self.inp_file.text(), self._out_file, self.base_dir.text())
self.out_text.appendPlainText('Liste der Dateien: %s' % self.inp_file.text())
self.out_text.appendPlainText('Basisordner: %s' % self.base_dir.text())
ffc.find_compare()
self.out_text.appendPlainText('Ausgabe wird gespeichert als %s' % self._out_file)
self.out_text.appendPlainText('Ausgabe als text:')
self.out_text.appendPlainText(ffc.generate_output())
ffc.save_output()
def populate_tv(self):
# TODO: populate the treeview
self.tv_out.show()
if __name__ == '__main__':
app = QApplication([])
win = PyFindFileCompare()
sys.exit(app.exec_())
</pre>
<p>I made some assumptions / simpilifications for the sake of usability / userfriendliness for now since I was in a rush .. so I am aware there are some issues / not very pretty things but it works and for now that was what mattered -- and to be honest it is such a short / simple program that I am going to be using myself for like 80% of the time if not 100% so whatever ^^ </p>Solid Edge Formelemente unterdrücken über Variablentabelle2018-07-06T09:02:44+00:002022-09-15T20:27:19.270353+00:00lordvanhttps://blog.lordvan.com/blog/author/lordvan/https://blog.lordvan.com/blog/solid-edge-formelemente-unterdr%C3%BCcken-%C3%BCber-variablentabelle/<p>For non-german speakers: This article is about how to use variables and formulas to suppress features + related ones - if someone is really interested i can translate it to english (but i'd need new screenshots i guess too so ..)</p>
<p><em>Vorab: mir ist das Konzept von Teilefamilien bekannt, aber bei Blechteilen ist das leider noch immer etwas suboptimal, da Teilkopien erstellt werden statt Blechteilen, was bei Teilen mit Eckbehandlungen schon zu Problemen führen kann).</em></p>
<p>Da ich öfters (sehr) ähnliche Blechteile brauche (Zuschnitte, Winkel, U-Profile, Schachteln) habe ich mir etwas überlegt um das ganze zu vereinfachen:</p>
<p>Der Ausgangspunkt ist eine rechteckige Lasche mit jeweils einem Lappen und 4 x Ecke schliessen:</p>
<p><img alt="Schachtel" height="318" src="https://blog.lordvan.com/static/media/uploads/Blog/Solid%20Edge/Schachtel%20mit%20Variablen/schachtel.png" width="800"/></p>
<p>Variable für alle Maße erstellen:</p>
<p><img alt="" height="149" src="https://blog.lordvan.com/static/media/uploads/Blog/Solid%20Edge/Schachtel%20mit%20Variablen/variablen.png" width="322"/></p>
<p>Diese Variablen werden dann den Formelementen zugewiesen (V420 und V422 sind wie man sieht Länge und Breite der Lasche):</p>
<p><img alt="" height="177" src="https://blog.lordvan.com/static/media/uploads/Blog/Solid%20Edge/Schachtel%20mit%20Variablen/variablen_den_formelementen_zuweisen.png" width="497"/></p>
<p>Danach wird für alle 4 Laschen eine Unterdrückungsvariable hinzugefügt:</p>
<p><img height="213" src="https://blog.lordvan.com/static/media/uploads/Blog/Solid%20Edge/Schachtel%20mit%20Variablen/unterdr%C3%BCckungsvariable_hinzuf%C3%BCgen.png" width="327"/></p>
<p>Danach einfach die Unterdrückungsvariablen dementsprechend Formeln zuweisen:</p>
<p><img alt="" height="86" src="https://blog.lordvan.com/static/media/uploads/Blog/Solid%20Edge/Schachtel%20mit%20Variablen/lappen_unterdr%C3%BCckungsvariablen.png" width="557"/></p>
<p>und zu guter letzt noch die Eckbehandlungen unterdrücken wo nötig:</p>
<p><img alt="" height="108" src="https://blog.lordvan.com/static/media/uploads/Blog/Solid%20Edge/Schachtel%20mit%20Variablen/ecke_schliessen_unterdr%C3%BCckungsvariablen.png" width="690"/></p>
<p>Jetzt kann man einfach durch ändern von L,B, S1-S4 von einem Zuschnitt, über Winkel und U-Profil bis zur kompletten Schachtel alles schnell erstellen, ohne lange zu überlegen und/oder fehlgeschlagene Formelemente zu haben, da die Eckbehandlungen so auch automatisch mit unterdrückt werden, sobald eine der 2 angrenzenden Laschen Länge 0 hat und deshalb unterdrückt wird.</p>Windows Active Directory GPO hinzufügen und zuweisen2018-03-01T08:50:51+00:002022-09-16T10:01:30.942318+00:00lordvanhttps://blog.lordvan.com/blog/author/lordvan/https://blog.lordvan.com/blog/windows-active-directory-gpo-hinzuf%C3%BCgen-und-zuweisen/<p>Vorraussetzungen / Requirements:</p>
<p><a href="https://www.microsoft.com/de-DE/download/details.aspx?id=7887">Remoteserver-Verwaltungstools für Windows 7 mit Service Pack 1 (SP1) </a></p>
<p>oder / or</p>
<p><a href="https://www.microsoft.com/de-at/download/details.aspx?id=45520">Remoteserver-Verwaltungstools für Windows 10 </a></p>
<p>und die benötigten Features installieren / and install the required features:</p>
<p><a>https://www.itsupportguides.com/knowledge-base/windows-7/windows-7-how-to-install-the-active-directory-users-and-computers-tools/</a></p>
<p>GPO Verwaltung starten (windows taste + r) / start gpo management (windows key + r)</p>
<pre>gpmc.msc</pre>
<p>Kurze Notiz wie man ein neues GPO (Group Policy Object) erstellen und mit OU (Organisational Unit) verlinken kann:</p>
<ul>
<li>OU Erstellen</li>
<li>neue GPO Erstellen & in OU verlinken<br/>
<ul>
<li>Gruppe (zB) hinzufügen bei Sicherheitsfilterung<br/>ACHTUNG: Authenticated Users *NICHT* entfernen (Tab "Bereich", "Sicherheitsfilterung")</li>
<li>"Delegierung" (Tab) -> gewünschte Gruppe/User -> Erweitert<br/>
<ul>
<li>bei "Authenticated Users" "Gruppenrichtlinie übernehmen" Haken bei "Zulassen" entfernen</li>
<li>bei gewünschter Gruppe "Gruppenrichtlinie übernehmen" Haken bei "Zulassen" hinzufügen</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><img src="https://blog.lordvan.com/static/media/uploads/Blog/Screenshots/gruppenrichtlinie_-_delegation_-_%C3%BCbernehmen.png" width="800"/></p>
<p>(the english version is likely not entirely correct when it comes to names of tabs options,.. as I do not have an english version installeD)</p>
<p>Quick note how to create a new GPO (Group Policy Object) and assign to an OU (Organisational Unit):</p>
<ul>
<li>Create OU</li>
<li>Create new GPO & link
<ul>
<li>Add group -- <strong>Careful: do not remove "Authenticated Users" !!</strong></li>
<li>"Delegation" tab -> pick user/group -> advanced<br/>
<ul>
<li>for "Authenticated Users" remove the tick for "apply group policy"</li>
<li>for the user/group you want add a tick for "apply group policy"</li>
</ul>
</li>
</ul>
</li>
</ul>A little useful addition for ssh login (from putty) to my .bashrc / .bash_profile2014-03-10T14:16:00+00:002024-03-29T08:43:06.334159+00:00lordvanhttps://blog.lordvan.com/blog/author/lordvan/https://blog.lordvan.com/blog/a-little-useful-addition-for-ssh-login-from-putty-to-my-bashrc-bash_profile/<p>A while ago I was getting increasingly annoyed with encoding problems through ssh - especially when using putty from windows to access my box with filenames,.. in de_AT.UTF-8 - so I was constantly setting locale back to 'C' or something similar.<br/> And well since I am lazy I did look for a way to make that happen automatically -- unfortunately I didn't find a -reasonably easy- way to see if I am using putty. But at least you can find out if you are logged in through ssh or not. So here's a little code snippet I added to my .bashrc to save myself from garbled console output:</p>
<pre>if [[ -n "$SSH_TTY" ]]
then
echo 'Logged in remotely changing LANG and LC_ALL to C'
export LANG=C
export LC_ALL=C
fi
</pre>
<p>While writing the above text I had some other idea so I tried this:<br/> Ssh has a way to send environment variables to be set to the server - and putty supports that too:</p>
<p><img alt="Putty settings screenshot" height="438" src="https://blog.lordvan.com/static/media/uploads/Blog/Screenshots/putty_connection_data_settings.png" width="456"/></p>
<p>So I think .. neat .. I try that .. to be greeted by the server with this:</p>
<pre>Server refused to set environment variables
</pre>
<p>A quick look in the <a href="http://linux.die.net/man/5/sshd_config">sshd_config man page</a> tells me there is a config setting called AcceptEnv. The default (on Gentoo) seems to be this:</p>
<pre># Allow client to pass locale environment variables #367017
AcceptEnv LANG LC_*
</pre>
<p>Makes sense from a security point of view I guess so for my use case just setting those instead of my 'own' variable to detect the client works just fine. -- And I can always still modify my sshd_config to accept my custom variable if I should need it for something else. So yeah I could've saved myself writing my little code snippet, but it might still come in handy if I need something else done automatically only through ssh login too and also that little bit of shell code is once per user on the server ... the putty settings would have to be on every machine i connect from, so I will keep that snippet in my .bashrc anyway ^^</p>