Welcome To Our Shell

Mister Spy & Souheyl Bypass Shell

Current Path : /home/ift/52_procpy/dataninja/

Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
Upload File :
Current File : //home/ift/52_procpy/dataninja/procapp.py

#  -*- coding: utf-8 -*-

import os,re,sys,procpy

try:
#    import Tables
    import tkinter
    import tkinter.ttk
except:
    import pip
#    pip.main(["install","Tables"])
#    pip.main(["install","tkinter"])
    pip.main(["install","pyttk"])
    pip.main(["install","canvasvg"])
    import tkinter
    import tkinter.ttk

import tkinter.filedialog
import procpy.graphproc
import procpy.storeproc

#**************************************************************************

class Procapp (object):

    def __init__ (self,app,filename=None,dbh={},dbtable=""):
    
        self.app     = app
        self.dbh     = dbh
        self.dbtable = dbtable
        
        self.mainmenu = tkinter.Menu(self.app)
        self.filemenu = tkinter.Menu(self.mainmenu,tearoff=0)
        self.mainmenu.add_cascade(label="File",menu=self.filemenu)
        self.filemenu.add_command(label="New",command=lambda: self.fileopen("untitled.py"))
        self.filemenu.add_command(label="Open",command=self.fileopen)
        self.filemenu.add_command(label="Save",command=self.filesave)
        self.app.bind('<Control-s>', lambda key: self.filesave)
        self.filemenu.add_command(label="Save As",command=self.filesaveas)
        self.filemenu.add_command(label="Export SVG",command=self.savesvg)
        self.filemenu.add_command(label="Quit",command=self.beenden)

#        self.editmenu     = Tkinter.Menu(self.mainmenu,tearoff=0)
#        self.mainmenu.add_cascade(label="Edit",menu=self.editmenu)
#        self.editmenu.add_command(label="Undo (Ctrl+Z)"      ,state="disabled")
#        self.editmenu.add_command(label="Edit Block (Ctrl+E)",state="disabled")
#        self.editmenu.entryconfig(0,state="disabled")

        self.viewmenu     = tkinter.Menu(self.mainmenu,tearoff=0)
        self.mainmenu.add_cascade(label="View",menu=self.viewmenu)
        self.viewmenu.add_command(label="Zoom In (Ctrl -)",      command=lambda: self.set_zoomfaktor(0.8))
        self.app.bind('<Control-minus>',                     lambda key: self.set_zoomfaktor(0.8))
        self.viewmenu.add_command(label="Zoom Out (Ctrl +)",     command=lambda: self.set_zoomfaktor(1.25))
        self.app.bind('<Control-plus>',                      lambda key: self.set_zoomfaktor(1.25))
        self.viewmenu.add_command(label="Fit to Width (Ctrl W)", command=lambda: self.set_zoomfaktor(-1))
        self.app.bind('<Control-w>',                         lambda key: self.set_zoomfaktor(-1))
        self.viewmenu.add_command(label="Fit to Height (Ctrl H)",command=lambda: self.set_zoomfaktor(-2))
        self.app.bind('<Control-h>',                         lambda key: self.set_zoomfaktor(-2))
        self.viewmenu.add_command(label="Fit to Canvas (Ctrl V)",command=lambda: self.set_zoomfaktor(-3))
        self.app.bind('<Control-v>',                         lambda key: self.set_zoomfaktor(-3))
        self.viewmenu.add_command(label="Graph/Code (Ctrl G)"   ,command=lambda: self.set_zoomfaktor(-5))
        self.app.bind('<Control-g>',                         lambda key: self.set_zoomfaktor(-5))
        self.viewmenu.add_command(label='---'                   ,command=lambda: self.act_gui_file().toggle_show_grid())
        self.app.bind('<Control-r>',                         lambda key: self.act_gui_file().toggle_show_grid())
        self.viewmenu.add_command(label='---'                   ,command=lambda: self.act_gui_file().toggle_snap_grid())
        self.app.bind('<Control-n>',                         lambda key: self.act_gui_file().toggle_snap_grid())

        self.prodmenu = tkinter.Menu(self.mainmenu,tearoff=0)
        self.mainmenu.add_cascade(label="Production",menu=self.prodmenu)
        self.prodmenu.add_command(label="New")                 #  ,command=lambda: self.fileopen("untitled.py"))
        self.prodmenu.add_command(label="Open")                #  ,command=self.fileopen)
        self.prodmenu.add_command(label="Save")                #  ,command=self.filesave)
        self.prodmenu.add_command(label="Save As")             #  ,command=self.filesaveas)


        self.extramenu    = tkinter.Menu(self.mainmenu,tearoff=0)
        self.mainmenu.add_cascade(label="Extras",menu=self.extramenu)
        self.extramenu.add_command(label="Tools",state="disabled")
        self.extramenu.add_command(label="Rearr Circle (Ctrl I)"      )#,command=lambda: self.act_gui_file().rearr_circle(0.8))
