本文整理汇总了Python中singleton_store.Screen类的典型用法代码示例。如果您正苦于以下问题:Python Screen类的具体用法?Python Screen怎么用?Python Screen使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Screen类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_begin
def on_begin( self, scaling=None):
self.paper.unselect_all()
if self.paper.get_paper_property( 'crop_svg'):
if len( self.paper.find_all()) <= 1: # background only
Store.log( _('There is nothing to export. If you want to export an empty paper disable cropping of the drawing in the File/Properties menu.'), message_type="error")
return 0
x1, y1, x2, y2 = self.paper.get_cropping_bbox()
dx = x2-x1
dy = y2-y1
scalex, scaley = scaling or self.get_scaling( dx, dy)
if not scalex:
# the setting of scaling was canceled
return 0
self.transformer = transform.transform()
self.transformer.set_move( -x1, -y1)
self.transformer.set_scaling_xy( scalex, scaley)
else:
dx = Screen.mm_to_px( self.paper._paper_properties['size_x'])
dy = Screen.mm_to_px( self.paper._paper_properties['size_y'])
scalex, scaley = scaling or self.get_scaling( dx, dy)
if not scalex:
# the setting of scaling was canceled
return 0
self.transformer = transform.transform()
self.transformer.set_scaling_xy( scalex, scaley)
x1, y1, x2, y2 = self.transformer.transform_4( (0, 0, dx, dy))
self.pagesize = tuple( map( round, (x2-x1, y2-y1)))
self.attrs['text_to_curves'] = False
self.converter = self.converter_class( **self.attrs)
return 1
示例2: add_atom_to
def add_atom_to( self, a1, bond_to_use=None, pos=None):
"""adds new atom bound to atom id with bond, the position of new atom can be specified in pos or is
decided calling find_place(), if x, y is specified and matches already existing atom it will be
used instead of creating new one """
if pos != None:
x, y = pos
else:
if bond_to_use:
x, y = self.find_place( a1, Screen.any_to_px( self.paper.standard.bond_length), added_order=bond_to_use.order)
else:
x, y = self.find_place( a1, Screen.any_to_px( self.paper.standard.bond_length))
a2 = None # the new atom
if pos:
# try if the coordinates are the same as of another atom
for at in self.atoms:
if abs( at.x - x) < 2 and abs( at.y - y) < 2 and not at == a1:
a2 = at
break
if not a2:
a2 = self.create_new_atom( x, y)
b = bond_to_use or bond( self.paper.standard, order=1, type='n')
self.add_edge( a1, a2, e=b)
b.molecule = self
b.draw()
return a2, b
示例3: add_arrow
def add_arrow( self, a, page):
for item in a.items:
# polygons (arrow heads, etc.)
if self.paper.type( item) == "polygon":
a_color = self.paper.itemcget( item, "fill")
l_color = self.paper.itemcget( item, "outline")
l_width = float( self.paper.itemcget( item, "width"))
s = graphics_style( stroke_color=self.paper.any_color_to_rgb_string( l_color),
fill_color=self.paper.any_color_to_rgb_string( a_color),
stroke_width=Screen.px_to_cm( l_width))
style_name = self.get_appropriate_style_name( s)
ps = geometry.coordinate_flat_list_to_xy_tuples( self.paper.coords( item))
points = [map( Screen.px_to_cm, p) for p in ps]
self.create_oo_polygon( points, page, style_name)
# polylines - standard arrows
elif self.paper.type( item) == "line":
line_pin = a._pins.index( self.paper.itemcget( item, 'arrow'))
end_pin, start_pin = None,None
if line_pin==1 or line_pin==3:
end_pin = 1
if line_pin==2 or line_pin==3:
start_pin = 1
l_color = self.paper.itemcget( item, "fill")
l_width = float( self.paper.itemcget( item, "width"))
s = graphics_style( stroke_color=self.paper.any_color_to_rgb_string( l_color),
marker_end=end_pin,
marker_start=start_pin,
stroke_width=Screen.px_to_cm( l_width))
style_name = self.get_appropriate_style_name( s)
ps = geometry.coordinate_flat_list_to_xy_tuples( self.paper.coords( item))
points = [map( Screen.px_to_cm, p) for p in ps]
if self.paper.itemcget( item, "smooth") == "0":
self.create_oo_polyline( points, page, style_name)
else:
self.create_oo_bezier( points, page, style_name)
示例4: add_plus_mark
def add_plus_mark( self, o, page):
s = graphics_style( stroke_color=self.paper.any_color_to_rgb_string( o.atom.line_color),
fill_color=self.paper.any_color_to_rgb_string( o.atom.area_color),
stroke_width=Screen.px_to_cm( 1))
style_name = self.get_appropriate_style_name( s)
# we must process oval first - it would otherwise cover the lines
for i in o.items:
if self.paper.type( i) == "oval":
x, y, x2, y2 = map( Screen.px_to_cm, self.paper.coords( i))
size = Screen.px_to_cm( o.size)
dom_extensions.elementUnder( page, 'draw:ellipse',
(( 'svg:x', '%fcm' % x),
( 'svg:y', '%fcm' % y),
( 'svg:width', '%fcm' % size),
( 'svg:height', '%fcm' % size),
( 'draw:style-name', style_name)))
for i in o.items:
if self.paper.type( i) == "line":
coords = self.paper.coords( i)
# because some weird bug in tcl/tk i had to hack the coordinates in marks.py
# the hack is reversed here in order to get the coords back
# I also reduce the size of the mark a little
#if o.items.index( i) == 1:
# coords[0] += 0
# coords[2] += -1
#elif o.items.index( i) == 2:
# coords[1] += 0
# coords[3] += -1
# end of hack
coords = map( Screen.px_to_cm, coords)
self.create_oo_line( coords, page, style_name)
示例5: on_begin
def on_begin( self):
self.paper.unselect_all()
scale = 720.0/self.paper.winfo_fpixels( '254m')
if self.paper.get_paper_property( 'crop_svg'):
margin = self.paper.get_paper_property('crop_margin')
items = list( self.paper.find_all())
items.remove( self.paper.background)
if not items:
Store.log( _('There is nothing to export. If you want to export an empty paper disable cropping of the drawing in the File/Properties menu.'), message_type="error")
return 0
x1, y1, x2, y2 = self.paper.list_bbox( items)
self.transformer = transform.transform()
self.transformer.set_move( -x1+margin, -y1+margin)
self.transformer.set_scaling( scale)
dx = x2-x1 +2*margin
dy = y2-y1 +2*margin
else:
self.transformer = transform.transform()
self.transformer.set_scaling( scale)
dx = Screen.mm_to_px( self.paper._paper_properties['size_x'])
dy = Screen.mm_to_px( self.paper._paper_properties['size_y'])
self.canvas = self.init_canvas( pagesize=(scale*dx, scale*dy))
self.converter = self.converter_class()
return 1
示例6: switch_to_type
def switch_to_type( self, type):
if type in "wha" and self.type not in "wha":
# get the standard width only if the changes is not within the "wha" group
self.wedge_width = Screen.any_to_px( self.paper.standard.wedge_width)
elif type not in "wha" and self.type in "wha":
# when both are outside the 'wha' do the similar
self.bond_width = Screen.any_to_px( self.paper.standard.bond_width)
self.type = type
示例7: read_standard_values
def read_standard_values( self, standard, old_standard=None):
meta_enabled.read_standard_values( self, standard, old_standard=old_standard)
# wedge width
if not old_standard or (standard.wedge_width != old_standard.wedge_width):
self.wedge_width = Screen.any_to_px( standard.wedge_width)
# line width
if not old_standard or (standard.line_width != old_standard.line_width):
self.line_width = Screen.any_to_px( standard.line_width)
# bond width
if not old_standard or (standard.bond_width != old_standard.bond_width):
if hasattr( self, 'bond_width'):
self.bond_width = misc.signum( self.bond_width) * Screen.any_to_px( standard.bond_width)
else:
self.bond_width = Screen.any_to_px( standard.bond_width)
示例8: add_radical_mark
def add_radical_mark( self, o, page):
s = graphics_style( stroke_color=self.paper.any_color_to_rgb_string( o.atom.line_color),
fill_color=self.paper.any_color_to_rgb_string( o.atom.line_color),
stroke_width=Screen.px_to_cm( 0.1))
style_name = self.get_appropriate_style_name( s)
for i in o.items:
x, y, x2, y2 = map( Screen.px_to_cm, self.paper.coords( i))
size = Screen.px_to_cm( o.size)
dom_extensions.elementUnder( page, 'draw:ellipse',
(( 'svg:x', '%fcm' % x),
( 'svg:y', '%fcm' % y),
( 'svg:width', '%fcm' % size),
( 'svg:height', '%fcm' % size),
( 'draw:style-name', style_name)))
示例9: add_polygon
def add_polygon( self, o, page):
s = graphics_style( stroke_color=self.paper.any_color_to_rgb_string( o.line_color),
fill_color=self.paper.any_color_to_rgb_string( o.area_color),
stroke_width=Screen.px_to_cm( o.line_width))
style_name = self.get_appropriate_style_name( s)
points = [map( Screen.px_to_cm, p.get_xy()) for p in o.points]
self.create_oo_polygon( points, page, style_name)
示例10: read_package
def read_package( self, package, atom):
typ = package.getAttribute( 'type')
cls = globals().get( typ, None)
if cls:
auto = 0 #package.getAttribute( 'auto') != None and package.getAttribute( 'auto')) or 0
x, y, z = Screen.read_xml_point( package)
size = package.getAttribute( 'size') and float( package.getAttribute( 'size')) or None
if size:
m = cls( atom, x, y, size=size, auto=int(auto))
else:
m = cls( atom, x, y, auto=int(auto))
# class specific attributes
for (attr, typ) in m.meta__save_attrs.items():
val = package.getAttribute( attr)
if val != '':
if typ == bool:
value = bool( data.booleans.index( val))
elif typ == int:
value = int( val)
else:
value = val
setattr( m, attr, value)
if hasattr( m, "_after_read_package"):
m._after_read_package()
return m
else:
raise ValueError("no such mark type %s" % typ)
示例11: get_transformed_template
def get_transformed_template(self, n, coords, type="empty", paper=None):
"""type is type of connection - 'bond', 'atom1'(for single atom), 'atom2'(for atom with more than 1 bond), 'empty'"""
pap = paper or Store.app.paper
pap.onread_id_sandbox_activate() # must be here to mangle the ids
current = molecule(pap, package=self.templates[n])
pap.onread_id_sandbox_finish(apply_to=[current]) # id mangling
current.name = ""
self._scale_ratio = 1
trans = transform()
# type empty - just draws the template - no conection
if type == "empty":
xt1, yt1 = current.t_atom.get_xy()
xt2, yt2 = current.next_to_t_atom.get_xy()
x1, y1 = coords
bond_length = Screen.any_to_px(Store.app.paper.standard.bond_length)
current.delete_items([current.t_atom], redraw=0, delete_single_atom=0)
trans.set_move(-xt2, -yt2)
trans.set_scaling(bond_length / math.sqrt((xt1 - xt2) ** 2 + (yt1 - yt2) ** 2))
trans.set_move(x1, y1)
# type atom
elif type == "atom1" or type == "atom2":
xt1, yt1 = current.t_atom.get_xy()
xt2, yt2 = current.next_to_t_atom.get_xy()
x1, y1, x2, y2 = coords
trans.set_move(-xt2, -yt2)
trans.set_scaling(
math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) / math.sqrt((xt1 - xt2) ** 2 + (yt1 - yt2) ** 2)
)
trans.set_rotation(math.atan2(xt1 - xt2, yt1 - yt2) - math.atan2(x1 - x2, y1 - y2))
trans.set_move(x2, y2)
# type bond
elif type == "bond":
if not (current.t_bond_first and current.t_bond_second):
warn("this template is not capable to be added to bond - sorry.")
return None
current.delete_items([current.t_atom], redraw=0, delete_single_atom=0)
xt1, yt1 = current.t_bond_first.get_xy()
xt2, yt2 = current.t_bond_second.get_xy()
x1, y1, x2, y2 = coords
self._scale_ratio = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) / math.sqrt(
(xt1 - xt2) ** 2 + (yt1 - yt2) ** 2
) # further needed for bond.bond_width transformation
trans.set_move(-xt1, -yt1)
trans.set_rotation(math.atan2(xt1 - xt2, yt1 - yt2) - math.atan2(x1 - x2, y1 - y2))
trans.set_scaling(self._scale_ratio)
trans.set_move(x1, y1)
self.transform_template(current, trans)
# remove obsolete info from template
if type == "atom1":
current.delete_items([current.t_atom], redraw=0, delete_single_atom=0)
elif type == "atom2":
current.t_atom.x = x1
current.t_atom.y = y1
current.t_atom = None
current.t_bond_first = None
current.t_bond_second = None
# return ready template
return current
示例12: add_electronpair_mark
def add_electronpair_mark( self, o, page):
i = o.items[0]
width = float( self.paper.itemcget( i, 'width'))
s = graphics_style( stroke_color=self.paper.any_color_to_rgb_string( o.atom.line_color),
fill_color=self.paper.any_color_to_rgb_string( o.atom.line_color),
stroke_width=Screen.px_to_cm( width))
style_name = self.get_appropriate_style_name( s)
coords = map( Screen.px_to_cm, self.paper.coords( i))
self.create_oo_line( coords, page, style_name)
示例13: expand
def expand( self):
"""expands the group and returns list of atoms that new drawing afterwords"""
if self.group_type == "builtin":
names = Store.gm.get_template_names()
if self.symbol in names:
a2 = self.neighbors[0]
x1, y1 = a2.get_xy()
x2, y2 = self.get_xy()
self.group_graph = Store.gm.get_transformed_template( names.index( self.symbol), (x1,y1,x2,y2), type='atom1')
replacement = self.group_graph.next_to_t_atom
else:
print "unknown group %s" % a.symbol
return None
elif self.group_type == "chain":
self.group_graph = self.molecule.create_graph()
p = PT.formula_dict( self.symbol)
n = p['C']
last = None
for i in range( n):
v = self.group_graph.add_vertex()
v.x, v.y = None, None
if last:
self.group_graph.add_edge( last, v)
last = v
replacement = self.group_graph.vertices[0]
replacement.x = self.x
replacement.y = self.y
elif self.group_type == "implicit":
if not self.group_graph:
self.set_name( self.symbol, occupied_valency=self.occupied_valency)
for v in self.group_graph.vertices:
v.x, v.y = None, None
v.show = v.symbol != 'C'
assert self.connecting_atom != None
replacement = self.connecting_atom
replacement.x = self.x
replacement.y = self.y
self.molecule.eat_molecule( self.group_graph)
self.molecule.move_bonds_between_atoms( self, replacement)
self.molecule.delete_vertex( self)
if self.occupied_valency:
oasa.coords_generator.calculate_coords( self.molecule, bond_length=-1)
else:
# if the group is the only vertex of the molecule we must set the bond_length explicitly
# and the move the whole molecule
replacement.x = None
replacement.y = None
x, y = self.x, self.y
oasa.coords_generator.calculate_coords( self.molecule, bond_length=Screen.any_to_px( self.paper.standard.bond_length))
dx = x - replacement.x
dy = y - replacement.y
[a.move( dx, dy) for a in self.group_graph.vertices]
return self.group_graph.vertices
示例14: add_bond
def add_bond( self, b, page):
"""adds bond item to page"""
s = graphics_style( stroke_color=self.paper.any_color_to_rgb_string( b.line_color),
stroke_width=Screen.px_to_cm( b.line_width))
style_name = self.get_appropriate_style_name( s)
l_group = page
# items to export
line_items, items = b.get_exportable_items()
# the export itself
if b.type in 'nhd':
for i in items:
coords = map( Screen.px_to_cm, self.paper.coords( i))
self.create_oo_line( coords, page, style_name)
elif b.type == 'o':
for i in items:
x, y, x2, y2 = map( Screen.px_to_cm, self.paper.coords( i))
size = Screen.px_to_cm( x2-x)
dom_extensions.elementUnder( page, 'draw:ellipse',
(( 'svg:x', '%fcm' % x),
( 'svg:y', '%fcm' % y),
( 'svg:width', '%fcm' % size),
( 'svg:height', '%fcm' % size),
( 'draw:style-name', style_name)))
elif b.type == 'b':
# bold bonds width is determined by the wedge_width
s = graphics_style( stroke_color=self.paper.any_color_to_rgb_string( b.line_color),
stroke_width=Screen.px_to_cm( b.wedge_width))
b_style_name = self.get_appropriate_style_name( s)
for i in items:
coords = map( Screen.px_to_cm, self.paper.coords( i))
self.create_oo_line( coords, page, b_style_name)
elif b.type == 'w':
s = graphics_style( stroke_color=self.paper.any_color_to_rgb_string( b.line_color),
fill_color=self.paper.any_color_to_rgb_string( b.line_color),
stroke_width=Screen.px_to_cm( b.line_width))
style_name = self.get_appropriate_style_name( s)
for i in items:
coords = map( Screen.px_to_cm, self.paper.coords( i))
point_array = []
for i in range( 0, len( coords), 2):
point_array.append( (coords[i], coords[i+1]))
self.create_oo_polygon( point_array, page, style_name)
elif b.type == 'a':
s = graphics_style( stroke_color=self.paper.any_color_to_rgb_string( b.line_color),
stroke_width=Screen.px_to_cm( b.line_width))
style_name = self.get_appropriate_style_name( s)
for i in items:
coords = self.paper.coords( i)
points = []
for j in range( 0, len( coords), 2):
points.append( ( Screen.px_to_cm( coords[j]), Screen.px_to_cm(coords[j+1])))
self.create_oo_polyline( points, page, style_name)
# line_items
for i in line_items:
coords = map( Screen.px_to_cm, self.paper.coords( i))
self.create_oo_line( coords, page, style_name)
示例15: add_oval
def add_oval( self, o, page):
s = graphics_style( stroke_color=self.paper.any_color_to_rgb_string( o.line_color),
fill_color=self.paper.any_color_to_rgb_string( o.area_color),
stroke_width=Screen.px_to_cm( o.line_width))
style_name = self.get_appropriate_style_name( s)
x, y, x2, y2 = map( Screen.px_to_cm, o.coords)
dom_extensions.elementUnder( page, 'draw:ellipse',
(( 'svg:x', '%fcm' % x),
( 'svg:y', '%fcm' % y),
( 'svg:width', '%fcm' % (x2-x)),
( 'svg:height', '%fcm' % (y2-y)),
( 'draw:style-name', style_name)))