gui stuff

This commit is contained in:
looooo
2015-06-23 06:48:00 +02:00
parent 5fc6b813e3
commit 97df5a8077
2 changed files with 50 additions and 26 deletions

View File

@@ -20,7 +20,7 @@
import os
from PySide import QtGui
from PySide import QtGui, QtCore
freecad_found = True
@@ -37,8 +37,22 @@ if freecad_found:
createCycloidGear, createBevelGear, createInvoluteRack)
class gearToolBox(object):
def __init__(self):
mw = Gui.getMainWindow()
[
self.involuteGearAction,
self.involuteRackAction,
self.bevelGearAction,
self.cycloidGearAction] = [None, None, None, None]
self.add_gear_wb()
mw.workbenchActivated.connect(self.add_gear_wb)
timer = mw.findChild(QtCore.QTimer)
timer.connect(timer, QtCore.SIGNAL("timeout()"), self.checkDocument)
def add_gear_wb(*args):
def add_gear_wb(self, *args):
print("Workbench_changed")
try:
wb = Gui.activeWorkbench()
@@ -60,30 +74,41 @@ if freecad_found:
# create commands
icon = QtGui.QIcon(this_path + "/Resources/icons/involutegear.svg")
involuteGearAction = QtGui.QAction(icon, "involute gear", App.gear.gear_toolbar)
involuteGearAction.setObjectName("GearToolbar")
involuteGearAction.triggered.connect(createInvoluteGear)
self.involuteGearAction = QtGui.QAction(icon, "involute gear", App.gear.gear_toolbar)
self.involuteGearAction.setObjectName("GearToolbar")
self.involuteGearAction.triggered.connect(createInvoluteGear)
icon = QtGui.QIcon(this_path + "/Resources/icons/involuterack.svg")
involuteRackAction = QtGui.QAction(icon, "involute rack", App.gear.gear_toolbar)
involuteRackAction.setObjectName("GearToolbar")
involuteRackAction.triggered.connect(createInvoluteRack)
self.involuteRackAction = QtGui.QAction(icon, "involute rack", App.gear.gear_toolbar)
self.involuteRackAction.setObjectName("GearToolbar")
self.involuteRackAction.triggered.connect(createInvoluteRack)
icon = QtGui.QIcon(this_path + "/Resources/icons/cycloidegear.svg")
cycloidGearAction = QtGui.QAction(icon, "cycloid gear", App.gear.gear_toolbar)
cycloidGearAction.setObjectName("GearToolbar")
cycloidGearAction.triggered.connect(createCycloidGear)
self.cycloidGearAction = QtGui.QAction(icon, "cycloid gear", App.gear.gear_toolbar)
self.cycloidGearAction.setObjectName("GearToolbar")
self.cycloidGearAction.triggered.connect(createCycloidGear)
icon = QtGui.QIcon(this_path + "/Resources/icons/bevelgear.svg")
bevelGearAction = QtGui.QAction(icon, "bevel gear", App.gear.gear_toolbar)
bevelGearAction.setObjectName("GearToolbar")
bevelGearAction.triggered.connect(createBevelGear)
self.bevelGearAction = QtGui.QAction(icon, "bevel gear", App.gear.gear_toolbar)
self.bevelGearAction.setObjectName("GearToolbar")
self.bevelGearAction.triggered.connect(createBevelGear)
temp1 = App.gear.gear_toolbar.addAction(self.involuteGearAction)
temp2 = App.gear.gear_toolbar.addAction(self.involuteRackAction)
temp3 = App.gear.gear_toolbar.addAction(self.cycloidGearAction)
temp4 = App.gear.gear_toolbar.addAction(self.bevelGearAction)
self.checkDocument()
temp1 = App.gear.gear_toolbar.addAction(involuteGearAction)
temp2 = App.gear.gear_toolbar.addAction(involuteRackAction)
temp3 = App.gear.gear_toolbar.addAction(cycloidGearAction)
temp4 = App.gear.gear_toolbar.addAction(bevelGearAction)
def checkDocument(self, *args):
print("hello")
enable = False
if App.ActiveDocument:
enable = True
print(App.ActiveDocument)
for action in [self.involuteGearAction, self.involuteRackAction,
self.bevelGearAction, self.cycloidGearAction]:
if action:
action.setEnabled(enable)
mw = Gui.getMainWindow()
add_gear_wb()
mw.workbenchActivated.connect(add_gear_wb)
if freecad_found:
a = gearToolBox()

View File

@@ -1,6 +1,7 @@
import sys
import os
from distutils.core import setup
def check_path(path):
_dir = os.path.dirname(path)
@@ -16,8 +17,7 @@ def setup_freecad():
except:
print("FreeCad is not found!!!")
return
user_path = FreeCAD.getUserAppDataDir()
fileName = user_path + "Mod/start_up/InitGui.py"
fileName = check_path("/usr/lib/freecad/Mod/start_up/InitGui.py")
try:
with open(fileName, "r") as startFile:
lines = startFile.readlines()
@@ -28,19 +28,18 @@ def setup_freecad():
start_file_exists = False
if start_file_exists:
for line in lines:
print(line)
if "import freecad_gear" in line:
start_input_exists = True
break
else:
start_input_exists = False
else:
start_input_exists = False
print(fileName)
if not start_input_exists:
with open(fileName, "a") as start_file:
start_file.write("\nimport freecad_gear")
from distutils.core import setup
setup(
name = 'freecad_gear',
packages = ['freecad_gear'],