#        self.app.bind('<Control-i>',                            lambda key: self.act_gui_file().rearr_circle(0.8))
        self.extramenu.add_command(label="Rearr Sugiyama (Ctrl B)"    )#,command=lambda: self.act_gui_file().rearr_sugiyama(0.8))
#        self.app.bind('<Control-q>',                            lambda key: self.act_gui_file().rearr_sugiyama(0.8))
        self.extramenu.add_command(label="Rearr Grid (Ctrl D)"        )#',command=lambda: self.act_gui_file().rearr_grid(0.5))
        self.app.bind('<Control-d>',                            lambda key: self.act_gui_file().graphmodel.rearr_grid(0.5))
        self.extramenu.add_command(label="Rearr Grid with Sy"         )#',command=lambda: self.act_gui_file().rearr_grid_arrows_with_sugiyama(3.0))
        self.extramenu.add_command(label="Rearr Circle slow"          )#,command=lambda: self.act_gui_file().rearr_circle(3.0))
        self.extramenu.add_command(label="Rearr Sugiyama slow"        )#,command=lambda: self.act_gui_file().rearr_sugiyama(3.0))
        self.extramenu.add_command(label="Rearr Grid slow"            )#,command=lambda: self.act_gui_file().rearr_sugiyama(3.0))

        self.helpmenu     = tkinter.Menu(self.mainmenu,tearoff=0)
        self.mainmenu.add_cascade(label="Help",menu=self.helpmenu)
        self.helpmenu.add_command(label="About",state="disabled")

        self.app.config(menu=self.mainmenu)

#        self.editmenu     = Tkinter.Menu(self.mainmenu,tearoff=0)
#        self.mainmenu.add_cascade(label="Edit",menu=self.editmenu)
#        self.editmenu.add_command(label="Undo (Ctrl+Z)"      ,state="disabled")
#        self.editmenu.add_command(label="Edit Block (Ctrl+E)",state="disabled")
#        self.editmenu.entryconfig(0,state="disabled")

        self.notebook     = tkinter.ttk.Notebook(self.app,width=1000,height=800)
        self.openfiles    = {}
        self.notebook.pack(expand=tkinter.TRUE,fill=tkinter.BOTH)

        app.bind("<Delete>",lambda key: self.act_gui_file().graphmodel.delete_highlighted_element())
        app.bind("<Escape>",lambda key: self.act_gui_file().graphmodel.unhighlight_block())

        if filename and not os.path.isfile(filename):
            filename = None
        if filename:
            self.app.after(0,self.fileopen,filename)
            
#        self.app.bind('<<NotebookTabChanged>>',   self.switch_tab)


#**********************************************************

    def mark (self,remark):
    
        t = time.clock()
#        print (t)
#        if 't0' in vars(self):
#            print ("%13.9f" % (t-self.t0)) + "  " + remark
        self.t0 = t

#*****************************************************************************
        
    def fileopen (self,filename=None):
        
        if not filename:
            filename = os.path.relpath( tkinter.filedialog.askopenfilename(
                           filetypes=[ 
                                       ('ProcPy files','*.ppy'),
                                       ('All files','*.*'),
                                     ]
                                ))
            
        if filename == "":
            filename = "untitled.py"
            
        fileroot = filename
        fileend  = ""
        m = re.search(r"^(.*)(\..*)$",filename)
        if m:
            fileroot = m.group(1)
            fileend  = m.group(2)
        
        while 0 == 0:
            if (fileroot+fileend) in self.openfiles:
                m = re.search(r"^(.*)\((\d+)\)",fileroot)
                if m:
                    fileroot = m.group(1) + "(" + str(int(m.group(2))+1) + ")"
                else:
                    fileroot = fileroot + "(1)"
            else:
                break
        
        newtab = procpy.graphproc.Graphproc(procpy.storeproc.Storeproc(app=self.app,
                                            dbh=self.dbh,dbtable=self.dbtable),self.notebook)
        newtab.storeproc.notifier = newtab
        newtab.pack(expand=tkinter.TRUE,fill=tkinter.BOTH)
        self.openfiles[fileroot+fileend] = 1
        self.notebook.add(newtab,text=fileroot+fileend)
        self.notebook.select(newtab)
        fileroot = re.sub(r" ","_SPACE_",fileroot,9999)
        fileroot = re.sub(r"\(","_BRACKETOPEN_",fileroot,9999)
        fileroot = re.sub(r"\)","_BRACKETCLOSE_",fileroot,9999)
        newtab.config(classname=fileroot)

        if os.path.isfile(filename):
            text = open(filename).read()
            self.act_gui_file().load(text)

        return(newtab)

