I'm using wxFormBuilder to write a series of GUI applications. So far it has worked wonderfully, but the documentation on their homepage is a broken link.
What I'd like to do is combine my programs into one program, each as a different tab in a wxNotebook. However, I can only get wxFormBuilder to generate one class, the class for my frame. Ideally, what I'd like is for each panel to be its own class, so then I can override each class individually, and not be stuck with one giant class which contains all the event handlers for 5 different applications.
Is this possible with wxFormBuilder? Is there a different program which would allow me to do this more easily?
I'm open to other wx programs, but can't departure from Python, and I'd really rather not have to write the wx code by hand.
Some people like wxGlade, Boa Constructor (old) or XRCed (included with wxPython). You might experiment with those. I've heard good things about wxFormBuilder, so I'm a little surprised it doesn't have that capability. Here are some links: http://www.oneminutepython.com/
http://sturlamolden.blogspot.com/2008/03/howto-using-wxformbuilder-with-wxpython.html
http://www.blog.pythonlibrary.org/2010/05/11/wxpython-an-introduction-to-xrc/
Hope that helps a little.
Related
I have a large amount (about 50) of SubVIs including beyond some usage specific code a small number of GUI elements (mostly about 2: input and output).
My goal is to reuse those VIs without creating a huge mess in a new ('main') VI and collect all GUI elements on a GUI common pane a user shall finally interact with.
I tried to use the Open VI Function, 'VI Reference' and 'Run SubVi' like in the examples to create references for subpanels, but the subpanel ui is only shown when the program is run and the amount of additional blocks is mostly bigger than the code in the respective SubVI.
The SubVIs should be loaded only once to construct the main User Interface.
In addition: In this tutorial they create a subVI and recreate GUI elements that are already defined in the subVI.
I assume this behaves like passing arguments as in a text based programming languages like the snippet:
def main_vi(x, y, z): # inputs x, y, z
s = sub_vi(x, y, z)
return s # output s
Is this necessary, or can the subvi's GUI controls directly be reused from outside?
Is it possible to use the subVIs inside of an "main" VI that includes everything and maps everything to a common UI using tabs?
Or is it better to copy everything to the main VI, i.e. no code reuse at all?
Thanks in advance!
Depending on the functionality you are going for, yo may want o look into XControls. This would allow you to encapsulate your functionality into a reusable control that could be used on a main panel without making the main panel very messy.
Large UI's can be a pain (pun with pane not intended), especially if there are a lot of controls and indicators. There are some useful ways to break UIs into modular components. XControls are one of those but I don't recommend them due to their unpredictable behaviors. Instead look into working with Sub Panels. There is a great toolkit for this from a company called Moore Good Ideas (or MGI). More info can be found on their website here.
There is also a better alternative to XControls, called QControls. More info on them can be found here.
In general, though, you might want to look into a more modular framework. More info on Frameworks can be found here.
I need to drive a testbench with labview.
The test scenarios are written in a languages that can be automaticaly translated into labview diagrams.
Is this an API that allow to create "labview diagrams" from another software ? or with labview itself ?
I agree that LabVIEW scripting is one approach, but let me throw out another option.
If you are planning to do a one time migration from your test code to LabVIEW than scripting is great, but if you plan to regularly update your test code (because it's easier to use the "test" language than LabVIEW) than it could become quite painful to constantly perform the migration every time your test code has changed.
I've had great success with simply putting my state machine inside of a for loop and then reading in "commands" from a text file that was generated using my "test" language (see pic).
For example, to do an IV sweep my text file might say something like:
SourceV, 5
ReadI
Wait, 1
SourceV, 6
ReadI
This image is greatly simplified - I'm not using a state machine and I don't show how to use "parameters," but I can provide a more comprehensive example if needed. Again, I've had great success doing this with around 30 "commands" controlling multiple instruments and then I generated the text input using VBA or Python.
It's called LabVIEW scripting. You will need to enable an option in the VI Server page in the options dialog to see the relevant features.
A few things to note:
Scripting isn't complicated, but you do need to be aware of how LV code is built.
While scripting is public, it was initially created as an internal tool. There are still corners of it which are incomplete.
Scripting code can be tedious. If you can get away with it, try creating templates of code.
NI has something called CodeGen, which I believe are a series of functions which make some scripting easier, although I never really looked into it.
I have certain Modules that I would like to setup to be referencable by multiple solutions, as the code always behaves in basically the same manner (ex. code for logging errors). They make no sense as classes, so it seems like a class library is out; and I haven't seen any other suggestions for sharing code between solutions.
So I'm left wondering what would be the best way to create one thing that I can just use across multiple solutions to avoid having to rewrite the same code?
It sounds like a class library is exactly what you want. Build it, reference it within each solution, and code against it. One source, multiple solutions running off that code.
You could also implement the functionality into a separate piece such as an API. This is dependent on the function of the code obviously, but logging errors is a good use case.
I'm trying to make a new UI to visualize my Alloy instances. I've got an A4Solution and have been successful in extracting atoms, relations, checking atom signatures BUT I can't seem to understand how to project the instance on some sig.
I've noticed that I can try to use the edu.mit.csail.sdg.alloy4viz.AlloyInstance, I've got options to project there, but that'd imply in starting over, from a different angle.
Would that be the way to go? I'd prefer to extract that from the A4Solution object.
Thanks
You might want to look at the edu.mit.csail.sdg.alloy4viz.StaticProjector class and its project methods---that's how the Alloy Visualizer implements projections. If your visualization uses the edu.mit.csail.sdg.alloy4viz.AlloyModel class, you should be able to reuse the existing code in StaticProjector; from your post it seems, however, that you'd prefer not use any of the alloy4viz classes, in which case it should not be too difficult to understand how StaticProjector works and reapply the same ideas to your project. Or you could convert an A4Solution object to an AlloyInstance[1] and build your visualizer around the alloy4viz classes, which, in my opinion, would be a good way to go about your project.
[1] something like:
a4sol.writeXML("instance.xml")
AlloyInstance inst = StaticInstanceReader.parseInstance(new File("instance.xml"));
I'm creating a plugin in Quantum GIS that is using Postgres as the back end and QT Designer to make the GUI. I'm using psycopg2 to run scripts in the database and even fetch results of queries to set the values of labels in the GUI. This stuff is working fine for me.
What I would like to do now after some queries are run by clicking a 'calculate' button is for the resulting table to be shown in the plugin as a TableView. I know there widget exists expressly for the purpose of viewing tables but I can't quite figure out how to go about it. I'm not sure if I should be using psycopg2 or PySide, since most examples I have seen online use the latter.
I am wondering if someone can tell me which between psycopg2 and PySide should be used to create the TableView. Second, I am wondering what the 'signal' should be to the TableView widget to display the results of a query in Postgres. Lastly, is anyone can offer some instruction as to how to set up the code it would be hugely appreciated!
Cheers,
Roman
I've gone ahead and tried following the PyQt documentation, but as it's provided in C++ and I'm only a beginner programmer using Python I'm not sure if I've caught all the necessary amendments to the code syntax. Anyways, this is what I have so far:
db = QSqlDatabase.addDatabase("database")
db.setHostName("localhost")
db.setUserName("postgres")
db.setPassword("password")
#Not sure what to do to set the connection. The C++ documentation says to put "bool ok = db.open();"
model = QSqlQueryModel()
model.setQuery("SELECT name, density, deveff FROM public." +str(filename)+ "_rezoning ORDER BY gid;")
model.setHeaderData(0, Qt.Horizontal, "Name")
model.setHeaderData(1, Qt.Horizontal, "Density")
model.setHeaderData(2, Qt.Horizontal, "DevEff")
view = QTableView()
view.setModel(model)
view.show()
What happens when I click the button in my GUI to run the calculations, a small blank QGIS window briefly flashes and goes away. At least I'm not getting an error, but it's obviously not complete. I assume part of the issue is the connection to the database that is missing and that I do not know how to set. The other issue is that I would like this to show in the tableView widget in the GUI, but I'm not sure how to specify this...
Any further tips? I really appreciate it.
Roman
If you're planning to use Qt widgets and models, PySide (PyQt, or plain Qt/C++) is the way to go.
With bare psycopg2 you'll have a lot more work to do, and you'll need to implement your own model in order to leverage Qt's model/view classes. This is simply not the Qt way of doing things. PySide (and PyQt) has it own means to connect to a supported database, there's no need for pure Python database adapters like psycopg2. It uses the underlying libqt4-sql library (C++) and the installed plugins (QPSQL, QMYSQL, QSQLITE, etc).
Essentially you need to:
Connect to a database.
Instantiate a model (QSqlQueryModel, QSqlTableModel or a custom QAbstractTableModel derived class)
Attach that model to a view (ie. QTableView).
Take a look at the PySide QtSql Documentation and the PyQt documentation to get an idea. They're mostly compatible/interchangeable, but at a glance I see that the PyQt documentation looks more complete.
EDIT (after your edit):
A Qt GUI application requires an event loop to run, and that's provided by a QApplication instance. Before going any further with the specifics of your app, take the time to understand a few basic concepts first. Here's a nice Getting Started with PyQt Guide.