Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Saturday, 23 November 2013

Using LaTeX and Kile: .gls file does not exist and how to build one

Recently while working on a LaTeX document in Kile, the KDE LaTeX environment, I found myself working on a glossary that failed on the last step. I had set up a glossary .tex file that I included, put the \usepackage[toc]{glossaries}, /makeglossary and /printglossaries lines into the file and tested one of the glossary entries.

No go.

Kile could not find the .gls file. After some navigating the internets for answers, I came upon this blog post.

http://texblog.org/2007/11/01/glossary-in-latex/

After running the command, it did indeed generate the .gls file I needed. But would it regenerate every time my glossary changed? I kept looking for an answer specific to Kile. After a while, I did find it, but it didn't seem to finish what I needed. Kile has a way for the user to create their own build commands which can be run from inside the application. I'll spare you the details, but here's how to integrate glossary building into Kile:


  1. Go to Settings -> Configure Kile ... -> Tools > Build menu (found on the left-hand side of the Settings window)
  2. Under the Select a Tool pane, click the New button to create new tool.
  3. Name the tool "MakeGlossary", click Next button and Select MakeIndex from the list.
  4. ( Here is where the original post I was looking at dropped off... )
  5. In the General tab, for Command: write "makeindex".
  6. Under Command:, type this into the options:
    '%S.glo' -s '%S.ist' -t '%S.glg' -o '%S.glx'

    - Recognize it from the blog post?
  7. Just to be sure and thorough, click on Advanced Tab. For Source extension, write "glo". For Target extension, write "gls".


I have tested the above and it works for me. It does involve two steps (running MakeGlossary and then PDFLaTeX), though it could be possible to string the two commands together somehow. For now, I have what I want and I hope this blog post helps those looking for those same answers.



Cheers.

Thursday, 3 October 2013

Including Dbus in a Python QT4 application

Dbus isn't the most complicated beast in software, but it's notable.

There are a list of things I *don't* like about dbus.

- The C/C++ code is well documented, but good tutorials are absent
- The Python code is poorly documented if it exists, but there are some great tutorials to look off of
- Python Dbus + Qt or GTK requires that the process is forked or put into a daemon in order to allow connections. (Cannot initiate in a GUI application without detachment)

I just spent an hour figuring out that last one. I'm big on documentation, both in my work and when using other people's code. If it isn't there, the difficulties in developing with the software is exponentially greater and my time is wasted.

That said, dbus is amazing when it works and I love that KDE and QT/Maemo have taken great lengths to adopt it. Even the KDEOnWindows project uses dbus, on Windows!



I am trying to create a dbus interface so that my GUI application can talk to different portions of itself without messy imports and passing of variables. I will have a dbus/ folder that contains one module with one class that inherits dbus services and imports respective modules. Each method will pass the call and any arguments it includes to the function, which in turn passes it to the UI.

