Skip to content

Commit

Permalink
.tools files refatoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Heitor-Tasso committed Mar 1, 2022
1 parent 914a774 commit 723b851
Show file tree
Hide file tree
Showing 20 changed files with 737 additions and 659 deletions.
2 changes: 1 addition & 1 deletion designer/components/dialogs/new_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from os.path import join
from kivy.uix.scrollview import ScrollView

from utils import constants
from utils.utils import constants
from utils.utils import get_kd_data_dir
from kivy.factory import Factory
from kivy.properties import ObjectProperty
Expand Down
2 changes: 1 addition & 1 deletion designer/core/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

from uix.confirmation_dialog import ConfirmationDialog
from utils import constants
from utils.utils import constants
from utils.utils import (
get_current_project,
get_fs_encoding,
Expand Down
2 changes: 1 addition & 1 deletion designer/core/profile_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shutil

from uix.confirmation_dialog import ConfirmationDialog
from utils import constants
from utils.utils import constants
from utils.utils import get_config_dir, get_kd_data_dir
from kivy.config import ConfigParser
from kivy.properties import DictProperty, ObjectProperty
Expand Down
3 changes: 1 addition & 2 deletions designer/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import sys
from distutils.spawn import find_executable

from utils.utils import get_config_dir, get_kd_data_dir, get_kd_dir, constants
from uix.settings import SettingList, SettingShortcut
from utils import constants
from utils.utils import get_config_dir, get_kd_data_dir, get_kd_dir
from kivy.config import ConfigParser
from kivy.properties import ObjectProperty
from kivy.uix.settings import Settings
Expand Down
2 changes: 0 additions & 2 deletions designer/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from screens.inicial.main_inicial import ToolBarTopDesigner

from uix.sandbox import DesignerSandbox
from designer import DesignerException, Designer
from utils.toolbox_widgets import toolbox_widgets
Expand Down
8 changes: 4 additions & 4 deletions designer/screens/inicial/main_inicial.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.lang.builder import Builder
from utils import constants
from utils.utils import constants
from utils.utils import (
ignore_proj_watcher, get_kd_data_dir,
show_message, get_kd_dir,
show_message, get_kd_dir, get_path,
utils_source_rst,
)
from tempfile import mkdtemp
from util import get_path
from distutils.dir_util import copy_tree
from kivy.clock import Clock
from kivy.metrics import dp
Expand Down Expand Up @@ -66,7 +66,7 @@ def show_help(self, *args):
return False
if self.designer.help_dlg is None:
self.designer.help_dlg = HelpDialog()
self.designer.help_dlg.rst.source = os.path.join(get_kd_dir(), 'help.rst')
self.designer.help_dlg.rst.source = utils_source_rst('help')

self.popup = Popup(
title='Kivy Designer Help', content=self.designer.help_dlg,
Expand Down
95 changes: 50 additions & 45 deletions designer/tools/bug_reporter.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import os
import sys
import webbrowser
__all__ = ['ReportWarning', 'BugReporter', 'BugReporterApp']

from six.moves import urllib
from kivy.app import App
from kivy.core.clipboard import Clipboard
from kivy.lang import Builder
from kivy.properties import ObjectProperty, StringProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.popup import Popup

import os, sys, platform
from textwrap import dedent
import webbrowser
import urllib

try: # for pip >= 10
from pip._internal.req import parse_requirements
from pip._internal.network.download import PipSession
except ImportError: # for pip <= 9.0.3
from pip.req import parse_requirements
from pip.download import PipSession

Builder.load_string('''
<BugReporter>:
txt_traceback: txt_traceback
Image:
Expand Down Expand Up @@ -94,13 +103,11 @@ class ReportWarning(Popup):
text = StringProperty('')
'''Warning Message
'''

__events__ = ('on_release',)

def on_release(self, *args):
pass


class BugReporter(FloatLayout):
txt_traceback = ObjectProperty(None)
'''TextView to show the traceback message
Expand Down Expand Up @@ -129,7 +136,7 @@ def on_report(self, *args):
self.warning = warning

def _do_report(self, *args):
txt = six.moves.urllib.parse.quote(
txt = urllib.parse.quote(
self.txt_traceback.text.encode('utf-8'))
url = 'https://github.com/kivy/kivy-designer/issues/new?body=' + txt
webbrowser.open(url)
Expand All @@ -149,52 +156,50 @@ def __init__(self, **kw):
super(BugReporterApp, self).__init__(**kw)

def build(self):
rep = BugReporter()
template = '''
## Environment Info
%s
## Traceback
```
%s
```
End of Traceback
'''
env_info = 'Pip is not installed'
try:
from pip.req import parse_requirements
from pip.download import PipSession
import platform

requirements = parse_requirements(os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'..',
'..',
'requirements.txt'),
session=PipSession()
)
env_info = ''
for req in requirements:
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'requirements.txt')
requirements = parse_requirements(path, session=PipSession())
env_info = '\n'
space = ' ' * 16

for req in requirements:
try:
version = req.installed_version
if version is None:
version = 'Not installed'
env_info += req.name + ': ' + version + '\n'
env_info += '\nPlatform: ' + platform.platform()
env_info += '\nPython: ' + platform.python_version()

except ImportError:
pass
except AttributeError:
version = req.requirement

if version is None:
version = 'Not installed'

try:
env_info += f'{space}{req.name}: {version}\n'
except AttributeError:
env_info += f'{space}{version}\n'

env_info += f'\n{space}Platform: {platform.platform()}'
env_info += f'\n{space}Python: {platform.python_version()}'

if isinstance(self.traceback, bytes):
encoding = sys.getfilesystemencoding()
if not encoding:
encoding = sys.stdin.encoding
if encoding:
self.traceback = self.traceback.decode(encoding)
rep.txt_traceback.text = template % (env_info, self.traceback)

template = dedent(f'''
## Environment Info
{env_info}
## Traceback
```
{self.traceback}
```
End of Traceback
''')

rep = BugReporter()
rep.txt_traceback.text = template
return rep


Expand Down
Loading

0 comments on commit 723b851

Please sign in to comment.