
| 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 |
| Current File : //home/ift/52_procpy/dataninja/grappp.py |
# coding: utf8
import os,re,sys,time,math,random,tkinter,codecs,procpy
import procpy.block
import procpy.swimlane
import procpy.arrow
import procpy.rearr_grid
import pdb
import procpy.procobj
#from PIL import ImageTk
#from PIL import Image
class Graphmodel(tkinter.Canvas):
def __init__(self, graphproc, *pars, **args):
'''
The class procpy.graphmodel.Graphmodel provides a Tkinter.Canvas which contains
blocks and arrows. A special kind of blocks are swimlanes.
Blocks can be highlighted.
'''
tkinter.Canvas.__init__(self, *pars, **args)
self.config(background="white")
self.bind("<Button-1>", self.unhighlight_block)
self.bind("<ButtonRelease-1>", self.release_button_event)
self.bind("<B1-Motion>", self.move_mouse_event)
self.blocks = []
self.swimlanes = []
self.blockwidth = args.setdefault('blockwidth', 70)
self.blockheight = args.setdefault('blockheight', 40)
self.swimlane_width = args.setdefault('swimlane_width', 15)
self.zoom_factor = 1
self.hl_block = [None, None, None] # the high-lighted block, with history, contains None's or block objects
self.graphproc = graphproc # The calling widget, typically a Tkinter.Frame
self.config(scrollregion=(0, 0, 3000, 1000))
self.hidden = 0
self.last_pressed = -100 # for computing doubleclicks
self.wait_for_doubleclick_in_milliseconds = int(1000 * procpy.config.WAIT_FOR_DOUBLECLICK)
self.set_background_image(procpy.config.FILENAME)
def create_block_event(self, event): # the double mouseclick callback event
overlapping_elements = self.find_overlapping(event.x, event.y, event.x, event.y)
if overlapping_elements:
for overlapping_element in overlapping_elements:
if not self.type(overlapping_element) == "image":
return ()
x0 = self.canvasx(event.x) - 0.5 * self.blockwidth * self.zoom_factor
x1 = self.canvasx(event.x) + 0.5 * self.blockwidth * self.zoom_factor
y0 = self.canvasy(event.y) - 0.5 * self.blockheight * self.zoom_factor
y1 = self.canvasy(event.y) + 0.5 * self.blockheight * self.zoom_factor
self.create_block(x0, y0, x1, y1)
print("creat_block event")
# ************************************************************************************
def create_block(self, x0, y0, x1, y1):
# if not self.new_block_is_possible():
# return()
self.after(self.wait_for_doubleclick_in_milliseconds, self.highlight_block,
None) # wait: maybe we had a double-click
if x0 < 0: # if the block creating event is very much at the left side
w = self.swimlane_width * self.zoom_factor
self.swimlanes.append(procpy.swimlane.Swimlane(self, [0, y0, w, y1]))
else:
self.blocks.append(procpy.block.Block(self, [x0, y0, x1, y1]))
self.rearr_grid(procpy.config.MOVESPEED)
print("creat_block ")