Exemple #1
0
def show_gencalhelp(parent):
    "Create HelpWindow; called from Idle Help event handler."
    #filename = rejoin(abspath(dirname(__file__)), 'help.html')
    filename = resource_path('help.html')
    if not isfile(filename):
        # try copy_strip, present message
        return
    HelpWindow(parent, filename, 'Gencal Help')
Exemple #2
0
 def CreateWidgets(self):
     self['borderwidth'] = 0
     release = version[:version.index(' ')]
     '''
     logofn = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                           "Icons", "gencal_48.gif")
     '''
     logofn = resource_path('Icons/gencal_48.gif')
     self.picture = PhotoImage(master=self._root(), file=logofn)
     self.frameBg = frameBg = Frame(self, bg=self.bg, borderwidth=0)
     frameBg.grid(sticky='nsew')
     labelTitle = Label(frameBg,
                        text='Gencal ' + G.Version,
                        fg=self.fg,
                        bg=self.bg,
                        font=('courier', 24, 'bold'))
     labelTitle.grid(row=0, column=1, sticky=W, padx=10, pady=[10, 0])
     labelPicture = Label(frameBg, image=self.picture, bg=self.bg)
     labelPicture.grid(row=0,
                       column=0,
                       sticky=NE,
                       rowspan=2,
                       padx=10,
                       pady=10)
     byline = "Generate Calabration Gcode"
     labelDesc = Label(frameBg,
                       text=byline,
                       justify=LEFT,
                       fg=self.fg,
                       bg=self.bg)
     labelDesc.grid(row=1,
                    column=1,
                    sticky=W,
                    columnspan=3,
                    padx=10,
                    pady=[0, 20])
     # labelEmail = Label(frameBg, text='email:  [email protected]',
     #                    justify=LEFT, fg=self.fg, bg=self.bg)
     # labelEmail.grid(row=6, column=1, columnspan=2,
     #                 sticky=W, padx=10, pady=0)
     # labelWWW = Label(frameBg, text='https://docs.python.org/' +
     #                  version[:3] + '/library/idle.html',
     #                  justify=LEFT, fg=self.fg, bg=self.bg)
     #labelWWW.grid(row=7, column=1, columnspan=2, sticky=W, padx=10, pady=0)
     tkVer = self.tk.call('info', 'patchlevel')
     labelVersion = Label(frameBg,
                          text='Python ' + release + '     (with Tk ' +
                          tkVer + ')',
                          fg=self.fg,
                          bg=self.bg)
     labelVersion.grid(row=4, column=1, sticky=W, padx=10, pady=[0, 5])
     self.morelink = Label(frameBg,
                           text='More...',
                           fg='blue',
                           bg=self.bg,
                           cursor='hand2')
     self.morelink.grid(column=0, columnspan=3, pady=10, padx=10, sticky=E)
     self.morelink.bind('<1>', self.showMore)
Exemple #3
0
 def load_from_file(self, key, filename, encoding=None):
     #fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
     fn = resource_path(filename)
     try:
         with open(fn, 'r', encoding=encoding) as file:
             contents = file.read()
     except IOError:
         pass
     else:
         self.info.append((key, contents))