Why have dbus classes and modules in one folder? So I can iterate through the folder and add every dbus service without having to manually type it all in; automate it! (It's inspired by the debian and gentoo directory.d/ style of configuration management. I plan to extend this to a plugin system at some point.) Make sure all dbus files are referenced before the mainloop but after application is started.

It seems that walking through a directory and dynamically loading dbus objects still causes dbus to hang. My guess is that every dbus.service object needs to be placed into its own mainloop and importing a module with dbus methods doesn't properly place it into the mainloop.

Sorry for the mess. Dbus services must be added after the QApplication or QCoreApplication is initialized. I was adding them before, then getting this message in the terminal:

QSocketNotifier: Can only be used with threads started with QThread

Create references to dbus objects after application initialization!

For a real-world example, I will launch a dbus service that contains a method for creating a new project. I will name it NewProject and it will have an argument of a name. We will not worry about uniqueness or purpose for now.

------------------------------------------------------------

Import Code:

import dbus
import dbus.service
from dbus.mainloop.qt import DBusQtMainLoop

If this fails, you need to install dbus dependencies. This could be python3-dbus.mainloop.qt, python3-dbus/python-dbus, or python3-pyqt4. You will need to check with your distribution for the proper package names. A search for "dbus" is usually adequate.

Define an Interface Name:

This should reflect your application or purpose. I usually store it as a global variable.

INTERFACE = 'org.qtcide'

Write your class with the dbus methods
class DbusTest(dbus.service.Object):

    def __init__(self):
        busName = dbus.service.BusName(INTERFACE, bus = dbus.SessionBus())
        dbus.service.Object.__init__(self, busName, '/org/qtcide')
        

    @dbus.service.method(INTERFACE,
                        in_signature = 's', out_signature = 's')
    def NewProject(self, name):
        return name

Initialize application and mainloop:
DBusQtMainLoop(set_as_default = True)    
app = QtGui.QApplication(sys.argv)

Keep it looping:
sys.exit(app.exec_())


And you should have a dbus process running. Currently the NewProject method only returns the name you give it, but adding an import and calling a method with that Name is simple, and I shall explain how in the next post.

Forking may have some strange consequences on Windows, as true forking is resource intensive and not native.


For those of you interested, you can find my project I'm basing this tutorial on here: https://github.com/NucleaPeon/QTCIDE

Friday, 13 September 2013

How to install your own python modules

Problem: You have python code, such as a library, that you want available for other programs you, or others, may be developing. You also may want to add your code into a debian or rpm package for easy distribution.


Solution: Add a [name].pth file and your package to /usr/local/lib/pythonX.Y/dist-packages.


Important Notes:
  • site-packages is no longer used. Read the site.py module for more information on this.
  • The [name].pth contains a relative or absolute path to the directory or specific python files you want added to the interpreter, each item on its own line. (Comments prefixed with # are also recognized)

So I have this example:

/usr/local/lib/python3.2/dist-packages/mylib.pth
    # This file contains path to my library (relative):
    # Adds every .py file in mylib/ folder
    mylib/
    mylib/static/mylibvars.py



The path /usr/local/lib/python3.2/dist-packages/mylib/ contains library files and /usr/local/lib/python3.2/dist-packages/mylib/static/mylibvars.py is just to show how to specify an individual file.


Once you open up your interpreter, type in the following commands to check your work.


>>> import sys
>>> print(sys.path)

Friday, 19 July 2013

Creating an Android Studio Desktop File for launching on your panel or toolbar in GNU/Linux

I spent a while (read: too much time) trying to get Android Studio launching on my KDE panel via an icon.

The program would not launch, even after editing the studio.sh script so the user wouldn't have to press the key. Since I compiled and installed IcedTea Java 7, it would always warn me before launch. Oracle Java is recommended for running Android Studio, but I take some issue with Oracle as a company, so I would prefer not to use it. Plus, on Gentoo, the package manager requires the manual downloading of oracle's java.bin files because they do not allow Gentoo to carry it in their package repository due to copyright or some crap like that.

Anyway, back to the application launching: even when exporting JAVA_HOME in my .bashrc file (which gets run every login shell), the application would fail to run. The fix for this is to manually add the path to the EXEC= line in the .desktop file. Here is mine as an example:

[Desktop Entry]
Comment=
Exec=JDK_HOME="/usr/lib/jvm/icedtea-7/" /home/celestia/Programs/android-studio/bin/studio.sh
Icon=/home/celestia/Pictures/Icons/android.png
Name=AndroidStudio
NoDisplay=false
Path[$e]=
StartupNotify=true
Terminal=0
TerminalOptions=
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=

I used the KDE Menu Editor to generate the template, but regardless of how you create your .desktop file, it's the EXEC line you need.
If your paths are set up system-wide, I doubt there will be any errors when you run studio.sh without the JDK_HOME path.

Hope this helps.
Cheers!

Friday, 7 June 2013

Multiple hosted websites are redirecting to only one of my sites on Apache

I had an interesting problem today.

I am attempting to host 3 different web sites on an apache configuration on a raspberry pi. Individually, I can launch each webpage without issue and have the site show up. However, somehow, when I enabled more than one site at a time, each one on different ports, it would show only one site across all ports.

I tried configuring different sites with different ports, changed <Directory> tags to see if my directories were overriding each other, etc.

Most of the data is stored in /var/www/[site-name], so it was only until I tried adding another site at /var/www/[different-site-name] and have it still happen that I knew it was not a path conflict. I fudged with the apache settings for a while to no effect.

A little voice in my head hinted at one of the configuration files I had used a long time ago, the /etc/apache2/conf.d/virtual.conf file. I checked it out, and it had this to say:


NameVirtualServer *


Now, in my website ports.conf file, I specified lines like this:
NameVirtualServer *:80
NameVirtualServer *:8081
NameVirtualServer *:8082

Somehow it clicked. I disabled the /etc/apache2/conf.d/virtual.conf contents by changing the line to this:

# NameVirtualServer *

saved and restarted apache.

Now everything works as configured.

It may seem like a trivial problem, but it cost me a couple hours of my valuable time and I *could not* find a solution on google. Granted, I didn't scour the bowels of the internet for this small problem.

Hopefully this will help others in my position.

(Performed on a Raspbian installation)