project structure and database

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
papshoika
Posts: 6
Joined: Tue May 27, 2014 5:08 pm

project structure and database

Postby papshoika » Tue May 27, 2014 5:30 pm

Hello for everyone!
My English is bad, I'm new here, but I hope you understand me.
I am a student. To solve my problem, I decided to create a workbench.
I have 3 questions:
1. What should be a structure of module?
I have a few finished pieces of code with the GUI (PyQt). I looked through the code in arch module, but do not quite understand how my pieces have to be arranged.
2. Achievements I need to store in the database. Database file should be placed in the folder of the module? Could this become a problem?
3. How to add commands to the context menu? :)
I would be grateful for an answer or links to the information I needed.
User avatar
cblt2l
Posts: 155
Joined: Sat May 15, 2010 3:59 am

Re: project structure and database

Postby cblt2l » Tue May 27, 2014 6:17 pm

Check here:
http://freecadweb.org/wiki/index.php?ti ... e_Creation

And:
https://github.com/FreeCAD/FreeCAD_sf_m ... platePyMod

Those helped me a lot in understanding how the workbench modules function.
papshoika
Posts: 6
Joined: Tue May 27, 2014 5:08 pm

Re: project structure and database

Postby papshoika » Tue May 27, 2014 9:02 pm

TemplatePyMod just what I need. Thank you!
papshoika
Posts: 6
Joined: Tue May 27, 2014 5:08 pm

encoding and QDialogs

Postby papshoika » Tue Jun 03, 2014 11:00 am

I have two more question.
1. I I noticed strange behavior dialogues inside my widget. When I run it separately - dialog works. Inside freeCAD - no. Does FreeCAD puts any restrictions?
this is my code:

Code: Select all

...
        QtCore.QObject.connect(self.SaveBtn, QtCore.SIGNAL(_fromUtf8("clicked()")), self.saveFile)
...
def saveFile(self):
        filename = QtGui.QFileDialog.getSaveFileName(None, 'Save File', os.getenv('HOME'))
        f = open(filename, 'w')
        filedata = self.textEdit.toPlainText()
        f.write(filedata)
        f.close()
...
app = QtGui.QApplication
FCmw = app.activeWindow() # I also tried mw = FreeCADGui.getMainWindow(), but it couses name error 
redactor = QtGui.QDockWidget()
redactor.ui = my_ui()
redactor.ui.setupUi(redactor) # setup the ui
FCmw.addDockWidget(QtCore.Qt.RightDockWidgetArea, redactor)
2. And encoding problem. ToolTip for my tools.py file doesn't work with cyrillic symbols.
f1.png
f1.png (2.04 KiB) Viewed 2105 times
I used getpreferredencoding in console and saw it was ascii. I changed locale end now
>>> locale.getpreferredencoding()
'cp1251'
but it still doesn't work. But when i change # -*- coding: utf-8 -*- to other coding symbols are also changing, but not the ones that I need.
Ui from QtDesigner works ok.
Attachments
f2.PNG
f2.PNG (1.01 KiB) Viewed 2105 times
User avatar
yorik
Site Admin
Posts: 12148
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

Re: project structure and database

Postby yorik » Tue Jun 03, 2014 1:48 pm

It is hard to know what is wrong, but normally it should work. FreeCAD dialogs usually can display non-ascii charaters without problems. Maybe make sure everything is always utf-8? It's the best way to avoid encoding problems... In any case, if your dialog file is encoded in utf-8 your qt preferred encoding inside freecad should also be utf-8, I think.
papshoika
Posts: 6
Joined: Tue May 27, 2014 5:08 pm

Re: project structure and database

Postby papshoika » Tue Jun 03, 2014 2:14 pm

yorik wrote:... Maybe make sure everything is always utf-8?
All my python files start with # -*- coding: utf-8 -*-. That should be enough for it, yes?
Maybe this is my Windows 7 problem. Thank you!