Skip to content

Commit f6abea6

Browse files
committed
Switch to python3
1 parent 14269ff commit f6abea6

File tree

8 files changed

+263
-239
lines changed

8 files changed

+263
-239
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v0.6.0
2+
- Switch to Python3
3+
4+
15
v0.5.7
26
Fixes:
37
- Missing dependencies

DEBIAN/control

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Priority: extra
33
Maintainer: Denis Kovalev <[email protected]>
44
Package: indicator-fileshare
55
Architecture: all
6-
Description: Imgur and Droplr applet indicator
7-
Depends: gnome-icon-theme, libgtk-3-bin, python-gconf, python-cairo, libappindicator3-dev, python-gi, python-gi-cairo
6+
Description: Imgur applet indicator
7+
Depends: gnome-icon-theme, libgtk-3-bin, python-gconf, python3-cairo, libappindicator3-dev, python3-gi, python3-gi-cairo, python3-requests, gir1.2-notify-0.7
88
Homepage: http://aikikode.github.com/fileshare/
9-
Version: 0.5.7
9+
Version: 0.6.0

INSTALL

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ INSTALLATION
44
Linux
55
-----
66
Currently deb-based system are supported.
7-
To install Fileshare Applet first run the following command:
8-
$ ./build_deb.sh
9-
It will create deb package in the current dir. Install it with:
10-
# dpkg -i <deb file>
7+
Download and install latest deb package from releases page:
8+
https://github.com/aikikode/fileshare/releases
9+
10+
Alternatively you may build deb package yourself (requires Docker):
11+
$ ./ci/build.sh
12+
13+
It will create deb package in the ./dist/ dir. Install it with:
14+
# apt install <deb file>
1115

