To get DMS format e.g. 403121N in QGIS we can use 'Field Calculator' with formula for e.g.
In the format of DMS labels E and N or N and W, depend on the coordinate system we use. It is necessary to check the axes for the coordinate system we use ...
The solution is to use for all the items the function:
$y_at (0) and $x_at (0) (coordinates of the first point of the polyline)
$y_at (-1) and $x_at (-1) (coordinates of the last point of the polyline)
What you have there is not a plugin class but a dialog class. I am not sure exactly how you are running this code or trying to install it as a plugin, but the first thing I would suggest is that you need to create separate classes for plugin logic and dialog (they may or may not be separate files). The main plugin class should take the qgisinterface object ...