Exemple #1
0
 def refreshActivationMenu(self):
     menu = FreeCADGui.getMainWindow().menuBar().findChild(
         PySide.QtGui.QMenu, MenuName)
     if menu:
         mks = [mk for mk in machinekit.Instances() if mk.isValid()]
         ma = menu.findChild(PySide.QtGui.QMenu,
                             MachinekitCommandActivate.MenuText)
         actions = ma.actions()
         if mks:
             mkNames = [mk.name() for mk in mks]
             for action in actions:
                 name = action.text()
                 if name in mkNames:
                     mkNames.remove(name)
                     mk = [mk for mk in mks if mk.name() == name][0]
                     action.setEnabled(mk != MK)
                 else:
                     ma.removeAction(action)
             for name in mkNames:
                 mk = [mk for mk in mks if mk.name() == name][0]
                 action = PySide.QtGui.QAction(name, ma)
                 action.setEnabled(mk != MK)
                 PathLog.track(mk.name(), [s for s in mk.instance.endpoint])
                 action.triggered.connect(
                     lambda x=False, mk=mk: self.activate(mk))
                 ma.addAction(action)
         else:
             if 1 != len(actions) or actions[0].objectName(
             ) != MachinekitCommandActivateNone.__name__:
                 for action in actions:
                     ma.removeAction(action)
                 action = PySide.QtGui.QAction(
                     MachinekitCommandActivateNone.MenuText, ma)
                 action.setEnabled(False)
                 ma.addAction(action)
Exemple #2
0
 def saveSettings(self):
     import machinekit
     setHudPreferences(self.form.workCoordinates.isChecked(),
                       self.form.machineCoordinates.isChecked(),
                       self.form.fontSize.value(),
                       self.form.fontName.currentFont().family())
     for mk in machinekit.Instances():
         mk.preferencesUpdate.emit()
Exemple #3
0
def ActiveMK(setIfNone=False):
    if MK:
        return MK
    mks = [mk for mk in machinekit.Instances() if mk.isValid()]
    if 1 == len(mks):
        if setIfNone:
            SetMK(mks[0])
        return mks[0]
    return None
Exemple #4
0
 def saveSettings(self):
     '''Store preferences from the UI back to the model so they can be saved.'''
     import machinekit
     setGeneralPreferences(self.form.startOnLoad.isChecked(), self.form.addToPathWB.isChecked())
     setHudPreferences(self.form.workCoordinates.isChecked(), self.form.machineCoordinates.isChecked())
     setHudPreferencesFont(self.form.fontName.currentFont().family(), self.form.fontSize.value(), self.form.fontColorUnhomed.property('color'), self.form.fontColorHomed.property('color'))
     setHudPreferencesTool(self.form.toolShowShape.isChecked(), self.form.toolColorStopped.property('color'), self.form.toolColorSpinning.property('color'))
     for mk in machinekit.Instances():
         mk.preferencesUpdate.emit()
 def saveSettings(self):
     '''Store preferences from the UI back to the model so they can be saved.'''
     import machinekit
     servers = []
     for row in range(self.form.restServers.count()):
         s = self.form.restServers.item(row).text()
         if s and s != self.AdditionalItemLabel:
             servers.append(s)
     setGeneralPreferences(self.form.startOnLoad.isChecked(),
                           self.form.addToPathWB.isChecked(), servers)
     for mk in machinekit.Instances():
         mk.preferencesUpdate.emit()
Exemple #6
0
 def refreshComboWB(self):
     if 'PathWorkbench' in FreeCADGui.listWorkbenches():
         wb = FreeCADGui.getWorkbench('PathWorkbench')
         if hasattr(wb, '__Workbench__'):
             MachinekitPreferences.Setup()
             mks = {}
             for mk in [
                     mk for mk in machinekit.Instances() if mk.isValid()
             ]:
                 if self.comboTB.get(mk) is None:
                     name = "%s_%d" % (MachinekitCommandCombo.__name__,
                                       self.comboID)
                     cmd = MachinekitCommandCombo(mk)
                     self._addCommand(name, cmd)
                     mks[mk] = (name, cmd)
                     self.comboID = self.comboID + 1
                 else:
                     mks[mk] = self.comboTB[mk]
             tb = FreeCADGui.getMainWindow().findChild(
                 PySide.QtGui.QToolBar, 'MachinekitCombo')
             if tb:
                 # first remove all tool buttons which are no longer valid
                 for mk in [mk for mk in self.comboTB if not mk in mks]:
                     actions = tb.actions()
                     for action in actions:
                         if action.text() == mk.name():
                             PathLog.track('removing', mk.name())
                             tb.removeAction(action)
                 for mk in [mk for mk in mks if not mk in self.comboTB]:
                     icon = machinekit.IconResource('machinekiticon.svg')
                     PathLog.track('adding', mk.name())
                     tb.addAction(icon, mk.name(), mks[mk][1].Activated)
             elif mks:
                 if 'PathWorkbench' == FreeCADGui.activeWorkbench().name():
                     PathLog.track('createToolbar')
                     tb = PySide.QtGui.QToolBar()
                     tb.setObjectName('MachinekitCombo')
                     for mk in [mk for mk in mks if not mk in self.comboTB]:
                         icon = machinekit.IconResource(
                             'machinekiticon.svg')
                         PathLog.track('adding+', mk.name(), icon)
                         tb.addAction(icon, mk.name(), mks[mk][1].Activated)
                     FreeCADGui.getMainWindow().addToolBar(tb)
                 tools = [mks[mk][0] for mk in mks]
                 PathLog.track('appendToolbar', tools)
                 wb.appendToolbar('MachinekitCombo', tools)
             self.comboTB = mks
         else:
             PathLog.track('no __Workbench__')
 def tick(self):
     '''Periodically called by the timer to updated menus and tool bars depending on
     discovered and lost MK instances.'''
     self.holdoff = self.holdoff - 1
     if machinekit.Instances() or self.holdoff < 1:
         machinekit._update()
     if self.holdoff < 1:
         active = [cmd.IsActive() for cmd in self.commands]
         def aString(activation):
             return '.'.join(['1' if a else '0' for a in activation])
         if self.active != active:
             PathLog.info("Command activation changed from %s to %s" % (aString(self.active), aString(active)))
             FreeCADGui.updateCommands()
             self.active = active
         self.refreshActivationMenu()
         if MachinekitPreferences.addToPathWB():
             self.refreshComboWB()
         self.holdoff = MachinekitUiHoldoff
 def saveSettings(self):
     '''Store preferences from the UI back to the model so they can be saved.'''
     import machinekit
     setHudPreferences(self.form.workCoordinates.isChecked(),
                       self.form.machineCoordinates.isChecked())
     setHudPreferencesFont(self.form.fontName.currentFont().family(),
                           self.form.fontSize.value(),
                           self.form.fontColorUnhomed.property('color'),
                           self.form.fontColorHomed.property('color'))
     setHudPreferencesTool(self.form.toolShowShape.isChecked(),
                           self.form.toolColorStopped.property('color'),
                           self.form.toolColorSpinning.property('color'))
     setHudPreferencesProgr(self.form.progrHide.isChecked(),
                            self.form.progrBar.isChecked(),
                            self.form.progrPercent.isChecked(),
                            self.form.progrElapsed.isChecked(),
                            self.form.progrRemaining.isChecked(),
                            self.form.progrTotal.isChecked(),
                            self.form.progrFontName.currentFont().family(),
                            self.form.progrFontSize.value(),
                            self.form.progrColor.property('color'))
     for mk in machinekit.Instances():
         mk.preferencesUpdate.emit()