def transit_clicked(obj, item=None): win = StandardWindow("transit", "Transit") win.autodel = True bx = Box(win) bx.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND win.resize_object_add(bx) bx.size_hint_min = 318, 318 bx.show() ic = Image(win, file=os.path.join(img_path, "icon_11.png"), size_hint_aspect=(EVAS_ASPECT_CONTROL_VERTICAL, 1, 1)) bt = Button(win, text="ImageAnimation Effect") bt.part_content_set("icon", ic) bx.pack_end(bt) bt.show() ic.show() bt.callback_clicked_add(transit_image_animation, ic) bt = Button(win, text="Color, Rotation and Translation") bx.pack_end(bt) bt.show() bt.callback_clicked_add(transit_rotation_translation_color) bt = Button(win, text="Wipe Effect") bx.pack_end(bt) bt.show() bt.callback_clicked_add(transit_wipe) win.show()
class Bubble(SmartObject): def __init__(self, win): SmartObject.__init__(self, win.evas) self.name = "bubble" #, pos=(0,100) bubble_size = (2*106, 2*159) self.bubble = Image(win, size=bubble_size, file=os.path.join(img_path, "bulle.png")) self.bubble.clip = Rectangle(win.evas, size=bubble_size, color=(255,255,255,200) ) self.member_add(self.bubble) self.member_add(self.bubble.clip) self.show() def show(self): self.bubble.clip.show() self.bubble.show() def hide(self): self.bubble.clip.hide() def add(self, content, ratio=1.0, offset_y=None): if not offset_y: offset_y=(180- 180/ratio)/2 content.size=(180,180/ratio) content.show() content.pos=self.pos content.clip=self.bubble.clip self.content=content self.member_add(content) content.move_relative(15,15+offset_y)
def fileExists(self, filePath): self.confirmPopup = Popup(self.mainWindow, size_hint_weight=EXPAND_BOTH) # Add a table to hold dialog image and text to Popup tb = Table(self.confirmPopup, size_hint_weight=EXPAND_BOTH) self.confirmPopup.part_content_set("default", tb) tb.show() # Add dialog-error Image to table need_ethumb() icon = Icon(self.confirmPopup, thumb='True') icon.standard_set('dialog-question') # Using gksudo or sudo fails to load Image here # unless options specify using preserving their existing environment. # may also fail to load other icons but does not raise an exception # in that situation. # Works fine using eSudo as a gksudo alternative, # other alternatives not tested try: dialogImage = Image(self.confirmPopup, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH, file=icon.file_get()) tb.pack(dialogImage, 0, 0, 1, 1) dialogImage.show() except RuntimeError: # An error message is displayed for this same error # when aboutWin is initialized so no need to redisplay. pass # Add dialog text to table dialogLabel = Label(self.confirmPopup, line_wrap=ELM_WRAP_WORD, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) current_file = os.path.basename(filePath) dialogLabel.text = "'%s' already exists. Overwrite?<br><br>" \ % (current_file) tb.pack(dialogLabel, 1, 0, 1, 1) dialogLabel.show() # Close without saving button no_btt = Button(self.mainWindow) no_btt.text = "No" no_btt.callback_clicked_add(self.closePopup, self.confirmPopup) no_btt.show() # Save the file and then close button sav_btt = Button(self.mainWindow) sav_btt.text = "Yes" sav_btt.callback_clicked_add(self.doSelected) sav_btt.callback_clicked_add(self.closePopup, self.confirmPopup) sav_btt.show() # add buttons to popup self.confirmPopup.part_content_set("button1", no_btt) self.confirmPopup.part_content_set("button3", sav_btt) self.confirmPopup.show()
class TestElmImage(unittest.TestCase): def setUp(self): self.w = Window("t", ELM_WIN_BASIC) self.o = Image(self.w) def tearDown(self): self.o.delete() self.w.delete() def testImageConstructor(self): self.assertIsNotNone(self.o) self.assertEqual(Eo.parent_get(self.o), self.w) def testImageFile(self): self.o.file = os.path.join(script_path, u"icon.png") self.assertEqual( self.o.file[0], os.path.join(script_path, u"icon.png")) self.assertEqual(self.o.object_size, (48, 48)) def testImageFileException(self): self.assertRaises( RuntimeError, setattr, self.o, "file", u"this_fails.png") def testImageEvas(self): self.assertIsInstance(self.o.object, evasImage) def testImageBooleans(self): self.assertTrue(self.o.aspect_fixed) self.o.aspect_fixed = False self.assertFalse(self.o.aspect_fixed) self.assertFalse(self.o.editable) self.o.editable = True self.assertTrue(self.o.editable) self.assertFalse(self.o.fill_outside) self.o.fill_outside = True self.assertTrue(self.o.fill_outside) self.assertFalse(self.o.no_scale) self.o.no_scale = True self.assertTrue(self.o.no_scale) # Write-only value self.o.preload_disabled = True self.assertRaises(AttributeError, getattr, self.o, "preload_disabled") self.assertEqual(self.o.resizable, (True, True)) self.o.resizable = False, False self.assertEqual(self.o.resizable, (False, False)) self.assertTrue(self.o.smooth) self.o.smooth = False self.assertFalse(self.o.smooth)
class TestElmImage(unittest.TestCase): def setUp(self): self.w = Window("t", ELM_WIN_BASIC) self.o = Image(self.w) def tearDown(self): self.o.delete() self.w.delete() def testImageConstructor(self): self.assertIsNotNone(self.o) self.assertEqual(Eo.parent_get(self.o), self.w) def testImageFile(self): self.o.file = os.path.join(script_path, u"icon.png") self.assertEqual(self.o.file[0], os.path.join(script_path, u"icon.png")) self.assertEqual(self.o.object_size, (48, 48)) def testImageFileException(self): self.assertRaises(RuntimeError, setattr, self.o, "file", u"this_fails.png") def testImageEvas(self): self.assertIsInstance(self.o.object, evasImage) def testImageBooleans(self): self.assertTrue(self.o.aspect_fixed) self.o.aspect_fixed = False self.assertFalse(self.o.aspect_fixed) self.assertFalse(self.o.editable) self.o.editable = True self.assertTrue(self.o.editable) self.assertFalse(self.o.fill_outside) self.o.fill_outside = True self.assertTrue(self.o.fill_outside) self.assertFalse(self.o.no_scale) self.o.no_scale = True self.assertTrue(self.o.no_scale) # Write-only value self.o.preload_disabled = True self.assertRaises(AttributeError, getattr, self.o, "preload_disabled") self.assertEqual(self.o.resizable, (True, True)) self.o.resizable = False, False self.assertEqual(self.o.resizable, (False, False)) self.assertTrue(self.o.smooth) self.o.smooth = False self.assertFalse(self.o.smooth)
class CalibratorModule(EmcModule): name = 'calibrator' label = _('Screen calibrator') icon = 'icon/calib' info = _('Use this module to calibrate your screen parameters.') path = os.path.dirname(__file__) def __init__(self): config_gui.root_item_add('calibrator', 100, _('Screen calibrator'), icon='icon/calib', callback=self.startup) def __shutdown__(self): config_gui.root_item_del('calibrator') def startup(self): self.i = Image(gui.win, aspect_fixed=False, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) gui.win.resize_object_add(self.i) self.i.show() input_events.listener_add(self.name, self.input_event_cb) self.current = -1 self.next_sheet() def next_sheet(self): self.current = self.current + 1 if self.current < len(sheets) - 1 else 0 self.i.file = os.path.join(self.path, sheets[self.current]) print('Loaded: ' + sheets[self.current]) def prev_sheet(self): self.current = self.current - 1 if self.current > 0 else len(sheets) - 1 self.i.file = os.path.join(self.path, sheets[self.current]) def close(self): self.i.delete() input_events.listener_del(self.name) def input_event_cb(self, event): if event in ('RIGHT', 'DOWN', 'OK'): self.next_sheet() return input_events.EVENT_BLOCK elif event in ('LEFT', 'UP'): self.prev_sheet() return input_events.EVENT_BLOCK elif event in ('BACK', 'EXIT'): self.close() return input_events.EVENT_BLOCK return input_events.EVENT_CONTINUE
def __init__(self): StandardWindow.__init__(self, "ex5", "Static Image", size=(300, 200)) self.callback_delete_request_add(lambda o: elm.exit()) ourImage = Image(self) ourImage.size_hint_weight = EXPAND_BOTH ourImage.file_set("images/logo.png") ourImage.tooltip_text_set("A picture!") ourImage.show() self.resize_object_add(ourImage)
class PictureFrame(Frame): def __init__(self, parent_widget, ourText=None, image=None, *args, **kwargs): Frame.__init__(self, parent_widget, *args, **kwargs) self.text = ourText self.ourImage = Image(self) self.ourImage.size_hint_weight = EXPAND_BOTH if image: self.ourImage.file_set(image) self.content_set(self.ourImage) def file_set(self, image): self.ourImage.file_set(image)
def __init__(self, ourParent, ourMsg, ourIcon=None, *args, **kwargs): Popup.__init__(self, ourParent, *args, **kwargs) self.callback_block_clicked_add(lambda obj: self.delete()) # Add a table to hold dialog image and text to Popup tb = Table(self, size_hint_weight=EXPAND_BOTH) self.part_content_set("default", tb) tb.show() # Add dialog-error Image to table need_ethumb() icon = Icon(self, thumb='True') icon.standard_set(ourIcon) # Using gksudo or sudo fails to load Image here # unless options specify using preserving their existing environment. # may also fail to load other icons but does not raise an exception # in that situation. # Works fine using eSudo as a gksudo alternative, # other alternatives not tested try: dialogImage = Image(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH, file=icon.file_get()) tb.pack(dialogImage, 0, 0, 1, 1) dialogImage.show() except RuntimeError: # An error message is displayed for this same error # when aboutWin is initialized so no need to redisplay. pass # Add dialog text to table dialogLabel = Label(self, line_wrap=ELM_WRAP_WORD, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) dialogLabel.text = ourMsg tb.pack(dialogLabel, 1, 0, 1, 1) dialogLabel.show() # Ok Button ok_btt = Button(self) ok_btt.text = "Ok" ok_btt.callback_clicked_add(lambda obj: self.delete()) ok_btt.show() # add button to popup self.part_content_set("button3", ok_btt)
def errorPopup(window, errorMsg): errorPopup = Popup(window, size_hint_weight=EXPAND_BOTH) errorPopup.callback_block_clicked_add(lambda obj: errorPopup.delete()) # Add a table to hold dialog image and text to Popup tb = Table(errorPopup, size_hint_weight=EXPAND_BOTH) errorPopup.part_content_set("default", tb) tb.show() # Add dialog-error Image to table need_ethumb() icon = Icon(errorPopup, thumb='True') icon.standard_set('dialog-warning') # Using gksudo or sudo fails to load Image here # unless options specify using preserving their existing environment. # may also fail to load other icons but does not raise an exception # in that situation. # Works fine using eSudo as a gksudo alternative, # other alternatives not tested try: dialogImage = Image(errorPopup, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH, file=icon.file_get()) tb.pack(dialogImage, 0, 0, 1, 1) dialogImage.show() except RuntimeError: # An error message is displayed for this same error # when aboutWin is initialized so no need to redisplay. pass # Add dialog text to table dialogLabel = Label(errorPopup, line_wrap=ELM_WRAP_WORD, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) dialogLabel.text = errorMsg tb.pack(dialogLabel, 1, 0, 1, 1) dialogLabel.show() # Ok Button ok_btt = Button(errorPopup) ok_btt.text = "Ok" ok_btt.callback_clicked_add(lambda obj: errorPopup.delete()) ok_btt.show() # add button to popup errorPopup.part_content_set("button3", ok_btt) errorPopup.show()
def __init__(self, parent_widget, ourText=None, image=None, *args, **kwargs): Frame.__init__(self, parent_widget, *args, **kwargs) self.text = ourText self.ourImage = Image(self) self.ourImage.size_hint_weight = EXPAND_BOTH if image: self.ourImage.file_set(image) self.content_set(self.ourImage)
def startup(self): self.i = Image(gui.win, aspect_fixed=False, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) gui.win.resize_object_add(self.i) self.i.show() input_events.listener_add(self.name, self.input_event_cb) self.current = -1 self.next_sheet()
def __init__(self, win): SmartObject.__init__(self, win.evas) self.name = "bubble" #, pos=(0,100) bubble_size = (2*106, 2*159) self.bubble = Image(win, size=bubble_size, file=os.path.join(img_path, "bulle.png")) self.bubble.clip = Rectangle(win.evas, size=bubble_size, color=(255,255,255,200) ) self.member_add(self.bubble) self.member_add(self.bubble.clip) self.show()
class EyeBalls(SmartObject): #Transformable def __init__(self, win, eyes): SmartObject.__init__(self, win.evas) self.name = "eyeballs" self.eyeballs = Image( win, pos=eyeballs_pos, size=eyeballs_size, file=os.path.join(img_path, "retine_sim.png")) self.member_add(self.eyeballs) #Transformable.__init__(self, self.eyeballs) self.show() def show(self): self.eyeballs.show() def hide(self): self.eyeballs.hide()
def transit6_clicked(obj, item=None): win = StandardWindow("transit6","Transit 6", autodel=True, size=(300, 300)) ic = Image(win, file=os.path.join(img_path, "rock_01.jpg"), size_hint_max=(50, 50)) bt = Button(win, text="Before Button - Fade Effect", pos=(25, 125), size=(250, 50)) bt.part_content_set("icon", ic) bt.show() ic = Image(win, file=os.path.join(img_path, "rock_02.jpg"), size_hint_max=(50, 50)) bt2 = Button(win, text="After Button - Fade Effect", pos=(25, 125), size=(250, 50)) bt2.part_content_set("icon", ic) win.show() bt.callback_clicked_add(transit_fade, bt2) bt2.callback_clicked_add(transit_fade, bt)
def __init__(self): StandardWindow.__init__(self, "ex7", "Naviframe", size=(300, 200)) self.callback_delete_request_add(lambda o: elm.exit()) staticImage = staticImage = Image(self) staticImage.size_hint_weight = EXPAND_BOTH staticImage.file_set("images/logo.png") staticImage.tooltip_text_set("A picture!") staticImage.show() ourLabel = ourLabel = Label(self) ourLabel.size_hint_weight = EXPAND_BOTH ourLabel.text = "Hey look some text!" ourLabel.show() self.nf = Naviframe(self) self.nf.size_hint_weight = EXPAND_BOTH self.nf.size_hint_align = FILL_BOTH self.nf.show() buttonOne = Button(self) buttonOne.size_hint_weight = EXPAND_BOTH buttonOne.text = "Show image" buttonOne.callback_clicked_add(self.buttonPressed, staticImage) buttonOne.show() buttonTwo = Button(self) buttonTwo.size_hint_weight = EXPAND_BOTH buttonTwo.text = "Show label" buttonTwo.callback_clicked_add(self.buttonPressed, ourLabel) buttonTwo.show() buttonBox = Box(self) buttonBox.size_hint_weight = EXPAND_HORIZ buttonBox.horizontal_set(True) buttonBox.pack_end(buttonOne) buttonBox.pack_end(buttonTwo) buttonBox.show() mainBox = Box(self) mainBox.size_hint_weight = EXPAND_BOTH mainBox.pack_end(self.nf) mainBox.pack_end(buttonBox) mainBox.show() self.nf.item_simple_push(staticImage) self.resize_object_add(mainBox)
def __init__(self): StandardWindow.__init__(self, "ex6", "Selected Image", size=(300, 200)) self.callback_delete_request_add(lambda o: elm.exit()) self.ourImage = ourImage = Image(self) ourImage.size_hint_weight = EXPAND_BOTH ourImage.size_hint_align = FILL_BOTH ourImage.file_set("images/logo.png") ourImage.tooltip_text_set("A picture!") ourImage.show() ourButton = FileselectorButton(self) ourButton.size_hint_weight = EXPAND_HORIZ ourButton.text = "Select new Image" ourButton.callback_file_chosen_add(self.fileSelected) ourButton.show() ourBox = Box(self) ourBox.size_hint_weight = EXPAND_BOTH ourBox.pack_end(ourImage) ourBox.pack_end(ourButton) ourBox.show() self.resize_object_add(ourBox)
def setUp(self): self.w = Window("t", ELM_WIN_BASIC) self.o = Image(self.w)
def __init__(self, parent, canvas): self._parent = parent self._canvas = canvas # Dialog Window Basics self.aboutDialog = Window("epad", ELM_WIN_DIALOG_BASIC) # self.aboutDialog.callback_delete_request_add(self.closeabout) # Set Dialog background background = Background(self.aboutDialog, size_hint_weight=EXPAND_BOTH) self.aboutDialog.resize_object_add(background) background.show() # mainBox = Box(self.aboutDialog, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.aboutDialog.resize_object_add(mainBox) mainBox.show() # need_ethumb() icon = Icon(self.aboutDialog, thumb='True') icon.standard_set('accessories-text-editor') # Using gksudo or sudo fails to load Image here # unless options specify using preserving their existing environment. # may also fail to load other icons but does not raise an exception # in that situation. # Works fine using eSudo as a gksudo alternative, # other alternatives not tested try: aboutImage = Image(self.aboutDialog, no_scale=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, file=icon.file_get()) aboutImage.aspect_fixed_set(False) mainBox.pack_end(aboutImage) aboutImage.show() except RuntimeError as msg: print("Warning: to run as root please use:\n" "\t gksudo -k or sudo -E \n" "Continuing with minor errors ...") labelBox = Box(self.aboutDialog, size_hint_weight=EXPAND_NONE) mainBox.pack_end(labelBox) labelBox.show() # Entry to hold text titleStr = '<br>ePad version <em>{0}</em><br>'.format(__version__) aboutStr = ('<br>A simple text editor written in <br>' 'python and elementary<br>') aboutLbTitle = Label(self.aboutDialog, style='marker') aboutLbTitle.text = titleStr aboutLbTitle.show() labelBox.pack_end(aboutLbTitle) sep = Separator(self.aboutDialog, horizontal=True) labelBox.pack_end(sep) sep.show() aboutText = Label(self.aboutDialog) aboutText.text = aboutStr aboutText.show() labelBox.pack_end(aboutText) aboutCopyright = Label(self.aboutDialog) aboutCopyright.text = '<b>Copyright</b> © <i>2014 Bodhi Linux</i><br>' aboutCopyright.show() labelBox.pack_end(aboutCopyright) # Dialog Buttons # Horizontal Box for Dialog Buttons buttonBox = Box(self.aboutDialog, horizontal=True, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH, padding=PADDING) buttonBox.size_hint_weight_set(EVAS_HINT_EXPAND, 0.0) buttonBox.show() labelBox.pack_end(buttonBox) # Credits Button creditsBtn = Button(self.aboutDialog, text="Credits ", size_hint_weight=EXPAND_NONE) creditsBtn.callback_clicked_add(self.creditsPress) creditsBtn.show() buttonBox.pack_end(creditsBtn) # Close Button okBtn = Button(self.aboutDialog, text=" Close ", size_hint_weight=EXPAND_NONE) okBtn.callback_clicked_add(self.closeabout) okBtn.show() buttonBox.pack_end(okBtn) # Ensure the min height self.aboutDialog.resize(300, 100)
def main_loop(): win = StandardWindow("WLX42 Eyes", "Eyes of the robot", autodel=True) win.callback_delete_request_add(lambda o: elementary.exit()) bg = Rectangle(win.evas, size = screenSize, color=(0,0,100,255), pos=(0,0)) #bg.clip = Rectangle(win.evas, size = screenSize, color=(0,0,100,255), pos=(0,100) ) bg.show() underlay = Rectangle(win.evas, pos=global_offset, size = screenSize, color=(255,255,255,255)) underlay.show() eyes = Image(win, size = screenSize, pos=global_offset, file=os.path.join(img_path, "oeil-1.png")) #overlay.clip = Image(win, size = screenSize, pos=(0,0), file=os.path.join(img_path, "mb.png")) #overlay.clip.show() eyes.clip = Rectangle(win.evas, size = screenSize, color=(0,0,100,255), pos=(0,0) ) eyes.clip.show() eyes.show() mustache = Image(win, size=screenSize, pos=global_offset, file=os.path.join(img_path, "moustaches.png")) mustache.clip = Rectangle(win.evas, size = screenSize, color=(0,0,100,255), pos=(0,0) ) mustache.clip.show() mustache.stack_above(eyes) mustache.show() bubble_pos = (0,100) bubble_size = (2*106, 2*159) bubble = Image(win, size = bubble_size, pos=bubble_pos, file=os.path.join(img_path, "bulle.png")) bubble.clip = Rectangle(win.evas, size = bubble_size, color=(255,255,255,200), pos=bubble_pos ) bubble.clip.show() bubble.stack_above(eyes) bubble.show() bubble_text_pos=(bubble_pos[0]+10, bubble_pos[1]+10) bubble_text = Text(win.evas, text='', color=(255,255,255,255), pos=bubble_text_pos, size=(180,180)) bubble_text.font_source = font_path bubble_text.font = "FontAwesome", 150 bubble_text.style = EVAS_TEXT_STYLE_SOFT_SHADOW bubble_text.shadow_color = (64,64,64,127) bubble_text.stack_above(bubble) bubble_text.show() # bx = Box(win) # win.resize_object_add(bx) # bx.size_hint_weight = EXPAND_BOTH # bx.show() # lb.show() # lb = Label(win, text="Blah, Blah, Blah") # lb2 = Label(win, text="Tut, Tut, Tut!") # bb = Bubble(win, text = "Message 1", content = lb, # pos = ELM_BUBBLE_POS_TOP_LEFT, size_hint_weight = EXPAND_BOTH, # size_hint_align = FILL_BOTH) # bb.part_text_set("info", "Corner: top_left") # bb.part_content_set("icon", ic) # bx.pack_end(bb) # bb.show() eyeballs = Image(win, size = eyeballs_size, pos=eyeballs_pos, file=os.path.join(img_path, "retine_sim.png")) blink = Image(win, size = screenSize, pos = global_offset, file=os.path.join(img_path, "oeil-11.png")) blink.clip = eyes.clip; dead = Image(win, size = screenSize, pos = global_offset, file=os.path.join(img_path, "oeil-10.png")) #eyes eyeballs.stack_below(eyes) eyeballs.show() def on_tick(*args, **kargs): draw(win, bg, eyeballs, eyes, blink) return True Animator(on_tick) draw(win, bg, eyeballs, eyes, blink) win.resize(screenX, screenY) win.show()
def gg_content_get(obj, part, data): if part == "elm.swallow.icon": im = Image(obj, file=os.path.join(img_path, random.choice(images)), size_hint_aspect=(EVAS_ASPECT_CONTROL_BOTH, 1, 1)) return im return None
def image_clicked(obj): win = StandardWindow("image", "Image test", autodel=True, size=(320, 480)) if obj is None: win.callback_delete_request_add(lambda o: elementary.exit()) vbox = Box(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) win.resize_object_add(vbox) vbox.show() im = Image(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, file=os.path.join(img_path, "logo.png")) vbox.pack_end(im) im.show() sep = Separator(win, horizontal=True) vbox.pack_end(sep) sep.show() hbox = Box(win, layout=ELM_BOX_LAYOUT_FLOW_HORIZONTAL, size_hint_align=FILL_BOTH) vbox.pack_end(hbox) hbox.show() for rot in orients: b = Button(win, text=rot[0]) hbox.pack_end(b) b.callback_clicked_add(lambda b, y=rot[1]: im.orient_set(y)) b.show() sep = Separator(win, horizontal=True) vbox.pack_end(sep) sep.show() hbox = Box(win, horizontal=True, size_hint_align=FILL_BOTH) vbox.pack_end(hbox) hbox.show() b = Button(win, text="Set remote URL") hbox.pack_end(b) b.callback_clicked_add(lambda b: im.file_set(remote_url)) b.show() pb = Progressbar(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) hbox.pack_end(pb) pb.show() im.callback_download_start_add(_cb_im_download_start, pb) im.callback_download_done_add(_cb_im_download_done) im.callback_download_progress_add(_cb_im_download_progress, pb) im.callback_download_error_add(_cb_im_download_error, pb) win.show()
def __init__(self, parent_widget, *args, default_path='', default_populate=True, **kwargs): Box.__init__(self, parent_widget, *args, **kwargs) self.cancel_cb = None self.action_cb = None self.cb_dir_change = None self.threaded_fn = ThreadedFunction() # pylint: disable=c-extension-no-member self._timer = ecore.Timer(0.02, self.populate_file) # Watch key presses for ctrl+l to select entry parent_widget.elm_event_callback_add(self.cb_events) self.selected_dir = None self.show_hidden = False self.cur_dir = None self.focused_entry = None self.dir_only = False self.sort_reverse = False self.adding_hidden = False self.pending_files = deque() self.cur_subdirs = [] self.cur_files = [] # Mode should be 'save' or 'load' self.mode = 'save' self.home = os.path.expanduser('~') desktop = os.environ.get('XDG_DESKTOP_DIR') if desktop: self.desktop = desktop else: self.desktop = self.home + '/Desktop' self.root = '/' # Label+Entry for File Name self.filename_bx = Box(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) self.filename_bx.horizontal = True self.filename_bx.show() file_label = Label(self, size_hint_weight=(0.15, EVAS_HINT_EXPAND), size_hint_align=FILL_HORIZ) file_label.text = 'Filename:' file_label.show() self.file_entry = Entry(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_HORIZ) self.file_entry.single_line_set(True) self.file_entry.scrollable_set(True) self.file_entry.callback_changed_user_add(self.cb_file_entry) self.file_entry.show() self.filename_bx.pack_end(file_label) self.filename_bx.pack_end(self.file_entry) sep = Separator(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) sep.horizontal_set(True) sep.show() # Label+Entry for File Path self.filepath_bx = Box(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) self.filepath_bx.horizontal = True self.filepath_bx.show() file_label = Label(self, size_hint_weight=(0.15, EVAS_HINT_EXPAND), size_hint_align=FILL_HORIZ) file_label.text = 'Current Folder:' file_label.show() self.filepath_en = Entry(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_HORIZ) self.filepath_en.single_line_set(True) self.filepath_en.scrollable_set(True) self.filepath_en.callback_changed_user_add(self.cb_file_entry) self.filepath_en.callback_unfocused_add(self.cb_filepath_en) self.filepath_en.callback_activated_add(self.cb_filepath_en) # Wish this worked. Doesn't seem to do anything # Working now EFL 1.22 ? self.filepath_en.input_hint_set(ELM_INPUT_HINT_AUTO_COMPLETE) if default_path and os.path.isdir(default_path): start = default_path else: start = self.home self.filepath_en.show() self.filepath_bx.pack_end(file_label) self.filepath_bx.pack_end(self.filepath_en) self.autocomplete_hover = Hoversel(self, hover_parent=self) self.autocomplete_hover.callback_selected_add(self.cb_hover) self.autocomplete_hover.show() self.file_selector_bx = Panes(self, content_left_size=0.3, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.file_selector_bx.show() # Bookmarks Box contains: # # - Button - Up Arrow # - List - Home/Desktop/Root/GTK bookmarks # - Box # -- Button - Add Bookmark # -- Button - Remove Bookmark self.bookmark_bx = Box(self, size_hint_weight=(0.3, EVAS_HINT_EXPAND), size_hint_align=FILL_BOTH) self.bookmark_bx.show() up_ic = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, order_lookup=ELM_ICON_LOOKUP_THEME) up_ic.standard_set('arrow-up') up_ic.show() self.up_btn = Button(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ, content=up_ic) self.up_btn.text = 'Up' self.up_btn.callback_pressed_add(self.cb_up_btn) self.up_btn.show() self.bookmarks_lst = List(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.bookmarks_lst.callback_activated_add(self.cb_bookmarks_lst) self.bookmarks_lst.show() self.bookmark_modbox = Box(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) self.bookmark_modbox.horizontal = True self.bookmark_modbox.show() con = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) con.standard_set('list-add') con.show() self.add_btn = Button(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ, content=con) self.add_btn.callback_pressed_add(self.cb_add_btn) self.add_btn.disabled = True self.add_btn.show() con = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) con.standard_set('list-remove') con.show() self.rm_btn = Button(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ, content=con) self.rm_btn.callback_pressed_add(self.cb_remove) self.rm_btn.disabled = True self.rm_btn.show() self.bookmark_modbox.pack_end(self.add_btn) self.bookmark_modbox.pack_end(self.rm_btn) self.bookmark_bx.pack_end(self.up_btn) self.bookmark_bx.pack_end(self.bookmarks_lst) self.bookmark_bx.pack_end(self.bookmark_modbox) # Directory List self.file_list_bx = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.file_list_bx.show() self.file_sort_btn = Button(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) self.file_sort_btn.text = u'⬆ Name' self.file_sort_btn.callback_pressed_add(self.cb_sort) self.file_sort_btn.show() self.file_lst = Genlist(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, homogeneous=True, mode=ELM_LIST_COMPRESS) self.file_lst.callback_activated_add(self.cb_file_lst) self.file_lst.show() self.preview = preview = Image(self) preview.size_hint_align = FILL_BOTH preview.show() self.file_list_bx.pack_end(self.file_sort_btn) self.file_list_bx.pack_end(self.file_lst) self.file_list_bx.pack_end(self.preview) self.file_selector_bx.part_content_set('left', self.bookmark_bx) self.file_selector_bx.part_content_set('right', self.file_list_bx) # Cancel and Save/Open button self.button_bx = Box(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=(1.0, 0.5)) self.button_bx.horizontal = True self.button_bx.show() self.action_ic = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.action_ic.standard_set('document-save') self.action_ic.show() self.action_btn = Button(self, size_hint_weight=(0.0, 0.0), size_hint_align=(1.0, 0.5), content=self.action_ic) self.action_btn.text = 'Save ' self.action_btn.callback_pressed_add(self.cb_action_btn) self.action_btn.show() cancel_ic = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) cancel_ic.standard_set('application-exit') cancel_ic.show() self.cancel_btn = Button(self, size_hint_weight=(0.0, 0.0), size_hint_align=(1.0, 0.5), content=cancel_ic) self.cancel_btn.text = 'Cancel ' self.cancel_btn.callback_pressed_add(self.cb_cancel_btn) self.cancel_btn.show() con = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) con.standard_set('edit-find') con.show() self.hidden_btn = Button(self, size_hint_weight=(0.0, 0.0), size_hint_align=(1.0, 0.5), content=con) self.hidden_btn.text = 'Toggle Hidden ' self.hidden_btn.callback_pressed_add(self.cb_toggle_hidden) self.hidden_btn.show() con = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) con.standard_set('folder-new') con.show() self.create_dir_btn = Button(self, size_hint_weight=(0.0, 0.0), size_hint_align=(1.0, 0.5), content=con) self.create_dir_btn.text = 'Create Folder ' self.create_dir_btn.callback_pressed_add(self.cb_create_dir) self.create_dir_btn.show() self.button_bx.pack_end(self.create_dir_btn) self.button_bx.pack_end(self.hidden_btn) self.button_bx.pack_end(self.cancel_btn) self.button_bx.pack_end(self.action_btn) self.pack_end(self.filename_bx) self.pack_end(sep) self.pack_end(self.filepath_bx) self.pack_end(self.autocomplete_hover) self.pack_end(self.file_selector_bx) self.pack_end(self.button_bx) self.populate_bookmarks() self.create_popup = Popup(self) self.create_popup.part_text_set('title,text', 'Create Folder:') self.create_en = Entry(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) self.create_en.single_line_set(True) self.create_en.scrollable_set(True) self.create_en.show() self.create_popup.content = self.create_en bt0 = Button(self, text='Create') bt0.callback_clicked_add(self.cb_create_folder) self.create_popup.part_content_set('button1', bt0) bt1 = Button(self, text='Cancel') bt1.callback_clicked_add(self.cb_close_popup) self.create_popup.part_content_set('button2', bt1) self.recent = None # keeps pylint happy: if default_populate: self.populate_files(start)
def __init__(self, parent_widget, defaultPath="", defaultPopulate=True, *args, **kwargs): Box.__init__(self, parent_widget, *args, **kwargs) self.cancelCallback = None self.actionCallback = None self.directoryChangeCallback = None self.threadedFunction = ThreadedFunction() self._timer = ecore.Timer(0.02, self.populateFile) #Watch key presses for ctrl+l to select entry parent_widget.elm_event_callback_add(self.eventsCb) self.selectedFolder = None self.showHidden = False self.currentDirectory = None self.focusedEntry = None self.folderOnly = False self.sortReverse = False self.addingHidden = False self.pendingFiles = deque() self.currentSubFolders = [] self.currentFiles = [] #Mode should be "save" or "load" self.mode = "save" self.home = os.path.expanduser("~") self.root = "/" #Label+Entry for File Name self.filenameBox = Box(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) self.filenameBox.horizontal = True self.filenameBox.show() fileLabel = Label(self, size_hint_weight=(0.15, EVAS_HINT_EXPAND), size_hint_align=FILL_HORIZ) fileLabel.text = "Filename:" fileLabel.show() self.fileEntry = Entry(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_HORIZ) self.fileEntry.single_line_set(True) self.fileEntry.scrollable_set(True) self.fileEntry.callback_changed_user_add(self.fileEntryChanged) self.fileEntry.show() self.filenameBox.pack_end(fileLabel) self.filenameBox.pack_end(self.fileEntry) sep = Separator(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) sep.horizontal_set(True) sep.show() #Label+Entry for File Path self.filepathBox = Box(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) self.filepathBox.horizontal = True self.filepathBox.show() fileLabel = Label(self, size_hint_weight=(0.15, EVAS_HINT_EXPAND), size_hint_align=FILL_HORIZ) fileLabel.text = "Current Folder:" fileLabel.show() self.filepathEntry = Entry(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_HORIZ) self.filepathEntry.single_line_set(True) self.filepathEntry.scrollable_set(True) self.filepathEntry.callback_changed_user_add(self.fileEntryChanged) self.filepathEntry.callback_unfocused_add(self.filepathEditDone) self.filepathEntry.callback_activated_add(self.filepathEditDone) #Wish this worked. Doesn't seem to do anything #self.filepathEntry.input_hint_set(ELM_INPUT_HINT_AUTO_COMPLETE) if defaultPath and os.path.isdir(defaultPath): startPath = defaultPath else: startPath = self.home self.filepathEntry.show() self.filepathBox.pack_end(fileLabel) self.filepathBox.pack_end(self.filepathEntry) self.autocompleteHover = Hoversel(self, hover_parent=self) self.autocompleteHover.callback_selected_add(self.autocompleteSelected) #self.autocompleteHover.show() self.fileSelectorBox = Panes(self, content_left_size=0.3, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.fileSelectorBox.show() """Bookmarks Box contains: - Button - Up Arrow - List - Home/Root/GTK bookmarks - Box -- Button - Add Bookmark -- Button - Remove Bookmark""" self.bookmarkBox = Box(self, size_hint_weight=(0.3, EVAS_HINT_EXPAND), size_hint_align=FILL_BOTH) self.bookmarkBox.show() upIcon = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) upIcon.standard_set("go-up") upIcon.show() self.upButton = Button(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ, content=upIcon) self.upButton.text = "Up" self.upButton.callback_pressed_add(self.upButtonPressed) self.upButton.show() self.bookmarksList = List(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.bookmarksList.callback_activated_add(self.bookmarkDoubleClicked) self.bookmarksList.show() self.bookmarkModBox = Box(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) self.bookmarkModBox.horizontal = True self.bookmarkModBox.show() con = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) con.standard_set("add") con.show() self.addButton = Button(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ, content=con) self.addButton.callback_pressed_add(self.addButtonPressed) self.addButton.disabled = True self.addButton.show() con = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) con.standard_set("remove") con.show() self.removeButton = Button(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ, content=con) self.removeButton.callback_pressed_add(self.removeButtonPressed) self.removeButton.disabled = True self.removeButton.show() self.bookmarkModBox.pack_end(self.addButton) self.bookmarkModBox.pack_end(self.removeButton) self.bookmarkBox.pack_end(self.upButton) self.bookmarkBox.pack_end(self.bookmarksList) self.bookmarkBox.pack_end(self.bookmarkModBox) #Directory List self.fileListBox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.fileListBox.show() self.fileSortButton = Button(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) self.fileSortButton.text = u"⬆ Name" self.fileSortButton.callback_pressed_add(self.sortData) self.fileSortButton.show() self.fileList = Genlist(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, homogeneous=True, mode=ELM_LIST_COMPRESS) self.fileList.callback_activated_add(self.fileDoubleClicked) self.fileList.show() self.previewImage = previewImage = Image(self) #previewImage.size_hint_weight = EXPAND_BOTH previewImage.size_hint_align = FILL_BOTH previewImage.show() self.fileListBox.pack_end(self.fileSortButton) self.fileListBox.pack_end(self.fileList) self.fileListBox.pack_end(self.previewImage) self.fileSelectorBox.part_content_set("left", self.bookmarkBox) self.fileSelectorBox.part_content_set("right", self.fileListBox) #Cancel and Save/Open button self.buttonBox = Box(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=(1.0, 0.5)) self.buttonBox.horizontal = True self.buttonBox.show() self.actionIcon = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.actionIcon.standard_set("document-save") self.actionIcon.show() self.actionButton = Button(self, size_hint_weight=(0.0, 0.0), size_hint_align=(1.0, 0.5), content=self.actionIcon) self.actionButton.text = "Save " self.actionButton.callback_pressed_add(self.actionButtonPressed) self.actionButton.show() cancelIcon = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) cancelIcon.standard_set("dialog-cancel") cancelIcon.show() self.cancelButton = Button(self, size_hint_weight=(0.0, 0.0), size_hint_align=(1.0, 0.5), content=cancelIcon) self.cancelButton.text = "Cancel " self.cancelButton.callback_pressed_add(self.cancelButtonPressed) self.cancelButton.show() con = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) con.standard_set("gtk-find") con.show() self.toggleHiddenButton = Button(self, size_hint_weight=(0.0, 0.0), size_hint_align=(1.0, 0.5), content=con) self.toggleHiddenButton.text = "Toggle Hidden " self.toggleHiddenButton.callback_pressed_add( self.toggleHiddenButtonPressed) self.toggleHiddenButton.show() con = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) con.standard_set("folder-new") con.show() self.createFolderButton = Button(self, size_hint_weight=(0.0, 0.0), size_hint_align=(1.0, 0.5), content=con) self.createFolderButton.text = "Create Folder " self.createFolderButton.callback_pressed_add( self.createFolderButtonPressed) self.createFolderButton.show() self.buttonBox.pack_end(self.createFolderButton) self.buttonBox.pack_end(self.toggleHiddenButton) self.buttonBox.pack_end(self.cancelButton) self.buttonBox.pack_end(self.actionButton) self.pack_end(self.filenameBox) self.pack_end(sep) self.pack_end(self.filepathBox) self.pack_end(self.autocompleteHover) self.pack_end(self.fileSelectorBox) self.pack_end(self.buttonBox) self.populateBookmarks() self.createPopup = Popup(self) self.createPopup.part_text_set("title,text", "Create Folder:") self.createEn = en = Entry(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) en.single_line_set(True) en.scrollable_set(True) en.show() self.createPopup.content = en bt = Button(self, text="Create") bt.callback_clicked_add(self.createFolder) self.createPopup.part_content_set("button1", bt) bt2 = Button(self, text="Cancel") bt2.callback_clicked_add(self.closePopup) self.createPopup.part_content_set("button2", bt2) if defaultPopulate: self.populateFiles(startPath)