1216
Windows
1317
-------
14-
1. Download and install Python 2.x and PyGTK.
18+
1. Download and install Python 3.x and PyGTK.
1519
2. Run
16-
python ./indicator-fileshare
20+
python3 ./indicator-fileshare

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ Fileshare Applet
22
================
33
Fileshare applet development is inspired mostly by Droplr windows client. Its
44
purpose is to share images over the Internet using on-line services.
5-
By now [Imgur](http://imgur.com) and [Droplr](http://droplr.com) services are
6-
supported.
5+
By now [Imgur](http://imgur.com) service is supported.
76

87
### Fileshare applet features
98

@@ -21,7 +20,7 @@ supported.
2120
./ci/build.sh
2221
```
2322
this will create deb package in `dist` folder.
24-
2. Install it with command:
23+
2. Install it with the command:
2524
```bash
2625
# apt-get install <path to deb file>
2726
```

build_deb.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
# USAGE: ./build_deb.sh
77
#
8-
# DESCRIPTION: creates deb package
8+
# DESCRIPTION: Creates deb package
99
#
1010
# AUTHOR: Denis Kovalev ([email protected])
1111
#===============================================================================
@@ -25,11 +25,11 @@ then
2525
mkdir -p ${BUILDDIR}/usr/share/doc/${APPNAME}
2626

2727
cp ${APPNAME} ${BUILDDIR}/usr/local/bin/
28-
cp ./icons/*.png ${BUILDDIR}/usr/local/share/${APPNAME}/media/
29-
cp ./*.py ${BUILDDIR}/usr/local/share/${APPNAME}/
28+
cp ./icons/*.png ${BUILDDIR}/usr/local/share/${APPNAME}/media/
29+
cp ./*.py ${BUILDDIR}/usr/local/share/${APPNAME}/
3030
cp ${APPNAME}.desktop ${BUILDDIR}/usr/share/applications/
31-
cp ./AUTHORS ${BUILDDIR}/usr/share/doc/${APPNAME}/
32-
cp -r ./DEBIAN ${BUILDDIR}/
31+
cp ./AUTHORS ${BUILDDIR}/usr/share/doc/${APPNAME}/
32+
cp -r ./DEBIAN ${BUILDDIR}/
3333

3434
fakeroot dpkg-deb --build ${BUILDDIR} ${OUTPUTDIR}/indicator-fileshare-${VERSION}.deb
3535
rm -fr ${BUILDDIR}

grabbers.py

Lines changed: 71 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,13 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
3-
#
4-
# Copyright 2012
5-
#
6-
# Authors: Denis Kovalev <[email protected]>
7-
#
8-
# This program is free software: you can redistribute it and/or modify it
9-
# under the terms of either or both of the following licenses:
10-
#
11-
# 1) the GNU Lesser General Public License version 3, as published by the
12-
# Free Software Foundation; and/or
13-
# 2) the GNU Lesser General Public License version 2.1, as published by
14-
# the Free Software Foundation.
15-
#
16-
# This program is distributed in the hope that it will be useful, but
17-
# WITHOUT ANY WARRANTY; without even the implied warranties of
18-
# MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
19-
# PURPOSE. See the applicable version of the GNU Lesser General Public
20-
# License for more details.
21-
#
22-
# You should have received a copy of both the GNU Lesser General Public
23-
# License version 3 and version 2.1 along with this program. If not, see
24-
# <http://www.gnu.org/licenses>
25-
#
26-
27-
28-
__author__ = 'aikikode'
29-
301
import cairo
312
import os
323
import re
334
import tempfile
345
import threading
35-
from gi.repository import GObject
36-
from gi.repository import Gdk
37-
from gi.repository import GdkPixbuf
38-
from gi.repository import Gtk
6+
from gi.repository import GObject, Gdk, GdkPixbuf, Gtk
397

408
FILE_GRABBER_SIZE = 50
9+
MAX_PREVIEW_WIDTH = 800
10+
MAX_PREVIEW_HEIGHT = 600
4111

4212

4313
class FileGrabber:
@@ -61,13 +31,18 @@ def __init__(self, app_icon, upload_callback):
6131
# Add main widget for grabbing files
6232
self.image = Gtk.Image()
6333
pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.app_icon)
64-
scaled_buf = pixbuf.scale_simple(FILE_GRABBER_SIZE, FILE_GRABBER_SIZE, GdkPixbuf.InterpType.BILINEAR)
34+
scaled_buf = pixbuf.scale_simple(
35+
FILE_GRABBER_SIZE, FILE_GRABBER_SIZE,
36+
GdkPixbuf.InterpType.BILINEAR
37+
)
6538
self.image.set_from_pixbuf(scaled_buf)
6639
self.image.show()
6740
self.window.add(self.image)
6841
self.window.connect('drag-motion', self.window_drag_motion)
6942
self.window.connect('drag-drop', self.window_drag_drop)
70-
self.window.connect('drag-data-received', self.window_drag_data_received)
43+
self.window.connect(
44+
'drag-data-received', self.window_drag_data_received
45+
)
7146
self.isShown = False
7247

7348
def set_upload_callback(self, upload_callback):
@@ -79,23 +54,23 @@ def toggle_window(self):
7954
self.isShown = False
8055
else:
8156
self.window.show()
82-
self.window.set_keep_above(True) # This may not work: it depends on the window manager
57+
# This may not work: it depends on the window manager
58+
self.window.set_keep_above(True)
8359
self.isShown = True
8460

8561
def window_drag_motion(self, wid, context, x, y, time):
8662
Gdk.drag_status(context, Gdk.DragAction.COPY, time)
87-
return True # True means "I accept this data"
63+
return True # True means "I accept this data"
8864

8965
def window_drag_drop(self, wid, context, x, y, time):
9066
wid.drag_get_data(context, context.list_targets()[-1], time)
9167
return True
9268

9369
def window_drag_data_received(self, wid, context, x, y, data, info, time):
94-
if data.get_text():
95-
file_to_upload = data.get_text().splitlines()[0].replace('file://', '')
96-
else:
97-
file_to_upload = data.get_data().splitlines()[0].replace('file://', '')
98-
file_to_upload = re.sub(r'/([^/]+:/)', r'\1/', file_to_upload) # handle Win path
70+
text = data.get_text() or data.get_data()
71+
file_to_upload = text.splitlines()[0].replace('file://', '')
72+
# Handle Win path
73+
file_to_upload = re.sub(r'/([^/]+:/)', r'\1/', file_to_upload)
9974
context.finish(True, False, time)
10075
GObject.idle_add(self.upload_callback, file_to_upload, False)
10176

@@ -108,8 +83,8 @@ def __init__(self, upload_callback, quit_callback, log):
10883
self.log = log
10984
self.log.debug('ScreenGrabber: creating')
11085
self.selected = False
111-
self.screenWidth, self.screenHeight = Gdk.Screen.width(), Gdk.Screen.height()
112-
width, height = self.screenWidth, self.screenHeight
86+
self.screenWidth = width = Gdk.Screen.width()
87+
self.screenHeight = height = Gdk.Screen.height()
11388
self.drawingWindow = drawingWindow = Gtk.Window()
11489
drawingWindow.set_decorated(False)
11590
drawingWindow.set_skip_taskbar_hint(True)
@@ -135,14 +110,24 @@ def __init__(self, upload_callback, quit_callback, log):
135110
)
136111
drawingWindow.show()
137112
drawingWindow.present()
138-
drawingWindow.get_window().set_fullscreen_mode(Gdk.FullscreenMode.ALL_MONITORS)
113+
drawingWindow.get_window().set_fullscreen_mode(
114+
Gdk.FullscreenMode.ALL_MONITORS
115+
)
139116
cursor = Gdk.Cursor(Gdk.CursorType.CROSSHAIR)
140117
drawingWindow.get_window().set_cursor(cursor)
141118
drawingWindow.connect('draw', self.initial_draw)
142-
drawingWindow.connect('button-press-event', self.select_area_event_handler, self)
143-
drawingWindow.connect('button-release-event', self.select_area_event_handler, self)
144-
drawingWindow.connect('key-press-event', self.select_area_event_handler, self)
145-
drawingWindow.connect('motion-notify-event', self.select_area_event_handler, self)
119+
drawingWindow.connect(
120+
'button-press-event', self.select_area_event_handler, self
121+
)
122+
drawingWindow.connect(
123+
'button-release-event', self.select_area_event_handler, self
124+
)
125+
drawingWindow.connect(
126+
'key-press-event', self.select_area_event_handler, self
127+
)
128+
drawingWindow.connect(
129+
'motion-notify-event', self.select_area_event_handler, self
130+
)
146131

147132
def initial_draw(self, widget, cr):
148133
cr.set_source_rgba(0, 0, 0, 0.5)
@@ -157,11 +142,18 @@ def select_area_event_handler(self, widget, event, selector):
157142
selector.start_selection(event.x, event.y)
158143
elif event.type == Gdk.EventType.BUTTON_RELEASE and event.button == 1:
159144
selector.stop_selection(event.x, event.y)
160-
selector.set_complete_handler(self.take_screen_of_area_complete_handler)
145+
selector.set_complete_handler(
146+
self.take_screen_of_area_complete_handler
147+
)
161148
selector.__del__()
162149
del selector
163-
elif (event.type == Gdk.EventType.BUTTON_PRESS and event.button == 3) or (
164-
event.type == Gdk.EventType.KEY_PRESS and event.keyval == Gdk.keyval_from_name('Escape')):
150+
elif (
151+
(event.type == Gdk.EventType.BUTTON_PRESS and event.button == 3)
152+
or (
153+
event.type == Gdk.EventType.KEY_PRESS
154+
and event.keyval == Gdk.keyval_from_name('Escape')
155+
)
156+
):
165157
selector.__del__()
166158
del selector
167159

@@ -197,17 +189,23 @@ def response(dialog, resp_id):
197189
preview_dialog.set_decorated(False)
198190
preview_dialog.set_resizable(False)
199191
# Scale image for preview
200-
preview_image_width = float(image.get_width())
201-
preview_image_height = float(image.get_height())
202-
MAX_PREVIEW_WIDTH = 800
203-
MAX_PREVIEW_HEIGHT = 600
204-
if preview_image_width / preview_image_height > MAX_PREVIEW_WIDTH / MAX_PREVIEW_HEIGHT:
205-
preview_image_height = int(round((MAX_PREVIEW_WIDTH / preview_image_width) * preview_image_height))
206-
preview_image_width = MAX_PREVIEW_WIDTH
192+
preview_width = float(image.get_width())
193+
preview_height = float(image.get_height())
194+
if preview_width / preview_height > (
195+
MAX_PREVIEW_WIDTH / MAX_PREVIEW_HEIGHT
196+
):
197+
preview_height = int(
198+
round((MAX_PREVIEW_WIDTH / preview_width) * preview_height)
199+
)
200+
preview_width = MAX_PREVIEW_WIDTH
207201
else:
208-
preview_image_width = int(round((MAX_PREVIEW_HEIGHT / preview_image_height) * preview_image_width))
209-
preview_image_height = MAX_PREVIEW_HEIGHT
210-
preview_image = image.scale_simple(preview_image_width, preview_image_height, GdkPixbuf.InterpType.BILINEAR)
202+
preview_width = int(
203+
round((MAX_PREVIEW_HEIGHT / preview_height) * preview_width)
204+
)
205+
preview_height = MAX_PREVIEW_HEIGHT
206+
preview_image = image.scale_simple(
207+
preview_width, preview_height, GdkPixbuf.InterpType.BILINEAR
208+
)
211209
widget_image = Gtk.Image.new_from_pixbuf(preview_image)
212210
widget_image.show()
213211
preview_dialog.vbox.add(widget_image)
@@ -220,16 +218,23 @@ def __del__(self):
220218
return True
221219
ctx = self.drawingWindow.get_window().cairo_create()
222220
self.clear(ctx)
223-
# Give cairo some time to clear the screen before the destruction of the window
221+
# Give cairo some time to clear the screen before the destruction of
222+
# the window
224223
GObject.timeout_add(50, self.drawingWindow.destroy)
225224
if self.selected and hasattr(self, 'complete_handler'):
226225
x = int(round(min(self.selection_x_start, self.selection_x_end)))
227226
y = int(round(min(self.selection_y_start, self.selection_y_end)))
228-
width = int(round(abs(self.selection_x_end - self.selection_x_start)))
229-
height = int(round(abs(self.selection_y_end - self.selection_y_start)))
227+
width = int(
228+
round(abs(self.selection_x_end - self.selection_x_start))
229+
)
230+
height = int(
231+
round(abs(self.selection_y_end - self.selection_y_start))
232+
)
230233
# Do not take screen shot if grabbed area is too small
231234
if width > 10 and height > 10:
232-
GObject.timeout_add(150, self.complete_handler, x, y, width, height)
235+
GObject.timeout_add(
236+
150, self.complete_handler, x, y, width, height
237+
)
233238
else:
234239
self.log.debug('ScreenGrabber: selected area is too small')
235240
self.deleted = True

0 commit comments

Comments
 (0)