def build(self): Window.bind(on_draw=self.ondraw) self.ui = MainUI() glb.root = self.ui glb.app = self self.texture_ruddertrim_wheel = CoreImage.load('img/ruddertrimwheel.png').texture self.texture_ruddertrim_wheel.wrap = 'repeat' self.texture_elevatortrim_wheel = CoreImage.load('img/elevatortrimwheel.png').texture self.texture_elevatortrim_wheel.wrap = 'repeat' return self.ui #show it
def analiseImg(self, imgPath): print("analiseImg [%s]" % imgPath) img = Image.load(imgPath, keep_data=True) size = img.size self.wSize = size print("image size:", size) self.steps = self.analiseSteps(img) print("found legend steps", len(self.steps)) cPath = "%s_casch_" % imgPath cCover = "%s_cover" % cPath cPolis = "%s_polis" % cPath cMeshs = "%s_meshs" % cPath if self.fa.isFile(cMeshs): print("pickle meshs :) ?") m = DataSR_restore(cMeshs) self.polis = {} print("got from cashe file steps", len(m)) for si, k in enumerate(m.keys()): print("restoring step", k) print("meshes", len(m[k])) m0 = Polygon() meshs = m[k] for me in meshs: print("points:", len(me)) #print("->",me) m1 = Polygon(me).simplify(0.1, preserve_topology=True) m0 = m0.union(m1).simplify(0.1, preserve_topology=True) self.polis[int(k)] = m0 print("poli DONE area", self.polis[int(k)].area) else: self.cover, self.polis, self.meshs = self.analiseCover(img) DataSR_save(self.meshs, cMeshs)
def build(self): b = BoxLayout(orientation='vertical') im = "C:\\Users\\Admin\\Desktop\\hrithik.jpg" CoreImage.load(im) global num1 num1 = TextInput(text='') global num2 num2 = TextInput(text='') btn = Button(text='add') btn.bind(on_press=show) '''btn.bind(on_press=show)''' b.add_widget(num1) b.add_widget(num2) b.add_widget(btn) return b
def on_source(self, *args): v = self.source.split(".") source_down = ''.join(v[:-1])+"_down"+v[-1] self._fname_normal = resource_find(self.source) self._fname_down = resource_find(source_down) or self._fname_normal self.image_size = CoreImage.load(self._fname_normal).size self.background_normal = self._fname_normal self.background_down = self._fname_down
def get_texture(self): today = datetime.date.today() now = today.strftime("%Y%m%d") fig = self.create_figure(now, self._from, self._to, self.years) output = BytesIO() FigureCanvas(fig).print_png(output) # self.buttonFrom.bind(on_release = lambda btn: ddh.select(btn)) output.seek(0) return CoreImage.load(output, ext='png').texture
def test_save_into_bytesio(self): Image = self.cls if setupconfig.PLATFORM == "darwin": # XXX on OSX CI Builder, img_sdl2 is not used # therefore the test below wont work yet with imageio only. return # load kivy logo img = Image.load("data/logo/kivy-icon-512.png") self.assertIsNotNone(img) # try to save without any format with self.assertRaises(Exception) as context: bio = io.BytesIO() img.save(bio) # save it in png bio = io.BytesIO() self.assertTrue(img.save( bio, fmt="png")) # if False, then there is no provider pngdata = bio.read() self.assertTrue(len(pngdata) > 0) # try to save in a filename try: _, filename = tempfile.mkstemp(suffix=".png") self.assertTrue(img.save(filename, fmt="png")) finally: os.unlink(filename) # XXX Test wrote but temporary commented # XXX because of the issue #6123 on OSX # XXX https://github.com/kivy/kivy/issues/6123 # with open(filename, "rb") as fd2: # pngdatafile = fd2.read() # # check the png file data is the same as bytesio # self.assertTrue(pngdata == pngdatafile) # save it in jpeg bio = io.BytesIO() self.assertTrue(img.save( bio, fmt="jpg")) # if False, then there is no provider self.assertTrue(len(bio.read()) > 0) with tempfile.NamedTemporaryFile(suffix=".jpg") as fd: self.assertTrue(img.save(fd.name))
def test_save_into_bytesio(self): Image = self.cls if setupconfig.PLATFORM == "darwin": # XXX on OSX CI Builder, img_sdl2 is not used # therefore the test below wont work yet with imageio only. return # load kivy logo img = Image.load("data/logo/kivy-icon-512.png") self.assertIsNotNone(img) # try to save without any format with self.assertRaises(Exception) as context: bio = io.BytesIO() img.save(bio) # save it in png bio = io.BytesIO() # if False, then there is no provider self.assertTrue(img.save(bio, fmt="png")) pngdata = bio.read() self.assertTrue(len(pngdata) > 0) # try to save in a filename try: _, filename = tempfile.mkstemp(suffix=".png") self.assertTrue(img.save(filename, fmt="png")) finally: os.unlink(filename) # XXX Test wrote but temporary commented # XXX because of the issue #6123 on OSX # XXX https://github.com/kivy/kivy/issues/6123 # with open(filename, "rb") as fd2: # pngdatafile = fd2.read() # # check the png file data is the same as bytesio # self.assertTrue(pngdata == pngdatafile) # save it in jpeg bio = io.BytesIO() # if False, then there is no provider self.assertTrue(img.save(bio, fmt="jpg")) self.assertTrue(len(bio.read()) > 0) with tempfile.NamedTemporaryFile(suffix=".jpg") as fd: self.assertTrue(img.save(fd.name))
def on_paths(self, *args): """Make textures from the images in ``paths``, and assign them at the same index in my ``texs`` as in my ``paths``. """ for i, path in enumerate(self.paths): if path in self.pathtexs: if (self.pathtexs[path] in self.texs and self.texs.index(self.pathtexs[path]) == i): continue else: self.pathimgs[path] = img = Image.load(resource_find(path), keep_data=True) self.pathtexs[path] = img.texture if i == len(self.texs): self.texs.append(self.pathtexs[path]) else: self.texs[i] = self.pathtexs[path]
def __init__(self, source, **kwargs): super(Piece, self).__init__(**kwargs) self.auto_bring_to_front = False self.source = source # also look at StringProperty self.fabric = CoreImage.load(filename=self.source, keep_data=True) self.image = Image(texture=self.fabric.texture) self.scale = self.image.texture_size[0] / self.size[0] self.do_scale = False self.add_widget(self.image) self.pattern = pattern.Pattern() self.add_widget(self.pattern) self.instructions = InstructionGroup() self.canvas.add(self.instructions) self.stitch_coords = [] print("Self size:", self.size, "texture size:", self.image.texture_size, "Scale:", self.scale) print("Pattern size:", self.fabric.size)
def on_paths(self, *args): """Make textures from the images in ``paths``, and assign them at the same index in my ``texs`` as in my ``paths``. """ for i, path in enumerate(self.paths): if path in self.pathtexs: if ( self.pathtexs[path] in self.texs and self.texs.index(self.pathtexs[path])== i ): continue else: self.pathimgs[path] = img = Image.load( resource_find(path), keep_data=True ) self.pathtexs[path] = img.texture if i == len(self.texs): self.texs.append(self.pathtexs[path]) else: self.texs[i] = self.pathtexs[path]
def _draw_element(m): m.mrot = [ Rotate(0, 1, 0, 0), Rotate(0, 0, 1, 0), Rotate(0, 0, 0, 1) ] m.mrot = [ Rotate(0, -1, 0, 0), Rotate(0, 0, -1, 0), Rotate(0, 0, 0, -1) ] m.mrot[0].angle = 0.0 m.mrot[1].angle = 0.0 m.mrot[2].angle = 0.0 texture = None if 0: #m.textureFile != -1: print("- mesh with texture ", m.textureFile) print(" 1", self.mesh_texture) self.mesh_texture = Image.load('/tmp/g.jpg').texture self.mesh_texture.wrap = 'repeat' print(" 2", self.mesh_texture) mm = Mesh(vertices=m.vertices, indices=m.indices, fmt=m.vertex_format, mode='triangles', texture=self.mesh_texture) else: print("- mesh without texture") Mesh( vertices=m.vertices, indices=m.indices, fmt=m.vertex_format, mode='triangles', )
def on_source(self, *largs): if os.path.exists(self.source): self.texture = Image.load(self.source).texture self.texture.wrap = 'repeat' self._calc_tex_coords()
from kivy.app import App from kivy.uix.widget import Widget from kivy.uix.image import Image from kivy.core.image import Image as ImageForTest from kivy.properties import NumericProperty, ReferenceListProperty, ObjectProperty from kivy.vector import Vector from kivy.factory import Factory from kivy.clock import Clock from kivy.core.window import Window from kivy.lang import Builder from kivy.graphics import Color import math m = ImageForTest.load('testme.png',keep_data=True) Builder.load_string(""" <PongBall>: size: 50, 50 """) class Mazy(Image): def on_touch_down(self,touch): print "Testing...",touch.x,touch.y print m.read_pixel(touch.x,touch.y) class PongBall(Image): r = NumericProperty(.5) g = NumericProperty(.5) b = NumericProperty(.5)
def __init__(self, source_file): self.source_file = source_file self.texture = CoreImage.load(source_file).texture # Angle to pixels converters self.spherical_ratio_x = self.texture.width / 360.0 self.spherical_ratio_y = self.texture.height / 180.0
# save an image into bytesio from kivy.core.image import Image from io import BytesIO img = Image.load("data/logo/kivy-icon-512.png") bio = BytesIO() ret = img.save(bio, fmt="png") print("len=", len(bio.read())) bio = BytesIO() ret = img.save(bio, fmt="jpg") print("len=", len(bio.read()))
from kivy.uix.widget import Widget from kivy.core.image import Image as ImageForTest from kivy.uix.image import Image from kivy.uix.scatter import Scatter from kivy.properties import NumericProperty, ReferenceListProperty, ObjectProperty from kivy.vector import Vector from kivy.factory import Factory from kivy.clock import Clock from kivy.core.window import Window from kivy.lang import Builder from kivy.graphics import Color import math m = ImageForTest.load('maze_2.png',keep_data=True) Builder.load_string(""" <PongBall>: size: 50, 50 """) class Mazy(Image): def on_touch_down(self,touch): print "Testing...",touch.x,touch.y tx = touch.x ty = 600-touch.y print m.read_pixel(tx,ty) class PongBall(Image): r = NumericProperty(.5)
def __init__(self): self.mapSize = 32 self.wallGrid = [] #VariableListProperty(self.mapSize * self.mapSize) self.skybox = Image.load('./deathvalley_panorama.jpg') self.wallTexture = Image.load('./wall_texture.jpg') self.light = 0
# Size of the window; WINDOW_WIDTH = (WIDTH + 9) * BLOCK_SIZE WINDOW_HEIGHT = (HEIGHT + 2) * BLOCK_SIZE # Get the file names of textures files = os.listdir('textures') # Create TEXTURES dict TEXTURES = {} # Add every texture to TEXTURES for file in files: name = file[:file.index('.')] path = 'textures/' + file TEXTURES[name] = Image.load(path).texture del os, Image # Pieces organizations and textues definitions. PIECES = [ # PIECE I { 'rotations': [[(-2, 0), (-1, 0), (0, 0), (1, 0)], [(0, 0), (0, 1), (0, 2), (0, 3)]], 'texture': TEXTURES['cyan_block'] }, # PIECE S {
def run_task(self, task_info): self.__log_name_suffix__ = " | " + str(task_info["type"]) self.log_deep_debug("Current task array is", task_info) if task_info["type"] == "load_resource": if task_info["resource_type"] == "language": file = open(task_info["path"] + ".json", "r") array = json.load(file) array = lang.convert(array) self.paths_to_resources[task_info["path"]] = array file.close() elif task_info["resource_type"] == "texture": core_image = CoreImage.load(task_info["path"]) self.paths_to_resources[task_info["path"]] = core_image elif task_info["resource_type"] == "mtlFile": Models.load_materials(task_info["path"]) # self.paths_to_resources[task_info["path"]] = open(task_info["path"], "r").read() elif task_info["resource_type"] == "model": obj = Models.load_model(task_info["path"]) self.paths_to_resources[task_info["path"]] = obj elif task_info["resource_type"] == "audio": sound = SoundLoader.load(task_info["path"]) self.paths_to_resources[task_info["path"]] = sound elif task_info["resource_type"] == "font": LabelBase.register(name=task_info["section"] + "-" + task_info["option"], fn_regular=task_info["path"]) self.log_deep_debug( "Registered font -", task_info["path"], "for", task_info["section"] + "-" + task_info["option"]) elif task_info["resource_type"] == "gameConfig": parser = JSONParser(task_info["path"]) self.paths_to_resources[task_info["path"]] = parser else: self.log_critical("No know resource_type -", task_info["resource_type"]) elif task_info["type"] == "deal_resource": if task_info["resource_type"] == "language": Lang.register_array(self.paths_to_resources[task_info["path"]], task_info["option"]) elif task_info["resource_type"] == "texture": Textures.register(task_info["section"], task_info["option"], self.paths_to_resources[task_info["path"]]) # elif task_info["resource_type"] == "mtlFile": # Models.register_materials(self.paths_to_resources[task_info["path"]]) elif task_info["resource_type"] == "model": Models.register_model( task_info["option"], self.paths_to_resources[task_info["path"]]) elif task_info["resource_type"] == "audio": Audio.register(task_info["option"], self.paths_to_resources[task_info["path"]]) elif task_info["resource_type"] == "gameConfig": GameConfig.register(task_info["section"], task_info["option"], self.paths_to_resources[task_info["path"]]) else: self.log_critical("No know resource_type -", task_info["resource_type"]) elif task_info["type"] == "load_kv_lang": Builder.load_file(task_info["path"]) else: self.log_critical("No know task type -", task_info["type"]) self.__log_name_suffix__ = ""
def loadBackground(self): print 'loading bg', self.bg bg = CImage.load(self.bg, keep_data=True).texture with self.field.canvas.before: Rectangle(texture = bg, pos=(0,0), size=(1068,450))
def build(self): parent = Widget() painter = PointoutWidget() settingButton = Button(background_normal='data/task.png') sliderSize = Slider(min=1.0, max=100, value=30) parent.add_widget(painter) parent.add_widget(settingButton) #TODO: create a hover animation #load the welcome image welcomeTexture = Image.load('data/welcome.png', keep_data=True).texture welcomeImg = Rectangle(size=(500,200), pos=((Window.width/2)-250, (Window.height/2)-100), texture= welcomeTexture) #set on startup painter.canvas.add(welcomeImg) layout = GridLayout(cols=2) layout_row1 = GridLayout(cols=2) layout_row2 = GridLayout(cols=2) layout_row3 = GridLayout(cols=2) layout_row4 = GridLayout(cols=2) layout_row5 = GridLayout(cols=2) layout_row6 = GridLayout(cols=2) layout_row7 = GridLayout(cols=2) layout.add_widget(layout_row1) layout_row1.add_widget(Label(text=u'Понедельник:', font_size=15)) layout_row1.add_widget(buttonMonday) ########################## layout.add_widget(layout_row2) layout_row2.add_widget(Label(text=u'Вторник:', font_size=15)) layout_row2.add_widget(buttonTuesday) ########################## layout.add_widget(layout_row3) layout_row3.add_widget(Label(text=u'Среда:', font_size=15)) layout_row3.add_widget(buttonWednesday) ########################## layout.add_widget(layout_row4) layout_row4.add_widget(Label(text=u'Четверг:', font_size=15)) layout_row4.add_widget(buttonThursday) ########################## layout.add_widget(layout_row5) layout_row5.add_widget(Label(text=u'Пятница:', font_size=15)) layout_row5.add_widget(buttonFriday) ########################## layout.add_widget(layout_row6) layout_row6.add_widget(Label(text=u'Суббота:', font_size=15)) layout_row6.add_widget(buttonSaturday) ########################## popup = Popup(title=u'Расписание П-92', content=layout, size_hint=(None, None), size=(500, 500)) def setting_popup(obj): popup.open() settingButton.bind(on_release=setting_popup) def setting_popup_Monday(obj): content_Monday = Label(text=u'08.00 ауд.202 Мифология(л)\n\n09.50 ауд.425 Функ.прог.(п)\n\n11.40 ауд.211 ТРПО(л)\n\n13.45 ауд.211 ТРПО(л)(ВЕРХ)', font_size=20) popup_Monday = Popup(title=u'Понедельник', content=content_Monday, size_hint=(None, None), size=(500, 500)) popup_Monday.open() buttonMonday.bind(on_release=setting_popup_Monday) def setting_popup_Tuesday(obj): content_Tuesday = Label(text=u'08.00 ауд.407 ТЯПиМТ(л)\n\n09.50 ауд.419 ТЯПиМТ(п)\n\n11.40 ауд.218 Комп. графика(л)\n\n13.45 ауд.219 или 432а МСЗКИ(п)', font_size=20) popup_Tuesday = Popup(title=u'Вторник', content=content_Tuesday, size_hint=(None, None), size=(500, 500)) popup_Tuesday.open() buttonTuesday.bind(on_release=setting_popup_Tuesday) def setting_popup_Wednesday(obj): content_Wednesday = Label(text=u'08.00 ауд.402 ТРПО(п)\n\n09.50 ауд.302 Комп. графика(п)\n\n11.40 ауд.210 МСЗКИ(л)', font_size=20) popup_Wednesday = Popup(title=u'Среда', content=content_Wednesday, size_hint=(None, None), size=(500, 500)) popup_Wednesday.open() buttonWednesday.bind(on_release=setting_popup_Wednesday) def setting_popup_Thursday(obj): content_Thursday = Label(text=u'ВОЕНКА!!!', font_size=20) popup_Thursday = Popup(title=u'Четверг', content=content_Thursday, size_hint=(None, None), size=(500, 500)) popup_Thursday.open() buttonThursday.bind(on_release=setting_popup_Thursday) def setting_popup_Friday(obj): content_Friday = Label(text=u'08.00 ауд.418 Функ.прог.(л)\n\n09.50 ауд.409 Мифология(п)\n\n11.40 ОКНО(НИЗ)\n\n13.45 ауд.418 ТЯПиМТ(л)(НИЗ)', font_size=20) popup_Friday = Popup(title=u'Пятница', content=content_Friday, size_hint=(None, None), size=(500, 500)) popup_Friday.open() buttonFriday.bind(on_release=setting_popup_Friday) def setting_popup_Saturday(obj): content_Saturday = Label(text=u'СВОБОДА!!!', font_size=20) popup_Saturday = Popup(title=u'Суббота', content=content_Saturday, size_hint=(None, None), size=(500, 500)) popup_Saturday.open() buttonSaturday.bind(on_release=setting_popup_Saturday) return parent
def build(self): self.root = Builder.load_string(kv) self.texture = CoreImage.load( 'GrassGreenTexture0002.jpg').texture self.texture.wrap = 'repeat' return self.root
def __load_icon(self, app_dir: str) -> Image: iconPath = app_dir + "/Icon.png" icon = Image.load(iconPath) return icon
def loadBackground(self): print 'loading bg', self.bg tex = CImage.load(self.bg, keep_data=True).texture self.buildBackground(tex)
def build(self): parent = Widget() painter = PointoutWidget() settingButton = Button(background_normal='data/task.png') sliderSize = Slider(min=1.0, max=100, value=30) parent.add_widget(painter) parent.add_widget(settingButton) #TODO: create a hover animation #load the welcome image welcomeTexture = Image.load('data/welcome.png', keep_data=True).texture welcomeImg = Rectangle(size=(500, 200), pos=((Window.width / 2) - 250, (Window.height / 2) - 100), texture=welcomeTexture) #set on startup painter.canvas.add(welcomeImg) layout = GridLayout(cols=2) layout_row1 = GridLayout(cols=2) layout_row2 = GridLayout(cols=2) layout_row3 = GridLayout(cols=2) layout_row4 = GridLayout(cols=2) layout_row5 = GridLayout(cols=2) layout_row6 = GridLayout(cols=2) layout_row7 = GridLayout(cols=2) layout.add_widget(layout_row1) layout_row1.add_widget(Label(text=u'Понедельник:', font_size=15)) layout_row1.add_widget(buttonMonday) ########################## layout.add_widget(layout_row2) layout_row2.add_widget(Label(text=u'Вторник:', font_size=15)) layout_row2.add_widget(buttonTuesday) ########################## layout.add_widget(layout_row3) layout_row3.add_widget(Label(text=u'Среда:', font_size=15)) layout_row3.add_widget(buttonWednesday) ########################## layout.add_widget(layout_row4) layout_row4.add_widget(Label(text=u'Четверг:', font_size=15)) layout_row4.add_widget(buttonThursday) ########################## layout.add_widget(layout_row5) layout_row5.add_widget(Label(text=u'Пятница:', font_size=15)) layout_row5.add_widget(buttonFriday) ########################## layout.add_widget(layout_row6) layout_row6.add_widget(Label(text=u'Суббота:', font_size=15)) layout_row6.add_widget(buttonSaturday) ########################## popup = Popup(title=u'Расписание П-92', content=layout, size_hint=(None, None), size=(500, 500)) def setting_popup(obj): popup.open() settingButton.bind(on_release=setting_popup) def setting_popup_Monday(obj): content_Monday = Label( text= u'08.00 ауд.202 Мифология(л)\n\n09.50 ауд.425 Функ.прог.(п)\n\n11.40 ауд.211 ТРПО(л)\n\n13.45 ауд.211 ТРПО(л)(ВЕРХ)', font_size=20) popup_Monday = Popup(title=u'Понедельник', content=content_Monday, size_hint=(None, None), size=(500, 500)) popup_Monday.open() buttonMonday.bind(on_release=setting_popup_Monday) def setting_popup_Tuesday(obj): content_Tuesday = Label( text= u'08.00 ауд.407 ТЯПиМТ(л)\n\n09.50 ауд.419 ТЯПиМТ(п)\n\n11.40 ауд.218 Комп. графика(л)\n\n13.45 ауд.219 или 432а МСЗКИ(п)', font_size=20) popup_Tuesday = Popup(title=u'Вторник', content=content_Tuesday, size_hint=(None, None), size=(500, 500)) popup_Tuesday.open() buttonTuesday.bind(on_release=setting_popup_Tuesday) def setting_popup_Wednesday(obj): content_Wednesday = Label( text= u'08.00 ауд.402 ТРПО(п)\n\n09.50 ауд.302 Комп. графика(п)\n\n11.40 ауд.210 МСЗКИ(л)', font_size=20) popup_Wednesday = Popup(title=u'Среда', content=content_Wednesday, size_hint=(None, None), size=(500, 500)) popup_Wednesday.open() buttonWednesday.bind(on_release=setting_popup_Wednesday) def setting_popup_Thursday(obj): content_Thursday = Label(text=u'ВОЕНКА!!!', font_size=20) popup_Thursday = Popup(title=u'Четверг', content=content_Thursday, size_hint=(None, None), size=(500, 500)) popup_Thursday.open() buttonThursday.bind(on_release=setting_popup_Thursday) def setting_popup_Friday(obj): content_Friday = Label( text= u'08.00 ауд.418 Функ.прог.(л)\n\n09.50 ауд.409 Мифология(п)\n\n11.40 ОКНО(НИЗ)\n\n13.45 ауд.418 ТЯПиМТ(л)(НИЗ)', font_size=20) popup_Friday = Popup(title=u'Пятница', content=content_Friday, size_hint=(None, None), size=(500, 500)) popup_Friday.open() buttonFriday.bind(on_release=setting_popup_Friday) def setting_popup_Saturday(obj): content_Saturday = Label(text=u'СВОБОДА!!!', font_size=20) popup_Saturday = Popup(title=u'Суббота', content=content_Saturday, size_hint=(None, None), size=(500, 500)) popup_Saturday.open() buttonSaturday.bind(on_release=setting_popup_Saturday) return parent