Creating/Editing a Titan-Like Gui

Version
by (unknown)
Version 12
by (unknown)

Deletions or items before changed

Additions or items after changed

1 -
 
+
This guide is for people who are interested in creating a GUI for a command line tool.
2 +
3 +
==Using Titan's Java Framework ==
4 +
5 +
For this part of the guide. We assume that you have access to the code for either Titan or Puffin, and are planning on using it to create a similar gui.
6 +
7 +
Alternatively, this part of the guide also shows how to modify the GUIs for Puffin or Titan (since Puffin was built off Titan). Note that in some places there a series of xs as to specify the name of the program (since this applies to both Titan and Puffin).
8 +
9 +
=== Code structure ===
10 +
11 +
The code is broken up into four folders:
12 +
13 +
'''graphics''' - The code for the different entry boxes we can add into our code. To add a different kind of entry box, you will probably have to copy and modify one of this files.
14 +
15 +
'''io''' - Handles how data is stored and collected. You probably won't need to modify this code.
16 +
17 +
'''jobs''' - For code related to running jobs, creating files, and other such activities.
18 +
19 +
'''gui''' - Stores the code that makes up the gui, importing from io and graphics. If you want to add tabs or add lines to tabs, the files you want to edit are here.
20 +
21 +
=== How it works ===
22 +
23 +
When a job is ran, the following things happen:
24 +
25 +
1. All the information from the tabs is collected into a namePairValueGroup. (Using a subclass from the main class.)
26 +
27 +
2. We check to see if any needed information is missing (using the checkRequired class from jobs, which checks for the files specified in xxxGUIConstants).
28 +
29 +
3. We create an output folder if we haven't created one for this run already (using makeDirectory class from jobs).
30 +
31 +
4. We create a shell script of the command we want to run (using the makeFiles class from jobs).
32 +
33 +
5. We create a process to run the shell script without freezing the gui (using the runProcess class from jobs).
34 +
35 +
6. Our process can update various displays while running and upon completion.
36 +
37 +
=== Adding an new input to the Gui ===
38 +
39 +
Suppose that your backend code has recently added a new feature that allows putting in a date. You want to ask the user to input a date.
40 +
41 +
1. In the class xxxGUIConstants, add the name of your field. Also in xxxGUIConstants you can specify whether you want this field to default to something when the program starts up, and whether it is required for the run.
42 +
43 +
2. Choose one of the classes from the "graphics" folder as the way to input the date. You will most likely want a textInput for something like a date. However, some entries will work better with checkboxes, filesearches, or a custom made input class.
44 +
45 +
3. In the class for the tab you want to add the entry on. Add the entry class as a private variable. Increase the size of the values array.
46 +
47 +
4. Initiate your entry class. Add it to the values array. Then add it to the panel (with the add function).
48 +
49 +
5. Edit the makeFiles class to include your option in the run shell script.
50 +
51 +
=== Adding a New Tab to the Gui ===
52 +
53 +
Suppose you want to add a whole new tab of entries to the Gui.
54 +
55 +
1. Extend the class mayaGuiTab to create a class for your tab. Add in all your inputs onto your tab.
56 +
57 +
2. In the main class, add a private variable for your tab. Then initiate your tab and add it. In the fetchData subclass, add in your class to the getData function.
58 +
59 +
60 +
== Using a Python GUI Builder ==
61 +
62 +
If you do not want to use Java, you may want to use one of python's
63 +
64 +
=== Options for GUI Builders ===
65 +
66 +
I spent a bit of time looking for a good python gui builder. Of the ones I found:
67 +
68 +
'''Boa Constructor ''' - My tool of choice.
69 +
70 +
'''WXGlade''' - I found this tool rather unstable, it crashed several times on my machine.
71 +
72 +
'''Python TK Gui Builder''' - A good tool, but its output uses the TK python library instead of the wxpython library.
73 +
74 +
=== Running a job ===
75 +
76 +
I created a small python module to help with running jobs.
77 +
78 +
From what I've seen of the GUIs, they help you with the layout and give you space to implement what happens on button presses.
79 +
80 +
So here is how you use my class:
81 +
82 +
1. Import it. (import runJob)
83 +
84 +
[[File(runJob.py)]]
85 +
86 +
2. In order to receive feedback from a running job, you need to implement two functions.
87 +
88 +
'''addText(self, text)''' This gives what your job would normally be outputting to the command line. Consider adding it to a noneditable text box.
89 +
90 +
'''updateGui(self, state, job):''' This function is called twice, once when the job starts and once when the job ends. You provide a job name when you initiate the function. The state will be "Start" when the job starts and "Finished" when the job finishes. If you want to make a button unusable while your job is running, use this.
91 +
92 +
3. If you want to run in a folder, use os.chdir() to navigate to the folder you want to run in.
93 +
94 +
4. To run your job, first create a new runJob class. It takes 3 arguments:
95 +
96 +
A list whose first element is the function you want to run, and whose remaining elements are the arguments to that function. So if you want to run "ls -al ./subfolder" you submit the list ["ls", "-al", "./subfolder"].
97 +
98 +
Second a name for your job. This will be sent back to you in the updateGui function.
99 +
100 +
The final argument should just be "self", so that the thread can call the update functions.
101 +
102 +
5. Call the start function of your newly created class and you are done.
103 +
104 +
As an example, here is some code from a simple example app I made to check whether the module worked. Note that this is only a small part of the larger app, and that the name of the OnButton1Button function was generated by the Gui builder.
105 +
106 +
{{{
107 +
def OnButton1Button(self, event):
108 +
#Creating a runscript
109 +
f = open("runScript.sh", "w")
110 +
f.write("#!/bin/bash \n")
111 +
f.write("touch ")
112 +
f.write(self.textCtrl1.GetValue())
113 +
f.close()
114 +
os.chmod("runScript.sh", 0744)
115 +
#Running the job
116 +
t = runJob(["./runScript.sh"], "ExampleJob" , self)
117 +
t.start()
118 +
event.Skip()
119 +
#Functions needed to display
120 +
def addText(self, text):
121 +
print text
122 +
def updateGui(self, state, job):
123 +
self.textCtrl2.SetValue(state)
124 +
print state, job
125 +
}}}