Welcome To Our Shell

Mister Spy & Souheyl Bypass Shell

Current Path : /home/cgabriel/20_dev/12_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/cgabriel/20_dev/12_procpy/dataninja/gui1.py

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

import os
import re
import sys
import time
import math
import procpy
import procpy.multilingual
import procpy.config
import procpy.gui_file
import procpy.testapi
import tkinter.filedialog

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


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


class Gui1(object):

    def __init__ (self,loopobj,db,filename,lang="en"):

        self.loopobj    = loopobj
        self.db         = db
        self.filename   = filename
        self.translator = procpy.multilingual.Translation(lang,'''

key         en        de        fr         it
---------------------------------------------
yes         yes       ja        oui        si
        
        ''')

#        print self.translator.compute_ambiguity()   #  Show all translation ambiguities
        

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

    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 run (self,filename=None,startdir="."):
        
        self.app_w        = procpy.config.GENERAL_WIDTH
        self.app_h        = procpy.config.GENERAL_HEIGHT
        self.mainmenu     = tkinter.Menu(self.loopobj.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.loopobj.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.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.loopobj.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.loopobj.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.loopobj.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.loopobj.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.loopobj.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.loopobj.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.loopobj.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.loopobj.app.bind('<Control-n>',                         lambda key: self.act_gui_file().toggle_snap_grid())

        self.execmenu     = tkinter.Menu(self.mainmenu,tearoff=0)
        self.mainmenu.add_cascade(label="Execution",menu=self.execmenu)
        self.execmenu.add_command(label="Start",command=self.createprocess)

        self.monitormenu  = tkinter.Menu(self.mainmenu,tearoff=0)
        self.mainmenu.add_cascade(label="Monitor",menu=self.monitormenu)
        self.monitormenu.add_command(label="Processes"          ,command=self.monitoring)
        self.monitormenu.add_command(label="Autotest",state="disabled")

        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.loopobj.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.loopobj.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.loopobj.app.bind('<Control-d>',                            lambda key: self.act_gui_file().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.notebook     = tkinter.ttk.Notebook(self.loopobj.app,width=self.app_w,height=self.app_h)
        self.openfiles    = {}
        self.notebook.pack(expand=tkinter.TRUE,fill=tkinter.BOTH)
        #self.notebook.config(bg="black")
        self.loopobj.app.config(menu=self.mainmenu)

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

        
#        try:
        procpy.testapi.Testapi(self).run_test(self.filename)
#        except Exception as e:
#            print str(e)

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

    def fileopen (self,filename=None):
        
        if not filename:
            filename = os.path.relpath( tkinter.filedialog.askopenfilename(
                           filetypes=[ 
                                       ('Workflow files','*.py'),
                                       ('All files','*.*'),
                                     ]
                                ))
            
        if filename == "":
            print("no filename! \n")
            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
        print(filename, ' opened')
        
        newtab = procpy.gui_file.Gui_file(self.notebook)
        newtab.pack()
        newtab.init(filename,self)
        self.openfiles[fileroot+fileend] = 1
        self.notebook.add(newtab,text=fileroot+fileend)
        self.notebook.select(newtab)
        return(newtab)

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

    def filesave (self,saveas=False):
        act_tab      = self.notebook.select()               #  SAVE-001-VALID 
        filename     = self.notebook.tab( act_tab, 'text')  #  Read the tab's header
        
        if filename[0] == "[":
            file = 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=[ 
                                       ('Workflow files','*.py'),
                                       ('All files','*.*'),
                                     ],initialfile=filename))

        
        open(filename,"w").write( act_gui_file.save_graphics()) #  SAVE-001

        print(filename, ' saved')
        

        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.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 rearrange (self,mode,move_interval):
        act_gui_file = self.act_gui_file()
        if act_gui_file:
            print('act_gui_file = ', act_gui_file)
            self.act_gui_file().rearrange_graphics(mode,move_interval)

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

    def monitoring (self):   #  switches to the monitoring screen
    
        self.monitor = procpy.monitor.Monitor(self.loopobj.app)
        self.notebook.pack_forget()
        self.monitor     = tkinter.ttk.Notebook(self.loopobj.app,width=self.app_w,height=self.app_h)
        #b1=self.monitor.button(self.loopobj.app,text="close",command=self.loopobj.app.destroy)
        #b1.pack()
        self.monitor.pack(expand=tkinter.TRUE,fill=tkinter.BOTH)
        


#*************************************************************************
	
    def createprocess(self, filename=None):
        
        #print self.filename-
        num = re.sub(r'\\', ".", self.filename)
        text=re.sub(r'graphml', "PROG", num)
       
		
        try:
            prc = procpy.prcmanager.PROCInterface(self.db)
            return prc.run_process(object_identifier=text)  ## object_identifier= is name of file after conversion done by regualr expression

        except Exception as e:
            print(e)
        
        
        

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