#*****************************************************************************
        
    def filesave (self,saveas=False):
        act_tab      = self.notebook.select()               #  SAVE-001-REQ 
        filename     = self.notebook.tab( act_tab, 'text')  #  Read the tab's header
        
        if filename[0] == "[":
            filename = filename[1:-1]
        m            = re.search(r"^.*\.(.*)$",act_tab)
        act_gui_file = self.notebook.children[m.group(1)]

        if saveas or 'untitled' in filename:       # Dialogue Box if 'saveas' or filename is 'untitled' 
           filename = os.path.relpath( tkinter.filedialog.asksaveasfilename(
                           filetypes=[ 
                                       ('ProcPy files','*.ppy'),
                                       ('All files','*.*'),
                                     ],initialfile=filename))

        
        open(filename,"w").write( act_gui_file.save()) #  SAVE-001
        self.notebook.tab( act_tab,text=filename)   #  set the tabs header to the filename
        
        
#*************************************************************************

    def filesaveas (self):
        self.filesave(True)

#*************************************************************************

    def savesvg (self):
    
        act_tab      = self.notebook.select()
        filename     = self.notebook.tab( act_tab, 'text')  #  Read the tab's header
        m            = re.search(r"^.*\.(.*)$",act_tab)
        act_gui_file = self.notebook.children[m.group(1)]
        m = re.search(r"^(.*)\.(.*)$",filename)
        if not m:
            return()
        procpy.canvasvg.saveall(m.group(1)+".svg",act_gui_file.graphcanvas)
        
#        svgdoc = canvas.SVGdocument()
#        open(m.group(1)+".svg","w").write( canvasvg.convert(svgdoc,act_gui_file.graphcanvas) )
        

#*************************************************************************

    def set_rearrange_circle (self,key=0):
        self.rearrange(0,0.5)
    def set_rearrange_bpm    (self,key=0):
        self.rearrange(1,0.5)
    def set_rearrange_grid   (self,key=0):
        self.rearrange(3,0.5)

#*************************************************************************

    def act_gui_file (self):
        m = re.search(r"^.*\.(.*)$",self.notebook.select())
        if m:
            return(self.notebook.children[m.group(1)])
        else:
            return(None)

#*************************************************************************

    def xxrearrange (self,mode,move_interval):
        self.act_gui_file().rearrange_graphics(mode,move_interval)

#*************************************************************************

    def switch_tab (self,key=0):

        act_tab  = self.act_gui_file()
        griddata = act_tab.griddata
        text     = self.notebook.tab(act_tab)['text']
        if griddata['SHOW']:
            self.viewmenu.entryconfigure(6,label="v Show Grid (Ctrl R)")
        else:
            self.viewmenu.entryconfigure(6,label="  Show Grid (Ctrl R)")
        if griddata['SNAP']:
            if not text[0] == "[":
                self.notebook.tab(act_tab,text="["+text+"]")
            self.viewmenu.entryconfigure(7,label="v Snap to Grid (Ctrl N)")
        else:
            if text[0] == "[":
                self.notebook.tab(act_tab,text=text[1:-1])
            self.viewmenu.entryconfigure(7,label="  Snap to Grid (Ctrl N)")

#*************************************************************************

    def set_zoomfaktor (self,fac):
        act_gui_file = self.act_gui_file()
        if act_gui_file:
            act_gui_file.graphmodel.set_zoomfaktor(fac)

#*************************************************************************

    def toggle_show_grid (self,key=0):
        print('toggle grid')
        act_gui_file = self.act_gui_file()
        if act_gui_file:
            act_gui_file.toggle_show_grid()
        self.switch_tab()

#*************************************************************************

    def toggle_snap_to_grid (self,key=0):
        act_gui_file = self.act_gui_file()
        if act_gui_file:
            act_gui_file.toggle_snap_to_grid()
        self.switch_tab()

#*************************************************************************

    def edit (self,key=0):
        act_gui_file = self.act_gui_file()
        if act_gui_file:
            act_gui_file.edit(1.23)

#*************************************************************************

    def save (self,key=0):
        act_gui_file = self.act_gui_file()
        if act_gui_file:
            act_gui_file.save()

#*************************************************************************

    def beenden (self,key=0):
        act_gui_file = self.act_gui_file()
        if act_gui_file:
            act_gui_file.storeproc.dbh.commit()
        exit()

#*************************************************************************

    def rearrange (self,mode,move_interval):
        act_gui_file = self.act_gui_file()
        if act_gui_file:
            
            self.act_gui_file().rearrange_graphics(mode,move_interval)

#*************************************************************************



bypass 1.0, Devloped By El Moujahidin (the source has been moved and devloped)
Email: contact@elmoujehidin.net bypass 1.0, Devloped By El Moujahidin (the source has been moved and devloped) Email: contact@elmoujehidin.net