Exemple #4
0
def gen_gcode():
    global preamble
    global postamble
    global units
    global kerfsize
    global commGap

    #-- Cut
    global incCut
    global cutPower
    global cutFeed
    global cutXsize
    global cutYsize
    global cutPasses

    #-- Engrave
    global incEngrave
    global engraveFeed
    global engraveMaxP
    global engraveMinP
    global engraveNumPlev
    global engraveDistI
    global engraveBarWidth
    global engraveIdxPwr
    global engraveIdxMax

    #-- Picture
    global incPicture
    global picPower
    global picFeed
    global picTestsep
    global picSDsep
    global picSDnum
    global picDDsep
    global picDDnum
    global picDashWidth
    global picDashsep
    global picIncDithered
    global picDitheredFN

    #gcode[:] = [] #clear current gcode
    del G.gcode[:]

    # Gcode starting comments and preamble
    G.gcode.append('; Gencal_gcode generate calibration code')
    G.gcode.append('; kerfsize = ' + ls_comm_kerfEntry.get())
    G.gcode.append('; PREAMBLE')
    G.gcode.extend(preamble)

    if units == "G21":
        tmp = '; set units to mm'
    else:
        tmp = '; set units to inches'
    G.gcode.append(tmp)
    G.gcode.append(units)

    curX = 0.0
    curY = 0.0
    curPwr = 0
    i = 0
    k = 0

    #-- Cut gcode
    if incCut.get() == 1:
        G.gcode.append('; Cut calibration box size ' + cutXsize.get() + ' x ' +
                       cutYsize.get())
        G.gcode.append('G1 F' + cutFeed.get() + ' ;set feed rate')
        G.gcode.append('M04 S' + cutPower.get() +
                       ' ;Turn laser on and set power')
        # Cut box
        while i < float(cutPasses.get()):
            i += 1
            G.gcode.append(';Pass ' + str(i))
            G.gcode.append('G1 X' + strXY(curX) + 'Y' + strXY(curY))
            curY += float(cutYsize.get())
            G.gcode.append('G1 X' + strXY(curX) + 'Y' + strXY(curY))
            curX += float(cutXsize.get())
            G.gcode.append('G1 X' + strXY(curX) + 'Y' + str(curY))
            curY -= float(cutYsize.get())
            G.gcode.append('G1 X' + str(curX) + 'Y' + strXY(curY))
            curX -= float(cutXsize.get())
            G.gcode.append('G1 X' + strXY(curX) + 'Y' + strXY(curY))

        G.gcode.append('M05 S0 ;Turn Laser off and set power to 0')

        #-- move to next starting point
        curY += float(cutYsize.get()) + float(commGap.get())
        G.gcode.append('G0 X' + strXY(curX) + 'Y' + strXY(curY))
        G.gcode.append(';End of Cut calibration gcode')

    #-- Engrave gcode
    if incEngrave.get() == 1:
        G.gcode.append('; Engrave calibration')
        G.gcode.append('G1 F' + engraveFeed.get())
        #Loop drawing the lines of the engrave bar
        lstline = curY + float(engraveBarWidth.get())
        pwrinc = (float(engraveMaxP.get()) - float(engraveMinP.get())) / float(
            engraveNumPlev.get())

        while curY <= lstline:
            curX = 0
            curPwr = float(engraveMinP.get())
            G.gcode.append('M04 S' + str(curPwr))
            k = float(engraveNumPlev.get()) - 1
            while k > 0:
                curX += float(engraveDistI.get())
                curPwr += pwrinc
                G.gcode.append('G1 X' + strXY(curX) + 'Y' + strXY(curY) +
                               ' S' + str(int(curPwr)))
                k -= 1

            #last segment at Max power
            G.gcode.append('M04 S' + engraveMaxP.get())
            G.gcode.append('G1 X' + strXY(curX + float(engraveDistI.get())) +
                           'Y' + strXY(curY))

            #return X and increment to next Y for next line
            G.gcode.append('M05 S0')  #Turn laser off
            curX = 0
            curY += float(kerfsize.get())
            G.gcode.append('G0 X' + strXY(curX) + 'Y' + strXY(curY))

        # make indexing marks where power levels changed
        curY += float(kerfsize.get())
        G.gcode.append('; engrave make power index marks')
        G.gcode.append('G0 X' + strXY(curX) + 'Y' + strXY(curY))
        G.gcode.append('M04 S' + engraveIdxPwr.get())
        k = 0

        while k <= int(engraveNumPlev.get()):
            i = int(engraveIdxMax.get())
            if (k % 5) != 0:
                i /= 2

            G.gcode.append('G1 X' + str(curX) + 'Y' + strXY(curY + i))
            curX += float(engraveDistI.get())
            G.gcode.append('G0 X' + str(curX) + 'Y' + str(curY))
            k += 1

        G.gcode.append('M05 S0')  #Turn Laser off
        #-- move to next starting point
        curX = 0.0
        curY += float(engraveIdxMax.get()) + float(commGap.get())
        G.gcode.append('G0 X' + strXY(curX) + 'Y' + strXY(curY))

        G.gcode.append('M05 S0 ;Turn Laser off and set power to 0')

        #-- move to next starting point
        curY += float(cutYsize.get()) + float(commGap.get())
        G.gcode.append('G0 X' + strXY(curX) + 'Y' + strXY(curY))
        G.gcode.append(';End of Engrave calibration gcode')

    #-- Picture gcode
    if incPicture.get() == 1:
        G.gcode.append('; Picture calibration')
        G.gcode.append('G0 F' + picFeed.get())
        G.gcode.append('M03 S0')

        # Create a single row of dots
        G.gcode.append('; Picture single row of dots')
        i = 0
        G.gcode.append('G1')
        while i <= int(picSDnum.get()):
            G.gcode.append('X' + strXY(curX) + ' S' + picPower.get())
            curX += float(picSDsep.get())
            G.gcode.append('X' + strXY(curX) + 'S0')
            curX += float(kerfsize.get())
            i += 1

        curX = 0
        curY += float(picTestsep.get())
        G.gcode.append('G0 X' + strXY(curX) + 'Y' + strXY(curY))

        # Create a double row of dots
        G.gcode.append('; Picture double row of dots')
        i = 0
        while i <= int(picDDnum.get()):
            G.gcode.append('G1 X' + strXY(curX) + ' S' + picPower.get())
            curX += float(kerfsize.get())
            G.gcode.append('X' + strXY(curX) + ' S0')
            curX += float(picSDsep.get())
            i += 1

        curX = 0
        curY += float(kerfsize.get())
        G.gcode.append('G0 X' + strXY(curX) + 'Y' + strXY(curY))
        i = 0
        while i <= int(picDDnum.get()):
            G.gcode.append('G1 X' + strXY(curX) + ' S' + picPower.get())
            curX += float(kerfsize.get())
            G.gcode.append('X' + strXY(curX) + ' S0')
            curX += float(picSDsep.get())
            i += 1

        curX = 0
        curY += float(picTestsep.get())
        G.gcode.append('G0 X' + strXY(curX) + 'Y' + strXY(curY))

        # Create _ _ _ . . _ _ _ Pattern
        G.gcode.append('; Picture _ _ _ . . _ _ _ Pattern')

        dashwidth = float(kerfsize.get()) * float(picDashWidth.get())
        dashsep = float(picDashsep.get())
        # Dash 1
        G.gcode.append(';Dash 1')
        G.gcode.append('G1 X' + strXY(curX) + ' S0')
        curX += dashwidth
        G.gcode.append('X' + strXY(curX) + ' S' + picPower.get())
        curX += dashsep
        # Dash 2
        G.gcode.append(';Dash 2')
        G.gcode.append('X' + strXY(curX) + ' S0')
        curX += dashwidth
        G.gcode.append('X' + strXY(curX) + ' S' + picPower.get())
        curX += dashsep
        # Dash 3
        G.gcode.append(';Dash 3')
        G.gcode.append('X' + strXY(curX) + ' S0')
        curX += dashwidth
        G.gcode.append('X' + strXY(curX) + ' S' + picPower.get())
        curX += dashsep
        # Dot 1
        G.gcode.append(';Dot 1')
        G.gcode.append('X' + strXY(curX) + ' S0')
        curX += float(kerfsize.get())
        G.gcode.append('X' + strXY(curX) + ' S' + picPower.get())
        curX += float(picSDsep.get())
        # Dot 2
        G.gcode.append(';Dot 2')
        G.gcode.append('X' + strXY(curX) + ' S0')
        curX += float(kerfsize.get())
        G.gcode.append('X' + strXY(curX) + ' S' + picPower.get())
        curX += dashsep
        # Dash 4
        G.gcode.append(';Dash 4')
        G.gcode.append('X' + strXY(curX) + ' S0')
        curX += dashwidth
        G.gcode.append('X' + strXY(curX) + ' S' + picPower.get())
        curX += dashsep
        # Dash 5
        G.gcode.append(';Dash 5')
        G.gcode.append('X' + strXY(curX) + ' S0')
        curX += dashwidth
        G.gcode.append('X' + strXY(curX) + ' S' + picPower.get())
        curX += dashsep
        # Dash 6
        G.gcode.append(';Dash 6')
        G.gcode.append('X' + strXY(curX) + 'S0')
        curX += dashwidth
        G.gcode.append('X' + strXY(curX) + ' S' + picPower.get())
        G.gcode.append('G0 S0')

        #-- move to next starting point
        curX = 0
        curY += float(commGap.get())
        G.gcode.append('G0 X' + str(curX) + 'Y' + str(curY))

        #-- Dithered Image
        if picIncDithered.get() == 1:
            G.gcode.append("; Including Dithered Image Gcode")
            G.gcode.append("G92 X0 Y0 ;use current position as origin")
            with open(resource_path(picDitheredFN.get()), 'r') as f:
                picBuf = f.readlines()

            for line in picBuf:
                line = line.rstrip('\r\n')
                if len(line) != 0:
                    line = line.replace('Feed', 'F' + picFeed.get())
                    line = line.replace('Spwr', 'S' + picPower.get())
                    G.gcode.append(line)

    # Gcode ending comments and postamble
    G.gcode.append('; POSTAMBLE')
    G.gcode.extend(postamble)

    #-- update Gcode in the right-side Listbox
    rs_lstbox.delete(0, END)
    for line in G.gcode:
        rs_lstbox.insert(END, line)
    return TRUE
Exemple #5
0
import globals as G
from globals import resource_path
from ScrollableFrame import VerticalScrolledFrame
from MainWindow import Window

#-------------------------------------------------------------
#   Start of GUI setup
mw = tk.Tk()
mw.geometry("800x600")
app = Window(mw)

# set application icon

icondir = os.path.join(os.path.dirname(__file__), 'Icons')
if system() == 'Windows':
    iconfile = resource_path(os.path.join(icondir, 'gencal.ico'))
    mw.wm_iconbitmap(default=iconfile)
elif TkVersion >= 8.5:
    ext = '.png' if TkVersion >= 8.6 else '.gif'
    iconfiles = [
        resource_path(os.path.join(icondir, 'gencal_%d%s' % (size, ext)))
        for size in (16, 32, 48)
    ]
    icons = [tk.PhotoImage(file=iconfile) for iconfile in iconfiles]
    mw.wm_iconphoto(True, *icons)

#---- Global variables and there defaults
preamble = [
    ';make sure laser is off', 'M05 S0', ';use absolute prgraming XY', 'G90',
    ';set dwell to 0', 'G4 P0'
]